homescreenpluginsrv/hspsmanager/src/hspsthemeserversession.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:  HSPS Theme Server Session. For more information, see the header.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <f32file.h>
       
    21 
       
    22 #include "hsps_builds_cfg.hrh"
       
    23 #ifdef _hsps_PERFORMANCE_TEST_
       
    24 #include "hspstimemon.h"
       
    25 #endif //_hsps_PERFORMANCE_TEST_
       
    26 #include "hspsthemeserversession.h"
       
    27 #include "hspsthemeserver.h"
       
    28 #include "hspsinstallationhandler.h"
       
    29 #include "hspsmaintenancehandler.h"
       
    30 #include "hspsclientrequesthandler.h"
       
    31 #include "hspsserverutil.h"
       
    32 #include "hspsrominstaller.h"
       
    33 #ifdef HSPS_LOG_ACTIVE
       
    34 #include <hspsodtdump.h>
       
    35 #include <hspslogbusfile.h>
       
    36 #endif
       
    37 
       
    38 // CONSTANTS
       
    39 
       
    40 //
       
    41 //
       
    42 // Class ChspsThemeServerSession
       
    43 //
       
    44 //
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // ChspsThemeServerSession::ChspsThemeServerSession
       
    48 // (other items were commented in a header).
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 ChspsThemeServerSession::ChspsThemeServerSession(
       
    52     const TInt aAppUid )
       
    53     {
       
    54     iAppUid = aAppUid;
       
    55     }
       
    56   
       
    57 // -----------------------------------------------------------------------------
       
    58 // ChspsThemeServerSession::ChspsThemeServerSession
       
    59 // 2nd phase construct for sessions - called by the CServer framework
       
    60 // (other items were commented in a header).
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 void ChspsThemeServerSession::CreateL()
       
    64     {
       
    65 #ifdef HSPS_LOG_ACTIVE    
       
    66     iLogBus = ChspsLogBusFile::NewL( ChspsLogBusFile::CreateLogFilename( _L("themeserver_session") ) );
       
    67     iLogBus->LogText( _L( "ChspsThemeServerSession::CreateL" ) );
       
    68     iLogBus->LogText( _L( "--------------------------------------------------------" ) );
       
    69 #endif
       
    70     
       
    71     Server().AddSession();
       
    72     iHoldingResources = EFalse;
       
    73     User::LeaveIfError( iFs.Connect() );
       
    74     Server().CheckConfigurationL( iAppUid );
       
    75     }
       
    76 
       
    77 // Destructor
       
    78 ChspsThemeServerSession::~ChspsThemeServerSession()
       
    79     {
       
    80     iFs.Close();
       
    81     
       
    82     if ( iInstallationHandler )
       
    83         {
       
    84         delete iInstallationHandler;
       
    85         Server().DefinitionRepository().Unlock();
       
    86         }
       
    87   
       
    88     delete iMaintenanceHandler;
       
    89     // decrease number of resource holders if this sessions did hold one
       
    90     if ( iHoldingResources )
       
    91         {
       
    92         Server().DecreaseRequestClientCount();      
       
    93         }
       
    94     delete iClientRequestHandler;
       
    95    
       
    96     Server().DropSession();
       
    97 
       
    98 #ifdef HSPS_LOG_ACTIVE
       
    99     if( iLogBus )
       
   100         {
       
   101         iLogBus->LogText( _L( "ChspsThemeServerSession::~ChspsThemeServerSession" ) );
       
   102         iLogBus->LogText( _L( "--------------------------------------------------------" ) );
       
   103         }
       
   104     // Delete as last if another components use this log bus instance.
       
   105     delete iLogBus;
       
   106     iLogBus = NULL;
       
   107 #endif    
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // ChspsThemeServerSession::Server
       
   112 // ?implementation_description
       
   113 // (other items were commented in a header).
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 inline ChspsThemeServer& ChspsThemeServerSession::Server()
       
   117     {
       
   118     return *static_cast<ChspsThemeServer*>(const_cast<CServer2*>(CSession2::Server()));
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // ChspsThemeServerSession::ServiceL
       
   123 // Handle a client request.
       
   124 // Leaving is handled by ChspsThemeServerSession::ServiceError() which reports
       
   125 // the error code to the client
       
   126 // (other items were commented in a header).
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void ChspsThemeServerSession::ServiceL( const RMessage2& aMessage )
       
   130     {
       
   131     TRAPD( errorCode, DoServiceL( aMessage ) );
       
   132     if ( errorCode && !aMessage.IsNull() )        
       
   133         {
       
   134         aMessage.Complete( EhspsServiceRequestError );    
       
   135 #ifdef HSPS_LOG_ACTIVE        
       
   136         iLogBus->LogText( _L( "ServiceL: - error in calling function %d." ), aMessage.Function() );
       
   137 #endif
       
   138         }
       
   139 
       
   140 #ifdef HSPS_LOG_ACTIVE    
       
   141     iLogBus->LogText( _L( "ServiceL completed with code: %d" ), errorCode );
       
   142     iLogBus->LogText( _L( "--------------------------------------------------------" ) );
       
   143 #endif        
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // ChspsThemeServerSession::DoServiceL
       
   148 // -----------------------------------------------------------------------------
       
   149 void ChspsThemeServerSession::DoServiceL( const RMessage2& aMessage )    
       
   150     {    
       
   151     switch ( aMessage.Function() )
       
   152         {
       
   153         // installation:
       
   154         case EhspsInstallTheme:
       
   155             {
       
   156 #ifdef HSPS_LOG_ACTIVE        
       
   157             iLogBus->LogText( _L( "DoServiceL: EhspsInstallTheme" ) );
       
   158 #endif            
       
   159             InstallThemeL( aMessage );
       
   160             break;
       
   161             } 
       
   162           
       
   163         case EhspsInstallNextPhase:
       
   164             {
       
   165 #ifdef HSPS_LOG_ACTIVE        
       
   166             iLogBus->LogText( _L( "DoServiceL: EhspsInstallNextPhase" ) );
       
   167 #endif                   
       
   168             InstallNextPhaseL( aMessage );
       
   169             break;
       
   170             }   
       
   171           
       
   172         case EhspsCancelInstallTheme:
       
   173             {
       
   174 #ifdef HSPS_LOG_ACTIVE        
       
   175             iLogBus->LogText( _L( "DoServiceL: EhspsCancelInstallTheme" ) );
       
   176 #endif                    
       
   177             CancelInstallThemeL( aMessage );
       
   178             break;
       
   179             }
       
   180     
       
   181         case EhspsReinstallConf:
       
   182             {
       
   183 #ifdef HSPS_LOG_ACTIVE
       
   184             iLogBus->LogText( _L( "DoServiceL: EhspsReinstallConf" ) );
       
   185 #endif            
       
   186             ReinstallConfL( aMessage );
       
   187             break;
       
   188             }
       
   189     
       
   190             // maintenance
       
   191         case EhspsGetListHeaders:
       
   192             {
       
   193 #ifdef HSPS_LOG_ACTIVE        
       
   194             iLogBus->LogText( _L( "DoServiceL: EhspsGetListHeaders" ) );
       
   195 #endif            
       
   196             GetListHeadersL( aMessage );
       
   197             break;
       
   198             }
       
   199           
       
   200         case EhspsGetNextHeader:
       
   201             {
       
   202 #ifdef HSPS_LOG_ACTIVE        
       
   203             iLogBus->LogText( _L( "DoServiceL: EhspsGetNextHeader" ) );
       
   204 #endif                    
       
   205             GetNextHeaderL( aMessage );
       
   206             break;
       
   207             }
       
   208           
       
   209         case EhspsCancelGetListHeaders:
       
   210             {
       
   211 #ifdef HSPS_LOG_ACTIVE        
       
   212             iLogBus->LogText( _L( "DoServiceL: EhspsCancelGetListHeaders" ) );
       
   213 #endif                    
       
   214             CancelGetListHeadersL( aMessage );
       
   215             break;
       
   216             }
       
   217         
       
   218         case EhspsSetActiveTheme:
       
   219             {
       
   220 #ifdef HSPS_LOG_ACTIVE        
       
   221             iLogBus->LogText( _L( "DoServiceL: EhspsSetActiveTheme" ) );
       
   222 #endif            
       
   223             SetActiveThemeL( aMessage );
       
   224             break;
       
   225             }
       
   226     
       
   227         case EhspsRestoreDefault:
       
   228             {
       
   229 #ifdef HSPS_LOG_ACTIVE        
       
   230             iLogBus->LogText( _L( "DoServiceL: EhspsRestoreDefault" ) );
       
   231 #endif                    
       
   232             RestoreDefaultL( aMessage );
       
   233             break;
       
   234             }
       
   235           
       
   236         case EhspsRemoveTheme:
       
   237             {
       
   238 #ifdef HSPS_LOG_ACTIVE        
       
   239             iLogBus->LogText( _L( "DoServiceL: EhspsRemoveTheme" ) );
       
   240 #endif                    
       
   241             RemoveThemeL( aMessage );
       
   242             break;
       
   243             }
       
   244       
       
   245         // client request
       
   246         case EhspsGetODT:
       
   247             {
       
   248 #ifdef HSPS_LOG_ACTIVE        
       
   249             iLogBus->LogText( _L( "DoServiceL: EhspsGetODT" ) );
       
   250 #endif            
       
   251             GetOdtL( aMessage );
       
   252             break;
       
   253             }
       
   254         	
       
   255         case EhspsGetODTUpdate:
       
   256             {
       
   257 #ifdef HSPS_LOG_ACTIVE        
       
   258             iLogBus->LogText( _L( "DoServiceL: EhspsGetODTUpdate" ) );
       
   259 #endif            
       
   260             GetOdtUpdateL( aMessage );
       
   261             break;
       
   262             }
       
   263           
       
   264         case EhspsCancelGetODTUpdate:
       
   265             {
       
   266 #ifdef HSPS_LOG_ACTIVE        
       
   267             iLogBus->LogText( _L( "DoServiceL: EhspsCancelGetODTUpdate" ) );
       
   268 #endif                    
       
   269             CancelGetOdtUpdateL( aMessage );
       
   270             break;
       
   271             }
       
   272                    
       
   273         case EhspsAccessResourceFile:
       
   274             {
       
   275 #ifdef HSPS_LOG_ACTIVE        
       
   276             iLogBus->LogText( _L( "DoServiceL: EhspsAccessResourceFile" ) );
       
   277 #endif                    
       
   278             AccessResourceFileL( aMessage );
       
   279             break;
       
   280             } 
       
   281             
       
   282         case EhspsCopyResources:
       
   283         	{
       
   284 #ifdef HSPS_LOG_ACTIVE    	
       
   285         	iLogBus->LogText( _L( "DoServiceL: EhspsCopyResources" ) );
       
   286 #endif    	        	
       
   287         	CopyResourceFilesL( aMessage );
       
   288         	break;
       
   289         	}
       
   290         case EhspsAddPlugin:
       
   291         	{
       
   292 #ifdef HSPS_LOG_ACTIVE    	
       
   293         	iLogBus->LogText( _L( "DoServiceL: EhspsAddPlugin" ) );
       
   294 #endif    	        	
       
   295         	AddPluginL( aMessage );
       
   296         	break;
       
   297         	}
       
   298         case EhspsRemovePlugin:
       
   299         	{
       
   300 #ifdef HSPS_LOG_ACTIVE    	
       
   301         	iLogBus->LogText( _L( "DoServiceL: EhspsRemovePlugin" ) );
       
   302 #endif    	        	
       
   303         	RemovePluginL( aMessage );
       
   304         	break;
       
   305         	}
       
   306         case EhspsSetActivePlugin:
       
   307             {
       
   308 #ifdef HSPS_LOG_ACTIVE      
       
   309             iLogBus->LogText( _L( "DoServiceL: EhspsSetActivePlugin" ) );
       
   310 #endif                  
       
   311             SetActivePluginL( aMessage );
       
   312             break;
       
   313             }        	
       
   314         case EhspsReplacePlugin:
       
   315             {
       
   316 #ifdef HSPS_LOG_ACTIVE      
       
   317             iLogBus->LogText( _L( "DoServiceL: EhspsReplacePlugin" ) );
       
   318 #endif                  
       
   319             ReplacePluginL( aMessage );
       
   320             break;
       
   321             }        	
       
   322         case EhspsSetPluginSettings:
       
   323             {
       
   324 #ifdef HSPS_LOG_ACTIVE        
       
   325             iLogBus->LogText( _L( "DoServiceL: EhspsSetPluginSettings" ) );
       
   326 #endif                    
       
   327             SetPluginSettingsL( aMessage );
       
   328             break;
       
   329             } 	
       
   330         case EhspsGetPluginOdt:
       
   331         	{
       
   332 #ifdef HSPS_LOG_ACTIVE    	
       
   333             iLogBus->LogText( _L( "DoServiceL: EhspsGetPluginOdt" ) );
       
   334 #endif            
       
   335          	GetPluginOdtL( aMessage );
       
   336         	break;
       
   337         	}
       
   338         case EhspsMovePlugins:
       
   339         	{
       
   340 #ifdef HSPS_LOG_ACTIVE    	
       
   341         	iLogBus->LogText( _L( "DoServiceL: EhspsMovePlugins" ) );
       
   342 #endif    	        	
       
   343         	MovePluginsL( aMessage );
       
   344         	break;
       
   345         	}
       
   346         case EhspsSetConfState:
       
   347             {
       
   348 #ifdef HSPS_LOG_ACTIVE    	        
       
   349             iLogBus->LogText( _L( "DoServiceL: EhspsSetConfState" ) );
       
   350 #endif    
       
   351             SetConfStateL( aMessage );
       
   352             break;
       
   353             }
       
   354 	    case EhspsRestoreActiveAppConf:
       
   355 	        {
       
   356 #ifdef HSPS_LOG_ACTIVE              
       
   357 	        iLogBus->LogText( _L( "DoServiceL: EhspsRestoreActiveAppConf" ) );
       
   358 #endif
       
   359 	        RestoreActiveAppConfL( aMessage );
       
   360 	        break;
       
   361 	        }
       
   362         default:
       
   363             {
       
   364 #ifdef HSPS_LOG_ACTIVE        
       
   365             iLogBus->LogText( _L( "DoServiceL: - unrecognized function %d called." ), aMessage.Function() );
       
   366 #endif                                    
       
   367             User::Leave( KErrNotSupported ); 
       
   368             break;
       
   369             }
       
   370             
       
   371         } // switch   
       
   372     }
       
   373   
       
   374 
       
   375 // -----------------------------------------------------------------------------
       
   376 // ChspsThemeServerSession::ServiceError
       
   377 // Handle an error from ChspsThemeServerSession::ServiceL()
       
   378 // (other items were commented in a header).
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 void ChspsThemeServerSession::ServiceError(const RMessage2& aMessage,TInt aError)
       
   382     {
       
   383 #ifdef HSPS_LOG_ACTIVE    
       
   384     iLogBus->LogText( _L( "hspsThemeServer: ChspsThemeServerSession::ServiceError(): %d" ), aError ); 
       
   385 #endif
       
   386             
       
   387     CSession2::ServiceError(aMessage,aError);
       
   388     }
       
   389 
       
   390 // Installation 
       
   391 // ************
       
   392 // -----------------------------------------------------------------------------
       
   393 // ChspsThemeServerSession::InstallThemeL
       
   394 // (other items were commented in a header).
       
   395 // -----------------------------------------------------------------------------
       
   396 //
       
   397 void ChspsThemeServerSession::InstallThemeL(const RMessage2& aMessage)
       
   398     {
       
   399     // delete previous handler and create new one for this installation
       
   400     if ( iInstallationHandler )
       
   401         {
       
   402         delete iInstallationHandler;
       
   403         iInstallationHandler = NULL;
       
   404         }
       
   405     iInstallationHandler = ChspsInstallationHandler::NewL( Server() );
       
   406     
       
   407 #ifdef HSPS_LOG_ACTIVE    
       
   408     // set logging bus.
       
   409     iInstallationHandler->SetLogBus( iLogBus );
       
   410 #endif    
       
   411     
       
   412     // call the service
       
   413     iInstallationHandler->ServiceInstallThemeL(aMessage);
       
   414     } 
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 // ChspsThemeServerSession::InstallNextPhaseL
       
   418 // (other items were commented in a header).
       
   419 // -----------------------------------------------------------------------------
       
   420 //
       
   421 void ChspsThemeServerSession::InstallNextPhaseL(const RMessage2& aMessage)
       
   422     {
       
   423     // make an asynchronous request
       
   424     if (!iInstallationHandler)
       
   425         {
       
   426         User::Leave( KErrNotReady );
       
   427         }
       
   428     else
       
   429         {
       
   430         // call the service
       
   431         iInstallationHandler->ServiceInstallNextPhaseL( aMessage );
       
   432         }
       
   433     }
       
   434   
       
   435 // -----------------------------------------------------------------------------
       
   436 // ChspsThemeServerSession::CancelInstallTheme
       
   437 // (other items were commented in a header).
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 void ChspsThemeServerSession::CancelInstallThemeL(const RMessage2& aMessage)
       
   441     {
       
   442     if ( iInstallationHandler )
       
   443         {
       
   444         // wait until service has finalised itself
       
   445         ThspsServiceCompletedMessage ret = iInstallationHandler->hspsCancelInstallTheme();
       
   446         // clean up the service
       
   447         delete iInstallationHandler;
       
   448         iInstallationHandler = NULL;
       
   449         if ( !aMessage.IsNull() )
       
   450     	    {
       
   451        	    aMessage.Complete( ret );	
       
   452     	    }
       
   453         }
       
   454     else
       
   455         {
       
   456         User::Leave( KErrNotReady );
       
   457         }
       
   458     } 
       
   459 
       
   460 // -----------------------------------------------------------------------------
       
   461 // ChspsThemeServerSession::ReinstallConf
       
   462 // (other items were commented in a header).
       
   463 // -----------------------------------------------------------------------------
       
   464 //
       
   465 void ChspsThemeServerSession::ReinstallConfL( const RMessage2& aMessage )
       
   466     {
       
   467 
       
   468     ThspsParamReinstallConf params;        
       
   469     TPckg<ThspsParamReinstallConf> packagedStruct( params );    
       
   470     aMessage.ReadL( 1, packagedStruct );                      
       
   471 
       
   472     Server().ReinstallConfL( params.appUid, params.confUId );
       
   473         
       
   474     aMessage.Complete( EhspsReinstallConfSuccess );
       
   475     
       
   476     } 
       
   477 
       
   478 
       
   479 // Maintenance 
       
   480 // ***********
       
   481 // -----------------------------------------------------------------------------
       
   482 // ChspsThemeServerSession::GetListHeadersL
       
   483 // (other items were commented in a header).
       
   484 // -----------------------------------------------------------------------------
       
   485 //
       
   486 void ChspsThemeServerSession::GetListHeadersL(const RMessage2& aMessage)
       
   487     {
       
   488     // Exception: should be reset since previous instance might be pending
       
   489     if ( iMaintenanceHandler )
       
   490         {
       
   491         delete iMaintenanceHandler;
       
   492         iMaintenanceHandler = NULL;
       
   493         }
       
   494     
       
   495     CreateMaintenanceHandlerL( aMessage.SecureId().iId );
       
   496     iMaintenanceHandler->ServiceGetListHeadersL( aMessage );
       
   497     }
       
   498   
       
   499 // -----------------------------------------------------------------------------
       
   500 // ChspsThemeServerSession::GetNextHeaderL
       
   501 // ?implementation_description
       
   502 // (other items were commented in a header).
       
   503 // -----------------------------------------------------------------------------
       
   504 //
       
   505 void ChspsThemeServerSession::GetNextHeaderL(const RMessage2& aMessage)
       
   506     {
       
   507     if ( !iMaintenanceHandler )
       
   508         {
       
   509         User::Leave( KErrNotReady );
       
   510         }
       
   511     else
       
   512         {
       
   513         iMaintenanceHandler->ServiceGetNextHeaderL(aMessage); 
       
   514         }
       
   515     } 
       
   516   
       
   517 // -----------------------------------------------------------------------------
       
   518 // ChspsThemeServerSession::CancelGetListHeaders
       
   519 // (other items were commented in a header).
       
   520 // -----------------------------------------------------------------------------
       
   521 //
       
   522 void ChspsThemeServerSession::CancelGetListHeadersL(const RMessage2& aMessage)
       
   523     {
       
   524     if ( iMaintenanceHandler )
       
   525         {
       
   526         ThspsServiceCompletedMessage ret = iMaintenanceHandler->hspsCancelGetListHeaders();
       
   527         delete iMaintenanceHandler;
       
   528         iMaintenanceHandler = NULL;  
       
   529         if ( !aMessage.IsNull() )
       
   530     	    {
       
   531        	    aMessage.Complete( EhspsServiceRequestCanceled );	
       
   532     	    }	       
       
   533         }
       
   534     else
       
   535         {
       
   536         User::Leave( KErrNotReady );  
       
   537         }
       
   538     } 
       
   539   
       
   540 
       
   541 // -----------------------------------------------------------------------------
       
   542 // ChspsThemeServerSession::SetActiveThemeL
       
   543 // (other items were commented in a header).
       
   544 // -----------------------------------------------------------------------------
       
   545 //
       
   546 void ChspsThemeServerSession::SetActiveThemeL(const RMessage2& aMessage)
       
   547     {
       
   548     // make a synchronous request    
       
   549     CreateMaintenanceHandlerL( aMessage.SecureId().iId );
       
   550     iMaintenanceHandler->ServiceSetActiveThemeL(aMessage);
       
   551     }
       
   552   
       
   553 
       
   554 // -----------------------------------------------------------------------------
       
   555 // ChspsThemeServerSession::RestoreDefaultL
       
   556 // (other items were commented in a header).
       
   557 // -----------------------------------------------------------------------------
       
   558 //
       
   559 void ChspsThemeServerSession::RestoreDefaultL(const RMessage2& aMessage)
       
   560     {
       
   561     // make a synchronous request    
       
   562     CreateMaintenanceHandlerL( aMessage.SecureId().iId );    
       
   563     iMaintenanceHandler->ServiceRestoreDefaultL(aMessage);
       
   564     }
       
   565 
       
   566 // -----------------------------------------------------------------------------
       
   567 // ChspsThemeServerSession::RemoveThemeL
       
   568 // (other items were commented in a header).
       
   569 // -----------------------------------------------------------------------------
       
   570 //
       
   571 void ChspsThemeServerSession::RemoveThemeL(const RMessage2& aMessage)
       
   572     {
       
   573     // make a synchronous request    
       
   574     CreateMaintenanceHandlerL( aMessage.SecureId().iId );    
       
   575     iMaintenanceHandler->ServiceRemoveThemeL(aMessage);
       
   576     }
       
   577 
       
   578 // -----------------------------------------------------------------------------
       
   579 // ChspsThemeServerSession::AddPluginL
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 void ChspsThemeServerSession::AddPluginL(const RMessage2& aMessage)
       
   583     {
       
   584     CreateMaintenanceHandlerL( aMessage.SecureId().iId );
       
   585     iMaintenanceHandler->ServiceAddPluginL( aMessage );
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // ChspsThemeServerSession::RemovePluginL
       
   590 // -----------------------------------------------------------------------------
       
   591 //
       
   592 void ChspsThemeServerSession::RemovePluginL(const RMessage2& aMessage)
       
   593     {    
       
   594     CreateMaintenanceHandlerL( aMessage.SecureId().iId );
       
   595     iMaintenanceHandler->ServiceRemovePluginL( aMessage );
       
   596     }
       
   597 
       
   598 // -----------------------------------------------------------------------------
       
   599 // ChspsThemeServerSession::SetActivePluginL
       
   600 // -----------------------------------------------------------------------------
       
   601 //
       
   602 void ChspsThemeServerSession::SetActivePluginL(const RMessage2& aMessage)
       
   603     {    
       
   604     CreateMaintenanceHandlerL( aMessage.SecureId().iId );
       
   605     iMaintenanceHandler->ServiceSetActivePluginL( aMessage );
       
   606     }
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // ChspsThemeServerSession::ReplacePluginL
       
   610 // -----------------------------------------------------------------------------
       
   611 //
       
   612 void ChspsThemeServerSession::ReplacePluginL(const RMessage2& aMessage)
       
   613     {    
       
   614     CreateMaintenanceHandlerL( aMessage.SecureId().iId );
       
   615     iMaintenanceHandler->ServiceReplacePluginL( aMessage );
       
   616     }
       
   617 
       
   618 // -----------------------------------------------------------------------------
       
   619 // ChspsThemeServerSession::SetPluginSettingsL
       
   620 // -----------------------------------------------------------------------------
       
   621 //
       
   622 void ChspsThemeServerSession::SetPluginSettingsL(const RMessage2& aMessage)
       
   623     {    
       
   624     CreateMaintenanceHandlerL( aMessage.SecureId().iId );
       
   625     iMaintenanceHandler->ServiceSetPluginSettingsL( aMessage );
       
   626     }
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // ChspsThemeServerSession::GetPluginOdtL
       
   630 // -----------------------------------------------------------------------------
       
   631 //
       
   632 void ChspsThemeServerSession::GetPluginOdtL(const RMessage2& aMessage)
       
   633     {    
       
   634     CreateMaintenanceHandlerL( aMessage.SecureId().iId );
       
   635     iMaintenanceHandler->ServiceGetPluginOdtL( aMessage );
       
   636     }
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // ChspsThemeServerSession::MovePluginsL
       
   640 // -----------------------------------------------------------------------------
       
   641 //
       
   642 void ChspsThemeServerSession::MovePluginsL(const RMessage2& aMessage)
       
   643     {    
       
   644     CreateMaintenanceHandlerL( aMessage.SecureId().iId );
       
   645     iMaintenanceHandler->ServiceMovePluginsL( aMessage );
       
   646     }
       
   647 
       
   648 // -----------------------------------------------------------------------------
       
   649 // ChspsThemeServerSession::SetConfStateL
       
   650 // -----------------------------------------------------------------------------
       
   651 //
       
   652 void ChspsThemeServerSession::SetConfStateL(const RMessage2& aMessage)
       
   653     {    
       
   654     CreateMaintenanceHandlerL( aMessage.SecureId().iId );
       
   655     iMaintenanceHandler->ServiceSetConfStateL( aMessage );
       
   656     }
       
   657 
       
   658 // -----------------------------------------------------------------------------
       
   659 // ChspsThemeServerSession::RestoreActiveAppConfL
       
   660 // -----------------------------------------------------------------------------
       
   661 //
       
   662 void ChspsThemeServerSession::RestoreActiveAppConfL(const RMessage2& aMessage)
       
   663     {
       
   664 	CreateMaintenanceHandlerL( aMessage.SecureId().iId );
       
   665     iMaintenanceHandler->ServiceRestoreActiveAppConfL( aMessage );
       
   666     }
       
   667 
       
   668 // Client Request 
       
   669 // **************
       
   670 // -----------------------------------------------------------------------------
       
   671 // ChspsThemeServerSession::GetOdtL
       
   672 // (other items were commented in a header).
       
   673 // -----------------------------------------------------------------------------
       
   674 //
       
   675 void ChspsThemeServerSession::GetOdtL(const RMessage2& aMessage)
       
   676     {
       
   677     //Make an asynchronous request    
       
   678     CreateClientRequestHandlerL();    
       
   679     iClientRequestHandler->ServiceGetOdtL( aMessage );
       
   680     }
       
   681   
       
   682 // -----------------------------------------------------------------------------
       
   683 // ChspsThemeServerSession::GetOdtUpdateL
       
   684 // (other items were commented in a header).
       
   685 // -----------------------------------------------------------------------------
       
   686 //
       
   687 void ChspsThemeServerSession::GetOdtUpdateL(const RMessage2& aMessage)
       
   688     {
       
   689     // make an asynchronous request 
       
   690     if (!iClientRequestHandler)
       
   691         {
       
   692         User::Leave( KErrNotReady );
       
   693         }
       
   694     else
       
   695         {
       
   696         iClientRequestHandler->ServiceGetOdtUpdateL(aMessage);  
       
   697         }
       
   698     } 
       
   699 
       
   700 // -----------------------------------------------------------------------------
       
   701 // ChspsThemeServerSession::CancelGetOdtUpdate
       
   702 // (other items were commented in a header).
       
   703 // -----------------------------------------------------------------------------
       
   704 //
       
   705 void ChspsThemeServerSession::CancelGetOdtUpdateL(const RMessage2& aMessage)
       
   706     {
       
   707     if ( iClientRequestHandler )
       
   708         {
       
   709         ThspsServiceCompletedMessage ret = iClientRequestHandler->hspsCancelGetODTUpdate();
       
   710         if ( !aMessage.IsNull() )
       
   711     	    {
       
   712        	    aMessage.Complete( EhspsServiceRequestCanceled );	
       
   713     	    }
       
   714         }
       
   715     else
       
   716         {
       
   717         User::Leave( KErrNotReady );
       
   718         }
       
   719     } 
       
   720 
       
   721 // -----------------------------------------------------------------------------
       
   722 // ChspsThemeServerSession::AccessResourceFileL
       
   723 // (other items were commented in a header).
       
   724 // -----------------------------------------------------------------------------
       
   725 //
       
   726 void ChspsThemeServerSession::AccessResourceFileL(const RMessage2& aMessage)
       
   727     {
       
   728     //Make a synchronous request    
       
   729     CreateClientRequestHandlerL();        
       
   730         
       
   731 #ifdef _hsps_PERFORMANCE_TEST_
       
   732         ChspsTimeMon::PrintUserMem( _L("hspsThemeServer::AccessResourceFileL(): - accessing..") );
       
   733 #endif //_hsps_PERFORMANCE_TEST_        
       
   734 
       
   735     // call the service with TRAP
       
   736     iClientRequestHandler->ServiceAccessResourceFileL( aMessage );
       
   737     if ( !iHoldingResources )
       
   738         {
       
   739         iHoldingResources = ETrue;  
       
   740         // add number of resource holders
       
   741         Server().IncreaseRequestClientCount();
       
   742         }
       
   743 
       
   744 #ifdef _hsps_PERFORMANCE_TEST_
       
   745         ChspsTimeMon::PrintUserMem( _L("hspsThemeServer::AccessResourceFileL(): - file accessed.") );
       
   746 #endif //_hsps_PERFORMANCE_TEST_    
       
   747 
       
   748     }
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 // ChspsThemeServerSession::FindWidgetUids
       
   752 // -----------------------------------------------------------------------------
       
   753 void ChspsThemeServerSession::FindWidgetUidsL(
       
   754         ChspsODT& aAppODT,
       
   755         RArray<TInt>& aUidArray ) 
       
   756     {    
       
   757     aUidArray.Reset();       
       
   758     const TInt resourceCount = aAppODT.ResourceCount();
       
   759     for( TInt resourceIndex = 0; resourceIndex < resourceCount; resourceIndex++ )
       
   760         {      
       
   761         ChspsResource& r = aAppODT.ResourceL( resourceIndex );
       
   762         const TInt uid = r.ConfigurationUid();        
       
   763         if ( uid > 0 &&
       
   764              aUidArray.Find( uid ) == KErrNotFound )
       
   765             {
       
   766             aUidArray.Append( uid );
       
   767             }
       
   768         }                       
       
   769     }
       
   770 
       
   771 // -----------------------------------------------------------------------------
       
   772 // ChspsThemeServerSession::DoCopyResourceFilesL
       
   773 // -----------------------------------------------------------------------------
       
   774 TInt ChspsThemeServerSession::DoCopyResourceFilesL(
       
   775         ChspsODT& aAppODT,        
       
   776         CFileMan& aFilemanager,
       
   777         const TInt aConfUid,
       
   778         const TDesC& aDestination )
       
   779     {
       
   780     TInt error( KErrNone );
       
   781     RPointerArray<ChspsResource> widgetResources; // Objects are not owned.
       
   782     CleanupClosePushL( widgetResources );
       
   783     
       
   784     // Get resources that need to be copied.
       
   785     hspsServerUtil::GetValidResourcesL( aAppODT,
       
   786             aConfUid,
       
   787             Server().DeviceLanguage(),
       
   788             widgetResources );
       
   789         
       
   790     // Copy the resources found    
       
   791     for( TInt i = 0; ( i < widgetResources.Count() && !error ); i++ )
       
   792         {      
       
   793         ChspsResource* resource = widgetResources[i];
       
   794         if( !resource )
       
   795             {
       
   796             continue;
       
   797             }
       
   798                 
       
   799         // Get relative path under the themes folder 
       
   800         TPath relativePath;
       
   801         hspsServerUtil::GetRelativeResourcePath( 
       
   802                 resource->FileName(),
       
   803                 relativePath );
       
   804         
       
   805         // Strip language indicator from the relative path                                       
       
   806         hspsServerUtil::GetLocaleIndependentResourcePath( 
       
   807                 resource->Language(),                            
       
   808                 relativePath );   
       
   809         
       
   810         // Finalize target path
       
   811         TPath targetPath;
       
   812         targetPath.Copy( aDestination );
       
   813         targetPath.Append( relativePath );        
       
   814              
       
   815         // Create missing target path and copy files when needed only
       
   816         error = hspsServerUtil::CopyResourceFileL(
       
   817                 iFs,
       
   818                 aFilemanager, 
       
   819                 targetPath,
       
   820                 resource->FileName() );
       
   821         if ( !error )
       
   822             {
       
   823 #ifdef HSPS_LOG_ACTIVE
       
   824             if ( iLogBus )
       
   825                 {
       
   826                 iLogBus->LogText( 
       
   827                         _L( "hspsServerUtil::DoCopyResourceFilesL(): - %S was copied" ), 
       
   828                         &targetPath 
       
   829                         );
       
   830                 } 
       
   831 #endif
       
   832             }
       
   833         if ( error == KErrAlreadyExists )
       
   834             {
       
   835             error = KErrNone;
       
   836             }
       
   837         
       
   838         } // copy loop       
       
   839         
       
   840     widgetResources.Reset();
       
   841     CleanupStack::PopAndDestroy( 1, &widgetResources );
       
   842 
       
   843     return error;
       
   844     }
       
   845 
       
   846 // -----------------------------------------------------------------------------
       
   847 // ChspsThemeServerSession::CopyResourceFilesL
       
   848 // (other items were commented in a header).
       
   849 // -----------------------------------------------------------------------------
       
   850 //
       
   851 void ChspsThemeServerSession::CopyResourceFilesL(const RMessage2& aMessage)
       
   852 	{	 
       
   853 	// read paths from the buffer
       
   854 	TFileName odtPath;
       
   855     TPath destinationPath;  // Private root folder of the client application
       
   856 	aMessage.ReadL( 1, odtPath, 0 );
       
   857 	aMessage.ReadL( 2, destinationPath, 0 );
       
   858 	    	
       
   859 	ChspsODT* odt = ChspsODT::NewL();
       
   860     CleanupStack::PushL( odt );
       
   861 	
       
   862     // phase counter for cleaning and debug prints
       
   863     TInt phaseCounter = 1;
       
   864     
       
   865 	RFile odtfile;
       
   866 	CleanupClosePushL( odtfile );	    
       
   867     TInt error = odtfile.Open( iFs, odtPath, EFileRead );            	
       
   868     if( error == KErrNone )
       
   869     	{
       
   870     	phaseCounter++;
       
   871     	
       
   872 	    // set stream on file
       
   873     	CFileStore* store = CDirectFileStore::FromLC( odtfile );
       
   874 	    RStoreReadStream instream;
       
   875 	    CleanupClosePushL( instream );
       
   876 		instream.OpenLC( *store, store->Root() );
       
   877 		
       
   878 	    // stream in the ODT
       
   879 		instream >> *odt;
       
   880 		
       
   881 		// the file is no longer needed
       
   882 		odtfile.Close();
       
   883 		
       
   884 		// destroy the stream object and close the instream
       
   885 	    CleanupStack::PopAndDestroy(3); // instream,store 
       
   886     	}
       
   887     
       
   888     CleanupStack::PopAndDestroy(1, &odtfile); // odtfile
       
   889     
       
   890     if( error == KErrNone )
       
   891  		{
       
   892  		phaseCounter++;
       
   893  		 		
       
   894         RArray<TInt> widgetArray;
       
   895         CleanupClosePushL( widgetArray );
       
   896         
       
   897         // Find unique configuration UIDs from the resource array
       
   898         FindWidgetUidsL( *odt, widgetArray );
       
   899  		        
       
   900         CFileMan* fileManager = NULL;
       
   901  		fileManager = CFileMan::NewL( iFs );
       
   902  		CleanupStack::PushL( fileManager );
       
   903  		                        
       
   904         // Loop widgets belonging to the root configuration
       
   905         const TInt uidCount = widgetArray.Count();
       
   906 	    for( TInt i = 0; i < uidCount && !error; i++ )
       
   907 	    	{	    		    	
       
   908 	    	// Copy widget's resources to client's private folder	    	
       
   909 	    	error = DoCopyResourceFilesL(
       
   910                         *odt,
       
   911                         *fileManager, 
       
   912                         widgetArray[i],
       
   913                         destinationPath );	    
       
   914     		}
       
   915 	    
       
   916 	    widgetArray.Reset();
       
   917 	    
       
   918 	    CleanupStack::PopAndDestroy( 2, &widgetArray ); // fileManager, widgetArray    	           
       
   919  		} // KErrNone
       
   920  	
       
   921  	//Tidy-up
       
   922     if ( odt )
       
   923         {
       
   924         CleanupStack::PopAndDestroy( odt );
       
   925         }    
       
   926  	 	 	       
       
   927     if( error )
       
   928     	{
       
   929 #ifdef HSPS_LOG_ACTIVE    	
       
   930         iLogBus->LogText( _L( "ChspsThemeServerSession::CopyResourceFilesL(): - creating target directory failed! ( error : %d in phase: %d)." ),
       
   931                 error,
       
   932                 phaseCounter );
       
   933 #endif    	                
       
   934     	                
       
   935     	aMessage.Complete( EhspsResourceCopyFailed );
       
   936     	}
       
   937     else
       
   938     	{
       
   939     	aMessage.Complete( EhspsResourceCopySuccess );
       
   940     	}
       
   941 	}
       
   942 // -----------------------------------------------------------------------------
       
   943 // ChspsThemeServerSession::CreateMaintenanceHandlerL
       
   944 // (other items were commented in a header).
       
   945 // -----------------------------------------------------------------------------
       
   946 //
       
   947 void ChspsThemeServerSession::CreateMaintenanceHandlerL(
       
   948         const TUint aSecureId )
       
   949     {
       
   950     if( !iMaintenanceHandler )
       
   951         {        
       
   952         iMaintenanceHandler = ChspsMaintenanceHandler::NewL( Server(), aSecureId );
       
   953         iMaintenanceHandler->SetServerSession( this );
       
   954 #ifdef HSPS_LOG_ACTIVE    
       
   955         iMaintenanceHandler->SetLogBus( iLogBus );
       
   956 #endif
       
   957         }
       
   958 
       
   959     }
       
   960 
       
   961 // -----------------------------------------------------------------------------
       
   962 // ChspsThemeServerSession::CreateClientRequestHandlerL
       
   963 // (other items were commented in a header).
       
   964 // -----------------------------------------------------------------------------
       
   965 //
       
   966 void ChspsThemeServerSession::CreateClientRequestHandlerL()
       
   967     {
       
   968     if( !iClientRequestHandler )
       
   969         {        
       
   970         iClientRequestHandler = ChspsClientRequestHandler::NewL( Server() );
       
   971 
       
   972 #ifdef HSPS_LOG_ACTIVE  
       
   973         iClientRequestHandler->SetLogBus( iLogBus );        
       
   974 #endif  
       
   975         }
       
   976     }
       
   977 
       
   978 // -----------------------------------------------------------------------------
       
   979 // ChspsThemeServerSession::FileSystem
       
   980 // -----------------------------------------------------------------------------
       
   981 //
       
   982 RFs& ChspsThemeServerSession::FileSystem()
       
   983     {
       
   984     return iFs;
       
   985     }
       
   986 
       
   987 // end of file
       
   988