|
1 // Copyright (c) 2005-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 non-default resolver CExampleResolver. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @internalComponent |
|
20 @file |
|
21 */ |
|
22 |
|
23 #include <ecom/ecom.h> |
|
24 |
|
25 #include "TestUtilities.h" // For __FILE__LINE__ |
|
26 #include "ExampleResolver.h" |
|
27 #include "RegistryData.h" |
|
28 #include "ImplementationProxy.h" |
|
29 |
|
30 CExampleResolver* CExampleResolver::NewL(MPublicRegistry& aRegistry) |
|
31 { |
|
32 return new(ELeave) CExampleResolver(aRegistry); |
|
33 } |
|
34 |
|
35 CExampleResolver::~CExampleResolver() |
|
36 { |
|
37 if(iImplementationInfoArray) |
|
38 { |
|
39 iImplementationInfoArray->Reset(); |
|
40 delete iImplementationInfoArray; |
|
41 } |
|
42 } |
|
43 |
|
44 CExampleResolver::CExampleResolver(MPublicRegistry& aRegistry) |
|
45 : CResolver(aRegistry) |
|
46 { |
|
47 // Do nothing here |
|
48 } |
|
49 |
|
50 TUid CExampleResolver::IdentifyImplementationL(TUid aInterfaceUid, |
|
51 const TEComResolverParams& aAdditionalParameters)const |
|
52 { |
|
53 RImplInfoArray& implementationsInfo = iRegistry.ListImplementationsL(aInterfaceUid); |
|
54 TUid found = KNullUid; |
|
55 if(implementationsInfo.Count()) |
|
56 { |
|
57 found = Resolve(implementationsInfo, aAdditionalParameters); |
|
58 } |
|
59 return found; |
|
60 } |
|
61 |
|
62 TUid CExampleResolver::Resolve(const RImplInfoArray& aImplementationsInfo, |
|
63 const TEComResolverParams& aAdditionalParameters) const |
|
64 { |
|
65 // Loop through the implementations matching on type |
|
66 const TInt count = aImplementationsInfo.Count(); |
|
67 for(TInt index = 0; index < count; ++index) |
|
68 { |
|
69 const CImplementationInformation& impData = *aImplementationsInfo[index]; |
|
70 // As soon as we get a match on the datatype then return uid of the |
|
71 // implementation found. |
|
72 if (Match(impData.DataType(), // The Datatype of this implementation |
|
73 aAdditionalParameters.DataType(), // The type we are trying to find |
|
74 aAdditionalParameters.IsGenericMatch())) // If wildcards should be used |
|
75 return impData.ImplementationUid(); |
|
76 } |
|
77 |
|
78 return KNullUid; |
|
79 } |
|
80 |
|
81 RImplInfoArray* CExampleResolver::ListAllL(TUid aInterfaceUid, |
|
82 const TEComResolverParams& aAdditionalParameters) const |
|
83 { |
|
84 // Use the member var to create the array so that we get proper cleanup behaviour |
|
85 iImplementationInfoArray = new(ELeave) RImplInfoArray; |
|
86 RImplInfoArray* retList = iImplementationInfoArray; |
|
87 |
|
88 RImplInfoArray& fullList = iRegistry.ListImplementationsL(aInterfaceUid); |
|
89 |
|
90 const TBool useWildcards = aAdditionalParameters.IsGenericMatch(); |
|
91 const TDesC8& matchType = aAdditionalParameters.DataType(); |
|
92 const TInt numImps = fullList.Count(); |
|
93 for(TInt index = 0; index < numImps; ++index) |
|
94 { |
|
95 if(Match(fullList[index]->DataType(), matchType, useWildcards)) |
|
96 { |
|
97 User::LeaveIfError(retList->Append(fullList[index])); |
|
98 } |
|
99 } |
|
100 |
|
101 // Reset the member variable because we are passing ownership back |
|
102 iImplementationInfoArray = NULL; |
|
103 return retList; |
|
104 } |
|
105 |
|
106 TBool CExampleResolver::Match(const TDesC8& aImplementationType, |
|
107 const TDesC8& aMatchType, |
|
108 TBool aUseWildcards) const |
|
109 { |
|
110 TInt matchPos = KErrNotFound; |
|
111 |
|
112 _LIT8(dataSeparator, "||"); |
|
113 const TInt separatorLength = dataSeparator().Length(); |
|
114 |
|
115 // Look for the section separator marker '||' |
|
116 TInt separatorPos = aImplementationType.Find(dataSeparator); |
|
117 if(separatorPos == KErrNotFound) |
|
118 { |
|
119 // Match against the whole string |
|
120 if(aUseWildcards) |
|
121 matchPos = aMatchType.Match(aImplementationType); |
|
122 else |
|
123 matchPos = aMatchType.Compare(aImplementationType); |
|
124 } |
|
125 else |
|
126 { |
|
127 // Find the first section, up to the separator |
|
128 TPtrC8 dataSection = aImplementationType.Left(separatorPos); |
|
129 TPtrC8 remainingData = aImplementationType.Mid(separatorPos + separatorLength); |
|
130 // Match against each section in turn |
|
131 while(separatorPos != KErrNotFound) |
|
132 { |
|
133 // Search this section |
|
134 if(aUseWildcards) |
|
135 matchPos = aMatchType.Match(dataSection); |
|
136 else |
|
137 matchPos = aMatchType.Compare(dataSection); |
|
138 |
|
139 // If we found it then no need to continue, so return |
|
140 if(matchPos != KErrNotFound) |
|
141 return ETrue; |
|
142 |
|
143 // Move on to the next section |
|
144 separatorPos = remainingData.Find(dataSeparator); |
|
145 if(separatorPos != KErrNotFound) |
|
146 { |
|
147 dataSection.Set(remainingData.Left(separatorPos)); |
|
148 remainingData.Set(remainingData.Mid(separatorPos + separatorLength)); |
|
149 } |
|
150 else |
|
151 dataSection.Set(remainingData); |
|
152 } |
|
153 |
|
154 // Check the final part |
|
155 if(aUseWildcards) |
|
156 matchPos = aMatchType.Match(dataSection); |
|
157 else |
|
158 matchPos = aMatchType.Compare(dataSection); |
|
159 |
|
160 } |
|
161 return matchPos != KErrNotFound; |
|
162 } |
|
163 |
|
164 // __________________________________________________________________________ |
|
165 // Exported proxy for instantiation method resolution |
|
166 // Define the interface UIDs |
|
167 const TImplementationProxy ImplementationTable[] = |
|
168 { |
|
169 IMPLEMENTATION_PROXY_ENTRY(0x10244444,CExampleResolver::NewL), |
|
170 IMPLEMENTATION_PROXY_ENTRY(0x10999999,CExampleResolver::NewL) |
|
171 }; |
|
172 |
|
173 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
174 { |
|
175 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
176 |
|
177 return ImplementationTable; |
|
178 } |
|
179 |