homescreensrv_plat/sapi_homescreenplugin/hspsservice/src/hspspersonalisationservice.cpp
changeset 0 79c6a41cd166
child 4 1a2a00e78665
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     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:  Interface to HSPS service
       
    15 *
       
    16 */
       
    17 
       
    18 #include "hspspersonalisationservice.h"
       
    19 #include "hspsserviceutilities.h"
       
    20 
       
    21 
       
    22 // ======== LOCAL FUNCTIONS ====================================================
       
    23 
       
    24 
       
    25 // ======== MEMBER FUNCTIONS ===================================================
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // Two-phased constructor.
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C CHspsPersonalisationService* CHspsPersonalisationService::NewL()
       
    32     {
       
    33     CHspsPersonalisationService* self = new (ELeave) CHspsPersonalisationService;
       
    34     CleanupStack::PushL( self );
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop( self );
       
    37     return self;
       
    38     }
       
    39     
       
    40 // ---------------------------------------------------------------------------
       
    41 // Destructor.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CHspsPersonalisationService::~CHspsPersonalisationService()
       
    45     {
       
    46     if ( iHspsClient )
       
    47         {
       
    48         // Cancel asynchronous requests
       
    49         
       
    50         // Delete client
       
    51         delete iHspsClient;
       
    52         }
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // Constructor.
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CHspsPersonalisationService::CHspsPersonalisationService()
       
    60     {
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // Two-phased constructor.
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 void CHspsPersonalisationService::ConstructL()
       
    68     {
       
    69     iHspsClient = ChspsClient::NewL( *this );
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // Get Plugin list
       
    74 // -----------------------------------------------------------------------------
       
    75 EXPORT_C void CHspsPersonalisationService::GetPluginListL(
       
    76     TDesC8& aInterface,
       
    77     TDesC8& aType,
       
    78     TUint32 aFamily,
       
    79     CArrayPtrFlat<ChspsODT>& aList )
       
    80     {
       
    81     // Setup a mask for finding plugins with defined interface 
       
    82     ChspsODT *searchMask = ChspsODT::NewL();
       
    83     CleanupStack::PushL( searchMask );        
       
    84     TInt interfaceUid = HspsServiceUtilities::HexString2IntL( aInterface );
       
    85     searchMask->SetRootUid( interfaceUid );
       
    86     if ( aType.Length() > 0 )
       
    87         {
       
    88         TUint type;
       
    89         HspsServiceUtilities::GetConfigurationTypeL( 
       
    90             aType,
       
    91             type );
       
    92         searchMask->SetConfigurationType( type );
       
    93         }
       
    94 
       
    95     searchMask->SetFamily( aFamily );
       
    96     
       
    97     TInt err = iHspsClient->hspsGetHeaders( 
       
    98         *searchMask, 
       
    99         aList );
       
   100     
       
   101     CleanupStack::PopAndDestroy( searchMask );
       
   102     
       
   103     if ( err == KErrNotFound )
       
   104         {
       
   105         // Plugin list empty
       
   106         aList.ResetAndDestroy();
       
   107         err = KErrNone;
       
   108         }
       
   109     
       
   110     User::LeaveIfError( err );
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // Add plugin to the configuration
       
   115 // -----------------------------------------------------------------------------
       
   116 EXPORT_C void CHspsPersonalisationService::AddPluginL(
       
   117     TInt aAppUid,
       
   118     TDesC8& aConfId,
       
   119     TDesC8& aPluginUid,
       
   120     TDesC8& aPosition,
       
   121     TInt& aPluginId )
       
   122     {
       
   123 
       
   124     TInt confId = HspsServiceUtilities::DecString2Int( aConfId );
       
   125     TInt pluginUid = HspsServiceUtilities::HexString2IntL( aPluginUid );
       
   126     if ( confId < 1 || pluginUid < 1 )
       
   127         {
       
   128         User::Leave( KErrArgument );
       
   129         }
       
   130     
       
   131     TInt position( -1 );
       
   132     if ( aPosition.Length() > 0 )
       
   133         {
       
   134         position = HspsServiceUtilities::DecString2Int( aPosition );
       
   135         }
       
   136         
       
   137     ThspsServiceCompletedMessage ret = iHspsClient->hspsAddPlugin(
       
   138         aAppUid,
       
   139         confId,
       
   140         pluginUid,
       
   141         position,
       
   142         aPluginId );
       
   143 
       
   144     if ( ret != EhspsAddPluginSuccess )
       
   145         {
       
   146         // Check if disk full error case.
       
   147         ChspsResult* errorDetails = ChspsResult::NewL();
       
   148         CleanupStack::PushL( errorDetails );
       
   149         iHspsClient->GethspsResult( *errorDetails );
       
   150         
       
   151         if( errorDetails->iXuikonError == KErrDiskFull )
       
   152             {
       
   153             User::Leave( KErrDiskFull );
       
   154             }                
       
   155         
       
   156         CleanupStack::PopAndDestroy( errorDetails );
       
   157         
       
   158         // Other error cases.
       
   159         User::Leave( KErrGeneral );
       
   160         }        
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // Remove plugin from the configuration
       
   165 // -----------------------------------------------------------------------------
       
   166 EXPORT_C void CHspsPersonalisationService::RemovePluginL(
       
   167     TInt aAppUid,
       
   168     TDesC8& aPluginId )
       
   169     {
       
   170 
       
   171     TInt pluginId = HspsServiceUtilities::DecString2Int( aPluginId );
       
   172     if ( pluginId < 1 )
       
   173         {
       
   174         User::Leave( KErrArgument );
       
   175         }
       
   176 
       
   177     ThspsServiceCompletedMessage ret = iHspsClient->hspsRemovePlugin(
       
   178         aAppUid,
       
   179         pluginId );
       
   180     
       
   181     if ( ret != EhspsRemovePluginSuccess )
       
   182         {
       
   183         User::Leave( KErrNotFound );
       
   184         }
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // Set plugin settings
       
   189 // -----------------------------------------------------------------------------
       
   190 EXPORT_C void CHspsPersonalisationService::SetPluginSettingsL(
       
   191     TInt aAppUid,
       
   192     TDesC8& aPluginId,
       
   193     ChspsDomDocument& aDom,
       
   194     TBool aPluginStoringStatus)
       
   195     {
       
   196   
       
   197     // Setup a mask for finding plugins with defined interface 
       
   198     ChspsODT *searchMask = ChspsODT::NewL();
       
   199     CleanupStack::PushL( searchMask );        
       
   200     searchMask->SetRootUid( aAppUid );
       
   201     const TInt id = HspsServiceUtilities::DecString2Int( aPluginId );
       
   202     ThspsServiceCompletedMessage ret = 
       
   203      iHspsClient->hspsSetPluginSettings( *searchMask, id, aDom, aPluginStoringStatus );
       
   204     
       
   205     CleanupStack::PopAndDestroy( searchMask );
       
   206   
       
   207     if ( ret != EhspsSetPluginSettingsSuccess )
       
   208         {
       
   209         User::Leave( KErrGeneral );
       
   210         }
       
   211     }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // Get plugin Odt
       
   215 // -----------------------------------------------------------------------------
       
   216 EXPORT_C void CHspsPersonalisationService::GetPluginOdtL(
       
   217     TInt aAppUid,
       
   218     TDesC8& aPluginUid,
       
   219     ChspsODT* aPluginOdt )
       
   220     {
       
   221     const TInt plugUid = HspsServiceUtilities::HexString2IntL( aPluginUid );    
       
   222     ThspsServiceCompletedMessage ret = iHspsClient->hspsGetPluginOdtL( aAppUid, plugUid, aPluginOdt );
       
   223     
       
   224     if( ret != EhspsGetPluginOdtSuccess )
       
   225     	{
       
   226     	User::Leave( KErrNotFound );  
       
   227     	}
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // Updates plugin positions in a configuration
       
   232 // -----------------------------------------------------------------------------
       
   233 EXPORT_C void CHspsPersonalisationService::MovePluginsL(
       
   234     const TInt aAppUid,
       
   235     TDesC8& aConfId,
       
   236     CArrayFixFlat<TInt>& aPluginIds )
       
   237     {
       
   238     const TInt confId = HspsServiceUtilities::DecString2Int( aConfId );        
       
   239     if ( confId < 1 )
       
   240         {
       
   241         User::Leave( KErrArgument );
       
   242         }
       
   243         
       
   244     const ThspsServiceCompletedMessage ret = iHspsClient->hspsMovePluginsL(
       
   245         aAppUid,
       
   246         confId,
       
   247         aPluginIds );
       
   248     
       
   249     if ( ret != EhspsMovePluginsSuccess )
       
   250         {
       
   251         User::Leave( KErrArgument );
       
   252         }
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // Gets a list of available application configurations
       
   257 // -----------------------------------------------------------------------------
       
   258 EXPORT_C void CHspsPersonalisationService::GetAppConfListL(
       
   259     TInt aAppUid,
       
   260     TUint32 aFamily,
       
   261     CArrayPtrFlat<ChspsODT>& aList )
       
   262     {
       
   263     // Setup a mask for finding application configurations 
       
   264     ChspsODT *searchMask = ChspsODT::NewL();
       
   265     CleanupStack::PushL( searchMask );        
       
   266     searchMask->SetRootUid( aAppUid );
       
   267     searchMask->SetConfigurationType( EhspsAppConfiguration );
       
   268     searchMask->SetFamily( aFamily );
       
   269 
       
   270     // Get application configurations
       
   271     User::LeaveIfError( iHspsClient->hspsGetHeaders( 
       
   272         *searchMask, 
       
   273         aList ) );
       
   274 
       
   275     CleanupStack::PopAndDestroy( searchMask );
       
   276 
       
   277     }
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // Set active application configuration
       
   281 // -----------------------------------------------------------------------------
       
   282 EXPORT_C void CHspsPersonalisationService::SetActiveAppConfL(
       
   283     TInt aAppUid,
       
   284     TDesC8& aConfUid )
       
   285     {
       
   286 
       
   287     const TInt confUid = HspsServiceUtilities::HexString2IntL( aConfUid );        
       
   288 
       
   289     // Setup a set mask for active configuration 
       
   290     ChspsODT *setMask = ChspsODT::NewL();
       
   291     CleanupStack::PushL( setMask );        
       
   292     setMask->SetRootUid( aAppUid );
       
   293     setMask->SetThemeUid( confUid );
       
   294     setMask->SetConfigurationType( EhspsAppConfiguration );
       
   295 
       
   296     ChspsODT *activeConf = ChspsODT::NewL();
       
   297     CleanupStack::PushL( activeConf );        
       
   298 
       
   299     // Get application configurations
       
   300     const ThspsServiceCompletedMessage ret = iHspsClient->hspsSetActiveTheme( 
       
   301         *setMask, 
       
   302         *activeConf );
       
   303 
       
   304     CleanupStack::PopAndDestroy( activeConf );
       
   305     CleanupStack::PopAndDestroy( setMask );
       
   306 
       
   307     if ( ret != EhspsSetActiveThemeSuccess )
       
   308         {
       
   309         User::Leave( KErrNotFound );
       
   310         }
       
   311     }
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // Set active application configuration
       
   315 // -----------------------------------------------------------------------------
       
   316 EXPORT_C void CHspsPersonalisationService::SetConfStateL(
       
   317     TInt aAppUid,
       
   318     TDesC8& aConfId,
       
   319     TDesC8& aState,
       
   320     TDesC8& aFilter )
       
   321     {
       
   322 
       
   323     const TInt confId = HspsServiceUtilities::DecString2Int( aConfId );        
       
   324 
       
   325     ThspsConfigurationState state;
       
   326     HspsServiceUtilities::GetConfigurationStateL( aState, state );
       
   327     
       
   328     ThspsConfStateChangeFilter filter;
       
   329     HspsServiceUtilities::GetConfigurationStateFilterL( aFilter, filter );
       
   330     // Set configuration state
       
   331     const ThspsServiceCompletedMessage ret = iHspsClient->hspsSetConfState( 
       
   332         aAppUid, 
       
   333         confId,
       
   334         state,
       
   335         filter );
       
   336 
       
   337     if ( ret != EhspsSetConfStateSuccess )
       
   338         {
       
   339         User::Leave( KErrNotFound );
       
   340         }
       
   341     }
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // Restore active application configuration
       
   345 // -----------------------------------------------------------------------------
       
   346 EXPORT_C void CHspsPersonalisationService::RestoreActiveAppConfL(
       
   347     TInt aAppUid,
       
   348     TDesC8& aConfUid )
       
   349     {
       
   350 
       
   351     const TInt confUid = HspsServiceUtilities::HexString2IntL( aConfUid );        
       
   352 
       
   353     // Set configuration state
       
   354     const ThspsServiceCompletedMessage ret = iHspsClient->hspsRestoreActiveAppConf( 
       
   355         aAppUid,
       
   356         confUid );
       
   357 
       
   358     if ( ret != EhspsRestoreActiveAppConfSuccess )
       
   359         {
       
   360         User::Leave( KErrNotFound );
       
   361         }
       
   362     }
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // Activates a plugin in active application configuration
       
   366 // -----------------------------------------------------------------------------
       
   367 EXPORT_C void CHspsPersonalisationService::SetActivePluginL(
       
   368     TInt aAppUid,
       
   369     TDesC8& aPluginId )
       
   370     {
       
   371 
       
   372     TInt pluginId = HspsServiceUtilities::DecString2Int( aPluginId );
       
   373     if ( pluginId < 1 )
       
   374         {
       
   375         User::Leave( KErrArgument );
       
   376         }
       
   377 
       
   378     ThspsServiceCompletedMessage ret = iHspsClient->hspsSetActivePlugin(
       
   379         aAppUid,
       
   380         pluginId );
       
   381     
       
   382     if ( ret != EhspsSetActivePluginSuccess )
       
   383         {
       
   384         User::Leave( KErrNotFound );
       
   385         }
       
   386     }
       
   387 
       
   388 // -----------------------------------------------------------------------------
       
   389 // Repaces a plugin in active application configuration
       
   390 // -----------------------------------------------------------------------------
       
   391 EXPORT_C void CHspsPersonalisationService::ReplacePluginL(
       
   392         const TInt aAppUid,
       
   393         const TDesC8& aPluginId,
       
   394         const TDesC8& aConfUid )
       
   395     {
       
   396     const TInt pluginId = HspsServiceUtilities::DecString2Int( aPluginId );
       
   397     const TInt confUid = HspsServiceUtilities::HexString2IntL( aConfUid );
       
   398     if ( aAppUid < 1 || pluginId < 1 || confUid < 1 )
       
   399         {
       
   400         User::Leave( KErrArgument );
       
   401         }
       
   402         
       
   403     const ThspsServiceCompletedMessage ret = iHspsClient->hspsReplacePlugin(
       
   404             aAppUid,
       
   405             pluginId,
       
   406             confUid );
       
   407 
       
   408     if( ret != EhspsReplacePluginSuccess )
       
   409         {
       
   410         // Check if disk full error case.
       
   411         ChspsResult* errorDetails = ChspsResult::NewL();
       
   412         CleanupStack::PushL( errorDetails );
       
   413         iHspsClient->GethspsResult( *errorDetails );
       
   414         
       
   415         if( errorDetails->iXuikonError == KErrDiskFull )
       
   416             {
       
   417             User::Leave( KErrDiskFull );
       
   418             }                
       
   419         
       
   420         CleanupStack::PopAndDestroy( errorDetails );
       
   421         
       
   422         // Other error cases.
       
   423         User::Leave( KErrNotFound );
       
   424         }
       
   425     }
       
   426 
       
   427 
       
   428 // ---------------------------------------------------------------------------
       
   429 // Hsps client service observer
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 void CHspsPersonalisationService::HandlehspsClientMessage( ThspsServiceCompletedMessage  /*aMessage*/ )
       
   433     {
       
   434     // Asynchronous service handling
       
   435     
       
   436     }
       
   437 // ======== GLOBAL FUNCTIONS ===================================================
       
   438 
       
   439 
       
   440 // End of file
       
   441