idlefw/plugins/sapidataplugin/src/sapidata.cpp
branchRCL_3
changeset 64 b276298d5729
parent 59 a0713522ab97
child 74 edd621764147
equal deleted inserted replaced
59:a0713522ab97 64:b276298d5729
   103 //
   103 //
   104 void CSapiData::ConstructL(CSapiDataPlugin* aPlugin)
   104 void CSapiData::ConstructL(CSapiDataPlugin* aPlugin)
   105     { 
   105     { 
   106      iPlugin = aPlugin;
   106      iPlugin = aPlugin;
   107 	 iUpdateNeeded = EFalse;
   107 	 iUpdateNeeded = EFalse;
       
   108 	 iGetMenuItems = ETrue;
   108     }
   109     }
   109     
   110     
   110 // ---------------------------------------------------------------------------
   111 // ---------------------------------------------------------------------------
   111 // Destructor
   112 // Destructor
   112 // Deletes all data created to heap
   113 // Deletes all data created to heap
   113 // ---------------------------------------------------------------------------
   114 // ---------------------------------------------------------------------------
   114 //
   115 //
   115 CSapiData::~CSapiData()
   116 CSapiData::~CSapiData()
   116     {
   117     {
   117     delete iCommandName;
       
   118 	delete iPublisher;
   118 	delete iPublisher;
   119 	delete iContentType;
       
   120 	delete iContentId;
   119 	delete iContentId;
   121 	delete iStartupReason;
   120 	delete iStartupReason;
   122 	
   121 	
   123 	if(iPubObserver)
   122 	if(iPubObserver)
   124 		{
   123 		{
   128     if(iContentObserver)
   127     if(iContentObserver)
   129         {
   128         {
   130         delete iContentObserver;
   129         delete iContentObserver;
   131         iContentObserver = NULL;
   130         iContentObserver = NULL;
   132         }
   131         }
   133     if( iInterface )
       
   134          {
       
   135          // This will also release all the registered observers
       
   136          iInterface->Close();
       
   137          iInterface = NULL;
       
   138          }
       
   139     if( iServiceHandler )
       
   140          {
       
   141          iServiceHandler->Reset();
       
   142          delete iServiceHandler;
       
   143          iServiceHandler = NULL;
       
   144          }
       
   145     iCpsExecute = NULL;
       
   146     iMenuItems.ResetAndDestroy();
   132     iMenuItems.ResetAndDestroy();
   147     iMenuTriggers.ResetAndDestroy();
   133     iMenuTriggers.ResetAndDestroy();
   148     iItemList.ResetAndDestroy();
   134     iItemList.ResetAndDestroy();
   149     // not owned
   135     // not owned
   150     iPlugin = NULL;
   136     iPlugin = NULL;
       
   137     iInterface = NULL;
       
   138     iServiceHandler = NULL;
       
   139     iCpsExecute = NULL;
       
   140     
   151     }
   141     }
   152 
   142 
   153 // ---------------------------------------------------------------------------
   143 // ---------------------------------------------------------------------------
   154 // ConfigureL
   144 // ConfigureL
   155 // ---------------------------------------------------------------------------
   145 // ---------------------------------------------------------------------------
   156 //
   146 //
   157 void CSapiData::ConfigureL(RAiSettingsItemArray& aConfigurations )
   147 void CSapiData::ConfigureL(RAiSettingsItemArray& aConfigurations )
   158     {
   148     {
   159     HBufC8* serviceName = NULL;
       
   160     HBufC8* interfaceName = NULL;
       
   161 
       
   162     TInt count = aConfigurations.Count();
   149     TInt count = aConfigurations.Count();
   163     
       
   164     for(TInt i = 0;i<count;i++)
   150     for(TInt i = 0;i<count;i++)
   165        {
   151        {
   166        MAiPluginConfigurationItem& confItem = ( aConfigurations[i] )->AiPluginConfigurationItem();
   152        MAiPluginConfigurationItem& confItem = ( aConfigurations[i] )->AiPluginConfigurationItem();
   167        // if owner is plugin then it (key,value) is for plugin configurations items
       
   168        if(confItem.Owner() == KPlugin())
   153        if(confItem.Owner() == KPlugin())
   169            {
   154            {
   170            if(confItem.Name() ==  KService())
   155            if( confItem.Name()  == KPublisher16() ) 
   171                {
       
   172                serviceName = CnvUtfConverter::ConvertFromUnicodeToUtf8L(confItem.Value());
       
   173                }
       
   174            else if( confItem.Name() == KInterface() )
       
   175                  {
       
   176                  interfaceName = CnvUtfConverter::ConvertFromUnicodeToUtf8L(confItem.Value());
       
   177                  }
       
   178            else if( confItem.Name() == KCommand() )
       
   179                  {
       
   180                  iCommandName  = CnvUtfConverter::ConvertFromUnicodeToUtf8L(confItem.Value());
       
   181                  }
       
   182            else if( confItem.Name()  == KPublisher16() ) 
       
   183 				  {
   156 				  {
   184 				  iPublisher = confItem.Value().AllocL();
   157 				  iPublisher = confItem.Value().AllocL();
   185 				  }
   158 				  }
   186            }
   159            }
   187        else if ( confItem.Name() == KContentType16() )
   160        else if ( confItem.Name() == KContentType16() )
   197            iItemList.AppendL( conItem );
   170            iItemList.AppendL( conItem );
   198            
   171            
   199            CleanupStack::PopAndDestroy(objectId);
   172            CleanupStack::PopAndDestroy(objectId);
   200            }
   173            }
   201        }
   174        }
   202     
       
   203     iItemCount = iItemList.Count();  
   175     iItemCount = iItemList.Count();  
   204     
   176     if( iPublisher->Des().Length() == 0 ) 
   205     if( !serviceName || !interfaceName || !iCommandName  
       
   206     		|| !iContentId || !iPublisher || !iItemCount )
       
   207         {
   177         {
   208         // No service to offer without plugin configurations 
   178         // No service to offer without plugin configurations 
   209         User::Leave( KErrNotSupported );
   179         User::Leave( KErrNotSupported );
   210         }
   180         }
   211     iServiceHandler = CLiwServiceHandler::NewL(); 
       
   212 
       
   213     // for convenience keep pointers to Service Handler param lists 
       
   214     CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
       
   215     CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
       
   216 
       
   217     CLiwCriteriaItem* criteriaItem = CLiwCriteriaItem::NewLC( KLiwCmdAsStr, *interfaceName , *serviceName );
       
   218     criteriaItem->SetServiceClass( TUid::Uid( KLiwClassBase ) );
       
   219     // Interface name 
       
   220     RCriteriaArray criteriaArray;
       
   221     criteriaArray.AppendL( criteriaItem );
       
   222     // attach Liw criteria
       
   223     iServiceHandler->AttachL( criteriaArray );
       
   224     iServiceHandler->ExecuteServiceCmdL( *criteriaItem, *inParamList, *outParamList );
       
   225 
       
   226     CleanupStack::PopAndDestroy(criteriaItem);
       
   227     criteriaArray.Reset();
       
   228 
       
   229     // extract CPS interface from output params
       
   230     TInt pos( 0 );
       
   231     outParamList->FindFirst( pos, *interfaceName );
       
   232     if( pos != KErrNotFound )
       
   233         {
       
   234         //iInterface is MLiwInterface*
       
   235         iInterface = (*outParamList)[pos].Value().AsInterface(); 
       
   236         User::LeaveIfNull( iInterface );
       
   237         }
       
   238     else
       
   239         {
       
   240         User::Leave( KErrNotFound );
       
   241         }
       
   242     inParamList->Reset();
       
   243     outParamList->Reset();
       
   244     delete interfaceName;
       
   245     delete serviceName;
       
   246 
       
   247 	//Gets the menu items from the publisher registry    
       
   248     GetMenuItemsL();
       
   249  
       
   250     iContentObserver = CSapiDataObserver::NewL( iInterface, this );   
   181     iContentObserver = CSapiDataObserver::NewL( iInterface, this );   
   251     iPubObserver = CSapiDataObserver::NewL( iInterface, this );
   182     iPubObserver = CSapiDataObserver::NewL( iInterface, this );
   252     }
   183     }
   253 
   184 
   254 // ---------------------------------------------------------------------------
   185 // ---------------------------------------------------------------------------
   438 // HasMenuItem
   369 // HasMenuItem
   439 // ---------------------------------------------------------------------------
   370 // ---------------------------------------------------------------------------
   440 //
   371 //
   441 TBool CSapiData::HasMenuItem(const TDesC& aMenuItem )
   372 TBool CSapiData::HasMenuItem(const TDesC& aMenuItem )
   442 	{
   373 	{
       
   374     if ( iGetMenuItems )
       
   375         {
       
   376         //Gets the menu items from the publisher registry
       
   377         TRAP_IGNORE( GetMenuItemsL() );
       
   378         iGetMenuItems = EFalse;
       
   379         }
       
   380     
   443 	TBool found = EFalse;
   381 	TBool found = EFalse;
   444 	for (TInt i = 0; i < iMenuItems.Count(); i++ )
   382 	for (TInt i = 0; i < iMenuItems.Count(); i++ )
   445 		{
   383 		{
   446 		if( aMenuItem == iMenuItems[i] )
   384 		if( aMenuItem == iMenuItems[i] )
   447 			{
   385 			{
   580     //append filter to input param
   518     //append filter to input param
   581     TLiwGenericParam item( KFilter, TLiwVariant( aInFilter ));
   519     TLiwGenericParam item( KFilter, TLiwVariant( aInFilter ));
   582     inParamList->AppendL( item );
   520     inParamList->AppendL( item );
   583     
   521     
   584     // execute service.It is assumed that iInterface is already initiated
   522     // execute service.It is assumed that iInterface is already initiated
   585     iInterface->ExecuteCmdL( *iCommandName, *inParamList, *aOutParamList);
   523     iInterface->ExecuteCmdL( KGetList, *inParamList, *aOutParamList);
   586     type.Reset();
   524     type.Reset();
   587     item.Reset();
   525     item.Reset();
   588     inParamList->Reset();
   526     inParamList->Reset();
   589 	}
   527 	}
   590 
   528 
   763     // add list of action triggers to execute
   701     // add list of action triggers to execute
   764     filter->InsertL(KActionTrigger, TLiwVariant(aActionsList) );
   702     filter->InsertL(KActionTrigger, TLiwVariant(aActionsList) );
   765     
   703     
   766     TLiwGenericParam item( KFilter, TLiwVariant( filter ));
   704     TLiwGenericParam item( KFilter, TLiwVariant( filter ));
   767     inParamList->AppendL( item );
   705     inParamList->AppendL( item );
       
   706 
   768     iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList);
   707     iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList);
   769     CleanupStack::PopAndDestroy( filter );
   708     CleanupStack::PopAndDestroy( filter );
   770     outParamList->Reset();
   709     outParamList->Reset();
   771     inParamList->Reset();
   710     inParamList->Reset();
   772 
   711 
   932 // ---------------------------------------------------------------------------
   871 // ---------------------------------------------------------------------------
   933 //
   872 //
   934 void CSapiData::SetCommandBuffer(TAny* aAny)
   873 void CSapiData::SetCommandBuffer(TAny* aAny)
   935     {
   874     {
   936     iCpsExecute = reinterpret_cast <MAiCpsCommandBuffer* > ( aAny );
   875     iCpsExecute = reinterpret_cast <MAiCpsCommandBuffer* > ( aAny );
       
   876     if ( iCpsExecute )
       
   877         {
       
   878         iInterface = iCpsExecute->CpsInterface();
       
   879         iServiceHandler = iCpsExecute->ServiceHandler();
       
   880         }
   937     }
   881     }
   938 
   882 
   939 // End of file
   883 // End of file