homescreenpluginsrv/homescreen_settings_api/src/hspluginsettings.cpp
branchRCL_3
changeset 18 bd874ee5e5e2
parent 1 844b978f8d5e
equal deleted inserted replaced
9:d0529222e3f0 18:bd874ee5e5e2
    21 #include <liwvariant.h>
    21 #include <liwvariant.h>
    22 #include <bamdesca.h>
    22 #include <bamdesca.h>
    23 
    23 
    24 #include <hspluginsettings.h>
    24 #include <hspluginsettings.h>
    25 #include "hspsconfiguration.h"
    25 #include "hspsconfiguration.h"
    26 //#include "pluginmap.h"
       
    27 #include "itemmap.h"
    26 #include "itemmap.h"
    28 #include "propertymap.h"
    27 #include "propertymap.h"
    29 //#include "objectmap.h"
       
    30 //#include "plugininfo.h"
       
    31 #include <mhomescreensettingsif.h>
    28 #include <mhomescreensettingsif.h>
    32 #include <mhomescreensettingsobserver.h>
    29 #include <mhomescreensettingsobserver.h>
    33 
    30 
    34 _LIT8( KHSPS, "Service.HSPS" );
    31 _LIT8( KHSPS, "Service.HSPS" );
    35 _LIT8( KHSPSConfigurationIf, "IConfiguration" );
    32 _LIT8( KHSPSConfigurationIf, "IConfiguration" );
    36 
       
    37 
       
    38 
    33 
    39 _LIT8( KHSPSCommandGetPluginConf, "GetPluginConf" );
    34 _LIT8( KHSPSCommandGetPluginConf, "GetPluginConf" );
    40 _LIT8( KHSPSSetPluginSettings, "SetPluginSettings" );
    35 _LIT8( KHSPSSetPluginSettings, "SetPluginSettings" );
    41 _LIT8( KPluginConfKey, "pluginConf" );
    36 _LIT8( KPluginConfKey, "pluginConf" );
    42 
    37 
    43 _LIT8( KOutKeyStatus ,"status");
    38 _LIT8( KOutKeyStatus ,"status");
    44 _LIT8( KHspsAppUid, "appUid" );
    39 _LIT8( KHspsAppUid, "appUid" );
    45 _LIT8( KKeyPluginId, "pluginId" );
    40 _LIT8( KKeyPluginId, "pluginId" );
    46 
    41 
    47 _LIT8( KKeyStoringParams, "storingParams" );
    42 _LIT8( KKeyStoringParams, "storingParams" );
    48 
       
    49 
    43 
    50 _LIT8( KKeyStorePluginRefence, "storePluginConf" );
    44 _LIT8( KKeyStorePluginRefence, "storePluginConf" );
    51 _LIT8( KKeyStoreAppConf, "storeAppConf" );
    45 _LIT8( KKeyStoreAppConf, "storeAppConf" );
    52 
    46 
    53 _LIT8( KKeyItemId, "itemId" );
    47 _LIT8( KKeyItemId, "itemId" );
    56 _LIT8( KKeyProperties, "properties" );
    50 _LIT8( KKeyProperties, "properties" );
    57 _LIT8( KKeySettings, "settings" );
    51 _LIT8( KKeySettings, "settings" );
    58 
    52 
    59 _LIT8( KRequestNotification, "RequestNotification" );
    53 _LIT8( KRequestNotification, "RequestNotification" );
    60 
    54 
    61 
       
    62 _LIT8( KSettingsChanged, "PluginSettingsChanged" );
    55 _LIT8( KSettingsChanged, "PluginSettingsChanged" );
       
    56 
    63 namespace HSPluginSettingsIf{
    57 namespace HSPluginSettingsIf{
    64 
    58 
    65 
    59 NONSHARABLE_CLASS( CTlsEntry ): public CBase
    66 
    60     {
    67 // ---------------------------------------------------------------------------
    61 public:
    68 // ---------------------------------------------------------------------------
    62     /**
    69 //
    63      * Instance to home screen settings.
    70 CHomescreenSettings::CHomescreenSettings(MHomeScreenSettingsObserver* aObserver, const TDesC8& aPluginId )
    64      */
    71     : iObserver( aObserver ), iPluginId( aPluginId )
    65     CHomescreenSettings* iInstance;
       
    66     
       
    67     /**
       
    68      * Reference count.
       
    69      */
       
    70     TInt iRefCount;
       
    71     };
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 EXPORT_C CHomescreenSettings* CHomescreenSettings::Instance()
       
    77     {
       
    78     CHomescreenSettings* instance = NULL;
       
    79     
       
    80     CTlsEntry* entry = static_cast<CTlsEntry*>( Dll::Tls() );
       
    81     if( entry )
       
    82         {
       
    83         instance = entry->iInstance;
       
    84         }
       
    85     
       
    86     return instance;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 EXPORT_C void CHomescreenSettings::InitializeL( const TDesC8& aAppUid )
       
    93     {
       
    94     CTlsEntry* entry = static_cast<CTlsEntry*>( Dll::Tls() );
       
    95     
       
    96     if( !entry )
       
    97         {
       
    98         entry = new (ELeave) CTlsEntry();
       
    99         entry->iInstance = NULL;
       
   100         entry->iRefCount = 1;
       
   101         
       
   102         CleanupStack::PushL( entry );
       
   103         entry->iInstance = CHomescreenSettings::NewL( aAppUid );
       
   104         CleanupStack::Pop( entry );                                
       
   105         
       
   106         Dll::SetTls( entry );
       
   107         }
       
   108     else
       
   109         {
       
   110         entry->iRefCount++;
       
   111         }
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 EXPORT_C void CHomescreenSettings::UnInitialize()
       
   118     {
       
   119     CTlsEntry* entry = static_cast<CTlsEntry*>( Dll::Tls() );
       
   120     
       
   121     if( !entry )
       
   122         {
       
   123         return;
       
   124         }
       
   125 
       
   126     entry->iRefCount--;
       
   127     
       
   128     if( entry->iRefCount == 0 )
       
   129         {
       
   130         delete entry->iInstance;
       
   131         entry->iInstance = NULL;
       
   132         delete entry;
       
   133         Dll::SetTls( NULL );
       
   134         }
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 EXPORT_C void CHomescreenSettings::AddObserverL( MHomeScreenSettingsObserver* aObserver )
       
   141     {
       
   142     if( iObservers.Find( aObserver ) == KErrNotFound )
       
   143         {
       
   144         iObservers.AppendL( aObserver );
       
   145         }
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C void CHomescreenSettings::RemoveObserver( MHomeScreenSettingsObserver* aObserver )
       
   152     {
       
   153     const TInt index = iObservers.Find( aObserver );
       
   154     if( index != KErrNotFound )
       
   155         {
       
   156         iObservers.Remove( index );
       
   157         }
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 CHomescreenSettings::CHomescreenSettings()
    72     {
   164     {
    73     }
   165     }
    74 
   166 
    75 // ---------------------------------------------------------------------------
   167 // ---------------------------------------------------------------------------
    76 // ---------------------------------------------------------------------------
   168 // ---------------------------------------------------------------------------
   116         }   
   208         }   
   117     
   209     
   118     inParamList.Reset();
   210     inParamList.Reset();
   119     outParamList.Reset();
   211     outParamList.Reset();
   120         
   212         
   121     if( iObserver )
   213     iTransactionId = -1;
   122         {        	
   214     iHspsInterface->ExecuteCmdL( KRequestNotification,
   123         iTransactionId = -1;
   215                                  inParamList,
   124         iHspsInterface->ExecuteCmdL( KRequestNotification,
   216                                  outParamList,
   125                                      inParamList,
   217                                  KLiwOptASyncronous,
   126                                      outParamList,
   218                                  this );
   127                                      KLiwOptASyncronous,
   219     
   128                                      this );   
   220     const TLiwGenericParam* outParam( NULL );
   129         const TLiwGenericParam* outParam( NULL );
   221             
   130                 
   222     pos = 0;
   131        TInt pos( 0 );
   223     outParam = outParamList.FindFirst( pos, _L8("status") );
   132        outParam = outParamList.FindFirst( pos, _L8("status") );
   224            
   133                
   225     if( outParam )
   134        if ( outParam )
   226         {
   135            {
   227         TInt retval;
   136            TInt retval;
   228         retval = outParam->Value().AsTInt32();
   137            retval = outParam->Value().AsTInt32();
   229         if( retval == KErrNone )
   138            if(retval == KErrNone )
   230             {
   139                {
   231             pos = 0;
   140                pos = 0;
   232             outParam = outParamList.FindFirst( pos, _L8( "TransactionID" ) );
   141                outParam = outParamList.FindFirst( pos, _L8("TransactionID") );
   233             if( outParam )
   142                if( outParam )
   234                 {
   143                    {
   235                 retval = outParam->Value().AsTInt32();
   144                    retval = outParam->Value().AsTInt32();
   236                 iTransactionId = retval;
   145                    iTransactionId = retval;
   237                 }
   146                    }
   238             }      
   147                }
   239         }
   148           
   240     }
   149            }
   241 
   150                   
   242 // ---------------------------------------------------------------------------
   151         }
   243 // ---------------------------------------------------------------------------
   152     }
   244 //
   153 
   245 CHomescreenSettings* CHomescreenSettings::NewL(
   154 // ---------------------------------------------------------------------------
   246     const TDesC8& aAppUid )
   155 // ---------------------------------------------------------------------------
   247     {
   156 //
   248     CHomescreenSettings* self = CHomescreenSettings::NewLC( aAppUid );
   157 EXPORT_C CHomescreenSettings* CHomescreenSettings::NewL(
       
   158     const TDesC8& aAppUid,
       
   159     const TDesC8& aPluginId, 
       
   160     MHomeScreenSettingsObserver* aObserver)
       
   161     {
       
   162     CHomescreenSettings* self = CHomescreenSettings::NewLC(aAppUid, aPluginId, aObserver);
       
   163     CleanupStack::Pop( self );
   249     CleanupStack::Pop( self );
   164     return self;
   250     return self;
   165     }
   251     }
   166 
   252 
   167 // ---------------------------------------------------------------------------
   253 // ---------------------------------------------------------------------------
   168 // ---------------------------------------------------------------------------
   254 // ---------------------------------------------------------------------------
   169 //
   255 //
   170 EXPORT_C CHomescreenSettings* CHomescreenSettings::NewLC(
   256 CHomescreenSettings* CHomescreenSettings::NewLC(
   171     const TDesC8& aAppUid,
   257     const TDesC8& aAppUid )
   172     const TDesC8& aPluginId,
   258     {    
   173     MHomeScreenSettingsObserver* aObserver)
   259     CHomescreenSettings* self = new( ELeave ) CHomescreenSettings();
   174     {
       
   175     CHomescreenSettings* self = new( ELeave ) CHomescreenSettings( aObserver, aPluginId );
       
   176     CleanupStack::PushL( self );
   260     CleanupStack::PushL( self );
   177     self->ConstructL(aAppUid);
   261     self->ConstructL( aAppUid );   
       
   262     
   178     return self;
   263     return self;
   179     }
   264     }
   180 
   265 
   181 // ---------------------------------------------------------------------------
   266 // ---------------------------------------------------------------------------
   182 // ---------------------------------------------------------------------------
   267 // ---------------------------------------------------------------------------
   183 //
   268 //
   184 EXPORT_C CHomescreenSettings::~CHomescreenSettings()
   269 CHomescreenSettings::~CHomescreenSettings()
   185     {
   270     {
       
   271     iObservers.Reset();
       
   272     
   186     if( iHspsInterface )
   273     if( iHspsInterface )
   187         {
   274         {
   188         // Close interface
   275         // Close interface
   189         iHspsInterface->Close();       
   276         iHspsInterface->Close();       
   190         }
   277         }
   199         }
   286         }
   200     
   287     
   201     delete iHspsService;
   288     delete iHspsService;
   202     delete iServiceHandler;    
   289     delete iServiceHandler;    
   203     }
   290     }
   204 
       
   205 
       
   206 
       
   207 
       
   208 
   291 
   209 // ---------------------------------------------------------------------------
   292 // ---------------------------------------------------------------------------
   210 // ---------------------------------------------------------------------------
   293 // ---------------------------------------------------------------------------
   211 //
   294 //
   212 TInt CHomescreenSettings::SetPluginSettingsL(
   295 TInt CHomescreenSettings::SetPluginSettingsL(
   527     CLiwGenericParamList& aEventParamList,
   610     CLiwGenericParamList& aEventParamList,
   528     const CLiwGenericParamList& /*aInParamList*/ )
   611     const CLiwGenericParamList& /*aInParamList*/ )
   529     {
   612     {
   530     TInt retval( KErrNone );
   613     TInt retval( KErrNone );
   531    
   614    
   532     if( iObserver && iTransactionId == aCmdId )
   615     if( iTransactionId == aCmdId && iObservers.Count() > 0 )
   533         {                 
   616         {                 
   534         const TLiwGenericParam* outParam( NULL );
   617         const TLiwGenericParam* outParam( NULL );
   535         
   618         
   536         TInt pos( 0 );
   619         TInt pos( 0 );
   537         outParam = aEventParamList.FindFirst( pos, _L8("status") );
   620         outParam = aEventParamList.FindFirst( pos, _L8("status") );
   564             pushCount++;
   647             pushCount++;
   565                 
   648                 
   566             variant = outParam->Value();
   649             variant = outParam->Value();
   567             
   650             
   568             const CLiwMap* notifMap( variant.AsMap() );
   651             const CLiwMap* notifMap( variant.AsMap() );
   569                                             
   652                                           
   570             if ( notifMap->FindL( _L8("event"), variant ) )
   653             if ( notifMap->FindL( _L8("event"), variant ) )
   571                 {
   654                 {
   572                 event = variant.AsData().AllocLC();
   655                 event = variant.AsData().AllocLC();
   573                 pushCount++;
   656                 pushCount++;
   574                 }    
   657                 }    
   575                 
   658                
   576             variant.Reset();    
   659             variant.Reset();    
   577             
   660             
   578             if ( event->Des().Compare( KSettingsChanged ) == 0 )
   661             if ( event && event->Des().Compare( KSettingsChanged ) == 0 )
   579                 {
   662                 {
   580                 if( notifMap->FindL( _L8("name"), variant ) )
   663                 if( notifMap->FindL( _L8("name"), variant ) )
   581                     {
   664                     {
   582                     pluginName = variant.AsData().AllocLC();            
   665                     pluginName = variant.AsData().AllocLC();            
   583                     pushCount++;
   666                     pushCount++;
   608                         {           
   691                         {           
   609                         pluginIdList->AtL( i, variant );
   692                         pluginIdList->AtL( i, variant );
   610                         HBufC8* pluginId( NULL );
   693                         HBufC8* pluginId( NULL );
   611                         pluginId = variant.AsData().AllocLC();
   694                         pluginId = variant.AsData().AllocLC();
   612                         
   695                         
   613                         if( pluginId->Des().Compare(iPluginId)== 0 )
   696                         for( TInt i = 0; i < iObservers.Count(); i++ )
   614                             {
   697                             {
   615                             retval = iObserver->SettingsChangedL( 
   698                             iObservers[i]->SettingsChangedL( 
   616                                 ( event ) ? *event : KNullDesC8(),  
   699                                 ( event ) ? *event : KNullDesC8(),  
   617                                 ( pluginName ) ? *pluginName : KNullDesC8(), 
   700                                 ( pluginName ) ? *pluginName : KNullDesC8(), 
   618                                 ( pluginUid ) ? *pluginUid : KNullDesC8(), 
   701                                 ( pluginUid ) ? *pluginUid : KNullDesC8(), 
   619                                 ( pluginId ) ? * pluginId : KNullDesC8() );
   702                                 ( pluginId ) ? *pluginId : KNullDesC8() );
   620                             }       
   703                             }
       
   704        
   621                         CleanupStack::PopAndDestroy( pluginId );                                                      
   705                         CleanupStack::PopAndDestroy( pluginId );                                                      
   622                         
   706                         
   623                         variant.Reset();
   707                         variant.Reset();                         
   624                          
   708                         }                        
   625                         }
       
   626                         
       
   627                     }
   709                     }
   628             
   710             
   629                 }
   711                 }
   630             
   712             
   631             CleanupStack::PopAndDestroy( pushCount );
   713             CleanupStack::PopAndDestroy( pushCount );
   677                     iTransactionId = retval;
   759                     iTransactionId = retval;
   678                     }
   760                     }
   679                 }     
   761                 }     
   680             }
   762             }
   681         
   763         
   682         }
   764         }   
   683    
       
   684     
   765     
   685     return retval;    
   766     return retval;    
   686     } 
   767     }
   687 
   768 
   688 }
   769 }
   689 //End of file
   770 //End of file