os/ossrv/syslibsapitest/syslibssvs/ecom/TestPlugin/Src/TestEComResolver.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/syslibsapitest/syslibssvs/ecom/TestPlugin/Src/TestEComResolver.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,133 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +#include "TestEComResolver.h"
    1.24 +
    1.25 +CTestEComResolver* CTestEComResolver::NewL(MPublicRegistry& aRegistry)
    1.26 +	{
    1.27 +	return new(ELeave) CTestEComResolver(aRegistry);
    1.28 +	}
    1.29 +
    1.30 +CTestEComResolver::~CTestEComResolver()
    1.31 +	{
    1.32 +	if(iImplementationInfoArray)
    1.33 +		{
    1.34 +		iImplementationInfoArray->Reset();
    1.35 +		delete iImplementationInfoArray;
    1.36 +		}
    1.37 +	}
    1.38 +
    1.39 +CTestEComResolver::CTestEComResolver(MPublicRegistry& aRegistry)
    1.40 +:	CResolver(aRegistry)
    1.41 +	{
    1.42 +	// Do nothing here
    1.43 +	}
    1.44 +
    1.45 +TUid CTestEComResolver::IdentifyImplementationL(
    1.46 +	TUid						aInterfaceUid,
    1.47 +	const TEComResolverParams&	aAdditionalParameters
    1.48 +) const
    1.49 +	{
    1.50 +	RImplInfoArray&	fullList = iRegistry.ListImplementationsL(aInterfaceUid);
    1.51 +
    1.52 +	// Loop through the implementations matching on type
    1.53 +	TUid			ret = KNullUid;
    1.54 +	const TDesC8&	matchType = aAdditionalParameters.DataType();
    1.55 +	const TBool		useWildcards = aAdditionalParameters.IsWildcardMatch();
    1.56 +	const TInt		count = fullList.Count();
    1.57 +	for(TInt index = 0; (index<count) && (ret==KNullUid); ++index)
    1.58 +		{
    1.59 +		CImplementationInformation*	impData = fullList[index];
    1.60 +		// As soon as we get a match on the datatype then return uid of the 
    1.61 +		// implementation found.
    1.62 +		if (Match(impData->DataType(), matchType, useWildcards))
    1.63 +			{
    1.64 +			ret=impData->ImplementationUid();
    1.65 +			}
    1.66 +		}
    1.67 +
    1.68 +	return ret;
    1.69 +	}
    1.70 +
    1.71 +RImplInfoArray* CTestEComResolver::ListAllL(
    1.72 +	TUid						aInterfaceUid,
    1.73 +	const TEComResolverParams&	aAdditionalParameters
    1.74 +) const
    1.75 +	{
    1.76 +	// Use the member var to create the array so that we get proper cleanup behaviour
    1.77 +	iImplementationInfoArray = new(ELeave) RImplInfoArray;
    1.78 +	RImplInfoArray*	retList = iImplementationInfoArray;
    1.79 +
    1.80 +	RImplInfoArray&	fullList = iRegistry.ListImplementationsL(aInterfaceUid);
    1.81 +
    1.82 +	const TDesC8&	matchType = aAdditionalParameters.DataType();
    1.83 +	const TBool		useWildcards = aAdditionalParameters.IsWildcardMatch();
    1.84 +	const TInt		numImps = fullList.Count();
    1.85 +	for(TInt index = 0; index < numImps; ++index)
    1.86 +		{
    1.87 +		CImplementationInformation*	impData = fullList[index];
    1.88 +		if(Match(impData->DataType(), matchType, useWildcards))
    1.89 +			{
    1.90 +			User::LeaveIfError(retList->Append(impData));
    1.91 +			}
    1.92 +		}
    1.93 +
    1.94 +	// Reset the member variable because we are passing ownership back
    1.95 +	iImplementationInfoArray = NULL;
    1.96 +	return retList;
    1.97 +	}
    1.98 +
    1.99 +TBool CTestEComResolver::Match(
   1.100 +	const TDesC8&	aImplementationType, 
   1.101 +	const TDesC8&	aMatchType, 
   1.102 +	TBool			aUseWildcards
   1.103 +) const
   1.104 +	{
   1.105 +	_LIT8(dataSeparator, "||");
   1.106 +	const TInt	separatorLength = dataSeparator().Length();
   1.107 +
   1.108 +	// Look for the section separator marker '||'
   1.109 +	TPtrC8	remainingData = aImplementationType;
   1.110 +	TInt	separatorPos = remainingData.Find(dataSeparator);
   1.111 +	TInt	matchPos=KErrNotFound;
   1.112 +	do 
   1.113 +		{
   1.114 +		TPtrC8	dataSection;
   1.115 +		if (separatorPos==KErrNotFound)
   1.116 +			{
   1.117 +			dataSection.Set(remainingData);
   1.118 +			}
   1.119 +		else
   1.120 +			{
   1.121 +			dataSection.Set(remainingData.Left(separatorPos));
   1.122 +			remainingData.Set(remainingData.Mid(separatorPos + separatorLength));
   1.123 +			}
   1.124 +		if(aUseWildcards)
   1.125 +			{
   1.126 +			matchPos=dataSection.Match(aMatchType);
   1.127 +			}
   1.128 +		else
   1.129 +			{
   1.130 +			matchPos=dataSection.Compare(aMatchType);
   1.131 +			}
   1.132 +		}
   1.133 +	while ((separatorPos!=KErrNotFound) && (matchPos==KErrNotFound));
   1.134 +
   1.135 +	return matchPos!=KErrNotFound;
   1.136 +	}