os/ossrv/lowlevellibsandfws/pluginfw/TestExecute/EComPerfTest/src/EComClientRequestPerfTestResolver.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Implements a custom resolver CClientRequestPerfTestResolver for use during resolver performance tests.
    15 // 
    16 //
    17 
    18 /**
    19  @internalComponent
    20 */
    21 
    22 #include <ecom/ecom.h>
    23 #include "ImplementationProxy.h"
    24 #include "EComClientRequestPerfTestResolver.h"
    25 
    26 CClientRequestPerfTestResolver* CClientRequestPerfTestResolver::NewL(MPublicRegistry& aRegistry)
    27 	{
    28 	return new(ELeave) CClientRequestPerfTestResolver(aRegistry);
    29 	}
    30 
    31 CClientRequestPerfTestResolver::~CClientRequestPerfTestResolver()
    32 	{
    33 	if(iImplementationInfoArray)
    34 		{
    35 		iImplementationInfoArray->Reset();
    36 		delete iImplementationInfoArray;
    37 		}
    38 	}
    39 
    40 CClientRequestPerfTestResolver::CClientRequestPerfTestResolver(MPublicRegistry& aRegistry)
    41 : CResolver(aRegistry)
    42 	{
    43 	// Do nothing here
    44 	}
    45 
    46 TUid CClientRequestPerfTestResolver::IdentifyImplementationL(TUid aInterfaceUid, 
    47 											   const TEComResolverParams& aAdditionalParameters) const
    48 	{
    49 	RImplInfoArray& implementationsInfo = iRegistry.ListImplementationsL(aInterfaceUid);
    50 	TUid found = KNullUid;
    51 	if(implementationsInfo.Count())
    52 		{
    53 		found = Resolve(implementationsInfo, aAdditionalParameters);
    54 		}
    55 	return found;
    56 	}
    57 
    58 TUid CClientRequestPerfTestResolver::Resolve(const RImplInfoArray& aImplementationsInfo, 
    59 							   const TEComResolverParams& aAdditionalParameters) const
    60 	{
    61 	// Loop through the implementations matching on type
    62 	const TInt count = aImplementationsInfo.Count();
    63 	for(TInt index = 0; index < count; ++index)
    64 		{
    65 		const CImplementationInformation& impData = *aImplementationsInfo[index];
    66 		// As soon as we get a match on the datatype then return uid of the 
    67 		// implementation found.
    68 		if (Match(impData.DataType(),						// The Datatype of this implementation
    69 				  aAdditionalParameters.DataType(),			// The type we are trying to find
    70 				  aAdditionalParameters.IsGenericMatch()))	// If wildcards should be used
    71 			return impData.ImplementationUid();
    72 		}
    73 
    74 	return KNullUid;
    75 	}
    76 
    77 RImplInfoArray* CClientRequestPerfTestResolver::ListAllL(TUid aInterfaceUid, 
    78 										   const TEComResolverParams& aAdditionalParameters) const
    79 	{
    80 	// Use the member var to create the array so that we get proper cleanup behaviour
    81 	iImplementationInfoArray = new(ELeave) RImplInfoArray;
    82 	RImplInfoArray* retList = iImplementationInfoArray;
    83 
    84 	RImplInfoArray& fullList = iRegistry.ListImplementationsL(aInterfaceUid);
    85 
    86 	const TBool useWildcards = aAdditionalParameters.IsGenericMatch();
    87 	const TDesC8& matchType = aAdditionalParameters.DataType();
    88 	const TInt numImps = fullList.Count();
    89 	for(TInt index = 0; index < numImps; ++index)
    90 		{
    91 		if(Match(fullList[index]->DataType(), matchType, useWildcards))
    92 			{
    93 			User::LeaveIfError(retList->Append(fullList[index]));
    94 			}
    95 		}
    96 
    97 	// Reset the member variable because we are passing ownership back
    98 	iImplementationInfoArray = NULL;
    99 	return retList;
   100 	}
   101 
   102 TBool CClientRequestPerfTestResolver::Match(const TDesC8& aImplementationType, 
   103 							  const TDesC8& aMatchType, 
   104 							  TBool aUseWildcards) const
   105 	{
   106 	TInt matchPos = KErrNotFound;
   107 
   108 	_LIT8(dataSeparator, "||");
   109 	const TInt separatorLength = dataSeparator().Length();
   110 
   111 	// Look for the section separator marker '||'
   112 	TInt separatorPos = aImplementationType.Find(dataSeparator);
   113 	if(separatorPos == KErrNotFound)
   114 		{
   115 		// Match against the whole string
   116 		if(aUseWildcards)
   117 			matchPos = aMatchType.Match(aImplementationType);
   118 		else
   119 			matchPos = aMatchType.Compare(aImplementationType);
   120 		}
   121 	else
   122 		{
   123 		// Find the first section, up to the separator
   124 		TPtrC8 dataSection = aImplementationType.Left(separatorPos);
   125 		TPtrC8 remainingData = aImplementationType.Mid(separatorPos + separatorLength);
   126 		// Match against each section in turn
   127 		while(separatorPos != KErrNotFound)
   128 			{
   129 			// Search this section
   130 			if(aUseWildcards)
   131 				matchPos = aMatchType.Match(dataSection);
   132 			else
   133 				matchPos = aMatchType.Compare(dataSection);
   134 
   135 			// If we found it then no need to continue, so return
   136 			if(matchPos != KErrNotFound)
   137 				return ETrue;
   138 
   139 			// Move on to the next section
   140 			separatorPos = remainingData.Find(dataSeparator);
   141 			if(separatorPos != KErrNotFound)
   142 				{
   143 				dataSection.Set(remainingData.Left(separatorPos));
   144 				remainingData.Set(remainingData.Mid(separatorPos + separatorLength));
   145 				}
   146 			else
   147 				dataSection.Set(remainingData);
   148 			}
   149 
   150 		// Check the final part
   151 		if(aUseWildcards)
   152 			matchPos = aMatchType.Match(dataSection);
   153 		else
   154 			matchPos = aMatchType.Compare(dataSection);
   155 
   156 		}
   157 	return matchPos != KErrNotFound;
   158 	}
   159 
   160 // __________________________________________________________________________
   161 // Exported proxy for instantiation method resolution
   162 // Define the interface UIDs
   163 const TImplementationProxy ImplementationTable[] = 
   164 	{
   165 		IMPLEMENTATION_PROXY_ENTRY(0x10009DF8,	CClientRequestPerfTestResolver::NewL)
   166 	};
   167 
   168 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   169 	{
   170 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
   171 	return ImplementationTable;
   172 	}
   173