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