examples/SysLibs/ECom/InterfaceDefinition/ExampleResolver.cpp

00001 /*
00002 Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 
00032 #include <ecom.h>
00033 #include <ecomerrorcodes.h>
00034 #include <ecomresolverparams.h>
00035 #include <implementationinformation.h>
00036 #include <publicregistry.h>
00037 
00038 #include "ExampleResolver.h"
00039 
00040 CExampleResolver* CExampleResolver::NewL(MPublicRegistry& aRegistry)
00041         {
00042         return new(ELeave) CExampleResolver(aRegistry);
00043         }
00044 
00045 CExampleResolver::~CExampleResolver()
00046         {
00047         if(iImplementationInfoArray)
00048                 {
00049                 iImplementationInfoArray->Reset();
00050                 delete iImplementationInfoArray;
00051                 }
00052         }
00053 
00054 CExampleResolver::CExampleResolver(MPublicRegistry& aRegistry)
00055 : CResolver(aRegistry)
00056         {
00057         // Do nothing here
00058         }
00059 
00060 TUid CExampleResolver::IdentifyImplementationL(TUid aInterfaceUid, 
00061         const TEComResolverParams& aAdditionalParameters) const
00062         {
00063         RImplInfoArray& implementationsInfo = iRegistry.ListImplementationsL(aInterfaceUid);
00064         TUid found = KNullUid;
00065         if(implementationsInfo.Count())
00066                 {
00067                 found = Resolve(implementationsInfo, aAdditionalParameters);
00068                 }
00069         return found;
00070         }
00071 
00072 TUid CExampleResolver::Resolve(const RImplInfoArray& aImplementationsInfo, 
00073         const TEComResolverParams& aAdditionalParameters) const
00074         {
00075         // Loop through the implementations matching on type
00076         const TInt count = aImplementationsInfo.Count();
00077         for(TInt index = 0; index < count; ++index)
00078                 {
00079                 const CImplementationInformation& impData = *aImplementationsInfo[index];
00080                 // As soon as we get a match on the datatype then return uid of the 
00081                 // implementation found.
00082                 if (Match(impData.DataType(),                                           // The Datatype of this implementation
00083                                   aAdditionalParameters.DataType(),                     // The type we are trying to find
00084                                   aAdditionalParameters.IsWildcardMatch()))     // If wildcards should be used
00085                         return impData.ImplementationUid();
00086                 }
00087 
00088         return KNullUid;
00089         }
00090 
00091 RImplInfoArray* CExampleResolver::ListAllL(TUid aInterfaceUid, 
00092         const TEComResolverParams& aAdditionalParameters) const
00093         {
00094         // Use the member var to create the array so that we get proper cleanup behaviour
00095         iImplementationInfoArray = new(ELeave) RImplInfoArray;
00096         RImplInfoArray* retList = iImplementationInfoArray;
00097 
00098         RImplInfoArray& fullList = iRegistry.ListImplementationsL(aInterfaceUid);
00099 
00100         const TBool useWildcards = aAdditionalParameters.IsWildcardMatch();
00101         const TDesC8& matchType = aAdditionalParameters.DataType();
00102         const TInt numImps = fullList.Count();
00103         for(TInt index = 0; index < numImps; ++index)
00104                 {
00105                 if(Match(fullList[index]->DataType(), matchType, useWildcards))
00106                         {
00107                         User::LeaveIfError(retList->Append(fullList[index]));
00108                         }
00109                 }
00110 
00111         // Reset the member variable because we are passing ownership back
00112         iImplementationInfoArray = NULL;
00113         return retList;
00114         }
00115 
00116 TBool CExampleResolver::Match(const TDesC8& aImplementationType, 
00117         const TDesC8& aMatchType, 
00118         TBool aUseWildcards) const
00119         {
00120         TInt matchPos = KErrNotFound;
00121 
00122         _LIT8(dataSeparator, "||");
00123         const TInt separatorLength = dataSeparator().Length();
00124 
00125         // Look for the section separator marker '||'
00126         TInt separatorPos = aImplementationType.Find(dataSeparator);
00127         if(separatorPos == KErrNotFound)
00128                 {
00129                 // Match against the whole string
00130                 if(aUseWildcards)
00131                         matchPos = aImplementationType.Match(aMatchType);
00132                 else
00133                         matchPos = aImplementationType.Compare(aMatchType);
00134                 }
00135         else
00136                 {
00137                 // Find the first section, up to the separator
00138                 TPtrC8 dataSection = aImplementationType.Left(separatorPos);
00139                 TPtrC8 remainingData = aImplementationType.Mid(separatorPos + separatorLength);
00140                 // Match against each section in turn
00141                 while(separatorPos != KErrNotFound)
00142                         {
00143                         // Search this section
00144                         if(aUseWildcards)
00145                                 matchPos = dataSection.Match(aMatchType);
00146                         else
00147                                 matchPos = dataSection.Compare(aMatchType);
00148 
00149                         // If we found it then no need to continue, so return
00150                         if(matchPos != KErrNotFound)
00151                                 return ETrue;
00152 
00153                         // Move on to the next section
00154                         separatorPos = remainingData.Find(dataSeparator);
00155                         if(separatorPos != KErrNotFound)
00156                                 {
00157                                 dataSection.Set(remainingData.Left(separatorPos));
00158                                 remainingData.Set(remainingData.Mid(separatorPos + separatorLength));
00159                                 }
00160                         else
00161                                 dataSection.Set(remainingData);
00162                         }
00163 
00164                 // Check the final part
00165                 if(aUseWildcards)
00166                         matchPos = dataSection.Match(aMatchType);
00167                 else
00168                         matchPos = dataSection.Compare(aMatchType);
00169 
00170                 }
00171         return matchPos != KErrNotFound;
00172         }

Generated by  doxygen 1.6.2