diff -r 1a2a00e78665 -r d0529222e3f0 idlefw/plugins/sapidataplugin/src/sapidataplugin.cpp --- a/idlefw/plugins/sapidataplugin/src/sapidataplugin.cpp Tue Feb 02 00:23:10 2010 +0200 +++ b/idlefw/plugins/sapidataplugin/src/sapidataplugin.cpp Fri Feb 19 23:07:29 2010 +0200 @@ -11,18 +11,14 @@ * * Contributors: * -* Description: Profile plug-in publisher +* Description: SAPI data plug-in publisher * */ - +// System includes #include #include -#include -#include -#include #include -#include #include #include #include @@ -30,6 +26,13 @@ #include #include #include + +// User includes +#include +#include +#include +#include +#include #include #include "sapidatapluginconst.h" @@ -37,7 +40,7 @@ #include "sapidataplugin.h" #include "sapidata.h" -// CONST CLASS VARIABLES +// Constants const TImplementationProxy KImplementationTable[] = { IMPLEMENTATION_PROXY_ENTRY( KImplUidDataPlugin, CSapiDataPlugin::NewL ) @@ -75,6 +78,7 @@ // --------------------------------------------------------------------------- // CSapiDataPlugin::CSapiDataPlugin() + : iNetworkStatus( EUnknown ), iPluginState( ENone ) { } @@ -83,14 +87,10 @@ // --------------------------------------------------------------------------- // void CSapiDataPlugin::ConstructL() - { - iInfo.iUid.iUid = SAPIDP_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_DATAPLUGIN; - iPluginState = ENone; - iHSForeGround = EFalse; - iKeyLockOn = EFalse; - iNetworkStatus = EUnknown; - iData = CSapiData::NewL(this); - + { + User::LeaveIfError( iRfs.Connect() ); + + iData = CSapiData::NewL( this ); } // --------------------------------------------------------------------------- @@ -101,123 +101,44 @@ CSapiDataPlugin::~CSapiDataPlugin() { // deactivate the publishers - if( iData ) + if ( iData ) { - TRAP_IGNORE(iData->DeActivateL()); + TRAP_IGNORE( iData->ChangePublisherStatusL( KDeActive )); + delete iData; } + iObservers.Close(); Release( iContent ); + iDataArray.ResetAndDestroy(); - if( iContentModel) + if ( iContentModel ) { - for( TInt i = iDataCount-1;i>=0 ; i-- ) + for ( TInt i = iDataCount - 1; i >= 0 ; i-- ) { User::Free((TAny*)iContentModel[i].cid); } - delete []iContentModel; - } - iIconArray.Reset(); - } - -// --------------------------------------------------------------------------- -// From class CAiContentPublisher -// Plug-ins take ownership of the settings array, so it must either -// store it in a member or free it. -// --------------------------------------------------------------------------- -// -void CSapiDataPlugin::ConfigureL( RAiSettingsItemArray& aSettings ) - { - if( iDataCount > 0 ) - { - // We own the array so destroy it - aSettings.ResetAndDestroy(); - return; + + delete [] iContentModel; } - RAiSettingsItemArray contentItemsArr; - RAiSettingsItemArray configurationItemsArr; + iIconArray.Reset(); - TInt count = aSettings.Count(); - for(TInt i = 0; i < count; i++ ) - { - MAiPluginSettings* pluginSetting = aSettings[i]; - if( pluginSetting->AiPluginItemType() == EAiPluginContentItem ) - { - contentItemsArr.Append(pluginSetting); - } - else if( pluginSetting->AiPluginItemType() == EAiPluginConfigurationItem ) - { - configurationItemsArr.Append(pluginSetting); - } - } - iDataCount = contentItemsArr.Count(); - if(iDataCount > 0 ) - { - // Create the content Model - HBufC* contentId = HBufC::NewLC( KAiContentIdMaxLength + KAiPluginNameMaxLength ); - iContentModel = new TAiContentItem[iDataCount]; - for(TInt i = 0; i < iDataCount; i++) - { - MAiPluginContentItem& contentItem = (contentItemsArr[i])->AiPluginContentItem(); - iContentModel[i].id = i; - if( contentItem.Type() == KText() || contentItem.Type() == KNewsTicker() ) - { - // text - iContentModel[i].type = KAiContentTypeText; - } - if( contentItem.Type() == KImage() ) - { - // image - iContentModel[i].type = KAiContentTypeBitmap; - } - - contentId->Des().Copy(contentItem.Name()); - contentId->Des().Delete(0, contentId->Des().LocateReverse(KPluginNameSeprator) +1); - - TInt sizeOfContentId = contentId->Des().Size()+sizeof(wchar_t); - iContentModel[i].cid = static_cast( User::Alloc( sizeOfContentId ) ); - Mem::Copy((TAny*)iContentModel[i].cid, contentId->Des().PtrZ(), sizeOfContentId); - - contentId->Des().Delete( 0, contentId->Des().Length()); - } - - CleanupStack::PopAndDestroy( contentId ); - iContent = AiUtility::CreateContentItemArrayIteratorL( iContentModel, iDataCount ); - // Configurations - iData->ConfigureL(configurationItemsArr); - - // Activate the publisher - iData->ActivateL(); - - // Register for notifications - iData->RegisterPublisherObserverL(); - - PublishL(); - - iPluginState = ESuspend; - iData->RegisterContentObserverL(); - } - contentItemsArr.Reset(); - configurationItemsArr.Reset(); - // We own the array so destroy it - aSettings.ResetAndDestroy(); - // publish the initial data + iRfs.Close(); } + // --------------------------------------------------------------------------- // Publishes widget's texts and images // --------------------------------------------------------------------------- // void CSapiDataPlugin::PublishL() - { - User::LeaveIfError( iRfs.Connect() ); - + { TInt observers( iObservers.Count() ); TInt transactionId = reinterpret_cast( this ); - for ( int i = 0; i < observers; i++ ) + for ( TInt i = 0; i < observers; i++ ) { MAiContentObserver* observer = iObservers[i]; @@ -233,8 +154,7 @@ // Release memory of the published icons iIconArray.Reset(); - } - iRfs.Close(); + } } // --------------------------------------------------------------------------- @@ -340,19 +260,20 @@ } else // Interpret as File path { - RFile* iconFile = new (ELeave) RFile(); - err = iconFile->Open( iRfs, aPath, EFileShareReadersOnly | EFileRead ); + RFile iconFile; + + err = iconFile.Open( iRfs, aPath, EFileShareReadersOnly | EFileRead ); + if( err == KErrNone ) { - aObserver->Publish( *this, aContentId, *iconFile, aContentId ); + aObserver->Publish( *this, aContentId, iconFile, aContentId ); } else { aObserver->Clean( *this, aContentId, aContentId ); } - iconFile->Close(); - delete iconFile; - iconFile = NULL; + + iconFile.Close(); } } } @@ -442,8 +363,7 @@ // --------------------------------------------------------------------------- // void CSapiDataPlugin::RefreshL(TDesC& aContentType, TDesC& aOperation) - { - User::LeaveIfError( iRfs.Connect() ); + { TInt observers( iObservers.Count() ); TInt transactionId = reinterpret_cast( this ); @@ -468,8 +388,7 @@ // Relese memory of the published text iDataArray.ResetAndDestroy(); iIconArray.Reset(); - } - iRfs.Close(); + } } // --------------------------------------------------------------------------- @@ -483,269 +402,287 @@ { aObserver->Clean( *this, aContentId, aContentId ); } + } - } -// --------------------------------------------------------------------------- -// From class CAiContentPublisher -// Plug-in is requested to unload its engines due backup operation -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::Start +// +// ---------------------------------------------------------------------------- +// +void CSapiDataPlugin::Start( TStartReason aReason ) + { + if( aReason == ESystemStartup ) + { + TRAP_IGNORE( iData->SetStartupReasonL( KSystemStartup )); + } + else if( aReason == EPageStartup ) + { + TRAP_IGNORE( iData->SetStartupReasonL( KPageStartup )); + } + else if( aReason == EPluginStartup ) + { + TRAP_IGNORE( iData->SetStartupReasonL( KPluginStartup)); + } + } + +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::Stop +// +// ---------------------------------------------------------------------------- +// +void CSapiDataPlugin::Stop( TStopReason aReason ) + { + if( aReason == ESystemShutdown ) + { + TRAP_IGNORE( iData->ChangePublisherStatusL( KSystemShutdown )); + } + else if( aReason == EPageShutdown ) + { + TRAP_IGNORE( iData->ChangePublisherStatusL( KPageShutdown )); + } + else if( aReason == EPluginShutdown ) + { + TRAP_IGNORE( iData->ChangePublisherStatusL( KPluginShutdown )); + } + } + +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::Resume +// +// ---------------------------------------------------------------------------- // -void CSapiDataPlugin::Stop( TAiTransitionReason aReason ) +void CSapiDataPlugin::Resume( TResumeReason aReason ) + { + if ( aReason == EForeground ) + { + iPluginState = EResume; + TRAP_IGNORE( iData->ChangePublisherStatusL( KResume )); + } + } + +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::Suspend +// +// ---------------------------------------------------------------------------- +// +void CSapiDataPlugin::Suspend( TSuspendReason aReason ) { - if( iPluginState == EResume ) + if ( aReason == EBackground ) + { + iPluginState = ESuspend; + TRAP_IGNORE( iData->ChangePublisherStatusL( KSuspend )); + } + } + +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::SetOnline +// +// ---------------------------------------------------------------------------- +// +void CSapiDataPlugin::SetOnline() + { + if ( iNetworkStatus != EOnline ) { - Suspend( aReason ); + iNetworkStatus = EOnline; + TRAP_IGNORE( iData->ChangePublisherStatusL( KOnLine )); + } + } + +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::SetOffline +// +// ---------------------------------------------------------------------------- +// +void CSapiDataPlugin::SetOffline() + { + if ( iNetworkStatus != EOffline ) + { + iNetworkStatus = EOffline; + TRAP_IGNORE( iData->ChangePublisherStatusL( KOffLine )); } } -// --------------------------------------------------------------------------- -// From class CAiContentPublisher -// Plug-in is instructed that it is allowed to consume CPU resources -// --------------------------------------------------------------------------- -// -void CSapiDataPlugin::Resume( TAiTransitionReason aReason ) - { - TRAP_IGNORE( DoResumeL( aReason ) ); - } - -// --------------------------------------------------------------------------- -// From class CAiContentPublisher -// Plug-in is instructed that it is not allowed to consume CPU resources -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::SubscribeL // -void CSapiDataPlugin::Suspend( TAiTransitionReason aReason ) - { - switch( aReason ) - { - case EAiKeylockDisabled: - case EAiKeylockEnabled: - { - // handled in resume - TRAP_IGNORE( DoResumeL( aReason ) ); - break; - } - default : - { - iPluginState = ESuspend; - TRAP_IGNORE ( iData->SuspendL() ); - } - } - } - -// --------------------------------------------------------------------------- -// From class CAiContentPublisher -// The plug-in MUST maintain a registry of subscribers and send -// notification to all of them whenever the state changes or new content -// is available -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- // void CSapiDataPlugin::SubscribeL( MAiContentObserver& aObserver ) - { + { iObservers.AppendL( &aObserver ); } - -// --------------------------------------------------------------------------- -// From class CAiContentPublisher -// Returns the extension interface. Actual type depends on the passed -// aUid argument. -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::ConfigureL +// +// ---------------------------------------------------------------------------- // -TAny* CSapiDataPlugin::Extension( TUid aUid ) - { - if ( aUid == KExtensionUidProperty ) - { - return static_cast( this ); - } - else if (aUid == KExtensionUidEventHandler) - { - return static_cast( this ); - } - else - { - return NULL; - } +void CSapiDataPlugin::ConfigureL( RAiSettingsItemArray& aSettings ) + { + if ( iDataCount > 0 ) + { + // We own the array so destroy it + aSettings.ResetAndDestroy(); + return; + } + + RAiSettingsItemArray contentItemsArr; + RAiSettingsItemArray configurationItemsArr; + + TInt count( aSettings.Count() ); + + for ( TInt i = 0; i < count; i++ ) + { + MAiPluginSettings* setting( aSettings[i] ); + + if ( setting->AiPluginItemType() == EAiPluginContentItem ) + { + contentItemsArr.Append( setting ); + } + else if ( setting->AiPluginItemType() == EAiPluginConfigurationItem ) + { + configurationItemsArr.Append( setting ); + } + } + + iDataCount = contentItemsArr.Count(); + + if ( iDataCount > 0 ) + { + // Create the content Model + HBufC* contentId = HBufC::NewLC( + KAiContentIdMaxLength + KAiPluginNameMaxLength ); + + iContentModel = new TAiContentItem[iDataCount]; + + for ( TInt i = 0; i < iDataCount; i++ ) + { + MAiPluginContentItem& contentItem( + contentItemsArr[i]->AiPluginContentItem() ); + + iContentModel[i].id = i; + + if( contentItem.Type() == KText() || + contentItem.Type() == KNewsTicker() || + contentItem.Type() == KTextEditor() ) + { + // text + iContentModel[i].type = KAiContentTypeText; + } + if( contentItem.Type() == KImage() ) + { + // image + iContentModel[i].type = KAiContentTypeBitmap; + } + + contentId->Des().Copy( contentItem.Name() ); + contentId->Des().Delete( 0, + contentId->Des().LocateReverse( KPluginNameSeprator ) + 1 ); + + TInt sizeOfContentId( contentId->Des().Size() + sizeof( wchar_t ) ); + + iContentModel[i].cid = + static_cast< const wchar_t* >( User::Alloc( sizeOfContentId ) ); + + Mem::Copy( ( TAny* )iContentModel[i].cid, + contentId->Des().PtrZ(), sizeOfContentId ); + + contentId->Des().Delete( 0, contentId->Des().Length() ); + } + + CleanupStack::PopAndDestroy( contentId ); + + iContent = AiUtility::CreateContentItemArrayIteratorL( + iContentModel, iDataCount ); + + iData->SetContentIdL( PublisherInfo().Namespace() ); + + // Configurations + iData->ConfigureL( configurationItemsArr ); + + // Activate the publisher + iData->ChangePublisherStatusL( KActive ); + + // Register for notifications + iData->RegisterPublisherObserverL(); + + PublishL(); + + iPluginState = ESuspend; + + iData->RegisterContentObserverL(); + } + + contentItemsArr.Reset(); + configurationItemsArr.Reset(); + + // We own the array so destroy it + aSettings.ResetAndDestroy(); } -// --------------------------------------------------------------------------- -// From class MAiPropertyExtension -// Read property of publisher plug-in. -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::GetProperty // -TAny* CSapiDataPlugin::GetPropertyL( TInt aProperty ) - { - TAny* property = NULL; - - switch ( aProperty ) - { - case EAiPublisherInfo: +// ---------------------------------------------------------------------------- +// +TAny* CSapiDataPlugin::GetProperty( TProperty aProperty ) + { + if ( aProperty == EPublisherContent ) { - property = static_cast( &iInfo ); - break; - } - - case EAiPublisherContent: - { - property = static_cast( iContent ); - break; - } - default: - break; + return static_cast< MAiContentItemIterator* >( iContent ); } - - return property; + + return NULL; } -// --------------------------------------------------------------------------- -// From class MAiPropertyExtension -// Write property value to optimize the content model. -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::HandleEvent // -void CSapiDataPlugin::SetPropertyL( TInt aProperty, TAny* aValue ) - { - if( aProperty == EAiPublisherInfo ) - { - ASSERT( aValue ); - - const TAiPublisherInfo* info( - static_cast( aValue ) ); - - iInfo = *info; - - iData->SetContentIdL( info->iNamespace ); - } - } - -// --------------------------------------------------------------------------- -// From class MAiEventHandlerExtension. -// Handles an event sent by the AI framework. -// --------------------------------------------------------------------------- -// -void CSapiDataPlugin::HandleEvent( TInt /*aEvent*/, const TDesC& /*aParam*/ ) - { - // This is not as there is no event id to retrieve in this dynamic plugin. - } - -// --------------------------------------------------------------------------- -// From class MAiEventHandlerExtension. -// Handles an event sent by the AI framework. -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- // void CSapiDataPlugin::HandleEvent( const TDesC& aEventName, const TDesC& aParam ) { - // We have no way of reporting errors to framework so just ignore them. - TRAP_IGNORE(iData->ExecuteActionL( aEventName , aParam ) ); + TRAP_IGNORE( iData->ExecuteActionL( aEventName , aParam ) ); + } + +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::HasMenuItem +// +// ---------------------------------------------------------------------------- +// +TBool CSapiDataPlugin::HasMenuItem( const TDesC16& aMenuItem ) + { + return iData->HasMenuItem ( aMenuItem ); } -// --------------------------------------------------------------------------- -// From class MAiEventHandlerExtension. -// Invoked by the framework for querying if plugin has menu item -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::IsActive // -TBool CSapiDataPlugin::HasMenuItem( const TDesC& aMenuItem ) - { - return iData->HasMenuItem ( aMenuItem ); - } - -// --------------------------------------------------------------------------- -// From class CAiContentPublisher -// framework instructs plug-in that it is allowed to consume CPU resources -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- // -void CSapiDataPlugin::DoResumeL( TAiTransitionReason aReason ) +TBool CSapiDataPlugin::IsActive() const { - //update in startup phase and idle is on foreground. - switch ( aReason ) - { - case EAiIdleOnLine: - { - iNetworkStatus = EOnline; - iData->OnLineL(); - break; - } - case EAiIdleOffLine: - { - iNetworkStatus = EOffline; - iData->OffLineL(); - break; - } - case EAiIdlePageSwitch: - { - if ( iPluginState == EResume ) - { - iData->SuspendL(); - } - iPluginState = EInActive; - iData->InActiveL(); - } - break; - case EAiSystemStartup: - case EAiIdleForeground: - { - iHSForeGround = ETrue; - } - case EAiBacklightOn: - { - if ( iPluginState == ESuspend && !iKeyLockOn ) - { - iPluginState = EResume; - iData->ResumeL(); - } - break; - } - case EAiKeylockDisabled: - { - iKeyLockOn = EFalse; - // Key lock events considered only if HS is in foreground - if ( iHSForeGround && iPluginState == ESuspend ) - { - iPluginState = EResume; - iData->ResumeL(); - } - break; - } - case EAiKeylockEnabled: - { - iKeyLockOn = ETrue; - // Key lock events considered only if HS is in foreground - if ( iHSForeGround && iPluginState == EResume ) - { - iPluginState = ESuspend ; - iData->SuspendL(); - } - break; - } - case EAiScreenLayoutChanged: - { - // ignore events - break; - } - case EAiGeneralThemeChanged: - { - // ignore event - break; - } - case EAiIdleBackground: - { - iHSForeGround = EFalse; - } - default : - { - if ( iPluginState == EResume ) - { - iPluginState = ESuspend; - iData->SuspendL(); - } - break; - } - } + return iPluginState == EResume; } -// --------------------------------------------------------------------------- -// Is plugin active to publish the data -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::Data +// +// ---------------------------------------------------------------------------- // -TBool CSapiDataPlugin::IsActive() +CSapiData* CSapiDataPlugin::Data() const { - return (iPluginState == EResume ); + return iData; } + +// ---------------------------------------------------------------------------- +// CSapiDataPlugin::NetworkStatus +// +// ---------------------------------------------------------------------------- +// +CSapiDataPlugin::TPluginNetworkStatus CSapiDataPlugin::NetworkStatus() const + { + return iNetworkStatus; + } + +// End of file