homescreenpluginsrv/hspsmanager/src/hspsclientrequesthandler.cpp
branchRCL_3
changeset 30 a5a39a295112
child 31 8baec10861af
equal deleted inserted replaced
29:0efa10d348c0 30:a5a39a295112
       
     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:  Retrieves configurations from the Definition Repository
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "hsps_builds_cfg.hrh"
       
    20 
       
    21 #include <f32file.h> 
       
    22 #include <centralrepository.h>
       
    23 #ifdef HSPS_LOG_ACTIVE
       
    24 #include <hspsodtdump.h>
       
    25 #include <hspslogbus.h>
       
    26 #endif
       
    27 
       
    28 #include "hspsresource.h"
       
    29 #include "hspsdomdocument.h"
       
    30 #include "hspsdomnode.h"
       
    31 #include "hspsthememanagement.h"
       
    32 #include "hspsdefinitionrepository.h"
       
    33 #include "hspsodt.h"
       
    34 #include "hspsresult.h"
       
    35 #include "hspsreqnotifparam.h"
       
    36 #ifdef _hsps_PERFORMANCE_TEST_
       
    37 #include "hspstimemon.h"
       
    38 #endif
       
    39 #include "hspsclientrequesthandler.h"
       
    40 #include "hspsmaintenancehandler.h"
       
    41 #include "hspssecurityenforcer.h"
       
    42 #include "hspsthemeserver.h"
       
    43 #include "hspscenreplistener.h"
       
    44 #include "hspsserverutil.h"
       
    45 #include "hspsdomattribute.h"
       
    46 #include "hspsdomlist.h"
       
    47 #include "hspsdomdepthiterator.h"
       
    48 #include "hspsdomnode.h"
       
    49 #include "hspsconfiguration.h"
       
    50 
       
    51 
       
    52 _LIT(KSourcesSubFolder, "\\sources\\");
       
    53 _LIT(KLocalesSubFolder, "\\locales\\");
       
    54 
       
    55 
       
    56 
       
    57 // ============================= LOCAL FUNCTIONS ===============================
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // Callback function for removing repository lock if error occurs while repository is locked
       
    61 // Returns: void
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 LOCAL_C void UnlockRepository( TAny* aObject )
       
    65     {
       
    66     ChspsDefinitionRepository* DefRep = reinterpret_cast<ChspsDefinitionRepository*>( aObject );
       
    67         
       
    68     if( DefRep->Locked() )
       
    69         {
       
    70         DefRep->Unlock();
       
    71         }
       
    72     }
       
    73     
       
    74 
       
    75 // ============================ MEMBER FUNCTIONS ===============================
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // ChspsClientRequestHandler::ChspsClientRequestHandler
       
    79 // C++ default constructor can NOT contain any code, that
       
    80 // might leave.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 ChspsClientRequestHandler::ChspsClientRequestHandler( ChspsThemeServer& aThemeServer ): 
       
    84     iThemeServer( aThemeServer ), 
       
    85     iCentralRepository( aThemeServer.CentralRepository() ),  
       
    86     iDefinitionRepository( aThemeServer.DefinitionRepository() ),
       
    87     iSecurityEnforcer( aThemeServer.SecurityEnforcer() ),
       
    88     iHeaderListCache (aThemeServer.HeaderListCache() )            
       
    89     { 
       
    90     iLastSuccessThemeLoadTime = 0;
       
    91     iRestoreDefault = EFalse;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // ChspsDefinitionRepository::NewL
       
    96 // Two-phased constructor.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 ChspsClientRequestHandler* ChspsClientRequestHandler::NewL( ChspsThemeServer& aThemeServer )
       
   100     {
       
   101     ChspsClientRequestHandler* h = ChspsClientRequestHandler::NewLC( aThemeServer );
       
   102     CleanupStack::Pop(h);
       
   103     return (h);
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // ChspsDefinitionRepository::NewLC
       
   108 // Two-phased constructor.
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 ChspsClientRequestHandler* ChspsClientRequestHandler::NewLC( ChspsThemeServer& aThemeServer )
       
   112     {
       
   113     ChspsClientRequestHandler* h = new (ELeave) ChspsClientRequestHandler( aThemeServer );
       
   114     CleanupStack::PushL(h);
       
   115     h->ConstructL();
       
   116     return (h);
       
   117     }
       
   118 
       
   119 // Destructor
       
   120 ChspsClientRequestHandler::~ChspsClientRequestHandler()
       
   121     {
       
   122     delete iOdt;
       
   123     delete iResult;
       
   124     delete iReqNotifParams;
       
   125     delete iRequestData;
       
   126     iFs.Close();
       
   127     delete iCenRepListener;
       
   128     iDefinitionRepository.UnregisterObserver( *this );
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // ChspsDefinitionRepository::ConstructL
       
   133 // Symbian 2nd phase constructor can leave.
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void ChspsClientRequestHandler::ConstructL()
       
   137     {
       
   138     // call the base class ConstructL
       
   139     User::LeaveIfError(iFs.Connect());
       
   140     iResult = ChspsResult::NewL();
       
   141     iReqNotifParams = ChspsRequestNotificationParams::NewL();
       
   142     iDefinitionRepository.RegisterObserverL( *this );    
       
   143     iCenRepListener = NULL;    
       
   144     
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // ChspsClientRequestHandler::ServiceGetOdtL
       
   149 // Serves hspsRequestClient on hspsGetODT() service call.
       
   150 // (other items were commented in a header).
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void ChspsClientRequestHandler::ServiceGetOdtL(const RMessage2& aMessage)
       
   154     {
       
   155     iThemeLoadRepeatCount = 0;
       
   156     TInt errorCode = KErrNone;
       
   157     RMessagePtr2 msgPtr = aMessage;
       
   158     // Get configuration from IPC slot #1
       
   159     ThspsConfiguration configuration;        
       
   160     TPckg<ThspsConfiguration> packagedStruct(configuration);    
       
   161     aMessage.ReadL(1, packagedStruct);                        
       
   162     iRootUid = configuration.rootUid;    
       
   163     iSecureId = msgPtr.SecureId().iId;
       
   164     iRequestMessage = (ThspsServiceRequestMessage) aMessage.Function();
       
   165     
       
   166     // Get header data from IPC slot #2
       
   167     TBuf8<KMaxHeaderDataLength8> requestData; 
       
   168     msgPtr.ReadL( 2, requestData, 0 );
       
   169     ThspsServiceCompletedMessage ret = EhspsGetODTFailed;
       
   170     
       
   171     // resetting previous request objects
       
   172     if ( iRequestData )
       
   173         {
       
   174         delete iRequestData;
       
   175         iRequestData = NULL;
       
   176         }
       
   177          
       
   178     // constructing new data request objects  
       
   179     iRequestData = requestData.AllocL();
       
   180     
       
   181     // reset previous ODT
       
   182     if ( iOdt )
       
   183         {
       
   184         delete iOdt;
       
   185         iOdt = NULL;
       
   186         }
       
   187     
       
   188     // constructing new ODT
       
   189     iOdt = ChspsODT::NewL();
       
   190     iOdt->UnMarshalHeaderL( iRequestData->Des() );
       
   191 
       
   192     TBool err = EFalse;
       
   193     
       
   194     if ( !iRootUid )
       
   195         {
       
   196         err = ETrue;
       
   197         iResult->iSystemError = KErrInUse;
       
   198         CompleteRequestL( EhspsServiceRequestError, msgPtr );
       
   199         }
       
   200         
       
   201     if ( !err )
       
   202         {
       
   203         // Get configuration: 1st attempt
       
   204         ret = hspsGetODT(iRootUid, *iOdt );
       
   205         
       
   206         // If fetching failed
       
   207         if ( ret != EhspsGetODTSuccess )
       
   208             {
       
   209             // If not restoring yet
       
   210             if ( iRestoreDefault )
       
   211                 {
       
   212                 // Restore a default configuration
       
   213                 TRAP( errorCode, RestoreDefaultL( *iOdt ) );    
       
   214                 if ( !errorCode )
       
   215                     {
       
   216                     // 2nd attempt: try to fetch the default configuration
       
   217                     ret = hspsGetODT(iRootUid, *iOdt );
       
   218                     if ( ret != EhspsGetODTSuccess )
       
   219                         {                         
       
   220 #ifdef HSPS_LOG_ACTIVE  
       
   221                         if( iLogBus )
       
   222                             {
       
   223                             iLogBus->LogText( _L( "ChspsClientRequestHandler::ServiceGetODTL(): - default theme for appuid %d is not available." ),
       
   224                                     iOdt->RootUid() );
       
   225                             }
       
   226 #endif                        
       
   227                         CompleteRequestL( EhspsGetODTFailed, msgPtr );
       
   228                         }
       
   229                     } // !errorCode
       
   230                 } // iRestoreDefault            
       
   231             } // !EhspsGetODTSuccess
       
   232             
       
   233         // If a configuration was found (either after the first attempt or after restoring the default configuration)
       
   234         if ( ret == EhspsGetODTSuccess )
       
   235             {           
       
   236             // If an application configuration was fetched
       
   237             if ( iOdt->ConfigurationType() == EhspsAppConfiguration )
       
   238                 {
       
   239                 // Finnish installation of the application configuration
       
   240                 HandlePluginReferencesL( *iOdt );
       
   241                 }                
       
   242             
       
   243             // write ODT-file path back to the client for theme load
       
   244             msgPtr.WriteL( 3, iODTPath, 0 );
       
   245             CompleteRequestL( ret, msgPtr );
       
   246             } // success
       
   247         else 
       
   248             {
       
   249             if ( !iHeaderListCache.Count() )
       
   250                 {
       
   251                 // header list cache is empty. This may also occur when memory is full
       
   252 #ifdef HSPS_LOG_ACTIVE  
       
   253                 if( iLogBus )
       
   254                     {
       
   255                     iLogBus->LogText( _L( "ChspsClientRequestHandler::ServiceGetODTL(): - theme cache is empty." ) );
       
   256                     }
       
   257 #endif                    
       
   258                 CompleteRequestL( EhspsGetODTFailed, msgPtr ); 
       
   259                 }
       
   260             else if ( iRestoreDefault )
       
   261                 {
       
   262 #ifdef HSPS_LOG_ACTIVE  
       
   263                 if( iLogBus )
       
   264                     {
       
   265                     iLogBus->LogText( _L( "ChspsClientRequestHandler::ServiceGetODTL(): - default theme cannot be restored." ) );
       
   266                     }
       
   267 #endif                   
       
   268                 CompleteRequestL( EhspsGetODTFailed, msgPtr );
       
   269                 }
       
   270             else if ( iDefinitionRepository.Locked() )
       
   271                 {
       
   272                 // possible repository lock, wait for checking the theme availability after a while
       
   273 #ifdef HSPS_LOG_ACTIVE  
       
   274                 if( iLogBus )
       
   275                     {
       
   276                     iLogBus->LogText( _L( "ChspsClientRequestHandler::ServiceGetODTL(): - theme repository is locked, trying again after reasonable time .." ) );
       
   277                     }
       
   278 #endif                    
       
   279                 CompleteRequestL( EhspsGetODTFailed, msgPtr ); 
       
   280                 }
       
   281             else
       
   282                 {
       
   283 #ifdef HSPS_LOG_ACTIVE  
       
   284                 if( iLogBus )
       
   285                     {
       
   286                     iLogBus->LogText( _L( "ChspsClientRequestHandler::ServiceGetODTL(): - theme load failed." ) );
       
   287                     }
       
   288 #endif                    
       
   289                 CompleteRequestL( EhspsGetODTFailed, msgPtr ); 
       
   290                 }
       
   291             } // else (!EhspsGetODTSuccess)
       
   292         } // !err
       
   293         
       
   294     }
       
   295     
       
   296 // -----------------------------------------------------------------------------
       
   297 // ChspsClientRequestHandler::HandlePluginReferencesL()
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 void ChspsClientRequestHandler::HandlePluginReferencesL(
       
   301         ChspsODT& aAppODT )
       
   302     {
       
   303     // Input validation
       
   304     if ( aAppODT.ConfigurationType() != EhspsAppConfiguration )
       
   305         {
       
   306         User::Leave( KErrGeneral );
       
   307         }
       
   308     
       
   309     // Assume that plugins need to be added
       
   310     TBool addPlugins = ETrue;     
       
   311     
       
   312     // Check whether the plugins needs to be added
       
   313     ChspsDomDocument& appDom = aAppODT.DomDocument(); 
       
   314     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *appDom.RootNode() );
       
   315     CleanupStack::PushL( iter );
       
   316     ChspsDomNode* prevNode = NULL;
       
   317     ChspsDomNode* node = iter->First();
       
   318     TInt tempCount = 0;
       
   319     while( node && prevNode != node && addPlugins )
       
   320         {           
       
   321         const TDesC8& name = node->Name();                
       
   322         if ( name == KConfigurationElement )
       
   323             {
       
   324             tempCount++;
       
   325             if ( tempCount > 1 )
       
   326                 {
       
   327                 addPlugins = EFalse;
       
   328                 }                           
       
   329             }    
       
   330         prevNode = node;    
       
   331         node = iter->NextL();   
       
   332         }
       
   333     CleanupStack::PopAndDestroy( iter );
       
   334     
       
   335     // If plugin configurations need to be added
       
   336     if ( addPlugins )
       
   337         {    
       
   338         if ( iDefinitionRepository.Locked() )
       
   339             {
       
   340             // Repository was locked by another session?!
       
   341             User::Leave( KErrAccessDenied );
       
   342             }
       
   343         
       
   344         // Lock the Plugin Repository (a.k.a. Def.rep)
       
   345         iDefinitionRepository.Lock();                               
       
   346         CleanupStack::PushL( TCleanupItem( UnlockRepository, &iDefinitionRepository ) );
       
   347                 
       
   348         // Go through the XML document, find all plugin nodes and append plugin specifc XML configurations
       
   349         AppendPluginConfigurationsL( aAppODT );       
       
   350 
       
   351         //Append widget instance specific predefined settings
       
   352         User::LeaveIfError( AppendInitialSettingsL( aAppODT ));
       
   353         
       
   354         // Set first plugin nodes from levels to be active. Others are to be deactivated.
       
   355         hspsServerUtil::EditPluginNodeActivityL( aAppODT.DomDocument().RootNode(),
       
   356                                                  hspsServerUtil::EActivateFirst );
       
   357                 
       
   358         // Update changes into the Plug-in Repository
       
   359         User::LeaveIfError( iDefinitionRepository.SetOdtL( aAppODT ) );           
       
   360         
       
   361         // Unlock after the changes have been done
       
   362         iDefinitionRepository.Unlock();
       
   363         CleanupStack::Pop(&iDefinitionRepository);        
       
   364         
       
   365 #ifdef HSPS_LOG_ACTIVE    
       
   366         if( iLogBus )
       
   367             {
       
   368             iLogBus->LogText( _L( "ChspsClientRequestHandler::HandlePluginReferencesL(): - dumping updated full XML document" ) );
       
   369             ChspsOdtDump::Dump( aAppODT, *iLogBus );
       
   370             }
       
   371 #endif        
       
   372         }
       
   373     }
       
   374 
       
   375 // -----------------------------------------------------------------------------
       
   376 // ChspsClientRequestHandler::AddErrorConfigurationL()
       
   377 // -----------------------------------------------------------------------------
       
   378 //
       
   379 void ChspsClientRequestHandler::AddErrorConfigurationL(
       
   380         ChspsDomDocument& aAppDom,
       
   381         ChspsDomNode& aMissingPluginNode,
       
   382         const TInt aPluginUid
       
   383         )        
       
   384     {    
       
   385     // Create a new dummy configuration element
       
   386     ChspsDomNode* confNode = aAppDom.CreateElementNSL( 
       
   387         KConfigurationElement,         
       
   388         aMissingPluginNode.Namespace()            
       
   389         );
       
   390     CleanupStack::PushL( confNode );        
       
   391         
       
   392     hspsServerUtil::AddAttributeDescL( *confNode, KConfigurationAttrType, KConfTypeWidget );
       
   393     _LIT8( KUnknown, "unknown" );
       
   394     hspsServerUtil::AddAttributeDescL( *confNode, KConfigurationAttrInterface, KUnknown );
       
   395     hspsServerUtil::AddAttributeNumericL( *confNode, KConfigurationAttrUid, aPluginUid, EHex );
       
   396     hspsServerUtil::AddAttributeDescL( *confNode, KConfigurationAttrName, KUnknown );
       
   397     hspsServerUtil::AddAttributeDescL( *confNode, KConfigurationAttrNameEntity, KUnknown );
       
   398     hspsServerUtil::AddAttributeDescL( *confNode, KConfigurationAttrVersion, KUnknown );        
       
   399     hspsServerUtil::AddAttributeNumericL( *confNode, KConfigurationAttrMaxChild, 0, EDecimal );        
       
   400     
       
   401     // Indicate that the configuration is in error state
       
   402     hspsServerUtil::AddAttributeDescL( *confNode, KConfigurationAttrState, KConfStateError );
       
   403             
       
   404     // Set parent node
       
   405     aMissingPluginNode.AddChildL( confNode );
       
   406     CleanupStack::Pop( confNode );
       
   407     confNode->SetParent( &aMissingPluginNode );
       
   408         
       
   409     // Mandatory configuration-control node
       
   410     ChspsDomNode* controlNode = aAppDom.CreateElementNSL( 
       
   411         KControlElement,         
       
   412         confNode->Namespace()            
       
   413         );
       
   414     CleanupStack::PushL( controlNode );    
       
   415     confNode->AddChildL( controlNode );
       
   416     CleanupStack::Pop( controlNode );
       
   417     controlNode->SetParent( confNode );
       
   418     
       
   419     // Mandatory configuration-control-settings node
       
   420     ChspsDomNode* settingsNode = aAppDom.CreateElementNSL( 
       
   421         KSettingsElement,         
       
   422         controlNode->Namespace()            
       
   423         );
       
   424     CleanupStack::PushL( settingsNode );    
       
   425     controlNode->AddChildL( settingsNode );
       
   426     CleanupStack::Pop( settingsNode );
       
   427     settingsNode->SetParent( controlNode );           
       
   428         
       
   429     // Mandatory configuration-resources node
       
   430     ChspsDomNode* resourcesNode = aAppDom.CreateElementNSL( 
       
   431         KResourcesElement,         
       
   432         confNode->Namespace()            
       
   433         );
       
   434     CleanupStack::PushL( resourcesNode );    
       
   435     confNode->AddChildL( resourcesNode );
       
   436     CleanupStack::Pop( resourcesNode );        
       
   437     resourcesNode->SetParent( confNode );           
       
   438     
       
   439     }
       
   440 
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // ChspsClientRequestHandler::PrepareAndCompleteRequestL()
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 void ChspsClientRequestHandler::PrepareAndCompleteRequestL( const ThspsRepositoryInfo& aInfo,
       
   447                                                             const ThspsServiceCompletedMessage& aMessage )
       
   448     {
       
   449     TBool LastDefinitionRepositoryEvent(ETrue);
       
   450     if( !iReqNotifParams )
       
   451         {
       
   452         User::Leave( KErrCorrupt );
       
   453         }
       
   454     if( !aInfo.iLastNotification )
       
   455         {
       
   456         LastDefinitionRepositoryEvent = EFalse;
       
   457         }
       
   458     
       
   459     // Prepare request notification object.
       
   460     if(iReqNotifParams->iEvent == EhspsNoEvent || iReqNotifParams->iEvent == aInfo.iEventType )
       
   461         {
       
   462         iReqNotifParams->iEvent = aInfo.iEventType;  
       
   463         iReqNotifParams->iAppUid = aInfo.iAppUid;
       
   464         iReqNotifParams->iAppConfUid = aInfo.iAppConfUid;
       
   465         iReqNotifParams->iOrigUid = aInfo.iSecureId;
       
   466         iReqNotifParams->iPluginUid = aInfo.iPluginUid;
       
   467         iReqNotifParams->iCount++;
       
   468         iReqNotifParams->iPluginIds.Append( aInfo.iPluginId );
       
   469      
       
   470         if( aInfo.iName.Length() > 0 )
       
   471             {
       
   472             iReqNotifParams->SetNameL( aInfo.iName );
       
   473             }   
       
   474         }
       
   475     if( LastDefinitionRepositoryEvent )
       
   476         {
       
   477         // Externalize request notification object to message structure.
       
   478         TInt errorCode = KErrNone;
       
   479         RDesWriteStream writeBuf( iReqNotifData );
       
   480         CleanupClosePushL( writeBuf );
       
   481         TRAP( errorCode, iReqNotifParams->ExternalizeL( writeBuf ) );
       
   482         CleanupStack::PopAndDestroy();
       
   483             
       
   484         if ( !iMessagePtr.IsNull() )
       
   485             {
       
   486             if ( errorCode )    
       
   487                 { 
       
   488                 iMessagePtr.WriteL( 1, KNullDesC8, 0 );
       
   489                 }    
       
   490             else
       
   491                 {
       
   492                 iMessagePtr.WriteL( 1, iReqNotifData, 0 );   
       
   493                 }
       
   494             }   
       
   495         // theres no request message pending until request new one
       
   496         iRequestMessage = EhspsClientRequestBase;
       
   497         // Send message.    
       
   498         CompleteRequestL( aMessage, iMessagePtr );
       
   499         
       
   500         iReqNotifParams->ResetData();
       
   501         
       
   502         }
       
   503     
       
   504    
       
   505     }
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // ChspsClientRequestHandler::AppendPluginConfigurationsL()
       
   509 // -----------------------------------------------------------------------------
       
   510 //
       
   511 void ChspsClientRequestHandler::AppendPluginConfigurationsL( 
       
   512         ChspsODT& aAppODT )
       
   513     {    
       
   514     ChspsDomDocument& appDom = aAppODT.DomDocument(); 
       
   515     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *appDom.RootNode() );
       
   516     CleanupStack::PushL( iter );
       
   517            
       
   518     // Each configuration element get's an unique id value - same applies to the plugin elements.
       
   519     // The ids are then used for referencing a specific configuration or plug-in instance 
       
   520     // in the whole application configuration
       
   521     TInt confId = 0;
       
   522     TInt pluginId = 0;    
       
   523     
       
   524     ChspsDomNode* prevNode = NULL;
       
   525     ChspsDomNode* node = iter->First();
       
   526     while( node && prevNode != node )
       
   527         {   
       
   528         
       
   529         const TDesC8& name = node->Name();
       
   530         
       
   531         // Configuration element 
       
   532         if ( name == KConfigurationElement )
       
   533             {                                   
       
   534             // Generate an ID attribute for the configuration element
       
   535             confId++;
       
   536             hspsServerUtil::AddAttributeNumericL( *node, KConfigurationAttrId, confId );                                    
       
   537             }
       
   538         
       
   539         // Plugin element
       
   540         else if ( name == KPluginElement )
       
   541             {
       
   542             // Check parent element
       
   543             ChspsDomNode* parentNode = node->Parent();
       
   544             const TDesC8& parentName = parentNode->Name();
       
   545             if( parentName == KPluginsElement )
       
   546                 { 
       
   547                 ChspsDomList& attrList = node->AttributeList();
       
   548                 
       
   549                 // Get configuration attribute from the plugin configuration                                                               
       
   550                 ChspsDomAttribute* pluginUidAttr = 
       
   551                     static_cast<ChspsDomAttribute*> ( attrList.FindByName(KPluginAttrUid) );                                                
       
   552                 if( !pluginUidAttr )
       
   553                     {
       
   554 #ifdef HSPS_LOG_ACTIVE  
       
   555                     if( iLogBus )
       
   556                         {
       
   557                         iLogBus->LogText( _L( "ChspsClientRequestHandler::AppendPluginConfigurationsL(): - Invalid XML" ) );
       
   558                         }
       
   559 #endif    
       
   560                     
       
   561                     User::Leave( KErrCorrupt );
       
   562                     }         
       
   563                 
       
   564                 // Convert uids from string to numeric format                                        
       
   565                 const TDesC8& pluginUidValue = pluginUidAttr->Value();                    
       
   566                 const TUid pluginUid = hspsServerUtil::ConvertDescIntoUid(pluginUidValue);
       
   567                                
       
   568                 // Get plugin configuration                                 
       
   569                 ChspsODT* pluginOdt = ChspsODT::NewL();
       
   570                 const TInt interfaceUid = 0; 
       
   571                 CleanupStack::PushL( pluginOdt );
       
   572                 iThemeServer.GetConfigurationL( 
       
   573                     interfaceUid, 
       
   574                     pluginUid.iUid,
       
   575                     *pluginOdt
       
   576                     );                
       
   577                 if ( !pluginOdt || !pluginOdt->ThemeUid() )
       
   578                     {
       
   579 #ifdef HSPS_LOG_ACTIVE  
       
   580                     if( iLogBus )
       
   581                         {
       
   582                         iLogBus->LogText( _L( "ChspsClientRequestHandler::AppendPluginConfigurationsL(): - Failed to find plugin uid %d" ),
       
   583                                 pluginUid.iUid );
       
   584                         }
       
   585 #endif
       
   586     
       
   587                     // Append an empty configuration with error status
       
   588                     AddErrorConfigurationL( 
       
   589                             appDom,
       
   590                             *node,
       
   591                             pluginUid.iUid );
       
   592                     
       
   593                     // Generate an ID attribute for the plugin element
       
   594                     pluginId++;
       
   595                     hspsServerUtil::AddAttributeNumericL( *node, KPluginAttrId, pluginId );                                        
       
   596                     }
       
   597                 else
       
   598                     {                
       
   599                     // Generate an ID attribute for the plugin element
       
   600                     pluginId++;
       
   601                     hspsServerUtil::AddAttributeNumericL( *node, KPluginAttrId, pluginId );
       
   602                                     
       
   603                     // Copy plug-in resources to the application configuration              
       
   604                     TInt resourceCount = pluginOdt->ResourceCount();
       
   605                     for ( TInt index=0; index < resourceCount; index++ )
       
   606                         {                   
       
   607                         ChspsResource* pluginResource = &pluginOdt->ResourceL(index);
       
   608                         
       
   609                         // Add only those that are located under the sources or locales folder
       
   610                         if ( pluginResource->FileName().FindF( KSourcesSubFolder ) > 0
       
   611                             || pluginResource->FileName().FindF( KLocalesSubFolder ) > 0 )
       
   612                             {                                               
       
   613                             ChspsResource* r = pluginResource->CloneL();
       
   614                             CleanupStack::PushL( r );
       
   615                             aAppODT.AddResourceL( r ); 
       
   616                             CleanupStack::Pop( r );
       
   617                             }
       
   618                         }
       
   619                     
       
   620                     ChspsDomDocument& document = pluginOdt->DomDocument();   
       
   621                     if ( !document.RootNode() )
       
   622                         {
       
   623                         User::Leave( KErrGeneral );
       
   624                         }
       
   625                     
       
   626                     // Find the KConfigurationElement to step over any optional xml elements 
       
   627                     ChspsDomDepthIterator* pluginIter = ChspsDomDepthIterator::NewL( *document.RootNode() );
       
   628                     CleanupStack::PushL( pluginIter );                                
       
   629                     ChspsDomNode* pluginNode =  pluginIter->First();                              
       
   630                     TBool steppingtoConfNode(EFalse);                     
       
   631                     while( pluginNode && !steppingtoConfNode )
       
   632                         {
       
   633                         const TDesC8& pluginNodeName = pluginNode->Name();
       
   634                          
       
   635                         if( pluginNodeName == KConfigurationElement )
       
   636                             {
       
   637                             steppingtoConfNode=ETrue;
       
   638                             }
       
   639                         else
       
   640                             {
       
   641                             pluginNode = pluginIter->NextL();
       
   642                             }                 
       
   643                         }
       
   644                     CleanupStack::PopAndDestroy( pluginIter );
       
   645                     
       
   646                     if ( pluginNode )
       
   647                         {
       
   648                         // Copy the plugin configuration to the main document.
       
   649                         ChspsDomNode* rootCopy = pluginNode->CloneL( node->StringPool());
       
   650                         if ( rootCopy )
       
   651                             {
       
   652                             rootCopy->SetParent( node );
       
   653                             node->AddChildL( rootCopy );
       
   654                             }
       
   655                         }
       
   656                     } // !pluginOdt else
       
   657                 
       
   658                 CleanupStack::PopAndDestroy( pluginOdt );
       
   659                 } // KPluginsElement
       
   660             } 
       
   661         prevNode = node;    
       
   662         node = iter->NextL();   
       
   663         }
       
   664     CleanupStack::PopAndDestroy( iter );     
       
   665     
       
   666     }
       
   667 // -----------------------------------------------------------------------------
       
   668 // ChspsClientRequestHandler::AppendInitialSettingsL()
       
   669 // -----------------------------------------------------------------------------
       
   670 //
       
   671 TInt ChspsClientRequestHandler::AppendInitialSettingsL( 
       
   672         ChspsODT& aAppODT )
       
   673     {    
       
   674     ChspsDomDocument& appDom = aAppODT.DomDocument(); 
       
   675     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *appDom.RootNode() );
       
   676     CleanupStack::PushL( iter );
       
   677            
       
   678     TInt error = KErrNone;  
       
   679     
       
   680     ChspsDomNode* prevNode = NULL;
       
   681     ChspsDomNode* parentNode = NULL;
       
   682     ChspsDomNode* node = iter->First();
       
   683     while( node && error == KErrNone  && prevNode != node)
       
   684         {  
       
   685         
       
   686         if( prevNode )
       
   687             {
       
   688             const TDesC8& prevNodeName = prevNode->Name();
       
   689             if( prevNodeName == KInitialSettingsElement )
       
   690                 {
       
   691                 // clean initial_settings
       
   692                 parentNode = prevNode->Parent();
       
   693                 parentNode->ChildNodes().RemoveItem(prevNode);
       
   694                 delete prevNode;
       
   695                 prevNode = NULL;
       
   696                 }
       
   697             }
       
   698             
       
   699         const TDesC8& name = node->Name();
       
   700         
       
   701         // Initial settings
       
   702         if ( name == KInitialSettingsElement )
       
   703             {
       
   704             // Check parent element
       
   705             parentNode = node->Parent();
       
   706             const TDesC8& parentName = parentNode->Name();            
       
   707             if( parentName == KPluginElement )
       
   708                 { 
       
   709                 ChspsDomList& initial_settings_childList = node->ChildNodes();                                              
       
   710                 ChspsDomNode* initialSettingsNode = 
       
   711                         static_cast<ChspsDomNode*>(initial_settings_childList.FindByName( KSettingsElement ));
       
   712                 if( initialSettingsNode )
       
   713                     {
       
   714                         
       
   715                     ChspsDomList& initial_items = initialSettingsNode->ChildNodes();                                    
       
   716                     ChspsDomNode* controlNode = hspsServerUtil::FindNodeByTagL(KControlElement, *parentNode ); 
       
   717                           
       
   718                     if( controlNode )
       
   719                         {
       
   720                         ChspsDomList& controlNode_childList = controlNode->ChildNodes();
       
   721                     
       
   722                         ChspsDomNode* settingsNode = static_cast<ChspsDomNode*>(controlNode_childList.FindByName( KSettingsElement ));
       
   723                     
       
   724                         if( settingsNode )
       
   725                             {
       
   726                             ChspsDomList& items = settingsNode->ChildNodes();
       
   727                                     
       
   728                             if( items.Length() == initial_items.Length() )                    
       
   729                                 {
       
   730                                 TInt index = controlNode->ItemIndex( *settingsNode );
       
   731                                 controlNode->DeleteChild(settingsNode);    
       
   732                                 ChspsDomNode* clone = initialSettingsNode->CloneL( aAppODT.DomDocument().StringPool() );
       
   733                                 CleanupStack::PushL( clone  );
       
   734                                 controlNode->AddChildL( clone, index );
       
   735                                 clone->SetParent( controlNode );             
       
   736                                 CleanupStack::Pop( clone );
       
   737                                 }
       
   738                             else if( items.Length() > initial_items.Length() )
       
   739                                 {
       
   740                                 error = ParseInitialSettingsItemsL(*initialSettingsNode,*settingsNode);        
       
   741                                 }
       
   742                             else
       
   743                                 {
       
   744                                 error = KErrCorrupt;
       
   745                                 }
       
   746                             }
       
   747                         else
       
   748                             {
       
   749                             error = KErrNotFound;
       
   750                             }
       
   751                         }
       
   752                     else
       
   753                         {
       
   754                         error = KErrCorrupt;
       
   755                         }
       
   756                         
       
   757                     // clean settings under initialsettings
       
   758                     node->ChildNodes().RemoveItem( initialSettingsNode );
       
   759                     delete initialSettingsNode;
       
   760                     initialSettingsNode = NULL;                    
       
   761                         
       
   762                     } 
       
   763                 else
       
   764                     {
       
   765                     // initialSettingsNode (KSettingsElement) not found
       
   766                     error = KErrCorrupt;
       
   767                     }
       
   768                    
       
   769                 }                   
       
   770             }
       
   771         
       
   772         prevNode = node;    
       
   773         node = iter->NextL();   
       
   774         }
       
   775     CleanupStack::PopAndDestroy( iter );      
       
   776           
       
   777     return error;
       
   778     
       
   779     }
       
   780  
       
   781 // -----------------------------------------------------------------------------
       
   782 // ChspsClientRequestHandler::ParseInitialSettingsItems
       
   783 // -----------------------------------------------------------------------------
       
   784 //   
       
   785 TInt ChspsClientRequestHandler::ParseInitialSettingsItemsL(ChspsDomNode& aInitialSettingsNode,ChspsDomNode& aSettingsNode)
       
   786     {
       
   787     TInt error(KErrNone);
       
   788     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aInitialSettingsNode );
       
   789     CleanupStack::PushL( iter );
       
   790     
       
   791     ChspsDomNode* sourceNode = iter->First();
       
   792     
       
   793     ChspsDomNode* prevSourceNode = NULL;
       
   794     ChspsDomNode* targetNode = NULL;
       
   795     
       
   796     while( sourceNode && error == KErrNone && sourceNode != prevSourceNode   )
       
   797         {
       
   798         const TDesC8& s_name = sourceNode->Name();
       
   799          
       
   800         if ( s_name == KItemElement )
       
   801             {
       
   802             ChspsDomList& s_attrList = sourceNode->AttributeList();
       
   803                                                                            
       
   804             ChspsDomAttribute* s_itemIdAttr = 
       
   805                           static_cast<ChspsDomAttribute*> ( s_attrList.FindByName(KItemAttrId) ); 
       
   806             if( s_itemIdAttr )
       
   807                 {
       
   808                 targetNode = &( FindRootNodeByIdentifierL( KItemElement, s_itemIdAttr->Value(), aSettingsNode ));
       
   809                 
       
   810                 if( targetNode )
       
   811                     {
       
   812                     if( HandlePropertyNodeL( *sourceNode, *targetNode) != KErrNone )
       
   813                         {
       
   814                         error = KErrNotFound;
       
   815                         }
       
   816                     }
       
   817                 else
       
   818                     {
       
   819                     error = KErrNotFound;
       
   820                     }
       
   821                 }
       
   822             else
       
   823                 {
       
   824                 error = KErrCorrupt;
       
   825                 }
       
   826             }
       
   827         prevSourceNode = sourceNode;    
       
   828         sourceNode = iter->NextL();
       
   829         }
       
   830     
       
   831     CleanupStack::PopAndDestroy( iter );  
       
   832     return error;
       
   833     }
       
   834 
       
   835 // -----------------------------------------------------------------------------
       
   836 // ChspsClientRequestHandler::HandlePropertyNodeL
       
   837 // ----------------------------------------------------------------------------- 
       
   838 TInt ChspsClientRequestHandler::HandlePropertyNodeL( 
       
   839      ChspsDomNode& aSourceItemNode, ChspsDomNode& aTargetItemNode  )
       
   840     {
       
   841    
       
   842    TInt error(KErrNone);
       
   843 
       
   844    TInt propertiesCount = (aSourceItemNode.ChildNodes()).Length();     
       
   845      
       
   846    if ( propertiesCount > 0 )
       
   847        {
       
   848        
       
   849        ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aSourceItemNode );
       
   850        CleanupStack::PushL( iter ); 
       
   851        
       
   852        ChspsDomNode* node = iter->First();
       
   853        ChspsDomNode* prevNode = NULL;
       
   854        
       
   855             // Find items for plugin settings
       
   856        while( node && error == KErrNone && node != prevNode )
       
   857            {
       
   858            const TDesC8& name = node->Name();
       
   859            
       
   860            if ( name == KPropertyElement ) 
       
   861                {
       
   862                ChspsDomList& attrList = node->AttributeList();
       
   863                                                                                           
       
   864                ChspsDomAttribute* nameAttr = static_cast<ChspsDomAttribute*> ( attrList.FindByName(KPropertyAttrName) ); 
       
   865                ChspsDomAttribute* valueAttr = static_cast<ChspsDomAttribute*> ( attrList.FindByName(KPropertyAttrValue) );     
       
   866                
       
   867                if( nameAttr && valueAttr )
       
   868                    {
       
   869                     const TDesC8& propertyName = nameAttr->Value();
       
   870                     const TDesC8& propertyValue = valueAttr->Value();
       
   871                            
       
   872                    error = HandlePropertyAttributesL(propertyName, propertyValue, aTargetItemNode );
       
   873                        
       
   874                    }
       
   875                else
       
   876                    {
       
   877                    error = KErrCorrupt;
       
   878                    }
       
   879                }
       
   880                    
       
   881             prevNode = node;    
       
   882             node = iter->NextL();                 
       
   883             }
       
   884        CleanupStack::PopAndDestroy( iter ); 
       
   885         }
       
   886    else
       
   887        {
       
   888        error=KErrNotFound;
       
   889        }
       
   890         
       
   891     return error;
       
   892    
       
   893     }
       
   894 //-----------------------------------------------------------------------------
       
   895 // ChspsClientRequestHandler::HandlePropertyAttributesL 
       
   896 // -----------------------------------------------------------------------------
       
   897 //
       
   898 TInt ChspsClientRequestHandler::HandlePropertyAttributesL(
       
   899          const TDesC8& aAttrName,
       
   900          const TDesC8& aAttrValue,
       
   901         ChspsDomNode& aNode )
       
   902     {
       
   903    
       
   904    
       
   905     TInt error(KErrNotFound);
       
   906     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aNode );
       
   907     CleanupStack::PushL( iter );                                
       
   908     ChspsDomNode* node = iter->First();                              
       
   909     TBool replaced(EFalse);                     
       
   910     
       
   911     while( node && !replaced )
       
   912         {
       
   913         const TDesC8& nodeName = node->Name();
       
   914         if( nodeName == KPropertyElement )
       
   915             {
       
   916             ChspsDomList& attrList = node->AttributeList();
       
   917             ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( attrList.FindByName(KPropertyAttrName) );     
       
   918             if ( attr )
       
   919                 {
       
   920                 const TDesC8& name = attr->Value(); 
       
   921                 if (aAttrName.Compare( name )== 0 ) 
       
   922                     {
       
   923                     ChspsDomAttribute* attr2 = static_cast<ChspsDomAttribute*>( attrList.FindByName(KPropertyAttrValue) );
       
   924                     if( attr2 )
       
   925                         {
       
   926                         attr2->SetValueL( aAttrValue );
       
   927                         replaced=ETrue;
       
   928                         error = KErrNone;
       
   929                         }
       
   930                     }
       
   931                 }
       
   932             }
       
   933         if( !replaced )
       
   934             {
       
   935             node = iter->NextL();
       
   936             }
       
   937         }
       
   938                 
       
   939     CleanupStack::PopAndDestroy( iter );
       
   940     
       
   941     return error;
       
   942    
       
   943     }  
       
   944 
       
   945 // -----------------------------------------------------------------------------
       
   946 // ChspsClientRequestHandler::FindRootNodeByIdentifierL
       
   947 // -----------------------------------------------------------------------------
       
   948 ChspsDomNode& ChspsClientRequestHandler::FindRootNodeByIdentifierL( 
       
   949         const TDesC8& aNodeTag,
       
   950         const TDesC8& aNodeIdentifier,
       
   951         ChspsDomNode& aNode )
       
   952     {
       
   953     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aNode );
       
   954     CleanupStack::PushL( iter );
       
   955     ChspsDomNode* targetNode( NULL );
       
   956     ChspsDomNode* node = iter->First();
       
   957     TBool found = EFalse;
       
   958     while( !found && node )
       
   959         {
       
   960         const TDesC8& name = node->Name();
       
   961         if ( name.Compare( aNodeTag ) == 0)
       
   962             {
       
   963             ChspsDomList& attrList = node->AttributeList();
       
   964             
       
   965             ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( 
       
   966                                           attrList.FindByName( KItemAttrId ));
       
   967             if( attr )
       
   968                 {                                          
       
   969                 const TDesC8& value = attr->Value();
       
   970                 if( value.CompareF( aNodeIdentifier ) == 0 )
       
   971                     {
       
   972                     found = ETrue;
       
   973                     targetNode = node;
       
   974                     }
       
   975                 }
       
   976             }
       
   977         node = iter->NextL();
       
   978         }   
       
   979     CleanupStack::PopAndDestroy( iter );
       
   980     return *targetNode;
       
   981     }
       
   982 // -----------------------------------------------------------------------------
       
   983 // ChspsClientRequestHandler::ServiceGetOdtUpdateL
       
   984 // Serves hspsRequestClient on hspsGetODTUpdate() service call.
       
   985 // (other items were commented in a header).
       
   986 // -----------------------------------------------------------------------------
       
   987 //
       
   988 void ChspsClientRequestHandler::ServiceGetOdtUpdateL(const RMessage2& aMessage)
       
   989     {
       
   990 #ifdef HSPS_LOG_ACTIVE  
       
   991     if( iLogBus )
       
   992         {
       
   993         iLogBus->LogText( _L( "ChspsClientRequestHandler::ServiceGetOdtUpdateL(): - subscription received." ) );
       
   994         }
       
   995 #endif
       
   996         // only allow one request to be submitted at a time and request must be valid
       
   997    
       
   998     if( iMessagePtr.IsNull() ) 
       
   999         {
       
  1000         iMessagePtr = aMessage;
       
  1001         iRequestMessage = (ThspsServiceRequestMessage)aMessage.Function();     
       
  1002         if ( !iCenRepListener )
       
  1003             {
       
  1004             iCenRepListener = ChspsCenRepListener::NewL( *this, KhspsThemeStatusRepositoryUid );
       
  1005             }
       
  1006         iCenRepListener->Setup( iOdt->RootUid() );
       
  1007         }
       
  1008     else
       
  1009         {
       
  1010         CompleteRequestL(EhspsServiceRequestError, iMessagePtr );
       
  1011         }
       
  1012     }
       
  1013 
       
  1014 
       
  1015 // -----------------------------------------------------------------------------
       
  1016 // ChspsClientRequestHandler::ServiceAccessResourceFileL
       
  1017 // Serves hspsRequestClient on hspsAccessResourceFile() service call.
       
  1018 // Allows synchronic request to be submitted even if there is a asynchronous request outstanding.
       
  1019 // This function should return a file handle to a file in its private area 
       
  1020 // in the parameter fileSubSessionHandle
       
  1021 // (other items were commented in a header).
       
  1022 // -----------------------------------------------------------------------------
       
  1023 //
       
  1024 void ChspsClientRequestHandler::ServiceAccessResourceFileL(const RMessage2& aMessage)
       
  1025     {
       
  1026     // incoming data: TIpcArgs: &iReturnData, aAppUid, &aFileName, &fileSubSessionHandle 
       
  1027     TInt errorCode = KErrNone;
       
  1028     
       
  1029     // Read packaged structure from slot 1
       
  1030     ThspsConfiguration configuration;        
       
  1031     TPckg<ThspsConfiguration> packagedStruct(configuration);    
       
  1032     aMessage.ReadL(1, packagedStruct);
       
  1033         
       
  1034     // Read packaged file name from slot 2
       
  1035     TFileName filename;
       
  1036     RMessagePtr2 messagePtr = aMessage;
       
  1037     aMessage.ReadL( 2, filename, 0 ); //file to open is in param slot 2
       
  1038 #ifdef HSPS_LOG_ACTIVE  
       
  1039     if( iLogBus )
       
  1040         {
       
  1041         iLogBus->LogText( _L( "ChspsClientRequestHandler::ServiceAccessResourceFileL(): - %S" ),
       
  1042                 &filename );
       
  1043         }
       
  1044 #endif
       
  1045     
       
  1046     // file server session and file to share to client
       
  1047     RFile file;
       
  1048     errorCode = iFs.ShareProtected();
       
  1049     errorCode = file.Open(iFs, filename, EFileShareReadersOnly );
       
  1050     CleanupClosePushL( file );
       
  1051     
       
  1052     // transfer the file to the client in parameter 3 of the IPC message
       
  1053     if ( !errorCode )
       
  1054         {
       
  1055         // client takes care of it from now on
       
  1056         errorCode = file.TransferToClient(aMessage,3);
       
  1057         }
       
  1058     else
       
  1059         {
       
  1060         // MARKMOIL 14.1.2006: 
       
  1061 		// Make sure that cache is up to date. This is actually needed in emulator only
       
  1062 		// because of possible manually altered repository content by a user;
       
  1063 		// user has removed a theme or resource. But next try should provide a better result.
       
  1064 #ifdef HSPS_LOG_ACTIVE  
       
  1065         if( iLogBus )
       
  1066             {
       
  1067             iLogBus->LogText( _L( "ChspsClientRequestHandler::ServiceAccessResourceFileL(): - cannnot access file, restoring default.." ) );
       
  1068             }
       
  1069 #endif
       
  1070         
       
  1071 		//RestoreDefaultL( *iOdt ); 
       
  1072 		iThemeServer.UpdateHeaderListCacheL();
       
  1073         }
       
  1074         
       
  1075         CleanupStack::PopAndDestroy( &file ); 
       
  1076         
       
  1077     User::LeaveIfError(errorCode);
       
  1078     }
       
  1079 
       
  1080 // -----------------------------------------------------------------------------
       
  1081 // ChspsClientRequestHandler::SetLogBus
       
  1082 // Set log bus to be used
       
  1083 // -----------------------------------------------------------------------------
       
  1084 //
       
  1085 #ifdef HSPS_LOG_ACTIVE
       
  1086 void ChspsClientRequestHandler::SetLogBus( ChspsLogBus* aLogBus )
       
  1087     {
       
  1088     iLogBus = aLogBus;
       
  1089     }
       
  1090 #endif
       
  1091 
       
  1092 // -----------------------------------------------------------------------------
       
  1093 // ChspsClientRequestHandler::hspsGetODT
       
  1094 // Implements hspsGetODT() API-function of MhspsClientRequestService interface.
       
  1095 // (other items were commented in a header).
       
  1096 // -----------------------------------------------------------------------------
       
  1097 //
       
  1098 ThspsServiceCompletedMessage ChspsClientRequestHandler::hspsGetODT(TInt aAppUid, ChspsODT& aODT)
       
  1099     {
       
  1100     // Get application's active theme from the central repository
       
  1101     TInt themeUid;       
       
  1102     TInt errorCode = iCentralRepository.Get( aAppUid, themeUid );    
       
  1103     if ( !errorCode )
       
  1104         {
       
  1105         // Update ODT: prepare mask for a search
       
  1106         aODT.SetRootUid( aAppUid );
       
  1107         aODT.SetThemeUid( themeUid );
       
  1108         
       
  1109         // Store the active theme uid 
       
  1110         iActiveThemeUid = themeUid;
       
  1111         
       
  1112         if ( iRequestMessage == EhspsGetODT )
       
  1113             {
       
  1114             TRAP(errorCode, CallGetODTPathL( aODT, iODTPath ));
       
  1115             }
       
  1116         else
       
  1117             {
       
  1118             errorCode = KErrGeneral;
       
  1119             }
       
  1120         }
       
  1121     
       
  1122     ThspsServiceCompletedMessage ret = EhspsGetODTFailed; 
       
  1123     if (errorCode)
       
  1124         {
       
  1125         ret = EhspsGetODTFailed;
       
  1126         iResult->iSystemError = errorCode;  
       
  1127         }
       
  1128     else
       
  1129         {
       
  1130         ret = EhspsGetODTSuccess;   
       
  1131         }
       
  1132   return ret;
       
  1133   }
       
  1134 
       
  1135 // -----------------------------------------------------------------------------
       
  1136 // ChspsClientRequestHandler::hspsGetODT
       
  1137 // Implements hspsGetODT(with resource  API-function of MhspsClientRequestService interface.
       
  1138 // (other items were commented in a header).
       
  1139 // -----------------------------------------------------------------------------
       
  1140 //
       
  1141 ThspsServiceCompletedMessage ChspsClientRequestHandler::hspsGetODT(TInt /*aAppUid*/, ChspsODT& /*aODT*/,
       
  1142                                                       CArrayPtrSeg<ChspsResource>& /*aResourceList*/)
       
  1143     {
       
  1144     return EhspsServiceNotSupported;
       
  1145     }
       
  1146 
       
  1147 
       
  1148 // -----------------------------------------------------------------------------
       
  1149 // ChspsClientRequestHandler::hspsGetODTUpdate
       
  1150 // Implements hspsGetODTUpdate() API-function of MhspsClientRequestService interface.
       
  1151 // (other items were commented in a header).
       
  1152 // -----------------------------------------------------------------------------
       
  1153 //
       
  1154 ThspsServiceCompletedMessage ChspsClientRequestHandler::hspsGetODTUpdate()
       
  1155     {
       
  1156     return EhspsServiceNotSupported;
       
  1157     }
       
  1158   
       
  1159 
       
  1160 // -----------------------------------------------------------------------------
       
  1161 // ChspsClientRequestHandler::hspsCancelGetODTUpdate
       
  1162 // Implements hspsCancelGetODTUpdate() API-function of MhspsClientRequestService interface.
       
  1163 // (other items were commented in a header).
       
  1164 // -----------------------------------------------------------------------------
       
  1165 //
       
  1166 ThspsServiceCompletedMessage ChspsClientRequestHandler::hspsCancelGetODTUpdate()
       
  1167     {
       
  1168     ThspsServiceCompletedMessage ret = EhspsServiceRequestCanceled;
       
  1169     iRequestMessage = EhspsCancelGetODTUpdate;
       
  1170     TRAP_IGNORE(CompleteRequestL( ret, iMessagePtr ));
       
  1171     return ret;
       
  1172     }
       
  1173   
       
  1174 // -----------------------------------------------------------------------------
       
  1175 // ChspsClientRequestHandler::hspsAccessResourceFile
       
  1176 // Not supported
       
  1177 // (other items were commented in a header).
       
  1178 // -----------------------------------------------------------------------------
       
  1179 //
       
  1180 ThspsServiceCompletedMessage ChspsClientRequestHandler::hspsAccessResourceFile( 
       
  1181         const TDesC& /*aResourceFileName*/,
       
  1182         const ThspsConfiguration& /*aConfiguration*/,
       
  1183         RFile& /*aFile*/ )
       
  1184     {
       
  1185     return EhspsServiceNotSupported;
       
  1186     }
       
  1187 // -----------------------------------------------------------------------------
       
  1188 // ChspsClientRequestHandler::HandleDefinitionRespositoryEvent()
       
  1189 // Handles events coming from hspsDefinitionRepository.
       
  1190 // (other items were commented in a header).
       
  1191 // -----------------------------------------------------------------------------
       
  1192 //
       
  1193 TBool ChspsClientRequestHandler::HandleDefinitionRespositoryEvent( ThspsRepositoryInfo aRepositoryInfo )
       
  1194     {
       
  1195     TInt errorCode = KErrNone;
       
  1196     TBool status(EFalse);
       
  1197     TRAP( errorCode, status = HandleDefinitionRespositoryEventL( aRepositoryInfo ) );
       
  1198     if( errorCode != KErrNone )
       
  1199         {
       
  1200 #ifdef HSPS_LOG_ACTIVE  
       
  1201         if( iLogBus )
       
  1202             {
       
  1203             iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - Error occured in HandleDefinitionRespositoryEventL" ) );
       
  1204             }
       
  1205 #endif        
       
  1206         }    
       
  1207     return status;    
       
  1208     }    
       
  1209 // -----------------------------------------------------------------------------
       
  1210 // ChspsClientRequestHandler::HandleDefinitionRespositoryEventL()
       
  1211 // Handles events coming from hspsDefinitionRepository.
       
  1212 // (other items were commented in a header).
       
  1213 // -----------------------------------------------------------------------------
       
  1214 //
       
  1215 TBool ChspsClientRequestHandler::HandleDefinitionRespositoryEventL( ThspsRepositoryInfo aRepositoryInfo )
       
  1216     {    
       
  1217     if ( aRepositoryInfo.iEventTime <= iLastSuccessThemeLoadTime )
       
  1218         {
       
  1219         // Do not consume this event because there could
       
  1220         // be some other still waiting for it.
       
  1221         return EFalse;
       
  1222         }
       
  1223 
       
  1224     // Check if event regards currently active configuration. 
       
  1225     TBool affectsActiveConfiguration = EFalse;
       
  1226     if( aRepositoryInfo.iAppUid == iRootUid &&
       
  1227         aRepositoryInfo.iAppConfUid == iActiveThemeUid )
       
  1228         {        
       
  1229         affectsActiveConfiguration = ETrue;
       
  1230         }    
       
  1231     
       
  1232     // Work.
       
  1233     if ( ( aRepositoryInfo.iEventType & EhspsODTUpdated ) &&
       
  1234          affectsActiveConfiguration )
       
  1235         {
       
  1236 #ifdef HSPS_LOG_ACTIVE  
       
  1237         if( iLogBus )
       
  1238             {
       
  1239             iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - theme update occurred." ) );
       
  1240             }
       
  1241 #endif
       
  1242         
       
  1243         if ( !iDefinitionRepository.Locked() )
       
  1244             {
       
  1245             PrepareAndCompleteRequestL( aRepositoryInfo, EhspsGetODTUpdateHot );                
       
  1246             }
       
  1247         }
       
  1248     else if( aRepositoryInfo.iEventType & EhspsODTAdded )
       
  1249         {       
       
  1250         //new plugin installed
       
  1251 #ifdef HSPS_LOG_ACTIVE  
       
  1252         if( iLogBus )
       
  1253             {
       
  1254             iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - theme update occurred." ) );
       
  1255             }
       
  1256 #endif
       
  1257         
       
  1258         if ( !iDefinitionRepository.Locked() )
       
  1259             {
       
  1260             PrepareAndCompleteRequestL( aRepositoryInfo, EhspsAddPluginSuccess );            
       
  1261             }
       
  1262         }        
       
  1263      else if ( ( aRepositoryInfo.iEventType & EhspsSettingsChanged ) &&
       
  1264                affectsActiveConfiguration )
       
  1265         {
       
  1266 #ifdef HSPS_LOG_ACTIVE  
       
  1267         if( iLogBus )
       
  1268             {
       
  1269             iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - theme settings changed occurred." ) );
       
  1270             }
       
  1271 #endif
       
  1272         
       
  1273         if ( !iDefinitionRepository.Locked() )
       
  1274             {
       
  1275             PrepareAndCompleteRequestL( aRepositoryInfo, EhspsSetPluginSettingsSuccess );            
       
  1276             }
       
  1277         }    
       
  1278      else if ( ( aRepositoryInfo.iEventType & EhspsODTModified ) &&
       
  1279                affectsActiveConfiguration )
       
  1280          {
       
  1281 #ifdef HSPS_LOG_ACTIVE  
       
  1282         if( iLogBus )
       
  1283             {
       
  1284             iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - theme settings changed occurred." ) );
       
  1285             }
       
  1286 #endif
       
  1287          
       
  1288          if ( !iDefinitionRepository.Locked() ) 
       
  1289              {
       
  1290              PrepareAndCompleteRequestL( aRepositoryInfo, EhspsGetODTUpdateHot );
       
  1291              }
       
  1292          }
       
  1293      else if ( ( aRepositoryInfo.iEventType & EhspsODTRemoved ) &&
       
  1294                affectsActiveConfiguration )
       
  1295          {
       
  1296 #ifdef HSPS_LOG_ACTIVE  
       
  1297           if( iLogBus )
       
  1298               {
       
  1299               iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - theme settings changed occurred." ) );
       
  1300               }
       
  1301 #endif
       
  1302         
       
  1303           if ( !iDefinitionRepository.Locked() ) 
       
  1304               {
       
  1305               PrepareAndCompleteRequestL( aRepositoryInfo, EhspsRemovePluginSuccess );
       
  1306               }
       
  1307           }
       
  1308      else if ( ( aRepositoryInfo.iEventType & EhspsClean ) &&
       
  1309                affectsActiveConfiguration )
       
  1310          {
       
  1311 #ifdef HSPS_LOG_ACTIVE  
       
  1312           if( iLogBus )
       
  1313               {            
       
  1314               iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - theme settings changed occurred." ) );
       
  1315               }
       
  1316 #endif           
       
  1317           if ( !iDefinitionRepository.Locked() )
       
  1318               {
       
  1319               PrepareAndCompleteRequestL( aRepositoryInfo, EhspsGetODTUpdateHot );
       
  1320               }
       
  1321          }
       
  1322      else if ( ( aRepositoryInfo.iEventType & EhspsPluginActivated ) &&
       
  1323                affectsActiveConfiguration )
       
  1324          {
       
  1325 #ifdef HSPS_LOG_ACTIVE  
       
  1326           if( iLogBus )
       
  1327               {            
       
  1328               iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - plugin active state change occured." ) );
       
  1329               }
       
  1330 #endif           
       
  1331           if ( !iDefinitionRepository.Locked() )
       
  1332               {
       
  1333               PrepareAndCompleteRequestL( aRepositoryInfo, EhspsSetActivePluginSuccess );
       
  1334               }
       
  1335          }
       
  1336      else if ( ( aRepositoryInfo.iEventType & EhspsPluginReplaced ) &&
       
  1337                affectsActiveConfiguration )
       
  1338          {
       
  1339 #ifdef HSPS_LOG_ACTIVE  
       
  1340           if( iLogBus )
       
  1341               {            
       
  1342               iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - plugin replace occured." ) );
       
  1343               }
       
  1344 #endif           
       
  1345           if ( !iDefinitionRepository.Locked() )
       
  1346               {
       
  1347               PrepareAndCompleteRequestL( aRepositoryInfo, EhspsReplacePluginSuccess );
       
  1348               }
       
  1349          }
       
  1350           
       
  1351     // do not consume this event because there could be some other still waiting for it    
       
  1352     return EFalse;
       
  1353     }
       
  1354 
       
  1355 // -----------------------------------------------------------------------------
       
  1356 // ChspsClientRequestHandler::HandleCenRepChangeL()
       
  1357 // Handles events coming from CentralRepository.
       
  1358 // (other items were commented in a header).
       
  1359 // -----------------------------------------------------------------------------
       
  1360 //
       
  1361 void ChspsClientRequestHandler::HandleCenRepChangeL( const TUint32 aId )
       
  1362     {        
       
  1363     // 1. Check if another theme is activated
       
  1364     TInt themeUid(0);
       
  1365     TInt errorCode = iCentralRepository.Get( aId, themeUid );
       
  1366     if ( !errorCode )
       
  1367         {
       
  1368         if ( iActiveThemeUid != themeUid )
       
  1369             {
       
  1370 #ifdef HSPS_LOG_ACTIVE  
       
  1371             if( iLogBus )
       
  1372                 {
       
  1373                 iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleCenRepChangeL(): - theme status change occurred." ) );
       
  1374                 }
       
  1375 #endif
       
  1376             
       
  1377             if ( !iDefinitionRepository.Locked() )
       
  1378                 {
       
  1379                 
       
  1380                 ThspsRepositoryInfo info( 
       
  1381                                    ThspsRepositoryEvent(EhspsODTActivated),
       
  1382                                    aId,
       
  1383                                    themeUid,
       
  1384                                    0,0,0,0,
       
  1385                                    0,0,
       
  1386                                    ETrue,
       
  1387                                    KNullDesC(),
       
  1388                                    ELangTest);  
       
  1389                                     
       
  1390                            
       
  1391                 
       
  1392                 PrepareAndCompleteRequestL( info, EhspsGetODTUpdateStatus );
       
  1393                 
       
  1394                 }
       
  1395             }
       
  1396         }
       
  1397     }
       
  1398     
       
  1399 // -----------------------------------------------------------------------------
       
  1400 // ChspsClientRequestHandler::CompleteRequestL()
       
  1401 // Completes client request. Writes hspsResult data back.
       
  1402 // (other items were commented in a header).
       
  1403 // -----------------------------------------------------------------------------
       
  1404 //  
       
  1405 void ChspsClientRequestHandler::CompleteRequestL(const ThspsServiceCompletedMessage aReturnMessage,
       
  1406                         RMessagePtr2& aMessagePtr, const TDesC8& /*aHeaderData*/ )
       
  1407     {
       
  1408     TInt errorCode = KErrNone;
       
  1409     RDesWriteStream writeBuf( iResultData );
       
  1410     CleanupClosePushL( writeBuf );
       
  1411     TRAP( errorCode, iResult->ExternalizeL( writeBuf ));
       
  1412     CleanupStack::PopAndDestroy();
       
  1413            
       
  1414     if ( !aMessagePtr.IsNull() ) 
       
  1415         {
       
  1416         if ( errorCode )
       
  1417             {
       
  1418             aMessagePtr.WriteL( 0, KNullDesC8, 0 );
       
  1419             }
       
  1420         else
       
  1421             {
       
  1422             aMessagePtr.WriteL( 0, iResultData, 0 );
       
  1423             }
       
  1424         aMessagePtr.Complete( aReturnMessage ); 
       
  1425         } 
       
  1426     }    
       
  1427     
       
  1428 // -----------------------------------------------------------------------------
       
  1429 // ChspsClientRequestHandler::CallGetODTPathL
       
  1430 // Retrieves a file path to the provided ODT instance
       
  1431 // -----------------------------------------------------------------------------
       
  1432 //
       
  1433 void ChspsClientRequestHandler::CallGetODTPathL( ChspsODT& aODT, TDes& aODTPath )
       
  1434     {
       
  1435 #ifdef _hsps_PERFORMANCE_TEST_
       
  1436     TTime start_time;
       
  1437     TBuf<KMaxHeaderDataLength8> tmp;
       
  1438     tmp.Format(
       
  1439         _L("ChspsClientRequestHandler::CallGetODTPathL(): -  getting path for theme %d .."), 
       
  1440         aODT.ThemeUid()
       
  1441         );
       
  1442     start_time = ChspsTimeMon::StartTiming( tmp ); 
       
  1443     ChspsTimeMon::PrintUserMem( _L("SERVER: - ready to get theme path.") );
       
  1444 #endif
       
  1445     
       
  1446     // retrieve specific ODT instance from the header cache
       
  1447     TInt errorCode = iThemeServer.GetConfigurationL( 
       
  1448             aODT.RootUid(), 
       
  1449             aODT.ThemeUid(),
       
  1450             aODT );        
       
  1451     if ( !errorCode )
       
  1452         {
       
  1453         // get path to the ODT file
       
  1454         iDefinitionRepository.GetResourcePathL( aODT, EResourceODT, aODTPath );
       
  1455         iLastSuccessThemeLoadTime.HomeTime();
       
  1456         
       
  1457 #ifdef _hsps_PERFORMANCE_TEST_ 
       
  1458         // calculating service time
       
  1459         tmp.Format(_L("ChspsClientRequestHandler::CallGetODTPathL(): - ODT ready."));      
       
  1460         ChspsTimeMon::StopTiming(start_time, tmp);
       
  1461         ChspsTimeMon::PrintUserMem( _L("SERVER: - theme file path ready.") );
       
  1462 #endif             
       
  1463         }
       
  1464     else
       
  1465         {        
       
  1466         // repository was unlocked but theme could not be found 
       
  1467 #ifdef HSPS_LOG_ACTIVE  
       
  1468         if( iLogBus )
       
  1469             {
       
  1470             iLogBus->LogText( _L( "ChspsClientRequestHandler::CallGetODTPathL(): - theme cannot be accessed." ) );
       
  1471             }
       
  1472 #endif
       
  1473         // default theme must be restored
       
  1474         iRestoreDefault = ETrue;
       
  1475         }    
       
  1476     
       
  1477     User::LeaveIfError( errorCode );
       
  1478     }
       
  1479    
       
  1480 // -----------------------------------------------------------------------------
       
  1481 // ChspsClientRequestHandler::RestoreDefaultL
       
  1482 // Restoring default theme after failed theme load because no active theme found.
       
  1483 // (other items were commented in a header).
       
  1484 // -----------------------------------------------------------------------------
       
  1485 //
       
  1486 void ChspsClientRequestHandler::RestoreDefaultL( ChspsODT& aOdt )
       
  1487     {
       
  1488     TInt errorCode = KErrNone;
       
  1489     ChspsMaintenanceHandler* mh = ChspsMaintenanceHandler::NewL(iThemeServer);
       
  1490     CleanupStack::PushL(mh);
       
  1491     ChspsODT* setmask = ChspsODT::NewL();
       
  1492     CleanupStack::PushL( setmask );
       
  1493     setmask->SetRootUid(iRootUid);
       
  1494     // lets make sure that all themes are in cache
       
  1495 #ifdef HSPS_LOG_ACTIVE  
       
  1496     if( iLogBus )
       
  1497         {
       
  1498         iLogBus->LogText( _L( "ChspsClientRequestHandler::RestoreDefaultL(): - updating cache." ) );
       
  1499         }
       
  1500 #endif
       
  1501     
       
  1502     iThemeServer.UpdateHeaderListCacheL();     
       
  1503     ThspsServiceCompletedMessage ret = mh->hspsRestoreDefault(*setmask, aOdt);
       
  1504     if ( ret == EhspsRestoreDefaultSuccess )
       
  1505         {
       
  1506         // inform for cache update to the repository so that everyone will know 
       
  1507         // about the change
       
  1508         ThspsRepositoryInfo info( EhspsCacheUpdate );
       
  1509         iDefinitionRepository.RegisterNotification( info );
       
  1510 
       
  1511 #ifdef HSPS_LOG_ACTIVE  
       
  1512         if( iLogBus )
       
  1513             {
       
  1514             iLogBus->LogText( _L( "ChspsClientRequestHandler::RestoreDefaultL(): - default theme restored." ) );
       
  1515             }
       
  1516 #endif        
       
  1517         }
       
  1518     else
       
  1519         {
       
  1520 #ifdef HSPS_LOG_ACTIVE  
       
  1521     if( iLogBus )
       
  1522         {
       
  1523         iLogBus->LogText( _L( "ChspsClientRequestHandler::RestoreDefaultL(): - failed." ) );
       
  1524         }
       
  1525 #endif
       
  1526         
       
  1527         errorCode = KErrNotFound;
       
  1528         }
       
  1529     iRestoreDefault = EFalse;
       
  1530     CleanupStack::PopAndDestroy( 2, mh ); 
       
  1531     User::LeaveIfError( errorCode );     
       
  1532     }
       
  1533        
       
  1534 // -----------------------------------------------------------------------------
       
  1535 // ChspsClientRequestHandler::RestoreValidThemeL
       
  1536 // 
       
  1537 // -----------------------------------------------------------------------------
       
  1538 void ChspsClientRequestHandler::RestoreValidThemeL(ChspsODT& aCorruptedOdt)    
       
  1539     {
       
  1540 
       
  1541     // Get current theme
       
  1542     ChspsODT* setmask = ChspsODT::NewL();
       
  1543     CleanupStack::PushL(setmask);
       
  1544     
       
  1545     setmask->SetRootUid( aCorruptedOdt.RootUid() );
       
  1546     setmask->SetThemeUid( aCorruptedOdt.ThemeUid() );
       
  1547 
       
  1548     if (aCorruptedOdt.Flags() & EhspsThemeStatusOperatorDefault)
       
  1549         {
       
  1550          // Need to delete corrupted operator theme to restore licensee default theme
       
  1551         setmask->SetFlags(EhspsThemeStatusClean);    
       
  1552         }
       
  1553 
       
  1554     ChspsODT* restoredOdt = ChspsODT::NewL();
       
  1555     CleanupStack::PushL(restoredOdt);
       
  1556                 
       
  1557     TInt errorCode = KErrNone;
       
  1558     ChspsMaintenanceHandler* mh = ChspsMaintenanceHandler::NewL(iThemeServer);
       
  1559     CleanupStack::PushL(mh);
       
  1560     iThemeServer.UpdateHeaderListCacheL();     
       
  1561     ThspsServiceCompletedMessage ret = mh->hspsRestoreDefault(*setmask, *restoredOdt);
       
  1562     if ( ret == EhspsRestoreDefaultSuccess )
       
  1563         {
       
  1564         // inform for cache update to the repository so that everyone will know 
       
  1565         // about the change
       
  1566         ThspsRepositoryInfo info( EhspsCacheUpdate );
       
  1567         iDefinitionRepository.RegisterNotification( info );
       
  1568         }
       
  1569     else
       
  1570         {
       
  1571         errorCode = KErrNotFound;
       
  1572         }
       
  1573 
       
  1574     iRestoreDefault = EFalse;
       
  1575     CleanupStack::PopAndDestroy( mh ); 
       
  1576     
       
  1577     CleanupStack::PopAndDestroy(restoredOdt);
       
  1578     
       
  1579     CleanupStack::PopAndDestroy(setmask);
       
  1580     
       
  1581     User::LeaveIfError( errorCode );     
       
  1582     }
       
  1583 
       
  1584 
       
  1585 //  End of File  
       
  1586