54 // |
54 // |
55 EXPORT_C TAny* CPluginValidator::GetImplementation( TUid aUid ) |
55 EXPORT_C TAny* CPluginValidator::GetImplementation( TUid aUid ) |
56 { |
56 { |
57 TPluginInfo pluginInfo; |
57 TPluginInfo pluginInfo; |
58 pluginInfo.iImplementationUid = aUid; |
58 pluginInfo.iImplementationUid = aUid; |
59 TInt index = iPluginArray.Find( pluginInfo, |
59 TInt index = iPluginArray.Find( pluginInfo, |
60 TIdentityRelation< TPluginInfo >(UidMatch) ); |
60 TIdentityRelation< TPluginInfo >(UidMatch) ); |
61 return GetImplementation( index ); |
61 return GetImplementation( index ); |
62 } |
62 } |
63 |
63 |
64 // ---------------------------------------------------------------------------- |
64 // ---------------------------------------------------------------------------- |
65 // |
65 // |
66 // ---------------------------------------------------------------------------- |
66 // ---------------------------------------------------------------------------- |
67 // |
67 // |
68 EXPORT_C TAny* CPluginValidator::GetImplementation( TInt aIndex ) |
68 EXPORT_C TAny* CPluginValidator::GetImplementation( TInt aIndex ) |
69 { |
69 { |
70 TAny* ret( NULL ); |
70 TAny* ret( NULL ); |
71 if (( aIndex != KErrNotFound ) && ( aIndex < iPluginArray.Count() )) |
71 if (( aIndex != KErrNotFound ) && ( aIndex < iPluginArray.Count() )) |
72 { |
72 { |
73 ret= iPluginArray[aIndex].iPlugin; |
73 ret= iPluginArray[aIndex].iPlugin; |
74 } |
74 } |
75 return ret; |
75 return ret; |
76 } |
76 } |
77 |
77 |
78 // ---------------------------------------------------------------------------- |
78 // ---------------------------------------------------------------------------- |
79 // |
79 // |
80 // ---------------------------------------------------------------------------- |
80 // ---------------------------------------------------------------------------- |
154 |
154 |
155 // ---------------------------------------------------------------------------- |
155 // ---------------------------------------------------------------------------- |
156 // |
156 // |
157 // ---------------------------------------------------------------------------- |
157 // ---------------------------------------------------------------------------- |
158 // |
158 // |
159 TBool CPluginValidator::PresentInArrayL( TPluginInfo aPluginInfo, |
159 TBool CPluginValidator::PresentInArrayL( TPluginInfo aPluginInfo, |
160 const RImplInfoPtrArray& aInfoArray ) |
160 const RImplInfoPtrArray& aInfoArray ) |
161 { |
161 { |
162 TBool result(EFalse); |
162 TBool result( EFalse ); |
163 for ( TInt i = 0; i< aInfoArray.Count(); i++ ) |
163 for( TInt i = 0; i < aInfoArray.Count(); i++ ) |
164 { |
164 { |
165 if ( aPluginInfo.iImplementationUid.iUid == |
165 if( aPluginInfo.iImplementationUid.iUid |
166 aInfoArray[i]->ImplementationUid().iUid) |
166 == aInfoArray[i]->ImplementationUid().iUid ) |
167 { |
167 { |
168 result = ETrue; |
168 result = ETrue; |
169 break; |
169 break; |
170 } |
170 } |
171 } |
171 } |
172 return result; |
172 return result; |
173 } |
173 } |
174 |
174 |
175 // ---------------------------------------------------------------------------- |
175 // ---------------------------------------------------------------------------- |
176 // |
176 // |
177 // ---------------------------------------------------------------------------- |
177 // ---------------------------------------------------------------------------- |
178 // |
178 // |
179 void CPluginValidator::DestroyPlugin( TInt aIndex ) |
179 void CPluginValidator::DestroyPlugin( TInt aIndex ) |
180 { |
180 { |
181 CBase* plugin = static_cast<CBase*>( iPluginArray[aIndex].iPlugin ); |
181 CBase* plugin = static_cast<CBase*>( iPluginArray[aIndex].iPlugin ); |
182 delete plugin; |
182 delete plugin; |
183 REComSession::DestroyedImplementation( |
183 REComSession::DestroyedImplementation( |
184 iPluginArray[aIndex].iDtor_ID_Key ); |
184 iPluginArray[aIndex].iDtor_ID_Key ); |
185 } |
185 } |
186 |
186 |
187 // ---------------------------------------------------------------------------- |
187 // ---------------------------------------------------------------------------- |
188 // |
188 // |
189 // ---------------------------------------------------------------------------- |
189 // ---------------------------------------------------------------------------- |
190 // |
190 // |
191 void CPluginValidator::CleanPluginsTable() |
191 void CPluginValidator::CleanPluginsTable() |
192 { |
192 { |
193 for ( TInt i = 0; i < iPluginArray.Count(); i++ ) |
193 for( TInt i = 0; i < iPluginArray.Count(); i++ ) |
194 { |
194 { |
195 DestroyPlugin( i ); |
195 DestroyPlugin( i ); |
196 } |
196 } |
197 } |
197 } |
198 |
198 |
199 // ---------------------------------------------------------------------------- |
199 // ---------------------------------------------------------------------------- |
200 // |
200 // |
201 // ---------------------------------------------------------------------------- |
201 // ---------------------------------------------------------------------------- |
202 // |
202 // |
203 void CPluginValidator::ManagePluginsL() |
203 void CPluginValidator::ManagePluginsL() |
204 { |
204 { |
205 // Read info about all implementations into infoArray |
205 // Read info about all implementations into infoArray |
206 RImplInfoPtrArray infoArray; |
206 RImplInfoPtrArray infoArray; |
207 CleanupResetAndDestroyPushL( infoArray ); |
207 CleanupResetAndDestroyPushL( infoArray ); |
208 |
208 |
209 REComSession::ListImplementationsL( iUid , infoArray ); |
209 REComSession::ListImplementationsL( iUid , infoArray ); |
210 TPluginInfo pluginInfo; |
210 TPluginInfo pluginInfo; |
211 //Load new plugins |
211 //Load new plugins |
212 for ( TInt i = 0; i < infoArray.Count( ); i++ ) |
212 for ( TInt i = 0; i < infoArray.Count( ); i++ ) |
213 { |
213 { |
214 pluginInfo.iImplementationUid = infoArray[i]->ImplementationUid( ); |
214 pluginInfo.iImplementationUid = infoArray[i]->ImplementationUid( ); |
215 pluginInfo.iVersion = infoArray[i]->Version(); |
215 pluginInfo.iVersion = infoArray[i]->Version(); |
216 |
216 |
217 TInt index = iPluginArray.Find( pluginInfo, |
217 TInt index = iPluginArray.Find( pluginInfo, |
218 TIdentityRelation< TPluginInfo >(UidMatch) ); |
218 TIdentityRelation< TPluginInfo >(UidMatch) ); |
219 |
219 |
220 if ( index == KErrNotFound ) |
220 if( index == KErrNotFound ) |
221 { |
221 { |
222 //plugin wasn't present, we load it now |
222 //plugin wasn't present, we load it now |
223 LoadPluginL( pluginInfo ); |
223 LoadPluginL( pluginInfo ); |
224 } |
224 } |
225 else if ( pluginInfo.iVersion > iPluginArray[index].iVersion ) |
225 else if( pluginInfo.iVersion > iPluginArray[index].iVersion ) |
226 { |
226 { |
227 //plugin was present but it is a newer version, |
227 //plugin was present but it is a newer version, |
228 //remove old and load a new one |
228 //remove old and load a new one |
229 DestroyPlugin( index ); |
229 DestroyPlugin( index ); |
230 iPluginArray.Remove( index ); |
230 iPluginArray.Remove( index ); |
231 LoadPluginL( pluginInfo ); |
231 LoadPluginL( pluginInfo ); |
232 } |
232 } |
233 } |
233 } |
234 //Remove old plugins |
234 //Remove old plugins |
235 for ( TInt i = iPluginArray.Count() - 1 ; i >= 0; i-- ) |
235 for( TInt i = iPluginArray.Count() - 1; i >= 0; i-- ) |
236 { |
236 { |
237 pluginInfo = iPluginArray[i]; |
237 pluginInfo = iPluginArray[i]; |
238 if ( !PresentInArrayL( pluginInfo, infoArray ) ) |
238 if ( !PresentInArrayL( pluginInfo, infoArray ) ) |
239 { |
239 { |
240 DestroyPlugin( i ); |
240 DestroyPlugin( i ); |
241 iPluginArray.Remove( i ); |
241 iPluginArray.Remove( i ); |
242 } |
242 } |
243 } |
243 } |
244 CleanupStack::PopAndDestroy( &infoArray ); |
244 CleanupStack::PopAndDestroy( &infoArray ); |
245 } |
245 } |
246 |
246 |
247 // ---------------------------------------------------------------------------- |
247 // ---------------------------------------------------------------------------- |
248 // |
248 // |
249 // ---------------------------------------------------------------------------- |
249 // ---------------------------------------------------------------------------- |
250 // |
250 // |
251 void CPluginValidator::LoadPluginL( TPluginInfo& aPluginInfo ) |
251 void CPluginValidator::LoadPluginL( TPluginInfo& aPluginInfo ) |
252 { |
252 { |
253 TAny* plug ( NULL ); |
253 TAny* plug( NULL ); |
254 TInt err( KErrNone ); |
254 TInt err( KErrNone ); |
255 TRAP( err, plug = REComSession::CreateImplementationL( |
255 TRAP( err, plug = REComSession::CreateImplementationL( |
256 aPluginInfo.iImplementationUid, |
256 aPluginInfo.iImplementationUid, |
257 aPluginInfo.iDtor_ID_Key, iParameter ) ); |
257 aPluginInfo.iDtor_ID_Key, iParameter ) ); |
258 if( err==KErrNone && plug ) |
258 if( err == KErrNone && plug ) |
259 { |
259 { |
260 CleanupStack::PushL( plug ); |
260 CleanupStack::PushL( plug ); |
261 aPluginInfo.iPlugin = plug; |
261 aPluginInfo.iPlugin = plug; |
262 iPluginArray.AppendL( aPluginInfo ); |
262 iPluginArray.AppendL( aPluginInfo ); |
263 CleanupStack::Pop( plug ); |
263 CleanupStack::Pop( plug ); |
264 } |
264 } |
265 } |
265 } |
266 |
|