1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/Example/ExampleResolver.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,166 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Implements a non-default resolver CExampleResolver.
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @internalComponent
1.23 +*/
1.24 +
1.25 +#include <ecom/ecom.h>
1.26 +
1.27 +#include "ExampleResolver.h"
1.28 +#include "RegistryData.h"
1.29 +
1.30 +CExampleResolver* CExampleResolver::NewL(MPublicRegistry& aRegistry)
1.31 + {
1.32 + return new(ELeave) CExampleResolver(aRegistry);
1.33 + }
1.34 +
1.35 +CExampleResolver::~CExampleResolver()
1.36 + {
1.37 + if(iImplementationInfoArray)
1.38 + {
1.39 + iImplementationInfoArray->Reset();
1.40 + delete iImplementationInfoArray;
1.41 + }
1.42 + }
1.43 +
1.44 +CExampleResolver::CExampleResolver(MPublicRegistry& aRegistry)
1.45 +: CResolver(aRegistry)
1.46 + {
1.47 + // Do nothing here
1.48 + }
1.49 +
1.50 +TUid CExampleResolver::IdentifyImplementationL(TUid aInterfaceUid,
1.51 + const TEComResolverParams& aAdditionalParameters) const
1.52 + {
1.53 + RImplInfoArray& implementationsInfo = iRegistry.ListImplementationsL(aInterfaceUid);
1.54 + TUid found = KNullUid;
1.55 + if(implementationsInfo.Count())
1.56 + {
1.57 + found = Resolve(implementationsInfo, aAdditionalParameters);
1.58 + }
1.59 + return found;
1.60 + }
1.61 +
1.62 +TUid CExampleResolver::Resolve(const RImplInfoArray& aImplementationsInfo,
1.63 + const TEComResolverParams& aAdditionalParameters) const
1.64 + {
1.65 + // Loop through the implementations matching on type
1.66 + const TInt count = aImplementationsInfo.Count();
1.67 + for(TInt index = 0; index < count; ++index)
1.68 + {
1.69 + const CImplementationInformation& impData = *aImplementationsInfo[index];
1.70 + // As soon as we get a match on the datatype then return uid of the
1.71 + // implementation found.
1.72 + if (Match(impData.DataType(), // The Datatype of this implementation
1.73 + aAdditionalParameters.DataType(), // The type we are trying to find
1.74 + aAdditionalParameters.IsGenericMatch())) // If wildcards should be used
1.75 + return impData.ImplementationUid();
1.76 + }
1.77 +
1.78 + return KNullUid;
1.79 + }
1.80 +
1.81 +RImplInfoArray* CExampleResolver::ListAllL(TUid aInterfaceUid,
1.82 + const TEComResolverParams& aAdditionalParameters) const
1.83 + {
1.84 + //Simulation for INC054125 - ECOM cleanup stack error
1.85 + _LIT8(KCriteriaData, "INC054125");
1.86 + const TDesC8& dataType = aAdditionalParameters.DataType();
1.87 + if(aInterfaceUid.iUid == 0x10009DC8 && dataType.Compare(KCriteriaData) == 0)
1.88 + {
1.89 + User::Leave(KErrGeneral);
1.90 + }
1.91 + // Use the member var to create the array so that we get proper cleanup behaviour
1.92 + iImplementationInfoArray = new(ELeave) RImplInfoArray;
1.93 + RImplInfoArray* retList = iImplementationInfoArray;
1.94 +
1.95 + RImplInfoArray& fullList = iRegistry.ListImplementationsL(aInterfaceUid);
1.96 +
1.97 + const TBool useWildcards = aAdditionalParameters.IsGenericMatch();
1.98 + const TDesC8& matchType = aAdditionalParameters.DataType();
1.99 + const TInt numImps = fullList.Count();
1.100 + for(TInt index = 0; index < numImps; ++index)
1.101 + {
1.102 + if(Match(fullList[index]->DataType(), matchType, useWildcards))
1.103 + {
1.104 + User::LeaveIfError(retList->Append(fullList[index]));
1.105 + }
1.106 + }
1.107 +
1.108 + // Reset the member variable because we are passing ownership back
1.109 + iImplementationInfoArray = NULL;
1.110 + return retList;
1.111 + }
1.112 +
1.113 +TBool CExampleResolver::Match(const TDesC8& aImplementationType,
1.114 + const TDesC8& aMatchType,
1.115 + TBool aUseWildcards) const
1.116 + {
1.117 + TInt matchPos = KErrNotFound;
1.118 +
1.119 + _LIT8(dataSeparator, "||");
1.120 + const TInt separatorLength = dataSeparator().Length();
1.121 +
1.122 + // Look for the section separator marker '||'
1.123 + TInt separatorPos = aImplementationType.Find(dataSeparator);
1.124 + if(separatorPos == KErrNotFound)
1.125 + {
1.126 + // Match against the whole string
1.127 + if(aUseWildcards)
1.128 + matchPos = aMatchType.Match(aImplementationType);
1.129 + else
1.130 + matchPos = aMatchType.Compare(aImplementationType);
1.131 + }
1.132 + else
1.133 + {
1.134 + // Find the first section, up to the separator
1.135 + TPtrC8 dataSection = aImplementationType.Left(separatorPos);
1.136 + TPtrC8 remainingData = aImplementationType.Mid(separatorPos + separatorLength);
1.137 + // Match against each section in turn
1.138 + while(separatorPos != KErrNotFound)
1.139 + {
1.140 + // Search this section
1.141 + if(aUseWildcards)
1.142 + matchPos = aMatchType.Match(dataSection);
1.143 + else
1.144 + matchPos = aMatchType.Compare(dataSection);
1.145 +
1.146 + // If we found it then no need to continue, so return
1.147 + if(matchPos != KErrNotFound)
1.148 + return ETrue;
1.149 +
1.150 + // Move on to the next section
1.151 + separatorPos = remainingData.Find(dataSeparator);
1.152 + if(separatorPos != KErrNotFound)
1.153 + {
1.154 + dataSection.Set(remainingData.Left(separatorPos));
1.155 + remainingData.Set(remainingData.Mid(separatorPos + separatorLength));
1.156 + }
1.157 + else
1.158 + dataSection.Set(remainingData);
1.159 + }
1.160 +
1.161 + // Check the final part
1.162 + if(aUseWildcards)
1.163 + matchPos = aMatchType.Match(dataSection);
1.164 + else
1.165 + matchPos = aMatchType.Compare(dataSection);
1.166 +
1.167 + }
1.168 + return matchPos != KErrNotFound;
1.169 + }