idlefw/plugins/sapidataplugin/src/sapidata.cpp
branchRCL_3
changeset 14 15e4dd19031c
parent 12 502e5d91ad42
child 15 a0713522ab97
equal deleted inserted replaced
12:502e5d91ad42 14:15e4dd19031c
    20 #include <liwservicehandler.h>
    20 #include <liwservicehandler.h>
    21 #include <aipluginsettings.h>
    21 #include <aipluginsettings.h>
    22 #include <utf.h>
    22 #include <utf.h>
    23 
    23 
    24 // User includes
    24 // User includes
       
    25 #include <aicpscommandbuffer.h>
    25 #include "sapidata.h"
    26 #include "sapidata.h"
    26 #include "sapidatapluginconst.h"
    27 #include "sapidatapluginconst.h"
    27 #include "sapidataobserver.h"
    28 #include "sapidataobserver.h"
    28 #include "sapidataplugin.h"
    29 #include "sapidataplugin.h"
    29 
    30 
   101 // ---------------------------------------------------------------------------
   102 // ---------------------------------------------------------------------------
   102 //
   103 //
   103 void CSapiData::ConstructL(CSapiDataPlugin* aPlugin)
   104 void CSapiData::ConstructL(CSapiDataPlugin* aPlugin)
   104     { 
   105     { 
   105      iPlugin = aPlugin;
   106      iPlugin = aPlugin;
   106      iCommandName = NULL;
       
   107 	 iContentId = NULL;
       
   108 	 iContentType = NULL;
       
   109 	 iUpdateNeeded = EFalse;
   107 	 iUpdateNeeded = EFalse;
   110     }
   108     }
   111     
   109     
   112 // ---------------------------------------------------------------------------
   110 // ---------------------------------------------------------------------------
   113 // Destructor
   111 // Destructor
   143          {
   141          {
   144          iServiceHandler->Reset();
   142          iServiceHandler->Reset();
   145          delete iServiceHandler;
   143          delete iServiceHandler;
   146          iServiceHandler = NULL;
   144          iServiceHandler = NULL;
   147          }
   145          }
       
   146     iCpsExecute = NULL;
   148     iMenuItems.ResetAndDestroy();
   147     iMenuItems.ResetAndDestroy();
   149     iMenuTriggers.ResetAndDestroy();
   148     iMenuTriggers.ResetAndDestroy();
   150     iItemList.ResetAndDestroy();
   149     iItemList.ResetAndDestroy();
   151     // not owned
   150     // not owned
   152     iPlugin = NULL;
   151     iPlugin = NULL;
   264 
   263 
   265 // ---------------------------------------------------------------------------
   264 // ---------------------------------------------------------------------------
   266 // SetStartupReasonL
   265 // SetStartupReasonL
   267 // ---------------------------------------------------------------------------
   266 // ---------------------------------------------------------------------------
   268 //
   267 //
   269 void CSapiData::SetStartupReasonL(const TDesC& aStartupReason)
   268 void CSapiData::SetStartupReasonL(const TDesC8& aStartupReason)
   270     {
   269     {
   271     delete iStartupReason;
   270     delete iStartupReason;
   272     iStartupReason = NULL;
   271     iStartupReason = NULL;
   273     iStartupReason = aStartupReason.AllocL();
   272     iStartupReason = aStartupReason.AllocL();
   274     ChangePublisherStatusL( aStartupReason );
   273     ChangePublisherStatusL( aStartupReason );
   568 // ---------------------------------------------------------------------------
   567 // ---------------------------------------------------------------------------
   569 //
   568 //
   570 void CSapiData::ExecuteCommandL(const TDesC& aRegistry, CLiwDefaultMap* aInFilter, 
   569 void CSapiData::ExecuteCommandL(const TDesC& aRegistry, CLiwDefaultMap* aInFilter, 
   571 		CLiwGenericParamList* aOutParamList)
   570 		CLiwGenericParamList* aOutParamList)
   572 	{
   571 	{
   573 	CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
   572     if( iInterface == NULL )
   574 	
   573         {
   575 	TLiwGenericParam type( KType, TLiwVariant( aRegistry ) );
   574         User::Leave( KErrNotSupported );
   576 	inParamList->AppendL( type );
   575         }
   577 	
   576     CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
   578 	//append filter to input param
   577     
   579 	 TLiwGenericParam item( KFilter, TLiwVariant( aInFilter ));
   578     TLiwGenericParam type( KType, TLiwVariant( aRegistry ) );
   580 	 inParamList->AppendL( item );
   579     inParamList->AppendL( type );
   581 	 
   580     
   582 	// execute service.It is assumed that iInterface is already initiated
   581     //append filter to input param
   583 	if(iInterface)
   582     TLiwGenericParam item( KFilter, TLiwVariant( aInFilter ));
   584 		{
   583     inParamList->AppendL( item );
   585 		iInterface->ExecuteCmdL( *iCommandName, *inParamList, *aOutParamList);
   584     
   586 		}
   585     // execute service.It is assumed that iInterface is already initiated
   587 	else
   586     iInterface->ExecuteCmdL( *iCommandName, *inParamList, *aOutParamList);
   588 		{
   587     type.Reset();
   589 		User::Leave( KErrNotSupported );
   588     item.Reset();
   590 		}
   589     inParamList->Reset();
   591 	type.Reset();
       
   592 	item.Reset();
       
   593 	inParamList->Reset();
       
   594 	}
   590 	}
   595 
   591 
   596 // ---------------------------------------------------------------------------
   592 // ---------------------------------------------------------------------------
   597 // ExecuteActionL
   593 // ExecuteActionL
   598 // ---------------------------------------------------------------------------
   594 // ---------------------------------------------------------------------------
   599 //
   595 //
   600 void CSapiData::ExecuteActionL(const TDesC& aObjectId, const TDesC& aTrigger )
   596 void CSapiData::ExecuteActionL(const TDesC& aObjectId, const TDesC& aTrigger )
   601    {
   597    {
       
   598     if( iInterface == NULL )
       
   599         {
       
   600         User::Leave( KErrNotSupported );
       
   601         }
   602    HBufC8* triggerName = HBufC8::NewLC( KSAPIContentNameMaxLength );
   602    HBufC8* triggerName = HBufC8::NewLC( KSAPIContentNameMaxLength );
   603   
   603   
   604    CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
   604    CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
   605    CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
   605    CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
   606    CLiwDefaultMap* filter = NULL;
   606    CLiwDefaultMap* filter = NULL;
   719     {
   719     {
   720     return iPlugin->IsActive();
   720     return iPlugin->IsActive();
   721     }
   721     }
   722 
   722 
   723 // ---------------------------------------------------------------------------
   723 // ---------------------------------------------------------------------------
   724 // PublisherStatusL
   724 // ChangePublisherStatusL
   725 // ---------------------------------------------------------------------------
   725 // ---------------------------------------------------------------------------
   726 //
   726 //
   727 void CSapiData::ChangePublisherStatusL(const TDesC& aStatus)
   727 void CSapiData::ChangePublisherStatusL(const TDesC8& aStatus)
   728     {
   728     {
       
   729     if( iCpsExecute == NULL )
       
   730         {
       
   731         User::Leave( KErrNotSupported );
       
   732         }
       
   733 
   729     if ( aStatus == KResume && iUpdateNeeded )
   734     if ( aStatus == KResume && iUpdateNeeded )
   730         {
   735         {
   731         iPlugin->PublishL();
   736         iPlugin->PublishL();
   732         iUpdateNeeded = EFalse;
   737         iUpdateNeeded = EFalse;
   733         }
   738         }
       
   739     CLiwDefaultMap* filter = CreateFilterLC( KWidget() );
       
   740     // Add execute command triggers. Idle framework will execute 
       
   741     iCpsExecute->AddCommand( *iContentId, KPubData, filter, aStatus );
       
   742     CleanupStack::PopAndDestroy( filter );
       
   743     
       
   744     }
       
   745 
       
   746 // ---------------------------------------------------------------------------
       
   747 // ChangePublisherStatusL
       
   748 // ---------------------------------------------------------------------------
       
   749 //
       
   750 void CSapiData::ChangePublisherStatusL(CLiwDefaultList* aActionsList)
       
   751     {
       
   752     if( iInterface == NULL )
       
   753         {
       
   754         User::Leave( KErrNotSupported );
       
   755         }
   734     
   756     
   735     CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
   757     CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
   736     CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
   758     CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
   737     HBufC8* triggerName = CnvUtfConverter::ConvertFromUnicodeToUtf8L(aStatus);
   759     
   738     CleanupStack::PushL( triggerName );
   760     TLiwGenericParam pluginId( KPluginId, TLiwVariant( iContentId ) );
   739 
   761     inParamList->AppendL( pluginId );
   740     TLiwGenericParam type( KType, TLiwVariant( KPubData ) );
   762     TLiwGenericParam type( KType, TLiwVariant( KPubData ) );
   741     inParamList->AppendL( type );
   763     inParamList->AppendL( type );
   742 			  
   764      
   743     CLiwDefaultMap* filter = CreateFilterLC( KWidget() );
   765     CLiwDefaultMap* filter = CreateFilterLC( KWidget() );
   744     filter->InsertL(KActionTrigger, TLiwVariant(triggerName->Des()) );
   766     // add list of action triggers to execute
   745    
   767     filter->InsertL(KActionTrigger, TLiwVariant(aActionsList) );
       
   768     
   746     TLiwGenericParam item( KFilter, TLiwVariant( filter ));
   769     TLiwGenericParam item( KFilter, TLiwVariant( filter ));
   747     inParamList->AppendL( item );
   770     inParamList->AppendL( item );
   748            
   771     iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList);
       
   772     CleanupStack::PopAndDestroy( filter );
       
   773     outParamList->Reset();
       
   774     inParamList->Reset();
       
   775 
       
   776     }
       
   777 
       
   778 // ---------------------------------------------------------------------------
       
   779 // TriggerActiveL
       
   780 // ---------------------------------------------------------------------------
       
   781 //
       
   782 void CSapiData::TriggerActiveL()
       
   783     {
   749     if(iInterface)
   784     if(iInterface)
   750 	   {
   785         {
   751 	   iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList);
   786         CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
   752 	   }
   787         CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
   753     else
   788         
   754 	   {
   789         TLiwGenericParam type( KType, TLiwVariant( KPubData ) );
   755 	   User::Leave( KErrNotSupported );
   790         inParamList->AppendL( type );
   756 	   }
   791         
   757     
   792         CLiwDefaultMap* filter = CreateFilterLC( KAll(), KAll() );
   758     CleanupStack::PopAndDestroy( filter );
   793         filter->InsertL(KActionTrigger, TLiwVariant( KActive() ));
   759     CleanupStack::PopAndDestroy( triggerName );
   794         
   760     inParamList->Reset();
   795         TLiwGenericParam item( KFilter, TLiwVariant( filter ));
   761     outParamList->Reset();
   796         inParamList->AppendL( item );
   762    }
   797         iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList, KDisableNotification );
   763 
   798         
   764 // ---------------------------------------------------------------------------
   799         CleanupStack::PopAndDestroy( filter );
   765 // TriggerActiveL
   800         inParamList->Reset();
   766 // ---------------------------------------------------------------------------
   801         outParamList->Reset();
   767 //
       
   768 void CSapiData::TriggerActiveL()
       
   769     {
       
   770     
       
   771     CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
       
   772     CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
       
   773  
       
   774     TLiwGenericParam type( KType, TLiwVariant( KPubData ) );
       
   775     inParamList->AppendL( type );
       
   776 
       
   777     CLiwDefaultMap* filter = CreateFilterLC( KAll(), KAll() );
       
   778     filter->InsertL(KActionTrigger, TLiwVariant( KActive() ));
       
   779    
       
   780     TLiwGenericParam item( KFilter, TLiwVariant( filter ));
       
   781     inParamList->AppendL( item );
       
   782     if(iInterface)
       
   783        {
       
   784        iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList, KDisableNotification );
       
   785        }
   802        }
   786     else
   803     else
   787        {
   804        {
   788        User::Leave( KErrNotSupported );
   805        User::Leave( KErrNotSupported );
   789        }
   806        }
   790     CleanupStack::PopAndDestroy( filter );
       
   791     inParamList->Reset();
       
   792     outParamList->Reset();
       
   793    }
   807    }
   794 // ---------------------------------------------------------------------------
   808 // ---------------------------------------------------------------------------
   795 // UpdatePublisherStatusL
   809 // UpdatePublisherStatusL
   796 // ---------------------------------------------------------------------------
   810 // ---------------------------------------------------------------------------
   797 //
   811 //
   798 void CSapiData::UpdatePublisherStatusL( TDesC& aPublisher )
   812 void CSapiData::UpdatePublisherStatusL( TDesC& aPublisher )
   799 	{
   813 	{
   800 	 if ( aPublisher == iPublisher )
   814 	 if ( aPublisher == iPublisher )
   801 		 {
   815         {
   802 		 // Resend the plugin status to publisher
   816        // Resend the plugin status to publisher
   803          ChangePublisherStatusL( KActive );
   817         CLiwDefaultList* actionsToLaunch = CLiwDefaultList::NewLC();
       
   818         actionsToLaunch->AppendL( TLiwVariant( KActive ));
   804          if( iStartupReason->Length() != 0 )
   819          if( iStartupReason->Length() != 0 )
   805              {
   820              {
   806              ChangePublisherStatusL( *iStartupReason );
   821              actionsToLaunch->AppendL( TLiwVariant( *iStartupReason ));
   807              }
   822              }
   808          
       
   809 		 if ( iPlugin->IsActive() )
   823 		 if ( iPlugin->IsActive() )
   810 			 {
   824 			 {
   811              ChangePublisherStatusL( KResume );
   825 		     actionsToLaunch->AppendL( TLiwVariant( KResume ));
   812 			 }
   826 			 }
   813 		 else
   827 		 else
   814 			 {
   828 			 {
   815              ChangePublisherStatusL( KSuspend );
   829 		     actionsToLaunch->AppendL(TLiwVariant( KSuspend ));
   816 			 }
   830 			 }
   817 		  // forward the network status if it uses.
   831 		  // forward the network status if it uses.
   818 		if ( iPlugin->NetworkStatus() == CSapiDataPlugin::EOnline )
   832 		if ( iPlugin->NetworkStatus() == CSapiDataPlugin::EOnline )
   819 			{
   833 			{
   820             ChangePublisherStatusL( KOnLine );
   834 		    actionsToLaunch->AppendL(TLiwVariant( KOnLine ));
   821 			}
   835 			}
   822 		else if ( iPlugin->NetworkStatus() == CSapiDataPlugin::EOffline )
   836 		else if ( iPlugin->NetworkStatus() == CSapiDataPlugin::EOffline )
   823 			{
   837 			{
   824             ChangePublisherStatusL( KOffLine );
   838 		    actionsToLaunch->AppendL(TLiwVariant( KOffLine ));
   825 			}
   839 			}
       
   840 	 
       
   841 	     ChangePublisherStatusL( actionsToLaunch );
       
   842 	     CleanupStack::PopAndDestroy( actionsToLaunch );
   826 		 }
   843 		 }
   827 	}
   844 	}
   828 
   845 
   829 // ---------------------------------------------------------------------------
   846 // ---------------------------------------------------------------------------
   830 // ResolveSkinItemId
   847 // ResolveSkinItemId
   910 //
   927 //
   911 void CSapiData::SetUpdateNeeded(TBool aStatus)
   928 void CSapiData::SetUpdateNeeded(TBool aStatus)
   912 	{
   929 	{
   913 	iUpdateNeeded = aStatus;
   930 	iUpdateNeeded = aStatus;
   914 	}
   931 	}
       
   932 
       
   933 // ---------------------------------------------------------------------------
       
   934 // SetCommandBuffer
       
   935 // ---------------------------------------------------------------------------
       
   936 //
       
   937 void CSapiData::SetCommandBuffer(TAny* aAny)
       
   938     {
       
   939     iCpsExecute = reinterpret_cast <MAiCpsCommandBuffer* > ( aAny );
       
   940     }
       
   941 
       
   942 // End of file