examples/SysLibs/ECom/InterfaceDefinition/ExampleResolver.cpp

00001 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 
00017 #include <ecom.h>
00018 #include <ecomerrorcodes.h>
00019 #include <ecomresolverparams.h>
00020 #include <implementationinformation.h>
00021 #include <publicregistry.h>
00022 
00023 #include "ExampleResolver.h"
00024 
00025 CExampleResolver* CExampleResolver::NewL(MPublicRegistry& aRegistry)
00026         {
00027         return new(ELeave) CExampleResolver(aRegistry);
00028         }
00029 
00030 CExampleResolver::~CExampleResolver()
00031         {
00032         if(iImplementationInfoArray)
00033                 {
00034                 iImplementationInfoArray->Reset();
00035                 delete iImplementationInfoArray;
00036                 }
00037         }
00038 
00039 CExampleResolver::CExampleResolver(MPublicRegistry& aRegistry)
00040 : CResolver(aRegistry)
00041         {
00042         // Do nothing here
00043         }
00044 
00045 TUid CExampleResolver::IdentifyImplementationL(TUid aInterfaceUid, 
00046         const TEComResolverParams& aAdditionalParameters) const
00047         {
00048         RImplInfoArray& implementationsInfo = iRegistry.ListImplementationsL(aInterfaceUid);
00049         TUid found = KNullUid;
00050         if(implementationsInfo.Count())
00051                 {
00052                 found = Resolve(implementationsInfo, aAdditionalParameters);
00053                 }
00054         return found;
00055         }
00056 
00057 TUid CExampleResolver::Resolve(const RImplInfoArray& aImplementationsInfo, 
00058         const TEComResolverParams& aAdditionalParameters) const
00059         {
00060         // Loop through the implementations matching on type
00061         const TInt count = aImplementationsInfo.Count();
00062         for(TInt index = 0; index < count; ++index)
00063                 {
00064                 const CImplementationInformation& impData = *aImplementationsInfo[index];
00065                 // As soon as we get a match on the datatype then return uid of the 
00066                 // implementation found.
00067                 if (Match(impData.DataType(),                                           // The Datatype of this implementation
00068                                   aAdditionalParameters.DataType(),                     // The type we are trying to find
00069                                   aAdditionalParameters.IsWildcardMatch()))     // If wildcards should be used
00070                         return impData.ImplementationUid();
00071                 }
00072 
00073         return KNullUid;
00074         }
00075 
00076 RImplInfoArray* CExampleResolver::ListAllL(TUid aInterfaceUid, 
00077         const TEComResolverParams& aAdditionalParameters) const
00078         {
00079         // Use the member var to create the array so that we get proper cleanup behaviour
00080         iImplementationInfoArray = new(ELeave) RImplInfoArray;
00081         RImplInfoArray* retList = iImplementationInfoArray;
00082 
00083         RImplInfoArray& fullList = iRegistry.ListImplementationsL(aInterfaceUid);
00084 
00085         const TBool useWildcards = aAdditionalParameters.IsWildcardMatch();
00086         const TDesC8& matchType = aAdditionalParameters.DataType();
00087         const TInt numImps = fullList.Count();
00088         for(TInt index = 0; index < numImps; ++index)
00089                 {
00090                 if(Match(fullList[index]->DataType(), matchType, useWildcards))
00091                         {
00092                         User::LeaveIfError(retList->Append(fullList[index]));
00093                         }
00094                 }
00095 
00096         // Reset the member variable because we are passing ownership back
00097         iImplementationInfoArray = NULL;
00098         return retList;
00099         }
00100 
00101 TBool CExampleResolver::Match(const TDesC8& aImplementationType, 
00102         const TDesC8& aMatchType, 
00103         TBool aUseWildcards) const
00104         {
00105         TInt matchPos = KErrNotFound;
00106 
00107         _LIT8(dataSeparator, "||");
00108         const TInt separatorLength = dataSeparator().Length();
00109 
00110         // Look for the section separator marker '||'
00111         TInt separatorPos = aImplementationType.Find(dataSeparator);
00112         if(separatorPos == KErrNotFound)
00113                 {
00114                 // Match against the whole string
00115                 if(aUseWildcards)
00116                         matchPos = aImplementationType.Match(aMatchType);
00117                 else
00118                         matchPos = aImplementationType.Compare(aMatchType);
00119                 }
00120         else
00121                 {
00122                 // Find the first section, up to the separator
00123                 TPtrC8 dataSection = aImplementationType.Left(separatorPos);
00124                 TPtrC8 remainingData = aImplementationType.Mid(separatorPos + separatorLength);
00125                 // Match against each section in turn
00126                 while(separatorPos != KErrNotFound)
00127                         {
00128                         // Search this section
00129                         if(aUseWildcards)
00130                                 matchPos = dataSection.Match(aMatchType);
00131                         else
00132                                 matchPos = dataSection.Compare(aMatchType);
00133 
00134                         // If we found it then no need to continue, so return
00135                         if(matchPos != KErrNotFound)
00136                                 return ETrue;
00137 
00138                         // Move on to the next section
00139                         separatorPos = remainingData.Find(dataSeparator);
00140                         if(separatorPos != KErrNotFound)
00141                                 {
00142                                 dataSection.Set(remainingData.Left(separatorPos));
00143                                 remainingData.Set(remainingData.Mid(separatorPos + separatorLength));
00144                                 }
00145                         else
00146                                 dataSection.Set(remainingData);
00147                         }
00148 
00149                 // Check the final part
00150                 if(aUseWildcards)
00151                         matchPos = dataSection.Match(aMatchType);
00152                 else
00153                         matchPos = dataSection.Compare(aMatchType);
00154 
00155                 }
00156         return matchPos != KErrNotFound;
00157         }

Generated by  doxygen 1.6.2