1 /* |
|
2 * Copyright (c) 2006 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 #include <ecom/ecom.h> |
|
20 #include <mmf/common/mmfcontrollerpluginresolver.h> |
|
21 #include "cpluginvalidator.h" |
|
22 |
|
23 // ======== MEMBER FUNCTIONS ======== |
|
24 |
|
25 // ---------------------------------------------------------------------------- |
|
26 // |
|
27 // ---------------------------------------------------------------------------- |
|
28 // |
|
29 EXPORT_C CPluginValidator* CPluginValidator::NewL( TUid aUid, |
|
30 TAny *aParameter ) |
|
31 { |
|
32 CPluginValidator* self = CPluginValidator::NewLC( aUid , aParameter ); |
|
33 CleanupStack::Pop( self ); |
|
34 return self; |
|
35 } |
|
36 |
|
37 // ---------------------------------------------------------------------------- |
|
38 // |
|
39 // ---------------------------------------------------------------------------- |
|
40 // |
|
41 EXPORT_C CPluginValidator* CPluginValidator::NewLC( TUid aUid, |
|
42 TAny *aParameter ) |
|
43 { |
|
44 CPluginValidator* self = new( ELeave ) CPluginValidator( aUid, |
|
45 aParameter ); |
|
46 CleanupStack::PushL( self ); |
|
47 self->ConstructL(); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 EXPORT_C TAny* CPluginValidator::GetImplementation( TUid aUid ) |
|
56 { |
|
57 TPluginInfo pluginInfo; |
|
58 pluginInfo.iImplementationUid = aUid; |
|
59 TInt index = iPluginArray.Find( pluginInfo, |
|
60 TIdentityRelation< TPluginInfo >(UidMatch) ); |
|
61 return GetImplementation( index ); |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 EXPORT_C TAny* CPluginValidator::GetImplementation( TInt aIndex ) |
|
69 { |
|
70 TAny* ret( NULL ); |
|
71 if (( aIndex != KErrNotFound ) && ( aIndex < iPluginArray.Count() )) |
|
72 { |
|
73 ret= iPluginArray[aIndex].iPlugin; |
|
74 } |
|
75 return ret; |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // |
|
80 // ---------------------------------------------------------------------------- |
|
81 // |
|
82 EXPORT_C TInt CPluginValidator::GetCount( ) |
|
83 { |
|
84 return iPluginArray.Count(); |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // destructor |
|
89 // --------------------------------------------------------------------------- |
|
90 CPluginValidator::~CPluginValidator() |
|
91 { |
|
92 Cancel(); |
|
93 CleanPluginsTable(); |
|
94 iPluginArray.Close( ); |
|
95 if( iSession ) |
|
96 { |
|
97 iSession->Close(); |
|
98 } |
|
99 REComSession::FinalClose( ); |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 void CPluginValidator::RunL() |
|
107 { |
|
108 ManagePluginsL(); |
|
109 iSession->NotifyOnChange( iStatus ); |
|
110 SetActive(); |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // |
|
115 // ---------------------------------------------------------------------------- |
|
116 // |
|
117 void CPluginValidator::DoCancel() |
|
118 { |
|
119 iSession->CancelNotifyOnChange( iStatus ); |
|
120 } |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // |
|
124 // ---------------------------------------------------------------------------- |
|
125 // |
|
126 TInt CPluginValidator::RunError( TInt /*aError*/) |
|
127 { |
|
128 return KErrNone; |
|
129 } |
|
130 // ---------------------------------------------------------------------------- |
|
131 // |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 CPluginValidator::CPluginValidator( TUid aUid, TAny* aParameter ): |
|
135 CActive(EPriorityStandard), |
|
136 iUid( aUid ), |
|
137 iParameter( aParameter ) |
|
138 { |
|
139 |
|
140 } |
|
141 |
|
142 // ---------------------------------------------------------------------------- |
|
143 // |
|
144 // ---------------------------------------------------------------------------- |
|
145 // |
|
146 void CPluginValidator::ConstructL() |
|
147 { |
|
148 iSession = &REComSession::OpenL(); |
|
149 ManagePluginsL(); |
|
150 iSession->NotifyOnChange( iStatus ); |
|
151 CActiveScheduler::Add( this ); |
|
152 SetActive(); |
|
153 } |
|
154 |
|
155 // ---------------------------------------------------------------------------- |
|
156 // |
|
157 // ---------------------------------------------------------------------------- |
|
158 // |
|
159 TBool CPluginValidator::PresentInArrayL( TPluginInfo aPluginInfo, |
|
160 const RImplInfoPtrArray& aInfoArray ) |
|
161 { |
|
162 TBool result(EFalse); |
|
163 for ( TInt i = 0; i< aInfoArray.Count(); i++ ) |
|
164 { |
|
165 if ( aPluginInfo.iImplementationUid.iUid == |
|
166 aInfoArray[i]->ImplementationUid().iUid) |
|
167 { |
|
168 result = ETrue; |
|
169 break; |
|
170 } |
|
171 } |
|
172 return result; |
|
173 } |
|
174 |
|
175 // ---------------------------------------------------------------------------- |
|
176 // |
|
177 // ---------------------------------------------------------------------------- |
|
178 // |
|
179 void CPluginValidator::DestroyPlugin( TInt aIndex ) |
|
180 { |
|
181 CBase* plugin = static_cast<CBase*>( iPluginArray[aIndex].iPlugin ); |
|
182 delete plugin; |
|
183 REComSession::DestroyedImplementation( |
|
184 iPluginArray[aIndex].iDtor_ID_Key ); |
|
185 } |
|
186 |
|
187 // ---------------------------------------------------------------------------- |
|
188 // |
|
189 // ---------------------------------------------------------------------------- |
|
190 // |
|
191 void CPluginValidator::CleanPluginsTable() |
|
192 { |
|
193 for ( TInt i = 0; i < iPluginArray.Count(); i++ ) |
|
194 { |
|
195 DestroyPlugin( i ); |
|
196 } |
|
197 } |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 // ---------------------------------------------------------------------------- |
|
203 // |
|
204 // ---------------------------------------------------------------------------- |
|
205 // |
|
206 void CPluginValidator::ManagePluginsL() |
|
207 { |
|
208 // Read info about all implementations into infoArray |
|
209 RImplInfoPtrArray infoArray; |
|
210 CleanupResetAndDestroyPushL( infoArray ); |
|
211 |
|
212 REComSession::ListImplementationsL( iUid , infoArray ); |
|
213 TPluginInfo pluginInfo; |
|
214 //Load new plugins |
|
215 for ( TInt i = 0; i < infoArray.Count( ); i++ ) |
|
216 { |
|
217 pluginInfo.iImplementationUid = infoArray[i]->ImplementationUid( ); |
|
218 pluginInfo.iVersion = infoArray[i]->Version(); |
|
219 |
|
220 TInt index = iPluginArray.Find( pluginInfo, |
|
221 TIdentityRelation< TPluginInfo >(UidMatch) ); |
|
222 |
|
223 if ( index == KErrNotFound ) |
|
224 { |
|
225 //plugin wasn't present, we load it now |
|
226 LoadPluginL( pluginInfo ); |
|
227 } |
|
228 else if ( pluginInfo.iVersion > iPluginArray[index].iVersion ) |
|
229 { |
|
230 //plugin was present but it is a newer version, |
|
231 //remove old and load a new one |
|
232 DestroyPlugin( index ); |
|
233 iPluginArray.Remove( index ); |
|
234 LoadPluginL( pluginInfo ); |
|
235 } |
|
236 } |
|
237 //Remove old plugins |
|
238 for ( TInt i = iPluginArray.Count() - 1 ; i >= 0; i-- ) |
|
239 { |
|
240 pluginInfo = iPluginArray[i]; |
|
241 if ( !PresentInArrayL( pluginInfo, infoArray ) ) |
|
242 { |
|
243 DestroyPlugin( i ); |
|
244 iPluginArray.Remove( i ); |
|
245 } |
|
246 } |
|
247 CleanupStack::PopAndDestroy( &infoArray ); |
|
248 } |
|
249 |
|
250 // ---------------------------------------------------------------------------- |
|
251 // |
|
252 // ---------------------------------------------------------------------------- |
|
253 // |
|
254 void CPluginValidator::LoadPluginL( TPluginInfo& aPluginInfo ) |
|
255 { |
|
256 TAny* plug ( NULL ); |
|
257 TInt err( KErrNone ); |
|
258 TRAP( err, plug = REComSession::CreateImplementationL( |
|
259 aPluginInfo.iImplementationUid, |
|
260 aPluginInfo.iDtor_ID_Key, iParameter ) ); |
|
261 if( err==KErrNone && plug ) |
|
262 { |
|
263 CleanupStack::PushL( plug ); |
|
264 aPluginInfo.iPlugin = plug; |
|
265 iPluginArray.AppendL( aPluginInfo ); |
|
266 CleanupStack::Pop( plug ); |
|
267 } |
|
268 } |
|
269 |
|