os/ossrv/syslibsapitest/syslibssvs/ecom/TestPlugin/Src/TestEComResolver.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 
    20 #include "TestEComResolver.h"
    21 
    22 CTestEComResolver* CTestEComResolver::NewL(MPublicRegistry& aRegistry)
    23 	{
    24 	return new(ELeave) CTestEComResolver(aRegistry);
    25 	}
    26 
    27 CTestEComResolver::~CTestEComResolver()
    28 	{
    29 	if(iImplementationInfoArray)
    30 		{
    31 		iImplementationInfoArray->Reset();
    32 		delete iImplementationInfoArray;
    33 		}
    34 	}
    35 
    36 CTestEComResolver::CTestEComResolver(MPublicRegistry& aRegistry)
    37 :	CResolver(aRegistry)
    38 	{
    39 	// Do nothing here
    40 	}
    41 
    42 TUid CTestEComResolver::IdentifyImplementationL(
    43 	TUid						aInterfaceUid,
    44 	const TEComResolverParams&	aAdditionalParameters
    45 ) const
    46 	{
    47 	RImplInfoArray&	fullList = iRegistry.ListImplementationsL(aInterfaceUid);
    48 
    49 	// Loop through the implementations matching on type
    50 	TUid			ret = KNullUid;
    51 	const TDesC8&	matchType = aAdditionalParameters.DataType();
    52 	const TBool		useWildcards = aAdditionalParameters.IsWildcardMatch();
    53 	const TInt		count = fullList.Count();
    54 	for(TInt index = 0; (index<count) && (ret==KNullUid); ++index)
    55 		{
    56 		CImplementationInformation*	impData = fullList[index];
    57 		// As soon as we get a match on the datatype then return uid of the 
    58 		// implementation found.
    59 		if (Match(impData->DataType(), matchType, useWildcards))
    60 			{
    61 			ret=impData->ImplementationUid();
    62 			}
    63 		}
    64 
    65 	return ret;
    66 	}
    67 
    68 RImplInfoArray* CTestEComResolver::ListAllL(
    69 	TUid						aInterfaceUid,
    70 	const TEComResolverParams&	aAdditionalParameters
    71 ) const
    72 	{
    73 	// Use the member var to create the array so that we get proper cleanup behaviour
    74 	iImplementationInfoArray = new(ELeave) RImplInfoArray;
    75 	RImplInfoArray*	retList = iImplementationInfoArray;
    76 
    77 	RImplInfoArray&	fullList = iRegistry.ListImplementationsL(aInterfaceUid);
    78 
    79 	const TDesC8&	matchType = aAdditionalParameters.DataType();
    80 	const TBool		useWildcards = aAdditionalParameters.IsWildcardMatch();
    81 	const TInt		numImps = fullList.Count();
    82 	for(TInt index = 0; index < numImps; ++index)
    83 		{
    84 		CImplementationInformation*	impData = fullList[index];
    85 		if(Match(impData->DataType(), matchType, useWildcards))
    86 			{
    87 			User::LeaveIfError(retList->Append(impData));
    88 			}
    89 		}
    90 
    91 	// Reset the member variable because we are passing ownership back
    92 	iImplementationInfoArray = NULL;
    93 	return retList;
    94 	}
    95 
    96 TBool CTestEComResolver::Match(
    97 	const TDesC8&	aImplementationType, 
    98 	const TDesC8&	aMatchType, 
    99 	TBool			aUseWildcards
   100 ) const
   101 	{
   102 	_LIT8(dataSeparator, "||");
   103 	const TInt	separatorLength = dataSeparator().Length();
   104 
   105 	// Look for the section separator marker '||'
   106 	TPtrC8	remainingData = aImplementationType;
   107 	TInt	separatorPos = remainingData.Find(dataSeparator);
   108 	TInt	matchPos=KErrNotFound;
   109 	do 
   110 		{
   111 		TPtrC8	dataSection;
   112 		if (separatorPos==KErrNotFound)
   113 			{
   114 			dataSection.Set(remainingData);
   115 			}
   116 		else
   117 			{
   118 			dataSection.Set(remainingData.Left(separatorPos));
   119 			remainingData.Set(remainingData.Mid(separatorPos + separatorLength));
   120 			}
   121 		if(aUseWildcards)
   122 			{
   123 			matchPos=dataSection.Match(aMatchType);
   124 			}
   125 		else
   126 			{
   127 			matchPos=dataSection.Compare(aMatchType);
   128 			}
   129 		}
   130 	while ((separatorPos!=KErrNotFound) && (matchPos==KErrNotFound));
   131 
   132 	return matchPos!=KErrNotFound;
   133 	}