idlefw/plugins/wrtdataplugin/src/wrtdataplugin.cpp
branchRCL_3
changeset 17 cb506ec2d869
parent 16 b276298d5729
child 19 edd621764147
equal deleted inserted replaced
13:c2817bb2a55c 17:cb506ec2d869
    32 #include <aicontentobserver.h>
    32 #include <aicontentobserver.h>
    33 #include <aiutility.h>
    33 #include <aiutility.h>
    34 #include <aipspropertyobserver.h>
    34 #include <aipspropertyobserver.h>
    35 #include <aipluginsettings.h>
    35 #include <aipluginsettings.h>
    36 #include <activeidle2domainpskeys.h>
    36 #include <activeidle2domainpskeys.h>
       
    37 #include <debug.h>
    37 
    38 
    38 #include "wrtdatapluginconst.h"
    39 #include "wrtdatapluginconst.h"
    39 #include "wrtdatapluginuids.hrh"
    40 #include "wrtdatapluginuids.hrh"
    40 #include "wrtdataplugin.h"
    41 #include "wrtdataplugin.h"
    41 #include "wrtdata.h"
    42 #include "wrtdata.h"
    43 // Constants
    44 // Constants
    44 const TImplementationProxy KImplementationTable[] =
    45 const TImplementationProxy KImplementationTable[] =
    45     {
    46     {
    46     IMPLEMENTATION_PROXY_ENTRY( KImplUidDataPlugin, CWrtDataPlugin::NewL ) 
    47     IMPLEMENTATION_PROXY_ENTRY( KImplUidDataPlugin, CWrtDataPlugin::NewL ) 
    47     };
    48     };
       
    49 
       
    50 const TInt KTryAgainDelay( 3000000 ); // 3 sec
    48 
    51 
    49 // ======== MEMBER FUNCTIONS ========
    52 // ======== MEMBER FUNCTIONS ========
    50 // ---------------------------------------------------------------------------
    53 // ---------------------------------------------------------------------------
    51 // ImplementationGroupProxy
    54 // ImplementationGroupProxy
    52 //
    55 //
   102 // Deletes all data created to heap
   105 // Deletes all data created to heap
   103 // ---------------------------------------------------------------------------
   106 // ---------------------------------------------------------------------------
   104 //
   107 //
   105 CWrtDataPlugin::~CWrtDataPlugin()
   108 CWrtDataPlugin::~CWrtDataPlugin()
   106     {
   109     {
       
   110     if ( iTimer )
       
   111         {
       
   112         iTimer->Cancel();
       
   113         delete iTimer;
       
   114         }
       
   115 
   107     delete iData;
   116     delete iData;
   108     iObservers.Close();
   117     iObservers.Close();
   109     Release( iContent );
   118     Release( iContent );
   110     iDataArray.ResetAndDestroy();
   119     iDataArray.ResetAndDestroy();
   111 
   120 
   130 void CWrtDataPlugin::Start( TStartReason aReason )
   139 void CWrtDataPlugin::Start( TStartReason aReason )
   131     {
   140     {
   132     if( aReason == ESystemStartup || 
   141     if( aReason == ESystemStartup || 
   133         aReason == EPluginStartup )
   142         aReason == EPluginStartup )
   134         {
   143         {
   135         // publish the initial data
   144         // Publish the initial data
   136         TRAP_IGNORE( PublishL());
   145         TRAP_IGNORE( PublishInitialDataL() );
   137         }
   146         }
   138     }
   147     }
   139 
   148 
   140 // ----------------------------------------------------------------------------
   149 // ----------------------------------------------------------------------------
   141 // CWrtDataPlugin::Stop
   150 // CWrtDataPlugin::Stop
   145 void CWrtDataPlugin::Stop( TStopReason aReason )
   154 void CWrtDataPlugin::Stop( TStopReason aReason )
   146     {
   155     {
   147     if( aReason == EPluginShutdown ||
   156     if( aReason == EPluginShutdown ||
   148         aReason == ESystemShutdown )
   157         aReason == ESystemShutdown )
   149         {
   158         {
   150         TRAP_IGNORE(iData->DeActivateL());
   159         TRAP_IGNORE(iData->NotifyPublisherL( KDeActive ));
   151         }
   160         }
   152     }
   161     }
   153 
   162 
   154 // ----------------------------------------------------------------------------
   163 // ----------------------------------------------------------------------------
   155 // CWrtDataPlugin::Resume
   164 // CWrtDataPlugin::Resume
   160     {
   169     {
   161     if ( aReason == EForeground )
   170     if ( aReason == EForeground )
   162         {
   171         {
   163         iPluginState = EResume;
   172         iPluginState = EResume;
   164 
   173 
   165         TRAP_IGNORE( iData->ResumeL() );        
   174         TRAP_IGNORE( iData->NotifyPublisherL( KResume ));        
   166         }    
   175         }    
   167     }
   176     }
   168 
   177 
   169 // ----------------------------------------------------------------------------
   178 // ----------------------------------------------------------------------------
   170 // CWrtDataPlugin::Suspend
   179 // CWrtDataPlugin::Suspend
   175     {    
   184     {    
   176     if ( aReason == EBackground )
   185     if ( aReason == EBackground )
   177         {
   186         {
   178         iPluginState = ESuspend;
   187         iPluginState = ESuspend;
   179         
   188         
   180         TRAP_IGNORE ( iData->SuspendL() );        
   189         TRAP_IGNORE ( iData->NotifyPublisherL( KSuspend ));        
   181         }        
   190         }        
   182     }
   191     }
   183 
   192 
   184 // ----------------------------------------------------------------------------
   193 // ----------------------------------------------------------------------------
   185 // CWrtDataPlugin::SetOnline
   194 // CWrtDataPlugin::SetOnline
   186 //
   195 //
   187 // ----------------------------------------------------------------------------
   196 // ----------------------------------------------------------------------------
   188 //
   197 //
   189 void CWrtDataPlugin::SetOnline()
   198 void CWrtDataPlugin::SetOnline()
   190     {    
   199     {    
   191     if ( iNetworkStatus != EOnline )
   200     iNetworkStatus = EOnline;
   192         {
   201     TRAP_IGNORE( iData->NotifyPublisherL( KOnLine ));            
   193         iNetworkStatus = EOnline;
       
   194         
       
   195         TRAP_IGNORE( iData->OnLineL() );            
       
   196         }    
       
   197     }
   202     }
   198 
   203 
   199 // ----------------------------------------------------------------------------
   204 // ----------------------------------------------------------------------------
   200 // CWrtDataPlugin::SetOffline
   205 // CWrtDataPlugin::SetOffline
   201 //
   206 //
   202 // ----------------------------------------------------------------------------
   207 // ----------------------------------------------------------------------------
   203 //
   208 //
   204 void CWrtDataPlugin::SetOffline()
   209 void CWrtDataPlugin::SetOffline()
   205     {
   210     {
   206     if ( iNetworkStatus != EOffline )
   211     iNetworkStatus = EOffline;
   207         {
   212     TRAP_IGNORE( iData->NotifyPublisherL( KOffLine ));            
   208         iNetworkStatus = EOffline;
       
   209         
       
   210         TRAP_IGNORE( iData->OffLineL() );            
       
   211         }    
       
   212     }
   213     }
   213 
   214 
   214 // ----------------------------------------------------------------------------
   215 // ----------------------------------------------------------------------------
   215 // CWrtDataPlugin::SubscribeL
   216 // CWrtDataPlugin::SubscribeL
   216 //
   217 //
   235          return;
   236          return;
   236         }
   237         }
   237     
   238     
   238     RAiSettingsItemArray contentItemsArr;
   239     RAiSettingsItemArray contentItemsArr;
   239     RAiSettingsItemArray configurationItemsArr;
   240     RAiSettingsItemArray configurationItemsArr;
   240     RAiSettingsItemArray settingItemsArr;
       
   241     
       
   242     TInt count( aSettings.Count() );
   241     TInt count( aSettings.Count() );
   243     
   242     
   244     for ( TInt i = 0; i < count; i++ )
   243     for ( TInt i = 0; i < count; i++ )
   245         {
   244         {
   246         MAiPluginSettings* setting( aSettings[i] );
   245         MAiPluginSettings* setting( aSettings[i] );
   250             contentItemsArr.Append( setting );
   249             contentItemsArr.Append( setting );
   251             }
   250             }
   252         else if( setting->AiPluginItemType() == EAiPluginConfigurationItem )
   251         else if( setting->AiPluginItemType() == EAiPluginConfigurationItem )
   253             {
   252             {
   254             configurationItemsArr.Append( setting );
   253             configurationItemsArr.Append( setting );
   255             }
       
   256         else 
       
   257             {
       
   258             settingItemsArr.Append( setting );
       
   259             }
   254             }
   260         }
   255         }
   261     
   256     
   262     iDataCount = contentItemsArr.Count();
   257     iDataCount = contentItemsArr.Count();
   263     
   258     
   313 
   308 
   314         // Register for notifications
   309         // Register for notifications
   315         iData->RegisterL();
   310         iData->RegisterL();
   316         
   311         
   317         // Activate the publisher 
   312         // Activate the publisher 
   318         iData->ActivateL();
   313         iData->NotifyPublisherL( KActive );
   319         }
   314         }
   320     
   315     
   321     settingItemsArr.Reset();
       
   322     contentItemsArr.Reset();
   316     contentItemsArr.Reset();
   323     configurationItemsArr.Reset();
   317     configurationItemsArr.Reset();
   324     
   318     // We own the array so destroy it
   325        // We own the array so destroy it
       
   326     aSettings.ResetAndDestroy();
   319     aSettings.ResetAndDestroy();
       
   320     }
       
   321 
       
   322 // ----------------------------------------------------------------------------
       
   323 // CWrtDataPlugin::SetProperty
       
   324 //
       
   325 // ----------------------------------------------------------------------------
       
   326 //
       
   327 void CWrtDataPlugin::SetProperty( TProperty aProperty, TAny* aAny )
       
   328     {
       
   329     if (aProperty == ECpsCmdBuffer )
       
   330         {   
       
   331         iData->SetCommandBuffer( aAny, PublisherInfo().Namespace() );
       
   332         }
   327     }
   333     }
   328 
   334 
   329 // ----------------------------------------------------------------------------
   335 // ----------------------------------------------------------------------------
   330 // CWrtDataPlugin::GetProperty
   336 // CWrtDataPlugin::GetProperty
   331 //
   337 //
   348 //
   354 //
   349 void CWrtDataPlugin::HandleEvent( const TDesC& aEventName, 
   355 void CWrtDataPlugin::HandleEvent( const TDesC& aEventName, 
   350     const TDesC& aParam )
   356     const TDesC& aParam )
   351     {
   357     {
   352     TRAP_IGNORE( iData->ExecuteActionL( aEventName , aParam ) );    
   358     TRAP_IGNORE( iData->ExecuteActionL( aEventName , aParam ) );    
   353     }
       
   354 
       
   355 // ----------------------------------------------------------------------------
       
   356 // CWrtDataPlugin::HasMenuItem
       
   357 //
       
   358 // ----------------------------------------------------------------------------
       
   359 //
       
   360 TBool CWrtDataPlugin::HasMenuItem( const TDesC& aMenuItem )
       
   361     {
       
   362     return iData->HasMenuItem ( aMenuItem );
       
   363     }
   359     }
   364 
   360 
   365 // ----------------------------------------------------------------------------
   361 // ----------------------------------------------------------------------------
   366 // CWrtDataPlugin::IsActive
   362 // CWrtDataPlugin::IsActive
   367 //
   363 //
   441         }
   437         }
   442     CleanupStack::PopAndDestroy( objectId );
   438     CleanupStack::PopAndDestroy( objectId );
   443     }
   439     }
   444 
   440 
   445 // ---------------------------------------------------------------------------
   441 // ---------------------------------------------------------------------------
   446 //Refresh a specific image of text in the widget
   442 //Refresh a specific image or text in the widget
   447 // ---------------------------------------------------------------------------
   443 // ---------------------------------------------------------------------------
   448 //
   444 //
   449 void CWrtDataPlugin::RefreshL( TDesC16& aOperation, CLiwDefaultMap* aDataMap )
   445 void CWrtDataPlugin::RefreshL( TDesC16& aOperation, CLiwDefaultMap* aDataMap )
   450     {
   446     {
       
   447     __PRINTS("*** CWrtDataPlugin::RefreshL ***");
       
   448     
       
   449     __PRINT( __DBG_FORMAT( "* Publisher name: %S, uid: 0x%x, operation: %S" ),          
       
   450         &PublisherInfo().Name(), PublisherInfo().Uid().iUid, &aOperation ); 
       
   451     
   451     TInt observers( iObservers.Count() );        
   452     TInt observers( iObservers.Count() );        
   452     TInt transactionId = reinterpret_cast<TInt>( this );
   453     TInt transactionId = reinterpret_cast<TInt>( this );
   453     
   454     
   454     for ( TInt obsIndex = 0; obsIndex < observers; obsIndex++ )
   455     for ( TInt obsIndex = 0; obsIndex < observers; obsIndex++ )
   455         {
   456         {
   474         // Relese memory of the published text
   475         // Relese memory of the published text
   475         iDataArray.ResetAndDestroy();
   476         iDataArray.ResetAndDestroy();
   476         // Release memory of the published icons
   477         // Release memory of the published icons
   477         iIconArray.Reset();
   478         iIconArray.Reset();
   478         }
   479         }
       
   480     
       
   481     __PRINTS("*** CWrtDataPlugin::RefreshL - done ***");        
   479     }
   482     }
   480 
   483 
   481 // ---------------------------------------------------------------------------
   484 // ---------------------------------------------------------------------------
   482 // Publish a specific text of the widget  
   485 // Publish a specific text of the widget  
   483 // ---------------------------------------------------------------------------
   486 // ---------------------------------------------------------------------------
   664 // ---------------------------------------------------------------------------
   667 // ---------------------------------------------------------------------------
   665 //
   668 //
   666 void CWrtDataPlugin::HideLoadingIcon(MAiContentObserver* aObserver)
   669 void CWrtDataPlugin::HideLoadingIcon(MAiContentObserver* aObserver)
   667     {
   670     {
   668     aObserver->SetProperty( *this, KElement , KDisplay , KHide );
   671     aObserver->SetProperty( *this, KElement , KDisplay , KHide );
       
   672 
       
   673     // Do not try to publish initial data anymore
       
   674     StopTimer();
   669     }
   675     }
   670 
   676 
   671 // ---------------------------------------------------------------------------
   677 // ---------------------------------------------------------------------------
   672 // Publishes widget's texts and images
   678 // Publishes widget's texts and images
   673 // ---------------------------------------------------------------------------
   679 // ---------------------------------------------------------------------------
   674 //
   680 //
   675 void CWrtDataPlugin::PublishL()
   681 void CWrtDataPlugin::PublishInitialDataL()
   676     {
   682     {
   677     TInt observers( iObservers.Count() );        
   683     TInt observers( iObservers.Count() );        
   678     TInt transactionId = reinterpret_cast<TInt>( this );
   684     TInt transactionId = reinterpret_cast<TInt>( this );
   679 
   685 
   680     for ( int i = 0; i < observers; i++ )
   686     for ( int i = 0; i < observers; i++ )
   681         {
   687         {
   682         MAiContentObserver* observer = iObservers[i];
   688         MAiContentObserver* observer = iObservers[i];
   683                 
   689 
       
   690         CleanupStack::PushL( TCleanupItem( CancelTransaction, observer ) );
       
   691 
   684         if ( observer->StartTransaction( transactionId ) == KErrNone )           
   692         if ( observer->StartTransaction( transactionId ) == KErrNone )           
   685             {// Publish default data
   693             {// Publish default data
   686             iData->PublishDefaultImageL(observer);
   694             iData->PublishInitialDataL(observer);
   687             observer->Commit( transactionId );
   695             observer->Commit( transactionId );
   688             }
   696             }
       
   697 
       
   698 		CleanupStack::Pop( observer );
   689 
   699 
   690         // Release memory of the published text
   700         // Release memory of the published text
   691         iDataArray.ResetAndDestroy();
   701         iDataArray.ResetAndDestroy();
   692         // Release memory of the published icons
   702         // Release memory of the published icons
   693         iIconArray.Reset();
   703         iIconArray.Reset();
   772            }
   782            }
   773        }
   783        }
   774    return (error == KErrNone );
   784    return (error == KErrNone );
   775    }
   785    }
   776 
   786 
       
   787 // ---------------------------------------------------------------------------
       
   788 // Cleanup callback for cancelling a transactions in case of leave
       
   789 // ---------------------------------------------------------------------------
       
   790 //
       
   791 void CWrtDataPlugin::CancelTransaction( TAny* aObserver )
       
   792     {
       
   793     if ( aObserver )
       
   794         {
       
   795         MAiContentObserver* obs = reinterpret_cast< MAiContentObserver*>( aObserver );
       
   796         TInt transactionId = reinterpret_cast<TInt>( aObserver );
       
   797         obs->CancelTransaction( transactionId );
       
   798         }
       
   799     }
       
   800 
       
   801 // ---------------------------------------------------------------------------
       
   802 // Create and start republish timer
       
   803 // ---------------------------------------------------------------------------
       
   804 //
       
   805 void CWrtDataPlugin::StartTimer()
       
   806     {
       
   807     TRAP_IGNORE(
       
   808         if ( !iTimer )
       
   809             {
       
   810             iTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   811             }
       
   812         
       
   813         if ( !iTimer->IsActive() )
       
   814             {
       
   815             TTimeIntervalMicroSeconds32 delay( KTryAgainDelay );
       
   816             iTimer->Start( delay, delay, TCallBack( Timeout, this ) );
       
   817             }
       
   818         );
       
   819     }
       
   820 
       
   821 // ---------------------------------------------------------------------------
       
   822 // Cancel republish timer
       
   823 // ---------------------------------------------------------------------------
       
   824 //
       
   825 void CWrtDataPlugin::CancelTimer()
       
   826     {
       
   827     if ( iTimer )
       
   828         {
       
   829         iTimer->Cancel();
       
   830         }
       
   831     }
       
   832 
       
   833 // ---------------------------------------------------------------------------
       
   834 // Stop and delete republish timer
       
   835 // ---------------------------------------------------------------------------
       
   836 //
       
   837 void CWrtDataPlugin::StopTimer()
       
   838     {
       
   839     if ( iTimer )
       
   840         {
       
   841         iTimer->Cancel();
       
   842         delete iTimer;
       
   843         iTimer = NULL;
       
   844         }
       
   845     }
       
   846 
       
   847 // ---------------------------------------------------------------------------
       
   848 // Initial data republish callback
       
   849 // ---------------------------------------------------------------------------
       
   850 //
       
   851 TInt CWrtDataPlugin::Timeout( TAny* aPtr )
       
   852     {
       
   853     CWrtDataPlugin* self = static_cast<CWrtDataPlugin*>( aPtr );
       
   854 
       
   855     // Cancel timer before publishing
       
   856     self->CancelTimer();
       
   857 
       
   858     TInt observers( self->iObservers.Count() );        
       
   859     TInt transactionId = reinterpret_cast<TInt>( self );
       
   860     TBool success( ETrue );
       
   861 
       
   862     // Publish for each observer
       
   863     for ( int i = 0; i < observers; i++ )
       
   864         {
       
   865         MAiContentObserver* observer = self->iObservers[i];
       
   866 
       
   867         if ( observer->StartTransaction( transactionId ) == KErrNone )           
       
   868             {
       
   869             // Publish default image
       
   870             TRAPD( err, self->iData->PublishDefaultImageL( observer ) );
       
   871             if ( KErrNone != err )
       
   872                 {
       
   873                 observer->CancelTransaction( transactionId );
       
   874                 success = EFalse;
       
   875                 }
       
   876             else
       
   877                 {
       
   878                 // 
       
   879                 observer->Commit( transactionId );
       
   880                 }
       
   881             }
       
   882         }
       
   883 
       
   884     // Start timer again if there is error in publishing
       
   885     if ( !success )
       
   886         {
       
   887         self->StartTimer();
       
   888         }
       
   889     else
       
   890         {
       
   891         self->StopTimer();
       
   892         }
       
   893 
       
   894     // Release memory of the published icons
       
   895     self->iIconArray.Reset();
       
   896 
       
   897     return KErrNone;
       
   898     }
       
   899 
       
   900 
       
   901 
   777 // End of file
   902 // End of file