13 * |
13 * |
14 * Description: Profile plug-in publisher |
14 * Description: Profile plug-in publisher |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 // System includes |
19 #include <ecom/ecom.h> |
19 #include <ecom/ecom.h> |
20 #include <ecom/implementationproxy.h> |
20 #include <ecom/implementationproxy.h> |
|
21 #include <PUAcodes.hrh> |
|
22 #include <AknUtils.h> |
|
23 |
|
24 // User includes |
|
25 #include <aiprofilepluginuids.hrh> |
21 #include <aicontentobserver.h> |
26 #include <aicontentobserver.h> |
22 #include <aiutility.h> |
27 #include <aiutility.h> |
23 #include <PUAcodes.hrh> |
|
24 #include <AknUtils.h> |
|
25 |
28 |
26 #include "aiprofileplugincontentmodel.h" |
29 #include "aiprofileplugincontentmodel.h" |
27 #include <aiprofilepluginuids.hrh> |
|
28 #include "caiprofileplugin.h" |
30 #include "caiprofileplugin.h" |
29 #include "caiprofileengine.h" |
31 #include "caiprofileengine.h" |
30 #include "aipluginsettings.h" |
32 #include "aipluginsettings.h" |
31 |
33 |
|
34 // Constants |
|
35 |
32 // PUA code for the timed profile, missing from PUAcodes.hrh |
36 // PUA code for the timed profile, missing from PUAcodes.hrh |
33 #define KAiTimedProfilePUA 0xF815 |
37 #define KAiTimedProfilePUA 0xF815 |
34 #define KAiRTL 0x200F |
38 #define KAiRTL 0x200F |
35 |
39 |
36 // CONST CLASS VARIABLES |
|
37 const TImplementationProxy KImplementationTable[] = |
40 const TImplementationProxy KImplementationTable[] = |
38 { |
41 { |
39 IMPLEMENTATION_PROXY_ENTRY( KImplUidProfilePlugin, CAiProfilePlugin::NewL ) |
42 IMPLEMENTATION_PROXY_ENTRY( KImplUidProfilePlugin, CAiProfilePlugin::NewL ) |
40 }; |
43 }; |
41 |
44 |
42 // ======== LOCAL FUNCTIONS ======== |
45 // ======== LOCAL FUNCTIONS ======== |
43 |
46 |
44 // ======== MEMBER FUNCTIONS ======== |
47 // ======== MEMBER FUNCTIONS ======== |
45 |
48 // --------------------------------------------------------------------------- |
46 // --------------------------------------------------------------------------- |
49 // CAiProfilePlugin::NewL |
47 // Symbian 2nd phase constructor can leave |
50 // |
48 // --------------------------------------------------------------------------- |
51 // --------------------------------------------------------------------------- |
49 // |
52 // |
50 CAiProfilePlugin* CAiProfilePlugin::NewL() |
53 CAiProfilePlugin* CAiProfilePlugin::NewL() |
51 { |
54 { |
52 CAiProfilePlugin* self = new (ELeave) CAiProfilePlugin; |
55 CAiProfilePlugin* self = new ( ELeave ) CAiProfilePlugin; |
53 CleanupStack::PushL( self ); |
56 CleanupStack::PushL( self ); |
54 self->ConstructL(); |
57 self->ConstructL(); |
55 CleanupStack::Pop( self ); |
58 CleanupStack::Pop( self ); |
56 |
59 |
57 return self; |
60 return self; |
58 } |
61 } |
59 |
62 |
60 // --------------------------------------------------------------------------- |
63 // --------------------------------------------------------------------------- |
61 // Default constructor |
64 // CAiProfilePlugin::CAiProfilePlugin() |
|
65 // |
62 // --------------------------------------------------------------------------- |
66 // --------------------------------------------------------------------------- |
63 // |
67 // |
64 CAiProfilePlugin::CAiProfilePlugin() |
68 CAiProfilePlugin::CAiProfilePlugin() |
65 { |
69 { |
66 } |
70 } |
67 |
71 |
68 // --------------------------------------------------------------------------- |
72 // --------------------------------------------------------------------------- |
69 // Symbian 2nd phase constructor can leave |
73 // CAiProfilePlugin::ConstructL |
|
74 // |
70 // --------------------------------------------------------------------------- |
75 // --------------------------------------------------------------------------- |
71 // |
76 // |
72 void CAiProfilePlugin::ConstructL() |
77 void CAiProfilePlugin::ConstructL() |
73 { |
78 { |
74 iInfo.iUid.iUid = AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_PROFILEPLUGIN; |
|
75 |
|
76 iContent = AiUtility::CreateContentItemArrayIteratorL( KAiProfileContent ); |
79 iContent = AiUtility::CreateContentItemArrayIteratorL( KAiProfileContent ); |
77 iEvents = AiUtility::CreateContentItemArrayIteratorL( KAiProfileEvents ); |
80 iEvents = AiUtility::CreateContentItemArrayIteratorL( KAiProfileEvents ); |
78 iResources = AiUtility::CreateContentItemArrayIteratorL( KAiProfileResources ); |
81 iResources = AiUtility::CreateContentItemArrayIteratorL( KAiProfileResources ); |
79 |
82 } |
80 iIsUpdated = ETrue; |
83 |
81 iAlive = EFalse; |
84 // --------------------------------------------------------------------------- |
82 } |
85 // CAiProfilePlugin::~CAiProfilePlugin |
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // Destructor |
|
86 // Deletes all data created to heap |
86 // Deletes all data created to heap |
87 // --------------------------------------------------------------------------- |
87 // --------------------------------------------------------------------------- |
88 // |
88 // |
89 CAiProfilePlugin::~CAiProfilePlugin() |
89 CAiProfilePlugin::~CAiProfilePlugin() |
90 { |
90 { |
91 CleanPublishedProfileNames(); |
91 CleanPublishedProfileNames(); |
|
92 |
92 Release( iContent ); |
93 Release( iContent ); |
93 Release( iEvents ); |
94 Release( iEvents ); |
94 Release( iResources ); |
95 Release( iResources ); |
|
96 |
95 delete iActiveProfileAndChar; |
97 delete iActiveProfileAndChar; |
96 delete iPreviousProfileNameAndChar; |
98 delete iPreviousProfileNameAndChar; |
97 delete iEngine; |
99 delete iEngine; |
|
100 |
98 iObservers.Close(); |
101 iObservers.Close(); |
99 } |
102 } |
100 |
103 |
101 // --------------------------------------------------------------------------- |
104 // --------------------------------------------------------------------------- |
|
105 // CAiProfilePlugin::PublishL |
102 // Publishes the profiles |
106 // Publishes the profiles |
103 // --------------------------------------------------------------------------- |
107 // --------------------------------------------------------------------------- |
104 // |
108 // |
105 void CAiProfilePlugin::PublishL() |
109 void CAiProfilePlugin::PublishL() |
106 { |
110 { |
107 TInt err( KErrNone ); |
111 TInt err( KErrNone ); |
108 TInt observers( iObservers.Count() ); |
112 TInt observers( iObservers.Count() ); |
109 TInt transactionId = reinterpret_cast<TInt>( this ); |
113 TInt transactionId ( reinterpret_cast<TInt>( this ) ); |
110 |
114 |
111 iCurrentCount = iEngine->NumberOfProfiles(); |
115 iCurrentCount = iEngine->NumberOfProfiles(); |
112 for ( int i = 0; i < observers; i++ ) |
116 |
113 { |
117 for ( TInt i = 0; i < observers; i++ ) |
114 MAiContentObserver* observer = iObservers[i]; |
118 { |
|
119 MAiContentObserver* observer( iObservers[i] ); |
|
120 |
115 err = observer->StartTransaction( transactionId ); |
121 err = observer->StartTransaction( transactionId ); |
116 |
122 |
117 if ( err == KErrNotSupported ) |
123 if ( err == KErrNotSupported ) |
118 { |
124 { |
119 // The observer does not support transactions, check for real errors. |
125 // The observer does not support transactions, check for real errors. |
248 iEngine->IsOffline() ) |
261 iEngine->IsOffline() ) |
249 { |
262 { |
250 observer->Clean( *this, EAiProfileActiveProfileSilentChar, EAiProfileActiveProfileSilentChar ); |
263 observer->Clean( *this, EAiProfileActiveProfileSilentChar, EAiProfileActiveProfileSilentChar ); |
251 observer->Clean( *this, EAiProfileActiveProfileIcon, 1 ); |
264 observer->Clean( *this, EAiProfileActiveProfileIcon, 1 ); |
252 observer->Clean( *this, EAiProfileActiveProfileIcon, 2 ); |
265 observer->Clean( *this, EAiProfileActiveProfileIcon, 2 ); |
253 // uncomment also this and respective policy lines in profiles.xml if whole widget needs to be hidden in AI3 |
266 |
|
267 // uncomment also this and respective policy lines in profiles.xml if whole widget needs to be hidden in AI3 |
254 //observer->Clean( *this, EAiProfileContentActiveProfileName, EAiProfileContentActiveProfileName ); |
268 //observer->Clean( *this, EAiProfileContentActiveProfileName, EAiProfileContentActiveProfileName ); |
255 } |
269 } |
|
270 |
256 if ( err == KErrNone ) |
271 if ( err == KErrNone ) |
257 { |
272 { |
258 err = observer->Commit( transactionId ); |
273 err = observer->Commit( transactionId ); |
259 |
274 |
260 if ( err == KErrNotSupported) |
275 if ( err == KErrNotSupported) |
261 { |
276 { |
262 return; |
277 return; |
263 } |
278 } |
264 } |
279 } |
265 |
280 } |
266 iIsUpdated = EFalse; |
281 |
267 } |
|
268 iPreviousCount = iCurrentCount; |
282 iPreviousCount = iCurrentCount; |
269 } |
283 } |
270 |
284 |
271 // --------------------------------------------------------------------------- |
285 // --------------------------------------------------------------------------- |
272 // From class CAiContentPublisher |
286 // CAiProfilePlugin::Start |
273 // Plug-in is requested to unload its engines due backup operation |
287 // |
274 // --------------------------------------------------------------------------- |
288 // --------------------------------------------------------------------------- |
275 // |
289 // |
276 void CAiProfilePlugin::Stop( TAiTransitionReason /*aReason*/ ) |
290 void CAiProfilePlugin::Start( TStartReason /*aReason*/ ) |
277 { |
291 { |
278 FreeEngine(); |
292 } |
279 } |
293 |
280 |
294 // --------------------------------------------------------------------------- |
281 // --------------------------------------------------------------------------- |
295 // CAiProfilePlugin::Stop |
282 // From class CAiContentPublisher |
296 // |
283 // Plug-in is instructed that it is allowed to consume CPU resources |
297 // --------------------------------------------------------------------------- |
284 // --------------------------------------------------------------------------- |
298 // |
285 // |
299 void CAiProfilePlugin::Stop( TStopReason /*aReason*/ ) |
286 void CAiProfilePlugin::Resume( TAiTransitionReason aReason ) |
300 { |
287 { |
301 } |
288 TRAP_IGNORE( DoResumeL( aReason ) ); |
302 |
289 } |
303 // --------------------------------------------------------------------------- |
290 |
304 // CAiProfilePlugin::Resume |
291 // --------------------------------------------------------------------------- |
305 // |
292 // From class CAiContentPublisher |
306 // --------------------------------------------------------------------------- |
293 // Plug-in is instructed that it is not allowed to consume CPU resources |
307 // |
294 // --------------------------------------------------------------------------- |
308 void CAiProfilePlugin::Resume( TResumeReason aReason ) |
295 // |
309 { |
296 void CAiProfilePlugin::Suspend( TAiTransitionReason /*aReason*/ ) |
310 if ( aReason == EForeground ) |
297 { |
311 { |
298 if ( iEngine && iAlive ) |
312 TRAP_IGNORE( DoResumeL() ); |
299 { |
313 } |
300 iEngine->Suspend(); |
314 } |
301 } |
315 |
302 |
316 // --------------------------------------------------------------------------- |
303 iAlive = EFalse; |
317 // CAiProfilePlugin::Suspend |
304 } |
318 // |
305 |
319 // --------------------------------------------------------------------------- |
306 // --------------------------------------------------------------------------- |
320 // |
307 // From class CAiContentPublisher |
321 void CAiProfilePlugin::Suspend( TSuspendReason /*aReason*/ ) |
308 // The plug-in MUST maintain a registry of subscribers and send |
322 { |
309 // notification to all of them whenever the state changes or new content |
323 } |
310 // is available |
324 |
|
325 // --------------------------------------------------------------------------- |
|
326 // CAiProfilePlugin::SubscribeL |
|
327 // |
311 // --------------------------------------------------------------------------- |
328 // --------------------------------------------------------------------------- |
312 // |
329 // |
313 void CAiProfilePlugin::SubscribeL( MAiContentObserver& aObserver ) |
330 void CAiProfilePlugin::SubscribeL( MAiContentObserver& aObserver ) |
314 { |
331 { |
315 iObservers.AppendL( &aObserver ); |
332 iObservers.AppendL( &aObserver ); |
316 } |
333 } |
317 |
334 |
318 // --------------------------------------------------------------------------- |
335 // --------------------------------------------------------------------------- |
319 // From class CAiContentPublisher |
336 // CAiProfilePlugin::ConfigureL |
320 // Plug-ins take ownership of the settings array, so it must either |
337 // |
321 // store it in a member or free it. |
338 // --------------------------------------------------------------------------- |
322 // --------------------------------------------------------------------------- |
339 // |
323 // |
340 void CAiProfilePlugin::ConfigureL( RAiSettingsItemArray& /*aSettings*/ ) |
324 void CAiProfilePlugin::ConfigureL( RAiSettingsItemArray& aSettings ) |
|
325 { |
|
326 aSettings.ResetAndDestroy(); |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // From class CAiContentPublisher |
|
331 // Returns the extension interface. Actual type depends on the passed |
|
332 // aUid argument. |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 TAny* CAiProfilePlugin::Extension( TUid aUid ) |
|
336 { |
341 { |
337 if (aUid == KExtensionUidProperty) |
342 } |
338 { |
343 |
339 return static_cast<MAiPropertyExtension*>(this); |
344 // --------------------------------------------------------------------------- |
340 } |
345 // CAiProfilePlugin::GetProperty |
341 else if (aUid == KExtensionUidEventHandler) |
346 // |
342 { |
347 // --------------------------------------------------------------------------- |
343 return static_cast<MAiEventHandlerExtension*>(this); |
348 // |
344 } |
349 TAny* CAiProfilePlugin::GetProperty( TProperty aProperty ) |
345 else |
350 { |
346 { |
351 if ( aProperty == EPublisherContent ) |
347 return NULL; |
352 { |
348 } |
353 return static_cast< MAiContentItemIterator* >( iContent ); |
349 } |
354 } |
350 |
355 else if ( aProperty == EPublisherEvents ) |
351 // --------------------------------------------------------------------------- |
356 { |
352 // From class MAiPropertyExtension |
357 return static_cast< MAiContentItemIterator* >( iEvents ); |
353 // Read property of publisher plug-in. |
358 } |
354 // --------------------------------------------------------------------------- |
359 else if ( aProperty == EPublisherResources ) |
355 // |
360 { |
356 TAny* CAiProfilePlugin::GetPropertyL( TInt aProperty ) |
361 return static_cast< MAiContentItemIterator* >( iResources ); |
357 { |
362 } |
358 TAny* property = NULL; |
363 |
359 |
364 return NULL; |
360 switch ( aProperty ) |
365 } |
361 { |
366 |
362 case EAiPublisherInfo: |
367 // --------------------------------------------------------------------------- |
363 { |
368 // CAiProfilePlugin::HandleEvent |
364 property = static_cast<TAiPublisherInfo*>( &iInfo ); |
369 // |
365 break; |
370 // --------------------------------------------------------------------------- |
366 } |
371 // |
367 |
372 void CAiProfilePlugin::HandleEvent( TInt aEvent, const TDesC& aParam ) |
368 case EAiPublisherContent: |
373 { |
369 { |
374 TRAP_IGNORE( iEngine->HandleAiEventL( aEvent, aParam ) ); |
370 property = static_cast<MAiContentItemIterator*>( iContent ); |
375 } |
371 break; |
376 |
372 } |
377 // --------------------------------------------------------------------------- |
373 |
378 // CAiProfilePlugin::DoResumeL |
374 case EAiPublisherEvents: |
379 // |
375 { |
380 // --------------------------------------------------------------------------- |
376 property = static_cast<MAiContentItemIterator*>( iEvents ); |
381 // |
377 break; |
382 void CAiProfilePlugin::DoResumeL() |
378 } |
383 { |
379 |
384 if( !iEngine ) |
380 case EAiPublisherResources: |
385 { |
381 property = static_cast<MAiContentItemIterator*>( iResources ); |
386 iEngine = CAiProfileEngine::NewL( this ); |
382 break; |
387 |
383 |
388 iEngine->UpdateProfileNamesL(); |
384 default: |
389 |
385 break; |
390 PublishL(); |
386 } |
|
387 |
|
388 return property; |
|
389 } |
|
390 |
|
391 // --------------------------------------------------------------------------- |
|
392 // From class MAiPropertyExtension |
|
393 // Write property value to optimize the content model. |
|
394 // --------------------------------------------------------------------------- |
|
395 // |
|
396 void CAiProfilePlugin::SetPropertyL( TInt aProperty, TAny* aValue ) |
|
397 { |
|
398 if( aProperty == EAiPublisherInfo ) |
|
399 { |
|
400 ASSERT( aValue ); |
|
401 |
|
402 const TAiPublisherInfo* info( |
|
403 static_cast<const TAiPublisherInfo*>( aValue ) ); |
|
404 |
|
405 iInfo = *info; |
|
406 } |
391 } |
407 } |
392 } |
408 |
393 |
409 // --------------------------------------------------------------------------- |
394 // --------------------------------------------------------------------------- |
410 // From class MAiEventHandlerExtension. |
395 // CAiProfilePlugin::NotifyContentUpdate() |
411 // Handles an event sent by the AI framework. |
396 // This method is called from the engine, when the profile data has changed |
412 // --------------------------------------------------------------------------- |
397 // --------------------------------------------------------------------------- |
413 // |
|
414 void CAiProfilePlugin::HandleEvent(TInt aEvent, const TDesC& aParam) |
|
415 { |
|
416 if ( iEngine ) |
|
417 { |
|
418 // We have no way of reporting errors to framework so just ignore them. |
|
419 TRAP_IGNORE( iEngine->HandleAiEventL( aEvent, aParam ) ); |
|
420 } |
|
421 } |
|
422 |
|
423 // --------------------------------------------------------- |
|
424 // This method is called from the engine, when the profile |
|
425 // data content has been changed. Method call is made through |
|
426 // the MAiProfilePluginNotifier interface. |
|
427 // --------------------------------------------------------- |
|
428 // |
398 // |
429 void CAiProfilePlugin::NotifyContentUpdate() |
399 void CAiProfilePlugin::NotifyContentUpdate() |
430 { |
400 { |
431 iIsUpdated = ETrue; |
|
432 |
|
433 TRAP_IGNORE( PublishL() ); |
401 TRAP_IGNORE( PublishL() ); |
434 } |
402 } |
435 |
403 |
436 // --------------------------------------------------------------------------- |
404 // --------------------------------------------------------------------------- |
437 // From class CAiContentPublisher |
405 // CAiProfilePlugin::CleanPublishedProfileNames |
438 // framework instructs plug-in that it is allowed to consume CPU resources |
|
439 // --------------------------------------------------------------------------- |
|
440 // |
|
441 void CAiProfilePlugin::DoResumeL( TAiTransitionReason aReason ) |
|
442 { |
|
443 if ( !iEngine ) |
|
444 { |
|
445 iEngine = CAiProfileEngine::NewL( this ); |
|
446 } |
|
447 |
|
448 //update in startup phase and idle is on foreground. |
|
449 if( aReason != EAiBacklightOff && aReason != EAiIdleBackground ) |
|
450 { |
|
451 // force republish in case layout has changed |
|
452 if ( aReason == EAiScreenLayoutChanged ) |
|
453 { |
|
454 delete iPreviousProfileNameAndChar; |
|
455 iPreviousProfileNameAndChar = NULL; |
|
456 } |
|
457 |
|
458 if ( !iAlive ) |
|
459 { |
|
460 iEngine->ResumeL(); |
|
461 } |
|
462 |
|
463 iEngine->UpdateProfileNamesL(); |
|
464 |
|
465 PublishL(); |
|
466 iAlive = ETrue; |
|
467 } |
|
468 } |
|
469 |
|
470 // --------------------------------------------------------------------------- |
|
471 // Frees engine resources |
|
472 // --------------------------------------------------------------------------- |
|
473 // |
|
474 void CAiProfilePlugin::FreeEngine() |
|
475 { |
|
476 delete iEngine; |
|
477 iEngine = NULL; |
|
478 iAlive = EFalse; |
|
479 } |
|
480 |
|
481 // --------------------------------------------------------------------------- |
|
482 // Clean profile names from content |
406 // Clean profile names from content |
483 // --------------------------------------------------------------------------- |
407 // --------------------------------------------------------------------------- |
484 // |
408 // |
485 void CAiProfilePlugin::CleanPublishedProfileNames() |
409 void CAiProfilePlugin::CleanPublishedProfileNames() |
486 { |
410 { |
487 TInt obsCount( iObservers.Count() ); |
411 TInt obsCount( iObservers.Count() ); |
|
412 |
488 for ( TInt i( 0 ); i < obsCount; i++ ) |
413 for ( TInt i( 0 ); i < obsCount; i++ ) |
489 { |
414 { |
490 MAiContentObserver* observer = iObservers[i]; |
415 MAiContentObserver* observer( iObservers[i] ); |
491 for( TInt j( 0 ); j < iCurrentCount && observer; j++ ) |
416 |
|
417 for ( TInt j( 0 ); j < iCurrentCount && observer; j++ ) |
492 { |
418 { |
493 observer->Clean( *this, EAiProfileContentProfileName, j + 1 ); |
419 observer->Clean( *this, EAiProfileContentProfileName, j + 1 ); |
494 } |
420 } |
495 } |
421 } |
496 } |
422 } |