|
1 /* |
|
2 * Copyright (c) 2005-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: Content plugin manager class for Active idle framework. |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <ecom/ecom.h> |
|
20 #include <ecom/implementationinformation.h> |
|
21 #include <AknGlobalNote.h> |
|
22 #include <StringLoader.h> |
|
23 #include <e32property.h> // For RProperty |
|
24 |
|
25 // User includes |
|
26 #include <aicontentobserver.h> |
|
27 #include <aiutility.h> |
|
28 #include <aiplugintool.h> |
|
29 #include <activeidle2domainpskeys.h> // PubSub category |
|
30 #include <activeidle2internalpskeys.h> // PubSub category key and values |
|
31 |
|
32 #include "aipluginfactory.h" |
|
33 #include "aicontentpluginmanager.h" |
|
34 #include "aipluginlifecycleobserver.h" |
|
35 |
|
36 #include "aiuicontroller.h" |
|
37 #include "aifwpanic.h" |
|
38 #include "debug.h" |
|
39 |
|
40 |
|
41 // ======== LOCAL FUNCTIONS ======== |
|
42 // ---------------------------------------------------------------------------- |
|
43 // CleanupResetAndDestroy() |
|
44 // ---------------------------------------------------------------------------- |
|
45 // |
|
46 template<class T> |
|
47 static void CleanupResetAndDestroy( TAny* aObj ) |
|
48 { |
|
49 if( aObj ) |
|
50 { |
|
51 static_cast<T*>( aObj )->ResetAndDestroy(); |
|
52 } |
|
53 } |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // CleanupResetAndDestroyPushL() |
|
57 // ---------------------------------------------------------------------------- |
|
58 // |
|
59 template<class T> |
|
60 static void CleanupResetAndDestroyPushL(T& aArray) |
|
61 { |
|
62 CleanupStack::PushL( TCleanupItem( &CleanupResetAndDestroy<T>, &aArray ) ); |
|
63 } |
|
64 |
|
65 // ======== MEMBER FUNCTIONS ======== |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // CAiPluginFactory::CAiPluginFactory() |
|
69 // ---------------------------------------------------------------------------- |
|
70 // |
|
71 CAiPluginFactory::CAiPluginFactory( |
|
72 RPointerArray<CAiContentPublisher>& aPlugins, |
|
73 CAiContentPluginManager& aManager ) |
|
74 : iPlugins( aPlugins ), iManager( aManager ) |
|
75 { |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // CAiPluginFactory::~CAiPluginFactory() |
|
80 // ---------------------------------------------------------------------------- |
|
81 // |
|
82 CAiPluginFactory::~CAiPluginFactory() |
|
83 { |
|
84 Release( iPluginTool ); |
|
85 |
|
86 iEComPlugins.ResetAndDestroy(); |
|
87 |
|
88 iLifecycleObservers.Reset(); |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // CAiPluginFactory::NewL() |
|
93 // ---------------------------------------------------------------------------- |
|
94 // |
|
95 CAiPluginFactory* CAiPluginFactory::NewL( |
|
96 RPointerArray<CAiContentPublisher>& aPlugins, |
|
97 CAiContentPluginManager& aManager ) |
|
98 { |
|
99 CAiPluginFactory* self = |
|
100 new ( ELeave ) CAiPluginFactory( aPlugins, aManager ); |
|
101 |
|
102 CleanupStack::PushL( self ); |
|
103 self->ConstructL(); |
|
104 CleanupStack::Pop( self ); |
|
105 return self; |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------------------------------- |
|
109 // CAiPluginFactory::ConstructL() |
|
110 // ---------------------------------------------------------------------------- |
|
111 // |
|
112 void CAiPluginFactory::ConstructL() |
|
113 { |
|
114 iPluginTool = AiUtility::CreatePluginToolL(); |
|
115 } |
|
116 |
|
117 // ---------------------------------------------------------------------------- |
|
118 // CAiPluginFactory::AddLifecycleObserverL() |
|
119 // ---------------------------------------------------------------------------- |
|
120 // |
|
121 void CAiPluginFactory::AddLifecycleObserverL( |
|
122 MAiPluginLifecycleObserver& aObserver ) |
|
123 { |
|
124 if( iLifecycleObservers.Find( &aObserver ) == KErrNotFound ) |
|
125 { |
|
126 iLifecycleObservers.AppendL( &aObserver ); |
|
127 } |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // CAiPluginFactory::CreatePluginL() |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 void CAiPluginFactory::CreatePluginL( |
|
135 const TAiPublisherInfo& aPublisherInfo, |
|
136 RPointerArray<CAiUiController>& aControllerArray ) |
|
137 { |
|
138 iEComPlugins.ResetAndDestroy(); |
|
139 |
|
140 // Discover Plugin implementations. |
|
141 __TIME_MARK( ecomOverhead ); |
|
142 |
|
143 REComSession::ListImplementationsL( |
|
144 KInterfaceUidContentPlugin, iEComPlugins ); |
|
145 |
|
146 __TIME_ENDMARK( "FW: ECom Discover plug-ins", ecomOverhead ); |
|
147 |
|
148 iPlugins.ReserveL( iPlugins.Count() + 1 ); |
|
149 |
|
150 TBool implFound( EFalse ); |
|
151 |
|
152 for( TInt i = 0; i < iEComPlugins.Count(); i++ ) |
|
153 { |
|
154 CImplementationInformation* information( iEComPlugins[i] ); |
|
155 |
|
156 if( information->ImplementationUid().iUid == aPublisherInfo.iUid.iUid ) |
|
157 { |
|
158 implFound = ETrue; |
|
159 break; |
|
160 } |
|
161 } |
|
162 |
|
163 if( aPublisherInfo.iNamespace == KNullDesC8 || !implFound ) |
|
164 { |
|
165 // No namespace available or no ecom implementation available |
|
166 User::Leave( KErrNotSupported ); |
|
167 } |
|
168 |
|
169 CAiContentPublisher* plugin( PluginByInfoL( aPublisherInfo ) ); |
|
170 |
|
171 if( plugin ) |
|
172 { |
|
173 User::Leave( KErrAlreadyExists ); |
|
174 } |
|
175 |
|
176 __PRINT( __DBG_FORMAT( "\t[I]\t Loading plug-in uid=%x name=%S"), |
|
177 aPublisherInfo.iUid, &(aPublisherInfo.iName) ); |
|
178 |
|
179 __TIME( "FW: Create plug-in:", |
|
180 plugin = CreatePluginLC( aPublisherInfo ); |
|
181 ) // __TIME |
|
182 |
|
183 __TIME( "FW: Subscribe content observers", |
|
184 SubscribeContentObserversL( *plugin, |
|
185 aPublisherInfo, aControllerArray ); |
|
186 ) // __TIME |
|
187 |
|
188 // Plug-in settings |
|
189 __TIME( "FW: Configure Plugin", |
|
190 ConfigurePluginL( aControllerArray, *plugin, aPublisherInfo ); |
|
191 ) // __TIME |
|
192 |
|
193 __PRINTS( "*** FW: Done - Load Plug-in ***" ); |
|
194 |
|
195 // This might fail and the plugin ends up destroyed |
|
196 for( TInt i = 0; i < iLifecycleObservers.Count(); ++i ) |
|
197 { |
|
198 iLifecycleObservers[i]->PluginCreatedL( *plugin ); |
|
199 } |
|
200 |
|
201 for( TInt i = 0; i < iLifecycleObservers.Count(); ++i ) |
|
202 { |
|
203 iLifecycleObservers[i]->AllPluginsCreated(); |
|
204 } |
|
205 |
|
206 // Move plugins to manager |
|
207 iPlugins.Append( plugin ); |
|
208 CleanupStack::Pop( plugin ); |
|
209 |
|
210 iEComPlugins.ResetAndDestroy(); |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------------------------------- |
|
214 // CAiPluginFactory::DestroyPluginL() |
|
215 // ---------------------------------------------------------------------------- |
|
216 // |
|
217 void CAiPluginFactory::DestroyPluginL( |
|
218 const TAiPublisherInfo& aPublisherInfo, |
|
219 RPointerArray< CAiUiController >& /*aControllerArray*/ ) |
|
220 { |
|
221 // TODO: check is there need to call |
|
222 // iUiControllerManager->RemovePluginFromUI( aPlugin ); |
|
223 // it will clean the published content. |
|
224 |
|
225 if( iPlugins.Count() == 0 ) |
|
226 { |
|
227 return; |
|
228 } |
|
229 |
|
230 CAiContentPublisher* plugin( PluginByInfoL( aPublisherInfo ) ); |
|
231 |
|
232 TInt index( iPlugins.Find( plugin ) ); |
|
233 |
|
234 if( plugin && index != KErrNotFound ) |
|
235 { |
|
236 for( TInt i = 0; i < iLifecycleObservers.Count(); i++ ) |
|
237 { |
|
238 iLifecycleObservers[i]->PluginDestroyed( *plugin ); |
|
239 } |
|
240 |
|
241 iPlugins.Remove( index ); |
|
242 |
|
243 delete plugin; |
|
244 plugin = NULL; |
|
245 } |
|
246 |
|
247 if( iPlugins.Count() == 0 ) |
|
248 { |
|
249 for( TInt i = 0; i < iLifecycleObservers.Count(); i++ ) |
|
250 { |
|
251 iLifecycleObservers[i]->AllPluginsDestroyed(); |
|
252 } |
|
253 } |
|
254 } |
|
255 |
|
256 // ---------------------------------------------------------------------------- |
|
257 // CAiPluginFactory::DestroyPlugins() |
|
258 // ---------------------------------------------------------------------------- |
|
259 // |
|
260 void CAiPluginFactory::DestroyPlugins() |
|
261 { |
|
262 for( TInt i = 0; i < iPlugins.Count(); i++ ) |
|
263 { |
|
264 CAiContentPublisher* plugin( iPlugins[i] ); |
|
265 |
|
266 for( TInt i = 0; i < iLifecycleObservers.Count(); i++ ) |
|
267 { |
|
268 iLifecycleObservers[i]->PluginDestroyed( *plugin ); |
|
269 } |
|
270 } |
|
271 |
|
272 iPlugins.ResetAndDestroy(); |
|
273 |
|
274 for( TInt i = 0; i < iLifecycleObservers.Count(); i++ ) |
|
275 { |
|
276 iLifecycleObservers[i]->AllPluginsDestroyed(); |
|
277 } |
|
278 } |
|
279 |
|
280 // ---------------------------------------------------------------------------- |
|
281 // CAiPluginFactory::CreatePluginLC() |
|
282 // ---------------------------------------------------------------------------- |
|
283 // |
|
284 CAiContentPublisher* CAiPluginFactory::CreatePluginLC( |
|
285 const TAiPublisherInfo& aPluginInfo ) |
|
286 { |
|
287 CAiContentPublisher* plugin = |
|
288 CAiContentPublisher::NewL( aPluginInfo.iUid ); |
|
289 |
|
290 CleanupStack::PushL( plugin ); |
|
291 |
|
292 MAiPropertyExtension* ext( iPluginTool->PropertyExt( *plugin ) ); |
|
293 |
|
294 if( !ext ) |
|
295 { |
|
296 User::Leave( KErrNotFound ); |
|
297 } |
|
298 |
|
299 ext->SetPropertyL( EAiPublisherInfo, (TAny*)&aPluginInfo ); |
|
300 |
|
301 const TAiPublisherInfo* info( ext->PublisherInfoL() ); |
|
302 |
|
303 if( info->iNamespace != aPluginInfo.iNamespace ) |
|
304 { |
|
305 // SetPropertyL is not implemented correctly |
|
306 User::Leave( KErrNotSupported ); |
|
307 } |
|
308 |
|
309 return plugin; |
|
310 } |
|
311 |
|
312 // ---------------------------------------------------------------------------- |
|
313 // CAiPluginFactory::SubscribeContentObserversL() |
|
314 // ---------------------------------------------------------------------------- |
|
315 // |
|
316 void CAiPluginFactory::SubscribeContentObserversL( |
|
317 CAiContentPublisher& aContentPublisher, |
|
318 const TAiPublisherInfo& aPublisherInfo, |
|
319 RPointerArray<CAiUiController>& aControllerArray ) |
|
320 { |
|
321 |
|
322 for( TInt i = 0; i < aControllerArray.Count(); i++ ) |
|
323 { |
|
324 MAiContentObserver& observer( |
|
325 aControllerArray[i]->GetContentObserver() ); |
|
326 |
|
327 if ( observer.RequiresSubscription( aPublisherInfo ) ) |
|
328 { |
|
329 // Subscribe observer only if it understands the plugin |
|
330 aContentPublisher.SubscribeL( observer ); |
|
331 } |
|
332 } |
|
333 } |
|
334 |
|
335 // ---------------------------------------------------------------------------- |
|
336 // CAiPluginFactory::ConfigurePluginL() |
|
337 // ---------------------------------------------------------------------------- |
|
338 // |
|
339 void CAiPluginFactory::ConfigurePluginL( |
|
340 RPointerArray<CAiUiController>& aControllerArray, |
|
341 CAiContentPublisher& aContentPublisher, |
|
342 const TAiPublisherInfo& aPubInfo ) |
|
343 { |
|
344 RAiSettingsItemArray pluginSettings; |
|
345 CleanupResetAndDestroyPushL( pluginSettings ); |
|
346 |
|
347 for( TInt i = 0; i < aControllerArray.Count(); i++ ) |
|
348 { |
|
349 // Get settings for plug-in |
|
350 aControllerArray[i]->GetSettingsL( aPubInfo, pluginSettings ); |
|
351 } |
|
352 |
|
353 // Configure plug-in with its settings |
|
354 aContentPublisher.ConfigureL( pluginSettings ); |
|
355 |
|
356 CleanupStack::PopAndDestroy( &pluginSettings ); |
|
357 } |
|
358 |
|
359 // ---------------------------------------------------------------------------- |
|
360 // CAiPluginFactory::PluginByInfoL() |
|
361 // ---------------------------------------------------------------------------- |
|
362 // |
|
363 CAiContentPublisher* CAiPluginFactory::PluginByInfoL( |
|
364 const TAiPublisherInfo& aInfo ) const |
|
365 { |
|
366 for( TInt i = 0; i < iPlugins.Count(); i++ ) |
|
367 { |
|
368 const TAiPublisherInfo* info( NULL ); |
|
369 |
|
370 info = iPluginTool->PublisherInfoL( *iPlugins[i] ); |
|
371 |
|
372 if( info && ( aInfo == *info ) ) |
|
373 { |
|
374 return iPlugins[i]; |
|
375 } |
|
376 } |
|
377 |
|
378 return NULL; |
|
379 } |
|
380 |
|
381 // ---------------------------------------------------------------------------- |
|
382 // CAiPluginFactory::PluginByNameL() |
|
383 // ---------------------------------------------------------------------------- |
|
384 // |
|
385 CAiContentPublisher* CAiPluginFactory::PluginByNameL( |
|
386 const TDesC& aName ) const |
|
387 { |
|
388 for( TInt i = 0; i < iPlugins.Count(); i++ ) |
|
389 { |
|
390 const TAiPublisherInfo* info( NULL ); |
|
391 |
|
392 TRAP_IGNORE( info = iPluginTool->PublisherInfoL( *iPlugins[i] ) ); |
|
393 |
|
394 if( info && info->iName == aName ) |
|
395 { |
|
396 return iPlugins[i]; |
|
397 } |
|
398 } |
|
399 |
|
400 return NULL; |
|
401 } |
|
402 |
|
403 // End of file |