idlehomescreen/sapiwrapper/hspswrapper/src/hspswrapper.cpp
changeset 0 f72a12da539e
child 1 5315654608de
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Encapsulates hsps liw service
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <LiwServiceHandler.h>
       
    20 #include <LiwVariant.h>
       
    21 #include <bamdesca.h>
       
    22 
       
    23 #include "hspswrapper.h"
       
    24 #include "hspsconfiguration.h"
       
    25 #include "pluginmap.h"
       
    26 #include "itemmap.h"
       
    27 #include "propertymap.h"
       
    28 #include "objectmap.h"
       
    29 #include "plugininfo.h"
       
    30 
       
    31 
       
    32 _LIT8( KHSPS, "Service.HSPS" );
       
    33 _LIT8( KHSPSConfigurationIf, "IConfiguration" );
       
    34 
       
    35 _LIT8( KHSPSCommandGetActiveAppConf, "GetActiveAppConf" );
       
    36 _LIT8( KHSPSCommandGetPluginConf, "GetPluginConf" );
       
    37 _LIT8( KHSPSCommandGetPlugins, "GetPlugins" );
       
    38 _LIT8( KHSPSCommandAddPlugin, "AddPlugin" );
       
    39 _LIT8( KHSPSCommandRemovePlugin, "RemovePlugin" );
       
    40 _LIT8( KHSPSCommandReplacePlugin, "ReplacePlugin" );
       
    41 _LIT8( KHSPSCommandSetActivePlugin, "SetActivePlugin" );
       
    42 _LIT8( KHSPSCommandSetConfState, "SetConfState" );
       
    43 _LIT8( KHSPSCommandGetAppConfs, "GetAppConfs" );
       
    44 _LIT8( KHSPSCommandSetAppConf, "SetActiveAppConf" );
       
    45 _LIT8( KHSPSMovePlugins, "MovePlugins");
       
    46 _LIT8( KHSPSSetPluginSettings, "SetPluginSettings" );
       
    47 _LIT8( KAppConfKey, "appConf" );
       
    48 _LIT8( KAppConfsKey, "appConfs" );
       
    49 _LIT8( KPluginConfKey, "pluginConf" );
       
    50 _LIT8( KPluginsKey, "plugins" );
       
    51 _LIT8( KConfId, "confId" );
       
    52 _LIT8( KPluginUid, "pluginUid" );
       
    53 _LIT8( KOutKeyStatus ,"status");
       
    54 _LIT8( KHspsAppUid, "appUid" );
       
    55 _LIT8( KKeyPluginId, "pluginId" );
       
    56 _LIT8( KKeyConfUid, "confUid" );
       
    57 _LIT8( KInterface, "interface" );
       
    58 _LIT8( KType, "type" );
       
    59 _LIT8( KKeyPlugins, "plugins" );
       
    60 _LIT8( KKeyItemId, "itemId" );
       
    61 _LIT8( KKeyName, "name" );
       
    62 _LIT8( KKeyValue, "value" );
       
    63 _LIT8( KKeyProperties, "properties" );
       
    64 _LIT8( KKeySettings, "settings" );
       
    65 _LIT8( KIndex, "position" );
       
    66 _LIT8( KConfState, "state" );
       
    67 _LIT8( KRequestNotification, "RequestNotification" );
       
    68 
       
    69 namespace hspswrapper{
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C CAddPluginResult::CAddPluginResult():iStatus(KErrNotFound)
       
    75     {}
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 EXPORT_C CAddPluginResult::~CAddPluginResult()
       
    81     {
       
    82     delete iPluginId;
       
    83     }
       
    84     
       
    85 // ---------------------------------------------------------------------------
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 EXPORT_C CAddPluginResult* CAddPluginResult::NewL()
       
    89     {
       
    90     CAddPluginResult* self = new( ELeave ) CAddPluginResult;
       
    91     return self;
       
    92     }
       
    93     
       
    94 // ---------------------------------------------------------------------------
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 EXPORT_C void CAddPluginResult::SetPluginIdL(
       
    98     const TDesC8& aPluginId )
       
    99     {
       
   100     delete iPluginId;
       
   101     iPluginId = NULL;
       
   102     iPluginId = aPluginId.AllocL();
       
   103     }
       
   104     
       
   105 // ---------------------------------------------------------------------------
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 EXPORT_C const TDesC8& CAddPluginResult::PluginId()const
       
   109     {
       
   110     if(iPluginId)
       
   111         {
       
   112         return *iPluginId;
       
   113         }
       
   114     else
       
   115         {
       
   116         return KNullDesC8;
       
   117         }
       
   118     }
       
   119     
       
   120 // ---------------------------------------------------------------------------
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C void CAddPluginResult::SetStatus(TInt aStatus )
       
   124     {
       
   125     iStatus = aStatus;
       
   126     }
       
   127     
       
   128 // ---------------------------------------------------------------------------
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C TInt CAddPluginResult::Status()const
       
   132     {
       
   133     return iStatus;
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 CHspsWrapper::CHspsWrapper(MHspsWrapperObserver* aObserver)
       
   140     : iObserver( aObserver )
       
   141     {
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CHspsWrapper::ConstructL(const TDesC8& aAppUid)
       
   148     {
       
   149     // Attach to HSPS:
       
   150     iServiceHandler = CLiwServiceHandler::NewL();
       
   151     
       
   152     iHspsService = CLiwCriteriaItem::NewL( 1, KHSPSConfigurationIf, KHSPS );
       
   153     iHspsService->SetServiceClass( TUid::Uid( KLiwClassBase ) );
       
   154     
       
   155     RCriteriaArray interestList;
       
   156     interestList.AppendL( iHspsService );
       
   157     iServiceHandler->AttachL( interestList );
       
   158     interestList.Reset();
       
   159     
       
   160     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   161     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   162     
       
   163     TLiwGenericParam appUid;
       
   164     TLiwVariant uidVar;
       
   165     uidVar.Set( aAppUid );
       
   166     appUid.SetNameAndValueL( KHspsAppUid, uidVar );
       
   167     appUid.PushL();
       
   168     inParamList.AppendL( appUid );
       
   169     CleanupStack::Pop();
       
   170     appUid.Reset();
       
   171     
       
   172     iServiceHandler->ExecuteServiceCmdL( *iHspsService,inParamList,outParamList );
       
   173     inParamList.Reset();
       
   174     TInt pos = 0;
       
   175     outParamList.FindFirst( pos, KHSPSConfigurationIf );
       
   176     if( pos != KErrNotFound )
       
   177         {
       
   178         iHspsInterface = outParamList[ pos ].Value().AsInterface();    
       
   179         outParamList.Reset();        
       
   180         }
       
   181     else
       
   182         {
       
   183         outParamList.Reset();       
       
   184         User::Leave( KErrNotFound );
       
   185         }   
       
   186     
       
   187     inParamList.Reset();
       
   188     outParamList.Reset();
       
   189         
       
   190     if( iObserver )
       
   191         {
       
   192         iTransactionId = -1;
       
   193         iHspsInterface->ExecuteCmdL( KRequestNotification,
       
   194                                      inParamList,
       
   195                                      outParamList,
       
   196                                      KLiwOptASyncronous,
       
   197                                      this );   
       
   198         const TLiwGenericParam* outParam( NULL );
       
   199                 
       
   200        TInt pos( 0 );
       
   201        outParam = outParamList.FindFirst( pos, _L8("status") );
       
   202                
       
   203        if ( outParam )
       
   204            {
       
   205            TInt retval;
       
   206            retval = outParam->Value().AsTInt32();
       
   207            if(retval == KErrNone )
       
   208                {
       
   209                pos = 0;
       
   210                outParam = outParamList.FindFirst( pos, _L8("TransactionID") );
       
   211                if( outParam )
       
   212                    {
       
   213                    retval = outParam->Value().AsTInt32();
       
   214                    iTransactionId = retval;
       
   215                    }
       
   216                }
       
   217           
       
   218            }
       
   219                   
       
   220         }
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 EXPORT_C CHspsWrapper* CHspsWrapper::NewL(const TDesC8& aAppUid,
       
   227                                           MHspsWrapperObserver* aObserver)
       
   228     {
       
   229     CHspsWrapper* self = CHspsWrapper::NewLC(aAppUid, aObserver);
       
   230     CleanupStack::Pop( self );
       
   231     return self;
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 EXPORT_C CHspsWrapper* CHspsWrapper::NewLC(const TDesC8& aAppUid,
       
   238                                            MHspsWrapperObserver* aObserver)
       
   239     {
       
   240     CHspsWrapper* self = new( ELeave ) CHspsWrapper( aObserver );
       
   241     CleanupStack::PushL( self );
       
   242     self->ConstructL(aAppUid);
       
   243     return self;
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 EXPORT_C CHspsWrapper::~CHspsWrapper()
       
   250     {
       
   251     if( iHspsInterface )
       
   252         {
       
   253         // Close interface
       
   254         iHspsInterface->Close();       
       
   255         }
       
   256     
       
   257     if( iServiceHandler && iHspsService )
       
   258         {
       
   259         // Detach services from the handler
       
   260         RCriteriaArray interestList;
       
   261         TRAP_IGNORE( interestList.AppendL( iHspsService ) );
       
   262         TRAP_IGNORE( iServiceHandler->DetachL( interestList ) );   
       
   263         interestList.Reset();        
       
   264         }
       
   265     
       
   266     delete iHspsService;
       
   267     delete iServiceHandler;    
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // ---------------------------------------------------------------------------
       
   272 //
       
   273 EXPORT_C CHspsConfiguration* CHspsWrapper::GetAppConfigurationL()
       
   274     {
       
   275     CHspsConfiguration* configuration = CHspsConfiguration::NewLC();
       
   276     
       
   277     // Fetch from liw service
       
   278     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   279     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   280        
       
   281     iHspsInterface->ExecuteCmdL( KHSPSCommandGetActiveAppConf, 
       
   282                                  inParamList, 
       
   283                                  outParamList );
       
   284                                            
       
   285     inParamList.Reset();
       
   286    
       
   287     // 1: get appConf map
       
   288     TInt index(0);
       
   289     const TLiwGenericParam* conf = outParamList.FindFirst(index,KAppConfKey);
       
   290     if(conf)
       
   291         {
       
   292         const CLiwMap* confMap  = conf->Value().AsMap();
       
   293         // 2: Process Configuration map
       
   294         if(confMap)
       
   295            {
       
   296            ProcessConfigurationMapL(*confMap,*configuration);
       
   297            }
       
   298         }
       
   299     outParamList.Reset();
       
   300     
       
   301     CleanupStack::Pop(configuration);
       
   302     return configuration;
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 EXPORT_C void CHspsWrapper::GetAppConfigurationsL(
       
   309     RPointerArray<CPluginInfo>& aPlugins )        
       
   310     {
       
   311     // Fetch from liw service
       
   312     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   313     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   314        
       
   315     iHspsInterface->ExecuteCmdL( KHSPSCommandGetAppConfs, 
       
   316                                  inParamList, 
       
   317                                  outParamList );
       
   318                                            
       
   319     inParamList.Reset();
       
   320    
       
   321     TInt index(0);
       
   322     const TLiwGenericParam* confs = outParamList.FindFirst(index,KAppConfsKey);
       
   323     if(confs)
       
   324         {
       
   325         const CLiwList* list = confs->Value().AsList();
       
   326         if(list)
       
   327             {
       
   328             TInt listCount = list->Count();
       
   329             TLiwVariant mapVar;
       
   330             mapVar.PushL();
       
   331             
       
   332             for ( TInt index(0); list->AtL( index, mapVar ); ++index )
       
   333                 {                               
       
   334                 const CLiwMap* confMap = mapVar.AsMap();
       
   335                 
       
   336                 if ( confMap )
       
   337                     {
       
   338                     CPluginInfo* plugin = CPluginInfo::NewLC();
       
   339                     
       
   340                     TLiwVariant confVar;
       
   341                     confVar.PushL();
       
   342                     
       
   343                     if( confMap->FindL( _L8("uid"), confVar ) )
       
   344                         {
       
   345                         plugin->SetUidL( confVar.AsData() );
       
   346                         }
       
   347                     
       
   348                     confVar.Reset();
       
   349                     
       
   350                     if( confMap->FindL(_L8("name"), confVar ) )
       
   351                         {
       
   352                         plugin->SetNameL( confVar.AsData() );
       
   353                         }
       
   354                     
       
   355                     CleanupStack::Pop(&confVar);
       
   356                     confVar.Reset();
       
   357                     
       
   358                     aPlugins.AppendL( plugin );
       
   359                     CleanupStack::Pop( plugin );
       
   360                     }
       
   361                 }
       
   362             CleanupStack::Pop(&mapVar);
       
   363             mapVar.Reset();
       
   364             }
       
   365         }
       
   366     outParamList.Reset();
       
   367     }
       
   368 
       
   369 
       
   370 // ---------------------------------------------------------------------------
       
   371 // ---------------------------------------------------------------------------
       
   372 //
       
   373 EXPORT_C TInt CHspsWrapper::SetAppConfigurationL(
       
   374     const TDesC8& aConfigurationUid )
       
   375     {
       
   376 #ifdef _XN_PERFORMANCE_TEST_
       
   377     RDebug::Print( _L( "CHspsWrapper::SetAppConfigurationL() - start" ) );
       
   378 #endif //_XN_PERFORMANCE_TEST_        
       
   379     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   380     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   381          
       
   382     // Compose Liw message
       
   383     TLiwGenericParam confIdParam;
       
   384     confIdParam.SetNameAndValueL( KKeyConfUid, TLiwVariant(aConfigurationUid) );
       
   385     confIdParam.PushL();
       
   386     inParamList.AppendL( confIdParam );
       
   387     CleanupStack::Pop(&confIdParam);
       
   388     confIdParam.Reset();
       
   389       
       
   390     iHspsInterface->ExecuteCmdL( KHSPSCommandSetAppConf, 
       
   391                                  inParamList, 
       
   392                                  outParamList ); 
       
   393       
       
   394     inParamList.Reset();
       
   395       
       
   396     // check success
       
   397     const TLiwGenericParam* outParam = NULL;
       
   398     TInt pos(0);
       
   399     outParam = outParamList.FindFirst( pos, KOutKeyStatus );
       
   400     TInt status(KErrGeneral);
       
   401     
       
   402     if ( outParam )
       
   403         {
       
   404         status = outParam->Value().AsTInt32();
       
   405         }
       
   406     outParamList.Reset();
       
   407 #ifdef _XN_PERFORMANCE_TEST_
       
   408     RDebug::Print( _L( "CHspsWrapper::SetAppConfigurationL() - end" ) );
       
   409 #endif //_XN_PERFORMANCE_TEST_            
       
   410     return status;
       
   411     }
       
   412 
       
   413 // ---------------------------------------------------------------------------
       
   414 // ---------------------------------------------------------------------------
       
   415 //
       
   416 EXPORT_C CHspsConfiguration* CHspsWrapper::GetPluginConfigurationL(
       
   417     const TDesC8& aPluginId)
       
   418     {
       
   419     CHspsConfiguration* configuration = CHspsConfiguration::NewLC();
       
   420         
       
   421     // Fetch from liw service
       
   422     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   423     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   424     // Form input message
       
   425     
       
   426     TLiwGenericParam pluginIdParam;
       
   427     TLiwVariant pluginIdVar;
       
   428     pluginIdVar.Set( aPluginId );
       
   429     pluginIdParam.SetNameAndValueL( KKeyPluginId, pluginIdVar );
       
   430     pluginIdParam.PushL();
       
   431     inParamList.AppendL( pluginIdParam );
       
   432     CleanupStack::Pop(&pluginIdParam);
       
   433     pluginIdParam.Reset();
       
   434         
       
   435     
       
   436     iHspsInterface->ExecuteCmdL( KHSPSCommandGetPluginConf, 
       
   437                                  inParamList, 
       
   438                                  outParamList );
       
   439     inParamList.Reset();
       
   440     
       
   441     // 1: get pluginConf map
       
   442     TInt index(0);
       
   443     const TLiwGenericParam* conf = outParamList.FindFirst(index,KPluginConfKey);
       
   444     if(conf)
       
   445         {
       
   446         const CLiwMap* confMap  = conf->Value().AsMap();
       
   447         // 2: Process Configuration map
       
   448         if(confMap)
       
   449            {
       
   450            ProcessConfigurationMapL(*confMap,*configuration);
       
   451            }
       
   452         }
       
   453    
       
   454     outParamList.Reset();
       
   455     CleanupStack::Pop(configuration);
       
   456     
       
   457     return configuration;
       
   458     } 
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // ---------------------------------------------------------------------------
       
   462 //
       
   463 EXPORT_C void CHspsWrapper::GetPluginsL(
       
   464     RPointerArray<CPluginInfo>& aPlugins,
       
   465     const TDesC8& aPluginInterface,
       
   466     const TDesC8& aPluginType)
       
   467     {
       
   468     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   469     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   470     
       
   471     // plugin interface
       
   472     TLiwGenericParam interfaceParam( KInterface, TLiwVariant( aPluginInterface ) );
       
   473     interfaceParam.PushL();
       
   474     inParamList.AppendL( interfaceParam );
       
   475     CleanupStack::Pop(&interfaceParam);
       
   476     interfaceParam.Reset();
       
   477     
       
   478     // plugin type
       
   479     TLiwGenericParam typeParam;
       
   480     typeParam.SetNameAndValueL( KType, TLiwVariant(aPluginType ) );
       
   481     typeParam.PushL();
       
   482     inParamList.AppendL( typeParam );
       
   483     CleanupStack::Pop(&typeParam);
       
   484     typeParam.Reset();
       
   485 
       
   486     iHspsInterface->ExecuteCmdL( KHSPSCommandGetPlugins, inParamList, outParamList ); 
       
   487     inParamList.Reset();
       
   488     
       
   489     TInt index(0);
       
   490     const TLiwGenericParam* plugins = outParamList.FindFirst(index,KPluginsKey);
       
   491     if(plugins)
       
   492         {
       
   493         const CLiwList* list = plugins->Value().AsList();
       
   494         if(list)
       
   495             {
       
   496             ProcessPluginsL(*list,aPlugins);
       
   497             }
       
   498         }
       
   499     outParamList.Reset();
       
   500     }
       
   501     
       
   502 // ---------------------------------------------------------------------------
       
   503 // ---------------------------------------------------------------------------
       
   504 //
       
   505 EXPORT_C CAddPluginResult* CHspsWrapper::AddPluginL(
       
   506     const TDesC8& aTargetConfiguration, 
       
   507     const TDesC8& aPluginUid)
       
   508     {
       
   509     // Compose AddPlugin hsps LIW message to Service.HomeScreenPluginConfiguration
       
   510     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   511     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   512       
       
   513     TLiwGenericParam confIdParam;
       
   514     confIdParam.SetNameAndValueL( KConfId, TLiwVariant(aTargetConfiguration) );
       
   515     confIdParam.PushL();
       
   516     inParamList.AppendL( confIdParam );
       
   517     CleanupStack::Pop(&confIdParam);
       
   518     confIdParam.Reset();
       
   519        
       
   520     TLiwGenericParam pluginUidParam;
       
   521     pluginUidParam.SetNameAndValueL( KPluginUid, TLiwVariant(aPluginUid) );
       
   522     pluginUidParam.PushL();
       
   523     inParamList.AppendL( pluginUidParam );
       
   524     CleanupStack::Pop(&pluginUidParam);
       
   525     pluginUidParam.Reset();
       
   526        
       
   527     // add widget to configuration
       
   528     iHspsInterface->ExecuteCmdL( KHSPSCommandAddPlugin, 
       
   529                                  inParamList, 
       
   530                                  outParamList ); 
       
   531     inParamList.Reset();
       
   532     
       
   533     CAddPluginResult* result = CAddPluginResult::NewL();
       
   534     CleanupStack::PushL(result);
       
   535     // test success
       
   536     const TLiwGenericParam* outParam = NULL;
       
   537     TInt pos(0);
       
   538     outParam = outParamList.FindFirst( pos, _L8("status") );
       
   539     if ( outParam )
       
   540        {
       
   541        result->SetStatus(outParam->Value().AsTInt32());
       
   542        }
       
   543     else
       
   544         {
       
   545         result->SetStatus(KErrNone);
       
   546         pos = 0;
       
   547         outParam = outParamList.FindFirst( pos, _L8("pluginId") );
       
   548         if ( outParam )
       
   549             {
       
   550             result->SetPluginIdL(outParam->Value().AsData());
       
   551             }
       
   552         else
       
   553             {
       
   554             // should never happen, but change status back to KErrNotFound 
       
   555             result->SetStatus(KErrNotFound);
       
   556             }
       
   557         }
       
   558   
       
   559     CleanupStack::Pop(result);
       
   560     return result;
       
   561     }
       
   562 
       
   563 // ---------------------------------------------------------------------------
       
   564 // ---------------------------------------------------------------------------
       
   565 //
       
   566 EXPORT_C CAddPluginResult* CHspsWrapper::AddPluginL(
       
   567     const TDesC8& aTargetConfiguration, 
       
   568     const TDesC8& aPluginUid,
       
   569     const TInt aIndex )
       
   570     {
       
   571     // Compose AddPlugin hsps LIW message to Service.HomeScreenPluginConfiguration
       
   572     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   573     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   574       
       
   575     TLiwGenericParam confIdParam;
       
   576     confIdParam.SetNameAndValueL( KConfId, TLiwVariant(aTargetConfiguration) );
       
   577     confIdParam.PushL();
       
   578     inParamList.AppendL( confIdParam );
       
   579     CleanupStack::Pop(&confIdParam);
       
   580     confIdParam.Reset();
       
   581    
       
   582     TLiwGenericParam pluginUidParam;
       
   583     pluginUidParam.SetNameAndValueL( KPluginUid, TLiwVariant(aPluginUid) );
       
   584     pluginUidParam.PushL();
       
   585     inParamList.AppendL( pluginUidParam );
       
   586     CleanupStack::Pop(&pluginUidParam);
       
   587     pluginUidParam.Reset();
       
   588     
       
   589     if(aIndex >= 0)
       
   590         {
       
   591         TBuf8<32> buf;
       
   592         buf.Num( aIndex );
       
   593         TLiwGenericParam indexParam;
       
   594         indexParam.SetNameAndValueL( KIndex, TLiwVariant( buf ) );
       
   595         indexParam.PushL();
       
   596         inParamList.AppendL( indexParam );
       
   597         CleanupStack::Pop(&indexParam);
       
   598         indexParam.Reset();
       
   599         }
       
   600     
       
   601     // add widget to configuration
       
   602     iHspsInterface->ExecuteCmdL( KHSPSCommandAddPlugin, 
       
   603                                  inParamList, 
       
   604                                  outParamList ); 
       
   605     inParamList.Reset();
       
   606     
       
   607     CAddPluginResult* result = CAddPluginResult::NewL();
       
   608     CleanupStack::PushL(result);
       
   609     // test success
       
   610     const TLiwGenericParam* outParam = NULL;
       
   611     TInt pos(0);
       
   612     outParam = outParamList.FindFirst( pos, _L8("status") );
       
   613     if ( outParam )
       
   614        {
       
   615        result->SetStatus(outParam->Value().AsTInt32());
       
   616        }
       
   617     else
       
   618         {
       
   619         result->SetStatus(KErrNone);
       
   620         pos = 0;
       
   621         outParam = outParamList.FindFirst( pos, _L8("pluginId") );
       
   622         if ( outParam )
       
   623             {
       
   624             result->SetPluginIdL(outParam->Value().AsData());
       
   625             }
       
   626         else
       
   627             {
       
   628             // should never happen, but change status back to KErrNotFound 
       
   629             result->SetStatus(KErrNotFound);
       
   630             }
       
   631         }
       
   632   
       
   633     CleanupStack::Pop(result);
       
   634     return result;
       
   635     }
       
   636 
       
   637 // ---------------------------------------------------------------------------
       
   638 // ---------------------------------------------------------------------------
       
   639 //
       
   640 EXPORT_C TInt CHspsWrapper::RemovePluginL(const TDesC8& aPluginId)
       
   641     {
       
   642     // Compose AddPlugin hsps LIW message to Service.HomeScreenPluginConfiguration
       
   643     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   644     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   645          
       
   646     // Compose Liw message
       
   647     TLiwGenericParam pluginIdParam;
       
   648     pluginIdParam.SetNameAndValueL( KKeyPluginId, TLiwVariant(aPluginId) );
       
   649     pluginIdParam.PushL();
       
   650     inParamList.AppendL( pluginIdParam );
       
   651     CleanupStack::Pop(&pluginIdParam);
       
   652     pluginIdParam.Reset();
       
   653       
       
   654     iHspsInterface->ExecuteCmdL( KHSPSCommandRemovePlugin, 
       
   655                                  inParamList, 
       
   656                                  outParamList ); 
       
   657       
       
   658     inParamList.Reset();
       
   659       
       
   660     // check success
       
   661     const TLiwGenericParam* outParam = NULL;
       
   662     TInt pos(0);
       
   663     outParam = outParamList.FindFirst( pos, KOutKeyStatus );
       
   664     TInt status(KErrGeneral);
       
   665     
       
   666     if ( outParam )
       
   667         {
       
   668         status = outParam->Value().AsTInt32();
       
   669         }
       
   670     outParamList.Reset();
       
   671     return status;
       
   672     }
       
   673 
       
   674 // ---------------------------------------------------------------------------
       
   675 // ---------------------------------------------------------------------------
       
   676 //
       
   677 EXPORT_C TInt CHspsWrapper::ReplacePluginL( 
       
   678         const TDesC8& aPluginId, 
       
   679         const TDesC8& aConfUid )
       
   680     {
       
   681     // Compose ReplacePlugin hsps LIW message to Service.HomeScreenPluginConfiguration
       
   682     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   683     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   684          
       
   685     // Compose Liw message
       
   686     TLiwGenericParam pluginIdParam;
       
   687     pluginIdParam.SetNameAndValueL( KKeyPluginId, TLiwVariant(aPluginId) );
       
   688     pluginIdParam.PushL();
       
   689     inParamList.AppendL( pluginIdParam );
       
   690     CleanupStack::Pop(&pluginIdParam);
       
   691     pluginIdParam.Reset();
       
   692     
       
   693     TLiwGenericParam confUidParam;
       
   694     confUidParam.SetNameAndValueL( KKeyConfUid, TLiwVariant( aConfUid ) );
       
   695     confUidParam.PushL();
       
   696     inParamList.AppendL( confUidParam );
       
   697     CleanupStack::Pop( &confUidParam );
       
   698     confUidParam.Reset();
       
   699       
       
   700     // Execute command
       
   701     iHspsInterface->ExecuteCmdL( KHSPSCommandReplacePlugin, 
       
   702                                  inParamList, 
       
   703                                  outParamList ); 
       
   704       
       
   705     inParamList.Reset();
       
   706       
       
   707     // check success
       
   708     const TLiwGenericParam* outParam = NULL;
       
   709     TInt pos(0);
       
   710     outParam = outParamList.FindFirst( pos, KOutKeyStatus );
       
   711     TInt status( KErrGeneral );
       
   712     
       
   713     if ( outParam )
       
   714         {
       
   715         status = outParam->Value().AsTInt32();
       
   716         }
       
   717     outParamList.Reset();
       
   718     return status;
       
   719     }
       
   720 
       
   721 // ---------------------------------------------------------------------------
       
   722 // ---------------------------------------------------------------------------
       
   723 //
       
   724 EXPORT_C TInt CHspsWrapper::SetActivePluginL(const TDesC8& aPluginId)
       
   725     {
       
   726     // Compose AddPlugin hsps LIW message to Service.HomeScreenPluginConfiguration
       
   727     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   728     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   729          
       
   730     // Compose Liw message
       
   731     TLiwGenericParam pluginIdParam;
       
   732     pluginIdParam.SetNameAndValueL( KKeyPluginId, TLiwVariant(aPluginId) );
       
   733     pluginIdParam.PushL();
       
   734     inParamList.AppendL( pluginIdParam );
       
   735     CleanupStack::Pop(&pluginIdParam);
       
   736     pluginIdParam.Reset();
       
   737       
       
   738     iHspsInterface->ExecuteCmdL( KHSPSCommandSetActivePlugin, 
       
   739                                  inParamList, 
       
   740                                  outParamList ); 
       
   741       
       
   742     inParamList.Reset();
       
   743       
       
   744     // check success
       
   745     const TLiwGenericParam* outParam = NULL;
       
   746     TInt pos(0);
       
   747     outParam = outParamList.FindFirst( pos, KOutKeyStatus );
       
   748     TInt status(KErrGeneral);
       
   749     
       
   750     if ( outParam )
       
   751         {
       
   752         status = outParam->Value().AsTInt32();
       
   753         }
       
   754     outParamList.Reset();
       
   755     return status;
       
   756     }
       
   757     
       
   758 // ---------------------------------------------------------------------------
       
   759 // ---------------------------------------------------------------------------
       
   760 //
       
   761 EXPORT_C TInt CHspsWrapper::MovePluginsL(
       
   762     const TDesC8& aConfId, 
       
   763     const MDesC8Array& aPluginIds)
       
   764     {
       
   765     // Compose AddPlugin hsps LIW message to Service.HomeScreenPluginConfiguration
       
   766     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   767     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   768     
       
   769     TLiwGenericParam confIdParam;
       
   770     confIdParam.SetNameAndValueL( KConfId, TLiwVariant(aConfId) );
       
   771     confIdParam.PushL();
       
   772     inParamList.AppendL( confIdParam );
       
   773     CleanupStack::Pop( &confIdParam );
       
   774     confIdParam.Reset();    
       
   775        
       
   776     // add "plugins" parameter to the inParamList
       
   777     CLiwDefaultList* inPluginList = CLiwDefaultList::NewLC();
       
   778     for( int i = 0; i < aPluginIds.MdcaCount(); i++ )
       
   779         {
       
   780         const TDesC8& id = aPluginIds.MdcaPoint(i);
       
   781         inPluginList->AppendL( TLiwVariant(id) );
       
   782         }
       
   783        
       
   784     TLiwGenericParam pluginsParam;
       
   785     pluginsParam.SetNameAndValueL( KKeyPlugins, TLiwVariant(inPluginList) );
       
   786     pluginsParam.PushL();
       
   787     inParamList.AppendL( pluginsParam );
       
   788     CleanupStack::Pop( &pluginsParam );
       
   789     pluginsParam.Reset();
       
   790 
       
   791     iHspsInterface->ExecuteCmdL( KHSPSMovePlugins, 
       
   792                                  inParamList, 
       
   793                                  outParamList ); 
       
   794 
       
   795     CleanupStack::PopAndDestroy( inPluginList );    
       
   796     inParamList.Reset();
       
   797     
       
   798       
       
   799     // check success
       
   800     const TLiwGenericParam* outParam = NULL;
       
   801     TInt pos(0);
       
   802     outParam = outParamList.FindFirst( pos, KOutKeyStatus );
       
   803     TInt status(KErrGeneral);
       
   804     
       
   805     if ( outParam )
       
   806         {
       
   807         status = outParam->Value().AsTInt32();
       
   808         }
       
   809     outParamList.Reset();
       
   810     return status;
       
   811     }
       
   812 
       
   813 // ---------------------------------------------------------------------------
       
   814 // ---------------------------------------------------------------------------
       
   815 //
       
   816 EXPORT_C TInt CHspsWrapper::SetPluginSettingsL(
       
   817     const TDesC8& aPluginId, 
       
   818     const RPointerArray<CItemMap>& aSettings)
       
   819     {
       
   820     // Compose AddPlugin hsps LIW message to Service.HomeScreenPluginConfiguration
       
   821     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   822     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   823     
       
   824     TLiwGenericParam pluginIdParam;
       
   825     pluginIdParam.SetNameAndValueL( KKeyPluginId, TLiwVariant(aPluginId) );
       
   826     pluginIdParam.PushL();
       
   827     inParamList.AppendL( pluginIdParam );
       
   828     CleanupStack::Pop( &pluginIdParam );
       
   829     pluginIdParam.Reset();    
       
   830        
       
   831     CLiwDefaultList* itemMapList = CLiwDefaultList::NewLC();
       
   832     for( int i = 0; i < aSettings.Count(); i++ )
       
   833         {
       
   834         CItemMap* itemMap = aSettings[i];
       
   835         
       
   836         CLiwDefaultMap* inItemMap = CLiwDefaultMap::NewLC();
       
   837         FillMapFromItemL(*inItemMap,*itemMap);
       
   838         itemMapList->AppendL( TLiwVariant(inItemMap) );
       
   839         CleanupStack::PopAndDestroy(inItemMap);
       
   840         }
       
   841        
       
   842     TLiwGenericParam settingsParam;
       
   843     settingsParam.SetNameAndValueL( KKeySettings, TLiwVariant(itemMapList) );
       
   844     settingsParam.PushL();
       
   845     inParamList.AppendL( settingsParam );
       
   846     CleanupStack::Pop( &settingsParam );
       
   847     settingsParam.Reset();
       
   848     
       
   849     iHspsInterface->ExecuteCmdL( KHSPSSetPluginSettings, 
       
   850                                  inParamList, 
       
   851                                  outParamList ); 
       
   852     
       
   853     CleanupStack::PopAndDestroy( itemMapList );  
       
   854     inParamList.Reset();
       
   855     
       
   856       
       
   857     // check success
       
   858     const TLiwGenericParam* outParam = NULL;
       
   859     TInt pos(0);
       
   860     outParam = outParamList.FindFirst( pos, KOutKeyStatus );
       
   861     TInt status(KErrGeneral);
       
   862     
       
   863     if ( outParam )
       
   864         {
       
   865         status = outParam->Value().AsTInt32();
       
   866         }
       
   867     outParamList.Reset();
       
   868     return status;
       
   869     }
       
   870 
       
   871 // ---------------------------------------------------------------------------
       
   872 // ---------------------------------------------------------------------------
       
   873 //
       
   874 EXPORT_C TInt CHspsWrapper::SetConfStateL( const TDesC8& aConfId, 
       
   875     const TDesC8& aState, TBool aIncludePlugins )
       
   876     {
       
   877     // Compose AddPlugin hsps LIW message to Service.HomeScreenPluginConfiguration
       
   878     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   879     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   880          
       
   881     // Compose Liw message
       
   882     TLiwGenericParam confIdParam;
       
   883     confIdParam.SetNameAndValueL( KConfId, TLiwVariant( aConfId ) );
       
   884     confIdParam.PushL();
       
   885     inParamList.AppendL( confIdParam );
       
   886     CleanupStack::Pop(&confIdParam);
       
   887     confIdParam.Reset();
       
   888     
       
   889     TLiwGenericParam pluginStateParam;
       
   890     pluginStateParam.SetNameAndValueL( KConfState, TLiwVariant( aState ) );
       
   891     pluginStateParam.PushL();
       
   892     inParamList.AppendL( pluginStateParam );
       
   893     CleanupStack::Pop(&pluginStateParam);
       
   894     pluginStateParam.Reset();
       
   895 
       
   896     iHspsInterface->ExecuteCmdL( KHSPSCommandSetConfState, 
       
   897                                  inParamList, 
       
   898                                  outParamList ); 
       
   899 
       
   900     const TLiwGenericParam* outParam = NULL;
       
   901     TInt pos(0);
       
   902     outParam = outParamList.FindFirst( pos, KOutKeyStatus );
       
   903     TInt status(KErrGeneral);
       
   904     
       
   905     if ( outParam )
       
   906         {
       
   907         status = outParam->Value().AsTInt32();
       
   908         }
       
   909     
       
   910     outParamList.Reset();
       
   911         
       
   912     if( !status && aIncludePlugins )
       
   913         {
       
   914         _LIT8( KFilter, "filter" );
       
   915         _LIT8( KFilterPlugins, "Plugins" );
       
   916         
       
   917         TLiwGenericParam filterParam;
       
   918         filterParam.PushL();
       
   919         filterParam.SetNameAndValueL( KFilter, TLiwVariant( KFilterPlugins ) );        
       
   920         inParamList.AppendL( filterParam );
       
   921         CleanupStack::Pop(&filterParam);
       
   922         filterParam.Reset();
       
   923         
       
   924         iHspsInterface->ExecuteCmdL( KHSPSCommandSetConfState, 
       
   925                                      inParamList, 
       
   926                                      outParamList );
       
   927         
       
   928         // check success
       
   929         pos = 0;
       
   930         outParam = outParamList.FindFirst( pos, KOutKeyStatus );
       
   931         status = KErrGeneral;
       
   932         
       
   933         if ( outParam )
       
   934             {
       
   935             status = outParam->Value().AsTInt32();
       
   936             }
       
   937 
       
   938         outParamList.Reset();        
       
   939         }
       
   940             
       
   941     inParamList.Reset();
       
   942       
       
   943     return status;
       
   944     }
       
   945     
       
   946 // ---------------------------------------------------------------------------
       
   947 // ---------------------------------------------------------------------------
       
   948 //
       
   949 EXPORT_C CLiwServiceHandler* CHspsWrapper::ServiceHandler() const
       
   950     {
       
   951     return iServiceHandler;  
       
   952     }
       
   953 
       
   954 // ---------------------------------------------------------------------------
       
   955 // ---------------------------------------------------------------------------
       
   956 //    
       
   957 EXPORT_C CLiwCriteriaItem* CHspsWrapper::HspsService() const
       
   958     {
       
   959     return iHspsService;
       
   960     }
       
   961     
       
   962 // ---------------------------------------------------------------------------
       
   963 // ---------------------------------------------------------------------------
       
   964 //
       
   965 EXPORT_C MLiwInterface* CHspsWrapper::HspsInterface() const
       
   966     {
       
   967     return iHspsInterface;
       
   968     }
       
   969         
       
   970 // ---------------------------------------------------------------------------
       
   971 // ---------------------------------------------------------------------------
       
   972 //
       
   973 void CHspsWrapper::ProcessConfigurationMapL(
       
   974     const CLiwMap& aSource, 
       
   975     CHspsConfiguration& aTarget)
       
   976     {
       
   977     TLiwVariant tempVariant;
       
   978     tempVariant.PushL();
       
   979         
       
   980     if ( aSource.FindL( _L8("id"), tempVariant ) )
       
   981         {
       
   982         aTarget.SetConfIdL(tempVariant.AsData());
       
   983         }
       
   984     if ( aSource.FindL( _L8("uid"), tempVariant ) )
       
   985         {
       
   986         aTarget.PluginInfo().SetUidL(tempVariant.AsData());
       
   987         }
       
   988     if ( aSource.FindL( _L8("type"), tempVariant ) )
       
   989         {
       
   990         aTarget.PluginInfo().SetTypeL(tempVariant.AsData());
       
   991         }
       
   992     if ( aSource.FindL( _L8("interface"), tempVariant ) )
       
   993         {
       
   994         aTarget.PluginInfo().SetInterfaceL(tempVariant.AsData());
       
   995         }        
       
   996     if ( aSource.FindL( _L8("name"), tempVariant ) )
       
   997         {
       
   998         aTarget.PluginInfo().SetNameL(tempVariant.AsData());
       
   999         }   
       
  1000     if ( aSource.FindL( _L8("state"), tempVariant ) )
       
  1001         {
       
  1002         aTarget.PluginInfo().SetConfigurationStateL(tempVariant.AsData());
       
  1003         }        
       
  1004     if ( aSource.FindL( _L8("multiinstance"), tempVariant ) )
       
  1005         {
       
  1006         aTarget.PluginInfo().SetMultiInstanceL( tempVariant.AsTInt32() );
       
  1007         }
       
  1008     if ( aSource.FindL( _L8( "max_child" ), tempVariant ) )
       
  1009         {
       
  1010         aTarget.PluginInfo().SetMaxChild( tempVariant.AsTInt32() );
       
  1011         }    
       
  1012     if( aSource.FindL( _L8("plugins"), tempVariant ) )
       
  1013         {
       
  1014         const CLiwList* plugins( tempVariant.AsList() );
       
  1015         if( plugins )
       
  1016             {
       
  1017             ProcessConfigurationPluginsL(*plugins,aTarget);
       
  1018             }
       
  1019         }
       
  1020     if( aSource.FindL( _L8("settings"), tempVariant ) )
       
  1021         {
       
  1022         const CLiwList* settings( tempVariant.AsList() );
       
  1023         if( settings )
       
  1024             {
       
  1025             ProcessConfigurationSettingsL(*settings,aTarget);
       
  1026             }
       
  1027         }
       
  1028     if( aSource.FindL( _L8("resources"), tempVariant ) )
       
  1029         {
       
  1030         const CLiwList* resources( tempVariant.AsList() );
       
  1031         if( resources )
       
  1032             {
       
  1033             ProcessConfigurationResourcesL(*resources,aTarget);
       
  1034             }
       
  1035         }
       
  1036     CleanupStack::Pop(&tempVariant);
       
  1037     tempVariant.Reset();
       
  1038     }
       
  1039 
       
  1040 // ---------------------------------------------------------------------------
       
  1041 // ---------------------------------------------------------------------------
       
  1042 //
       
  1043 void CHspsWrapper::ProcessConfigurationPluginsL(
       
  1044     const CLiwList& aPluginsList, 
       
  1045     CHspsConfiguration& aTarget)
       
  1046     {
       
  1047     TLiwVariant pluginMapVariant;
       
  1048     pluginMapVariant.PushL();
       
  1049     for( int i=0;i<aPluginsList.Count();++i )
       
  1050         {
       
  1051         if( aPluginsList.AtL(i,pluginMapVariant) )
       
  1052             {
       
  1053             const CLiwMap* pluginMap( pluginMapVariant.AsMap() );
       
  1054             TLiwVariant pluginVariant;
       
  1055             pluginVariant.PushL();
       
  1056             if( pluginMap )
       
  1057                 {
       
  1058                 CPluginMap* plugin = CPluginMap::NewLC();
       
  1059                 if( pluginMap->FindL( _L8("id"),pluginVariant) )
       
  1060                     {
       
  1061                     plugin->SetPluginIdL( pluginVariant.AsData() );
       
  1062                     }
       
  1063                 if( pluginMap->FindL( _L8("uid"),pluginVariant) )
       
  1064                     {
       
  1065                     plugin->SetPluginUidL( pluginVariant.AsData() );
       
  1066                     }
       
  1067                 if( pluginMap->FindL( _L8("activationstate"),pluginVariant ) )
       
  1068                     {
       
  1069                     plugin->SetActivationStateL( pluginVariant.AsData() );
       
  1070                     }
       
  1071                 if ( pluginMap->FindL( _L8( "locking_status" ), pluginVariant ) )
       
  1072                     {
       
  1073                     plugin->SetLockingStatusL( pluginVariant.AsData() );
       
  1074                     }
       
  1075                 aTarget.AddPluginMapL(plugin);                    
       
  1076                 CleanupStack::Pop(plugin);
       
  1077                 }
       
  1078             CleanupStack::Pop(&pluginVariant);
       
  1079             pluginVariant.Reset();
       
  1080             }
       
  1081        
       
  1082         }
       
  1083     CleanupStack::Pop(&pluginMapVariant);
       
  1084     pluginMapVariant.Reset();
       
  1085     }
       
  1086 
       
  1087 // ---------------------------------------------------------------------------
       
  1088 // ---------------------------------------------------------------------------
       
  1089 //
       
  1090 void CHspsWrapper::ProcessConfigurationSettingsL(
       
  1091     const CLiwList& aItemList, 
       
  1092     CHspsConfiguration& aTarget)
       
  1093     {
       
  1094     TLiwVariant itemMapVariant;
       
  1095     itemMapVariant.PushL();
       
  1096     for( int i=0;i<aItemList.Count();++i )
       
  1097         {
       
  1098         if( aItemList.AtL(i,itemMapVariant) )
       
  1099             {
       
  1100             const CLiwMap* itemMap( itemMapVariant.AsMap() );
       
  1101             TLiwVariant itemVariant;
       
  1102             itemVariant.PushL();
       
  1103             if( itemMap )
       
  1104                 {
       
  1105                 CItemMap* item = CItemMap::NewLC();
       
  1106                 if( itemMap->FindL( _L8("itemId"),itemVariant) )
       
  1107                     {
       
  1108                     item->SetItemIdL( itemVariant.AsData() );
       
  1109                     }
       
  1110                 if( itemMap->FindL( _L8("name"),itemVariant) )
       
  1111                     {
       
  1112                     item->SetItemNameL( itemVariant.AsData() );
       
  1113                     }
       
  1114                 if( itemMap->FindL( _L8("properties"),itemVariant) )
       
  1115                     {
       
  1116                     const CLiwList* properties( itemVariant.AsList() );
       
  1117                     if(properties)
       
  1118                         {
       
  1119                         ProcessConfItemPropertiesL(*properties,*item);
       
  1120                         }
       
  1121                     }
       
  1122                     
       
  1123                 aTarget.AddItemMapL(item);                    
       
  1124                 CleanupStack::Pop(item);
       
  1125                 }
       
  1126             CleanupStack::Pop(&itemVariant);
       
  1127             itemVariant.Reset();
       
  1128             }
       
  1129        
       
  1130         }
       
  1131     CleanupStack::Pop(&itemMapVariant);
       
  1132     itemMapVariant.Reset();
       
  1133     }
       
  1134 
       
  1135 // ---------------------------------------------------------------------------
       
  1136 // ---------------------------------------------------------------------------
       
  1137 //
       
  1138 void CHspsWrapper::ProcessConfigurationResourcesL(
       
  1139     const CLiwList& aObjectList, 
       
  1140     CHspsConfiguration& aTarget)
       
  1141     {
       
  1142     TLiwVariant objectMapVariant;
       
  1143     objectMapVariant.PushL();
       
  1144     for( int i=0;i<aObjectList.Count();++i )
       
  1145         {
       
  1146         if( aObjectList.AtL(i,objectMapVariant) )
       
  1147             {
       
  1148             const CLiwMap* objectMap( objectMapVariant.AsMap() );
       
  1149             TLiwVariant objectVariant;
       
  1150             objectVariant.PushL();
       
  1151             if( objectMap )
       
  1152                 {
       
  1153                 CObjectMap* object = CObjectMap::NewLC();
       
  1154                 if( objectMap->FindL( _L8("name"),objectVariant) )
       
  1155                     {
       
  1156                     object->SetNameL( objectVariant.AsData() );
       
  1157                     }
       
  1158                 if( objectMap->FindL( _L8("path"),objectVariant) )
       
  1159                     {
       
  1160                     object->SetPathL( objectVariant.AsData() );
       
  1161                     }
       
  1162                 if( objectMap->FindL( _L8("mediatype"),objectVariant) )
       
  1163                     {
       
  1164                     object->SetMediaTypeL( objectVariant.AsData() );
       
  1165                     }    
       
  1166                 if( objectMap->FindL( _L8("tag"),objectVariant) )
       
  1167                     {
       
  1168                     object->SetTagL( objectVariant.AsData() );
       
  1169                     }
       
  1170                 aTarget.AddObjectMapL(object);                    
       
  1171                 CleanupStack::Pop(object);
       
  1172                 }
       
  1173             CleanupStack::Pop(&objectVariant);
       
  1174             objectVariant.Reset();
       
  1175             }
       
  1176         }
       
  1177     CleanupStack::Pop(&objectMapVariant);
       
  1178     objectMapVariant.Reset();
       
  1179     }
       
  1180 
       
  1181 // ---------------------------------------------------------------------------
       
  1182 // ---------------------------------------------------------------------------
       
  1183 //
       
  1184 void CHspsWrapper::ProcessConfItemPropertiesL(
       
  1185     const CLiwList& aPropertyMapList,
       
  1186     CItemMap& aItemMap)
       
  1187     {
       
  1188     TLiwVariant propertyMapVariant;
       
  1189     propertyMapVariant.PushL();
       
  1190     for( int i=0;i<aPropertyMapList.Count();++i )
       
  1191        {
       
  1192        if( aPropertyMapList.AtL(i,propertyMapVariant) )
       
  1193            {
       
  1194            const CLiwMap* propertyMap( propertyMapVariant.AsMap() );
       
  1195            TLiwVariant propertyVariant;
       
  1196            propertyVariant.PushL();
       
  1197            if( propertyMap )
       
  1198                {
       
  1199                CPropertyMap* property = CPropertyMap::NewLC();
       
  1200                if( propertyMap->FindL( _L8("name"),propertyVariant ) )
       
  1201                    {
       
  1202                    property->SetNameL( propertyVariant.AsData() );
       
  1203                    }
       
  1204                if( propertyMap->FindL( _L8("value"),propertyVariant ) )
       
  1205                    {
       
  1206                    property->SetValueL( propertyVariant.AsData() );
       
  1207                    }
       
  1208                aItemMap.AddPropertyMapL(property);                    
       
  1209                CleanupStack::Pop(property);
       
  1210                }
       
  1211            CleanupStack::Pop(&propertyVariant);
       
  1212            propertyVariant.Reset();
       
  1213            }
       
  1214       
       
  1215        }
       
  1216     CleanupStack::Pop(&propertyMapVariant);
       
  1217     propertyMapVariant.Reset();
       
  1218     }
       
  1219     
       
  1220 // ---------------------------------------------------------------------------
       
  1221 // ---------------------------------------------------------------------------
       
  1222 //
       
  1223 void CHspsWrapper::ProcessPluginsL(
       
  1224     const CLiwList& aPluginInfoMapList, 
       
  1225     RPointerArray<CPluginInfo>& aPlugins)
       
  1226     {
       
  1227     // create widget array and populate it from HSPS list
       
  1228     TLiwVariant mapVar;
       
  1229     mapVar.PushL();
       
  1230     
       
  1231     for ( int index(0); aPluginInfoMapList.AtL( index, mapVar ); ++index )
       
  1232         {
       
  1233         const CLiwMap* pluginInfoMap = mapVar.AsMap();
       
  1234         if ( pluginInfoMap )
       
  1235             {
       
  1236             TLiwVariant pluginVar;
       
  1237             pluginVar.PushL();
       
  1238             CPluginInfo* pluginInfo = CPluginInfo::NewLC();
       
  1239             
       
  1240             if( pluginInfoMap->FindL( _L8("uid"), pluginVar) )
       
  1241                 {
       
  1242                 pluginInfo->SetUidL( pluginVar.AsData() );
       
  1243                 }
       
  1244             if( pluginInfoMap->FindL( _L8("interface"), pluginVar ) )
       
  1245                 {
       
  1246                 pluginInfo->SetInterfaceL( pluginVar.AsData() );
       
  1247                 }
       
  1248             if( pluginInfoMap->FindL( _L8("type"), pluginVar ) )
       
  1249                 {
       
  1250                 pluginInfo->SetTypeL( pluginVar.AsData() );
       
  1251                 }
       
  1252             if( pluginInfoMap->FindL( _L8("name"), pluginVar ) )
       
  1253                 {
       
  1254                 pluginInfo->SetNameL( pluginVar.AsData() );
       
  1255                 }
       
  1256             if ( pluginInfoMap->FindL( _L8("multiinstance"), pluginVar ) )
       
  1257                 {
       
  1258                 pluginInfo->SetMultiInstanceL( pluginVar.AsTInt32() );
       
  1259                 }
       
  1260             if ( pluginInfoMap->FindL( _L8( "max_child" ), pluginVar ) )
       
  1261                 {
       
  1262                 pluginInfo->SetMaxChild( pluginVar.AsTInt32() );
       
  1263                 }
       
  1264             if ( pluginInfoMap->FindL( _L8("desc"), pluginVar ) )
       
  1265                 {
       
  1266                 pluginInfo->SetDescriptionL( pluginVar.AsData() );
       
  1267                 }
       
  1268             if ( pluginInfoMap->FindL( _L8("logo"), pluginVar ) )
       
  1269                 {
       
  1270                 pluginInfo->SetLogoIconL( pluginVar.AsData() );
       
  1271                 }
       
  1272 
       
  1273             aPlugins.AppendL(pluginInfo);
       
  1274             CleanupStack::Pop(pluginInfo);
       
  1275             CleanupStack::Pop(&pluginVar);
       
  1276             pluginVar.Reset();
       
  1277             }
       
  1278         }
       
  1279     CleanupStack::Pop(&mapVar);
       
  1280     mapVar.Reset();
       
  1281     }
       
  1282 
       
  1283 // ---------------------------------------------------------------------------
       
  1284 // ---------------------------------------------------------------------------
       
  1285 //
       
  1286 void CHspsWrapper::FillMapFromItemL( CLiwDefaultMap& aMap, const CItemMap& aItemMap )
       
  1287     {
       
  1288     aMap.InsertL(  KKeyItemId, TLiwVariant(aItemMap.ItemId()) );
       
  1289     aMap.InsertL(  KKeyName, TLiwVariant(aItemMap.ItemName()) );
       
  1290     
       
  1291     CLiwDefaultList* inPropertyMapList = CLiwDefaultList::NewLC();
       
  1292     FillMapFromPropertiesL(*inPropertyMapList,aItemMap.Properties());
       
  1293     aMap.InsertL(  KKeyProperties, TLiwVariant(inPropertyMapList) );
       
  1294     CleanupStack::PopAndDestroy(inPropertyMapList);
       
  1295     }
       
  1296 
       
  1297 // ---------------------------------------------------------------------------
       
  1298 // ---------------------------------------------------------------------------
       
  1299 //
       
  1300 void CHspsWrapper::FillMapFromPropertiesL( 
       
  1301     CLiwDefaultList& aInPropertyMapList, 
       
  1302     const RPointerArray<CPropertyMap>& aProperties )
       
  1303     {
       
  1304     
       
  1305     for(int i=0; i<aProperties.Count(); ++i)
       
  1306         {
       
  1307         CLiwDefaultMap* inPropertyMap = CLiwDefaultMap::NewLC();
       
  1308         inPropertyMap->InsertL(  KKeyName, TLiwVariant(aProperties[i]->Name()) );
       
  1309         inPropertyMap->InsertL(  KKeyValue, TLiwVariant(aProperties[i]->Value()) );
       
  1310         aInPropertyMapList.AppendL(inPropertyMap);
       
  1311         CleanupStack::PopAndDestroy(inPropertyMap);
       
  1312         }
       
  1313     }
       
  1314 
       
  1315 // ---------------------------------------------------------------------------
       
  1316 // ---------------------------------------------------------------------------
       
  1317 //    
       
  1318 TInt CHspsWrapper::HandleNotifyL( TInt aCmdId, TInt aEventId,                        
       
  1319     CLiwGenericParamList& aEventParamList,
       
  1320     const CLiwGenericParamList& /*aInParamList*/ )
       
  1321     {
       
  1322     TInt retval( KErrNone );
       
  1323    
       
  1324     if( iObserver && iTransactionId == aCmdId )
       
  1325         {                 
       
  1326         const TLiwGenericParam* outParam( NULL );
       
  1327         
       
  1328         TInt pos( 0 );
       
  1329         outParam = aEventParamList.FindFirst( pos, _L8("status") );
       
  1330         
       
  1331         if ( outParam )
       
  1332             {    
       
  1333             retval = outParam->Value().AsTInt32();
       
  1334             }
       
  1335         else
       
  1336             {   
       
  1337             pos = 0;
       
  1338             
       
  1339             retval = KErrNotFound;
       
  1340                 
       
  1341             outParam = aEventParamList.FindFirst( pos, _L8("notification") );
       
  1342             
       
  1343             if( !outParam )
       
  1344                 {      
       
  1345                 // should never happen, but change status back to KErrNotFound 
       
  1346                 return retval;                
       
  1347                 }
       
  1348                 
       
  1349             HBufC8* event( NULL );
       
  1350             HBufC8* appConfUid( NULL );
       
  1351             HBufC8* pluginUid( NULL );
       
  1352             HBufC8* pluginName( NULL );
       
  1353             HBufC8* origUid( NULL );
       
  1354             TInt pushCount( 0 );
       
  1355                                                                 
       
  1356             TLiwVariant variant;
       
  1357             variant.PushL();
       
  1358             pushCount++;
       
  1359                 
       
  1360             variant = outParam->Value();
       
  1361             
       
  1362             const CLiwMap* notifMap( variant.AsMap() );
       
  1363                                             
       
  1364             if ( notifMap->FindL( _L8("event"), variant ) )
       
  1365                 {
       
  1366                 event = variant.AsData().AllocLC();
       
  1367                 pushCount++;
       
  1368                 }    
       
  1369                 
       
  1370             variant.Reset();    
       
  1371                                              
       
  1372             if( notifMap->FindL( _L8("appConfUid"), variant ) )
       
  1373                 {  
       
  1374                 appConfUid = variant.AsData().AllocLC();
       
  1375                 pushCount++;
       
  1376                 }
       
  1377                 
       
  1378             variant.Reset();
       
  1379                                            
       
  1380             if( notifMap->FindL( _L8("name"), variant ) )
       
  1381                 {
       
  1382                 pluginName = variant.AsData().AllocLC();
       
  1383                 pushCount++;
       
  1384                 }
       
  1385                    
       
  1386             variant.Reset();
       
  1387             
       
  1388             if( notifMap->FindL( _L8("origUid"), variant ) )
       
  1389                 {
       
  1390                 origUid = variant.AsData().AllocLC();
       
  1391                 pushCount++;
       
  1392                 }
       
  1393             
       
  1394             variant.Reset();
       
  1395                                             
       
  1396             if( notifMap->FindL( _L8("pluginUid"), variant ) )
       
  1397                 {
       
  1398                 pluginUid = variant.AsData().AllocLC();
       
  1399                 pushCount++;
       
  1400                 }        
       
  1401                 
       
  1402            variant.Reset();
       
  1403                              
       
  1404            if( notifMap->FindL( _L8("pluginIds"), variant ) )
       
  1405                {                                                                        
       
  1406                const CLiwList* pluginIdList( variant.AsList() );
       
  1407                     
       
  1408                variant.Reset();
       
  1409                     
       
  1410                TInt count( pluginIdList->Count() );
       
  1411                
       
  1412                retval = KErrNone;
       
  1413                
       
  1414                for( TInt i = 0; i < count && retval == KErrNone; i++ )
       
  1415                    {
       
  1416                    pluginIdList->AtL( i, variant );
       
  1417                                       
       
  1418                    HBufC8* pluginId( NULL );
       
  1419                    
       
  1420                    pluginId = variant.AsData().AllocLC();
       
  1421                                                          
       
  1422                    retval = iObserver->HandleNotifyL( 
       
  1423                                 ( event ) ? *event : KNullDesC8(), 
       
  1424                                 ( appConfUid ) ? *appConfUid : KNullDesC8(), 
       
  1425                                 ( pluginName ) ? *pluginName : KNullDesC8(),
       
  1426                                 ( origUid ) ? *origUid : KNullDesC8(),
       
  1427                                 ( pluginUid ) ? *pluginUid : KNullDesC8(), 
       
  1428                                 ( pluginId ) ? * pluginId : KNullDesC8() );
       
  1429                                                       
       
  1430                    CleanupStack::PopAndDestroy( pluginId );                                                      
       
  1431                    
       
  1432                    variant.Reset();
       
  1433                    }
       
  1434                }
       
  1435         
       
  1436             CleanupStack::PopAndDestroy( pushCount );
       
  1437             }
       
  1438         }
       
  1439         
       
  1440     if( retval != KErrNone && aEventId != KLiwEventInProgress)
       
  1441         {
       
  1442         CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
  1443         CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
  1444         
       
  1445         inParamList.Reset();
       
  1446         outParamList.Reset();
       
  1447         //cancel old notification request
       
  1448         iHspsInterface->ExecuteCmdL( KRequestNotification,
       
  1449                                      inParamList,
       
  1450                                      outParamList,
       
  1451                                      KLiwOptCancel,
       
  1452                                      this ); 
       
  1453         
       
  1454         inParamList.Reset();
       
  1455         outParamList.Reset();
       
  1456         //request notification again
       
  1457         iTransactionId = -1;
       
  1458         iHspsInterface->ExecuteCmdL( KRequestNotification,
       
  1459                                      inParamList,
       
  1460                                      outParamList,
       
  1461                                      KLiwOptASyncronous,
       
  1462                                      this );
       
  1463         
       
  1464         const TLiwGenericParam* outParam( NULL );
       
  1465                         
       
  1466         TInt pos( 0 );
       
  1467         outParam = outParamList.FindFirst( pos, _L8("status") );
       
  1468                        
       
  1469         if ( outParam )
       
  1470             {
       
  1471             TInt retval;
       
  1472             retval = outParam->Value().AsTInt32();
       
  1473             
       
  1474             if(retval == KErrNone )
       
  1475                 {
       
  1476                 pos = 0;
       
  1477                 outParam = outParamList.FindFirst( pos, _L8("TransactionID") );
       
  1478                        
       
  1479                 if( outParam )
       
  1480                     {
       
  1481                     retval = outParam->Value().AsTInt32();
       
  1482                     iTransactionId = retval;
       
  1483                     }
       
  1484                 }     
       
  1485             }
       
  1486         
       
  1487         }
       
  1488    
       
  1489     
       
  1490     return retval;    
       
  1491     }    
       
  1492 }
       
  1493 
       
  1494 //End of file