homescreenpluginsrv/hspsmanager/src/hspsclientrequesthandler.cpp
changeset 0 79c6a41cd166
child 3 ff572005ac23
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:  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                     // Copy the plugin configuration to the main document.
       
   647                     ChspsDomNode* rootCopy = pluginNode->CloneL( node->StringPool());
       
   648                     rootCopy->SetParent( node );
       
   649                     node->AddChildL( rootCopy );                                       
       
   650                     } // !pluginOdt else
       
   651                 
       
   652                 CleanupStack::PopAndDestroy( pluginOdt );
       
   653                 } // KPluginsElement
       
   654             } 
       
   655         prevNode = node;    
       
   656         node = iter->NextL();   
       
   657         }
       
   658     CleanupStack::PopAndDestroy( iter );     
       
   659     
       
   660     }
       
   661 // -----------------------------------------------------------------------------
       
   662 // ChspsClientRequestHandler::AppendInitialSettingsL()
       
   663 // -----------------------------------------------------------------------------
       
   664 //
       
   665 TInt ChspsClientRequestHandler::AppendInitialSettingsL( 
       
   666         ChspsODT& aAppODT )
       
   667     {    
       
   668     ChspsDomDocument& appDom = aAppODT.DomDocument(); 
       
   669     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *appDom.RootNode() );
       
   670     CleanupStack::PushL( iter );
       
   671            
       
   672     TInt error = KErrNone;  
       
   673     
       
   674     ChspsDomNode* prevNode = NULL;
       
   675     ChspsDomNode* parentNode = NULL;
       
   676     ChspsDomNode* node = iter->First();
       
   677     while( node && error == KErrNone  && prevNode != node)
       
   678         {  
       
   679         
       
   680         if( prevNode )
       
   681             {
       
   682             const TDesC8& prevNodeName = prevNode->Name();
       
   683             if( prevNodeName == KInitialSettingsElement )
       
   684                 {
       
   685                 // clean initial_settings
       
   686                 parentNode = prevNode->Parent();
       
   687                 parentNode->ChildNodes().RemoveItem(prevNode);
       
   688                 delete prevNode;
       
   689                 prevNode = NULL;
       
   690                 }
       
   691             }
       
   692             
       
   693         const TDesC8& name = node->Name();
       
   694         
       
   695         // Initial settings
       
   696         if ( name == KInitialSettingsElement )
       
   697             {
       
   698             // Check parent element
       
   699             parentNode = node->Parent();
       
   700             const TDesC8& parentName = parentNode->Name();
       
   701             
       
   702             if( parentName == KPluginElement )
       
   703                 { 
       
   704                 ChspsDomList& initial_settings_childList = node->ChildNodes(); 
       
   705                                              
       
   706                 ChspsDomNode* initialSettingsNode = static_cast<ChspsDomNode*>(initial_settings_childList.FindByName( KSettingsElement ));
       
   707                 
       
   708                 ChspsDomList& initial_items = initialSettingsNode->ChildNodes();
       
   709                                 
       
   710                 ChspsDomNode* controlNode = hspsServerUtil::FindNodeByTagL(KControlElement, *parentNode ); 
       
   711                       
       
   712                 if( controlNode )
       
   713                     {
       
   714                     ChspsDomList& controlNode_childList = controlNode->ChildNodes();
       
   715                 
       
   716                     ChspsDomNode* settingsNode = static_cast<ChspsDomNode*>(controlNode_childList.FindByName( KSettingsElement ));
       
   717                 
       
   718                     if( settingsNode )
       
   719                         {
       
   720                         ChspsDomList& items = settingsNode->ChildNodes();
       
   721                                 
       
   722                         if( items.Length() == initial_items.Length() )                    
       
   723                             {
       
   724                             TInt index = controlNode->ItemIndex( *settingsNode );
       
   725                             controlNode->DeleteChild(settingsNode);    
       
   726                             ChspsDomNode* clone = initialSettingsNode->CloneL( aAppODT.DomDocument().StringPool() );
       
   727                             CleanupStack::PushL( clone  );
       
   728                             controlNode->AddChildL( clone, index );
       
   729                             clone->SetParent( controlNode );             
       
   730                             CleanupStack::Pop( clone );
       
   731                             }
       
   732                         else if( items.Length() > initial_items.Length() )
       
   733                             {
       
   734                             error = ParseInitialSettingsItemsL(*initialSettingsNode,*settingsNode);        
       
   735                             }
       
   736                         else
       
   737                             {
       
   738                             error = KErrCorrupt;
       
   739                             }
       
   740                         }
       
   741                     else
       
   742                         {
       
   743                         error = KErrNotFound;
       
   744                         }
       
   745                     }
       
   746                 else
       
   747                     {
       
   748                     error = KErrCorrupt;
       
   749                     }
       
   750                 // clean settings under initialsettings
       
   751                 node->ChildNodes().RemoveItem( initialSettingsNode );
       
   752                 delete initialSettingsNode;
       
   753                 initialSettingsNode = NULL; 
       
   754                 }
       
   755             }
       
   756         
       
   757         prevNode = node;    
       
   758         node = iter->NextL();   
       
   759         }
       
   760     CleanupStack::PopAndDestroy( iter );      
       
   761           
       
   762     return error;
       
   763     
       
   764     }
       
   765  
       
   766 // -----------------------------------------------------------------------------
       
   767 // ChspsClientRequestHandler::ParseInitialSettingsItems
       
   768 // -----------------------------------------------------------------------------
       
   769 //   
       
   770 TInt ChspsClientRequestHandler::ParseInitialSettingsItemsL(ChspsDomNode& aInitialSettingsNode,ChspsDomNode& aSettingsNode)
       
   771     {
       
   772     TInt error(KErrNone);
       
   773     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aInitialSettingsNode );
       
   774     CleanupStack::PushL( iter );
       
   775     
       
   776     ChspsDomNode* sourceNode = iter->First();
       
   777     
       
   778     ChspsDomNode* prevSourceNode = NULL;
       
   779     ChspsDomNode* targetNode = NULL;
       
   780     
       
   781     while( sourceNode && error == KErrNone && sourceNode != prevSourceNode   )
       
   782         {
       
   783         const TDesC8& s_name = sourceNode->Name();
       
   784          
       
   785         if ( s_name == KItemElement )
       
   786             {
       
   787             ChspsDomList& s_attrList = sourceNode->AttributeList();
       
   788                                                                            
       
   789             ChspsDomAttribute* s_itemIdAttr = 
       
   790                           static_cast<ChspsDomAttribute*> ( s_attrList.FindByName(KItemAttrId) ); 
       
   791             if( s_itemIdAttr )
       
   792                 {
       
   793                 targetNode = &( FindRootNodeByIdentifierL( KItemElement, s_itemIdAttr->Value(), aSettingsNode ));
       
   794                 
       
   795                 if( targetNode )
       
   796                     {
       
   797                     if( HandlePropertyNodeL( *sourceNode, *targetNode) != KErrNone )
       
   798                         {
       
   799                         error = KErrNotFound;
       
   800                         }
       
   801                     }
       
   802                 else
       
   803                     {
       
   804                     error = KErrNotFound;
       
   805                     }
       
   806                 }
       
   807             else
       
   808                 {
       
   809                 error = KErrCorrupt;
       
   810                 }
       
   811             }
       
   812         prevSourceNode = sourceNode;    
       
   813         sourceNode = iter->NextL();
       
   814         }
       
   815     
       
   816     CleanupStack::PopAndDestroy( iter );  
       
   817     return error;
       
   818     }
       
   819 
       
   820 // -----------------------------------------------------------------------------
       
   821 // ChspsClientRequestHandler::HandlePropertyNodeL
       
   822 // ----------------------------------------------------------------------------- 
       
   823 TInt ChspsClientRequestHandler::HandlePropertyNodeL( 
       
   824      ChspsDomNode& aSourceItemNode, ChspsDomNode& aTargetItemNode  )
       
   825     {
       
   826    
       
   827    TInt error(KErrNone);
       
   828 
       
   829    TInt propertiesCount = (aSourceItemNode.ChildNodes()).Length();     
       
   830      
       
   831    if ( propertiesCount > 0 )
       
   832        {
       
   833        
       
   834        ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aSourceItemNode );
       
   835        CleanupStack::PushL( iter ); 
       
   836        
       
   837        ChspsDomNode* node = iter->First();
       
   838        ChspsDomNode* prevNode = NULL;
       
   839        
       
   840             // Find items for plugin settings
       
   841        while( node && error == KErrNone && node != prevNode )
       
   842            {
       
   843            const TDesC8& name = node->Name();
       
   844            
       
   845            if ( name == KPropertyElement ) 
       
   846                {
       
   847                ChspsDomList& attrList = node->AttributeList();
       
   848                                                                                           
       
   849                ChspsDomAttribute* nameAttr = static_cast<ChspsDomAttribute*> ( attrList.FindByName(KPropertyAttrName) ); 
       
   850                ChspsDomAttribute* valueAttr = static_cast<ChspsDomAttribute*> ( attrList.FindByName(KPropertyAttrValue) );     
       
   851                
       
   852                if( nameAttr && valueAttr )
       
   853                    {
       
   854                     const TDesC8& propertyName = nameAttr->Value();
       
   855                     const TDesC8& propertyValue = valueAttr->Value();
       
   856                            
       
   857                    error = HandlePropertyAttributesL(propertyName, propertyValue, aTargetItemNode );
       
   858                        
       
   859                    }
       
   860                else
       
   861                    {
       
   862                    error = KErrCorrupt;
       
   863                    }
       
   864                }
       
   865                    
       
   866             prevNode = node;    
       
   867             node = iter->NextL();                 
       
   868             }
       
   869        CleanupStack::PopAndDestroy( iter ); 
       
   870         }
       
   871    else
       
   872        {
       
   873        error=KErrNotFound;
       
   874        }
       
   875         
       
   876     return error;
       
   877    
       
   878     }
       
   879 //-----------------------------------------------------------------------------
       
   880 // ChspsClientRequestHandler::HandlePropertyAttributesL 
       
   881 // -----------------------------------------------------------------------------
       
   882 //
       
   883 TInt ChspsClientRequestHandler::HandlePropertyAttributesL(
       
   884          const TDesC8& aAttrName,
       
   885          const TDesC8& aAttrValue,
       
   886         ChspsDomNode& aNode )
       
   887     {
       
   888    
       
   889    
       
   890     TInt error(KErrNotFound);
       
   891     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aNode );
       
   892     CleanupStack::PushL( iter );                                
       
   893     ChspsDomNode* node = iter->First();                              
       
   894     TBool replaced(EFalse);                     
       
   895     
       
   896     while( node && !replaced )
       
   897         {
       
   898         const TDesC8& nodeName = node->Name();
       
   899         if( nodeName == KPropertyElement )
       
   900             {
       
   901             ChspsDomList& attrList = node->AttributeList();
       
   902             ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( attrList.FindByName(KPropertyAttrName) );     
       
   903             if ( attr )
       
   904                 {
       
   905                 const TDesC8& name = attr->Value(); 
       
   906                 if (aAttrName.Compare( name )== 0 ) 
       
   907                     {
       
   908                     ChspsDomAttribute* attr2 = static_cast<ChspsDomAttribute*>( attrList.FindByName(KPropertyAttrValue) );
       
   909                     if( attr2 )
       
   910                         {
       
   911                         attr2->SetValueL( aAttrValue );
       
   912                         replaced=ETrue;
       
   913                         error = KErrNone;
       
   914                         }
       
   915                     }
       
   916                 }
       
   917             }
       
   918         if( !replaced )
       
   919             {
       
   920             node = iter->NextL();
       
   921             }
       
   922         }
       
   923                 
       
   924     CleanupStack::PopAndDestroy( iter );
       
   925     
       
   926     return error;
       
   927    
       
   928     }  
       
   929 
       
   930 // -----------------------------------------------------------------------------
       
   931 // ChspsClientRequestHandler::FindRootNodeByIdentifierL
       
   932 // -----------------------------------------------------------------------------
       
   933 ChspsDomNode& ChspsClientRequestHandler::FindRootNodeByIdentifierL( 
       
   934         const TDesC8& aNodeTag,
       
   935         const TDesC8& aNodeIdentifier,
       
   936         ChspsDomNode& aNode )
       
   937     {
       
   938     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aNode );
       
   939     CleanupStack::PushL( iter );
       
   940     ChspsDomNode* targetNode( NULL );
       
   941     ChspsDomNode* node = iter->First();
       
   942     TBool found = EFalse;
       
   943     while( !found && node )
       
   944         {
       
   945         const TDesC8& name = node->Name();
       
   946         if ( name.Compare( aNodeTag ) == 0)
       
   947             {
       
   948             ChspsDomList& attrList = node->AttributeList();
       
   949             
       
   950             ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( 
       
   951                                           attrList.FindByName( KItemAttrId ));
       
   952             const TDesC8& value = attr->Value();
       
   953             if( value.Compare( aNodeIdentifier ) == 0 )
       
   954                 {
       
   955                 found = ETrue;
       
   956                 targetNode = node;
       
   957                 }
       
   958             }
       
   959         node = iter->NextL();
       
   960         }   
       
   961     CleanupStack::PopAndDestroy( iter );
       
   962     return *targetNode;
       
   963     }
       
   964 // -----------------------------------------------------------------------------
       
   965 // ChspsClientRequestHandler::ServiceGetOdtUpdateL
       
   966 // Serves hspsRequestClient on hspsGetODTUpdate() service call.
       
   967 // (other items were commented in a header).
       
   968 // -----------------------------------------------------------------------------
       
   969 //
       
   970 void ChspsClientRequestHandler::ServiceGetOdtUpdateL(const RMessage2& aMessage)
       
   971     {
       
   972 #ifdef HSPS_LOG_ACTIVE  
       
   973     if( iLogBus )
       
   974         {
       
   975         iLogBus->LogText( _L( "ChspsClientRequestHandler::ServiceGetOdtUpdateL(): - subscription received." ) );
       
   976         }
       
   977 #endif
       
   978         // only allow one request to be submitted at a time and request must be valid
       
   979    
       
   980     if( iMessagePtr.IsNull() ) 
       
   981         {
       
   982         iMessagePtr = aMessage;
       
   983         iRequestMessage = (ThspsServiceRequestMessage)aMessage.Function();     
       
   984         if ( !iCenRepListener )
       
   985             {
       
   986             iCenRepListener = ChspsCenRepListener::NewL( *this, KhspsThemeStatusRepositoryUid );
       
   987             }
       
   988         iCenRepListener->Setup( iOdt->RootUid() );
       
   989         }
       
   990     else
       
   991         {
       
   992         CompleteRequestL(EhspsServiceRequestError, iMessagePtr );
       
   993         }
       
   994     }
       
   995 
       
   996 
       
   997 // -----------------------------------------------------------------------------
       
   998 // ChspsClientRequestHandler::ServiceAccessResourceFileL
       
   999 // Serves hspsRequestClient on hspsAccessResourceFile() service call.
       
  1000 // Allows synchronic request to be submitted even if there is a asynchronous request outstanding.
       
  1001 // This function should return a file handle to a file in its private area 
       
  1002 // in the parameter fileSubSessionHandle
       
  1003 // (other items were commented in a header).
       
  1004 // -----------------------------------------------------------------------------
       
  1005 //
       
  1006 void ChspsClientRequestHandler::ServiceAccessResourceFileL(const RMessage2& aMessage)
       
  1007     {
       
  1008     // incoming data: TIpcArgs: &iReturnData, aAppUid, &aFileName, &fileSubSessionHandle 
       
  1009     TInt errorCode = KErrNone;
       
  1010     
       
  1011     // Read packaged structure from slot 1
       
  1012     ThspsConfiguration configuration;        
       
  1013     TPckg<ThspsConfiguration> packagedStruct(configuration);    
       
  1014     aMessage.ReadL(1, packagedStruct);
       
  1015         
       
  1016     // Read packaged file name from slot 2
       
  1017     TFileName filename;
       
  1018     RMessagePtr2 messagePtr = aMessage;
       
  1019     aMessage.ReadL( 2, filename, 0 ); //file to open is in param slot 2
       
  1020 #ifdef HSPS_LOG_ACTIVE  
       
  1021     if( iLogBus )
       
  1022         {
       
  1023         iLogBus->LogText( _L( "ChspsClientRequestHandler::ServiceAccessResourceFileL(): - %S" ),
       
  1024                 &filename );
       
  1025         }
       
  1026 #endif
       
  1027     
       
  1028     // file server session and file to share to client
       
  1029     RFile file;
       
  1030     errorCode = iFs.ShareProtected();
       
  1031     errorCode = file.Open(iFs, filename, EFileShareReadersOnly );
       
  1032     CleanupClosePushL( file );
       
  1033     
       
  1034     // transfer the file to the client in parameter 3 of the IPC message
       
  1035     if ( !errorCode )
       
  1036         {
       
  1037         // client takes care of it from now on
       
  1038         errorCode = file.TransferToClient(aMessage,3);
       
  1039         }
       
  1040     else
       
  1041         {
       
  1042         // MARKMOIL 14.1.2006: 
       
  1043 		// Make sure that cache is up to date. This is actually needed in emulator only
       
  1044 		// because of possible manually altered repository content by a user;
       
  1045 		// user has removed a theme or resource. But next try should provide a better result.
       
  1046 #ifdef HSPS_LOG_ACTIVE  
       
  1047         if( iLogBus )
       
  1048             {
       
  1049             iLogBus->LogText( _L( "ChspsClientRequestHandler::ServiceAccessResourceFileL(): - cannnot access file, restoring default.." ) );
       
  1050             }
       
  1051 #endif
       
  1052         
       
  1053 		//RestoreDefaultL( *iOdt ); 
       
  1054 		iThemeServer.UpdateHeaderListCacheL();
       
  1055         }
       
  1056         
       
  1057         CleanupStack::PopAndDestroy( &file ); 
       
  1058         
       
  1059     User::LeaveIfError(errorCode);
       
  1060     }
       
  1061 
       
  1062 // -----------------------------------------------------------------------------
       
  1063 // ChspsClientRequestHandler::SetLogBus
       
  1064 // Set log bus to be used
       
  1065 // -----------------------------------------------------------------------------
       
  1066 //
       
  1067 #ifdef HSPS_LOG_ACTIVE
       
  1068 void ChspsClientRequestHandler::SetLogBus( ChspsLogBus* aLogBus )
       
  1069     {
       
  1070     iLogBus = aLogBus;
       
  1071     }
       
  1072 #endif
       
  1073 
       
  1074 // -----------------------------------------------------------------------------
       
  1075 // ChspsClientRequestHandler::hspsGetODT
       
  1076 // Implements hspsGetODT() API-function of MhspsClientRequestService interface.
       
  1077 // (other items were commented in a header).
       
  1078 // -----------------------------------------------------------------------------
       
  1079 //
       
  1080 ThspsServiceCompletedMessage ChspsClientRequestHandler::hspsGetODT(TInt aAppUid, ChspsODT& aODT)
       
  1081     {
       
  1082     // Get application's active theme from the central repository
       
  1083     TInt themeUid;       
       
  1084     TInt errorCode = iCentralRepository.Get( aAppUid, themeUid );    
       
  1085     if ( !errorCode )
       
  1086         {
       
  1087         // Update ODT: prepare mask for a search
       
  1088         aODT.SetRootUid( aAppUid );
       
  1089         aODT.SetThemeUid( themeUid );
       
  1090         
       
  1091         // Store the active theme uid 
       
  1092         iActiveThemeUid = themeUid;
       
  1093         
       
  1094         if ( iRequestMessage == EhspsGetODT )
       
  1095             {
       
  1096             TRAP(errorCode, CallGetODTPathL( aODT, iODTPath ));
       
  1097             }
       
  1098         else
       
  1099             {
       
  1100             errorCode = KErrGeneral;
       
  1101             }
       
  1102         }
       
  1103     
       
  1104     ThspsServiceCompletedMessage ret = EhspsGetODTFailed; 
       
  1105     if (errorCode)
       
  1106         {
       
  1107         ret = EhspsGetODTFailed;
       
  1108         iResult->iSystemError = errorCode;  
       
  1109         }
       
  1110     else
       
  1111         {
       
  1112         ret = EhspsGetODTSuccess;   
       
  1113         }
       
  1114   return ret;
       
  1115   }
       
  1116 
       
  1117 // -----------------------------------------------------------------------------
       
  1118 // ChspsClientRequestHandler::hspsGetODT
       
  1119 // Implements hspsGetODT(with resource  API-function of MhspsClientRequestService interface.
       
  1120 // (other items were commented in a header).
       
  1121 // -----------------------------------------------------------------------------
       
  1122 //
       
  1123 ThspsServiceCompletedMessage ChspsClientRequestHandler::hspsGetODT(TInt /*aAppUid*/, ChspsODT& /*aODT*/,
       
  1124                                                       CArrayPtrSeg<ChspsResource>& /*aResourceList*/)
       
  1125     {
       
  1126     return EhspsServiceNotSupported;
       
  1127     }
       
  1128 
       
  1129 
       
  1130 // -----------------------------------------------------------------------------
       
  1131 // ChspsClientRequestHandler::hspsGetODTUpdate
       
  1132 // Implements hspsGetODTUpdate() API-function of MhspsClientRequestService interface.
       
  1133 // (other items were commented in a header).
       
  1134 // -----------------------------------------------------------------------------
       
  1135 //
       
  1136 ThspsServiceCompletedMessage ChspsClientRequestHandler::hspsGetODTUpdate()
       
  1137     {
       
  1138     return EhspsServiceNotSupported;
       
  1139     }
       
  1140   
       
  1141 
       
  1142 // -----------------------------------------------------------------------------
       
  1143 // ChspsClientRequestHandler::hspsCancelGetODTUpdate
       
  1144 // Implements hspsCancelGetODTUpdate() API-function of MhspsClientRequestService interface.
       
  1145 // (other items were commented in a header).
       
  1146 // -----------------------------------------------------------------------------
       
  1147 //
       
  1148 ThspsServiceCompletedMessage ChspsClientRequestHandler::hspsCancelGetODTUpdate()
       
  1149     {
       
  1150     ThspsServiceCompletedMessage ret = EhspsServiceRequestCanceled;
       
  1151     iRequestMessage = EhspsCancelGetODTUpdate;
       
  1152     TRAP_IGNORE(CompleteRequestL( ret, iMessagePtr ));
       
  1153     return ret;
       
  1154     }
       
  1155   
       
  1156 // -----------------------------------------------------------------------------
       
  1157 // ChspsClientRequestHandler::hspsAccessResourceFile
       
  1158 // Not supported
       
  1159 // (other items were commented in a header).
       
  1160 // -----------------------------------------------------------------------------
       
  1161 //
       
  1162 ThspsServiceCompletedMessage ChspsClientRequestHandler::hspsAccessResourceFile( 
       
  1163         const TDesC& /*aResourceFileName*/,
       
  1164         const ThspsConfiguration& /*aConfiguration*/,
       
  1165         RFile& /*aFile*/ )
       
  1166     {
       
  1167     return EhspsServiceNotSupported;
       
  1168     }
       
  1169 // -----------------------------------------------------------------------------
       
  1170 // ChspsClientRequestHandler::HandleDefinitionRespositoryEvent()
       
  1171 // Handles events coming from hspsDefinitionRepository.
       
  1172 // (other items were commented in a header).
       
  1173 // -----------------------------------------------------------------------------
       
  1174 //
       
  1175 TBool ChspsClientRequestHandler::HandleDefinitionRespositoryEvent( ThspsRepositoryInfo aRepositoryInfo )
       
  1176     {
       
  1177     TInt errorCode = KErrNone;
       
  1178     TBool status(EFalse);
       
  1179     TRAP( errorCode, status = HandleDefinitionRespositoryEventL( aRepositoryInfo ) );
       
  1180     if( errorCode != KErrNone )
       
  1181         {
       
  1182 #ifdef HSPS_LOG_ACTIVE  
       
  1183         if( iLogBus )
       
  1184             {
       
  1185             iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - Error occured in HandleDefinitionRespositoryEventL" ) );
       
  1186             }
       
  1187 #endif        
       
  1188         }    
       
  1189     return status;    
       
  1190     }    
       
  1191 // -----------------------------------------------------------------------------
       
  1192 // ChspsClientRequestHandler::HandleDefinitionRespositoryEventL()
       
  1193 // Handles events coming from hspsDefinitionRepository.
       
  1194 // (other items were commented in a header).
       
  1195 // -----------------------------------------------------------------------------
       
  1196 //
       
  1197 TBool ChspsClientRequestHandler::HandleDefinitionRespositoryEventL( ThspsRepositoryInfo aRepositoryInfo )
       
  1198     {    
       
  1199     if ( aRepositoryInfo.iEventTime <= iLastSuccessThemeLoadTime )
       
  1200         {
       
  1201         // Do not consume this event because there could
       
  1202         // be some other still waiting for it.
       
  1203         return EFalse;
       
  1204         }
       
  1205 
       
  1206     // Check if event regards currently active configuration. 
       
  1207     TBool affectsActiveConfiguration = EFalse;
       
  1208     if( aRepositoryInfo.iAppUid == iRootUid &&
       
  1209         aRepositoryInfo.iAppConfUid == iActiveThemeUid )
       
  1210         {        
       
  1211         affectsActiveConfiguration = ETrue;
       
  1212         }    
       
  1213     
       
  1214     // Work.
       
  1215     if ( ( aRepositoryInfo.iEventType & EhspsODTUpdated ) &&
       
  1216          affectsActiveConfiguration )
       
  1217         {
       
  1218 #ifdef HSPS_LOG_ACTIVE  
       
  1219         if( iLogBus )
       
  1220             {
       
  1221             iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - theme update occurred." ) );
       
  1222             }
       
  1223 #endif
       
  1224         
       
  1225         if ( !iDefinitionRepository.Locked() )
       
  1226             {
       
  1227             PrepareAndCompleteRequestL( aRepositoryInfo, EhspsGetODTUpdateHot );                
       
  1228             }
       
  1229         }
       
  1230     else if( aRepositoryInfo.iEventType & EhspsODTAdded )
       
  1231         {       
       
  1232         //new plugin installed
       
  1233 #ifdef HSPS_LOG_ACTIVE  
       
  1234         if( iLogBus )
       
  1235             {
       
  1236             iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - theme update occurred." ) );
       
  1237             }
       
  1238 #endif
       
  1239         
       
  1240         if ( !iDefinitionRepository.Locked() )
       
  1241             {
       
  1242             PrepareAndCompleteRequestL( aRepositoryInfo, EhspsAddPluginSuccess );            
       
  1243             }
       
  1244         }        
       
  1245      else if ( ( aRepositoryInfo.iEventType & EhspsSettingsChanged ) &&
       
  1246                affectsActiveConfiguration )
       
  1247         {
       
  1248 #ifdef HSPS_LOG_ACTIVE  
       
  1249         if( iLogBus )
       
  1250             {
       
  1251             iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - theme settings changed occurred." ) );
       
  1252             }
       
  1253 #endif
       
  1254         
       
  1255         if ( !iDefinitionRepository.Locked() )
       
  1256             {
       
  1257             PrepareAndCompleteRequestL( aRepositoryInfo, EhspsSetPluginSettingsSuccess );            
       
  1258             }
       
  1259         }    
       
  1260      else if ( ( aRepositoryInfo.iEventType & EhspsODTModified ) &&
       
  1261                affectsActiveConfiguration )
       
  1262          {
       
  1263 #ifdef HSPS_LOG_ACTIVE  
       
  1264         if( iLogBus )
       
  1265             {
       
  1266             iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - theme settings changed occurred." ) );
       
  1267             }
       
  1268 #endif
       
  1269          
       
  1270          if ( !iDefinitionRepository.Locked() ) 
       
  1271              {
       
  1272              PrepareAndCompleteRequestL( aRepositoryInfo, EhspsGetODTUpdateHot );
       
  1273              }
       
  1274          }
       
  1275      else if ( ( aRepositoryInfo.iEventType & EhspsODTRemoved ) &&
       
  1276                affectsActiveConfiguration )
       
  1277          {
       
  1278 #ifdef HSPS_LOG_ACTIVE  
       
  1279           if( iLogBus )
       
  1280               {
       
  1281               iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - theme settings changed occurred." ) );
       
  1282               }
       
  1283 #endif
       
  1284         
       
  1285           if ( !iDefinitionRepository.Locked() ) 
       
  1286               {
       
  1287               PrepareAndCompleteRequestL( aRepositoryInfo, EhspsRemovePluginSuccess );
       
  1288               }
       
  1289           }
       
  1290      else if ( ( aRepositoryInfo.iEventType & EhspsClean ) &&
       
  1291                affectsActiveConfiguration )
       
  1292          {
       
  1293 #ifdef HSPS_LOG_ACTIVE  
       
  1294           if( iLogBus )
       
  1295               {            
       
  1296               iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - theme settings changed occurred." ) );
       
  1297               }
       
  1298 #endif           
       
  1299           if ( !iDefinitionRepository.Locked() )
       
  1300               {
       
  1301               PrepareAndCompleteRequestL( aRepositoryInfo, EhspsGetODTUpdateHot );
       
  1302               }
       
  1303          }
       
  1304      else if ( ( aRepositoryInfo.iEventType & EhspsPluginActivated ) &&
       
  1305                affectsActiveConfiguration )
       
  1306          {
       
  1307 #ifdef HSPS_LOG_ACTIVE  
       
  1308           if( iLogBus )
       
  1309               {            
       
  1310               iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - plugin active state change occured." ) );
       
  1311               }
       
  1312 #endif           
       
  1313           if ( !iDefinitionRepository.Locked() )
       
  1314               {
       
  1315               PrepareAndCompleteRequestL( aRepositoryInfo, EhspsSetActivePluginSuccess );
       
  1316               }
       
  1317          }
       
  1318      else if ( ( aRepositoryInfo.iEventType & EhspsPluginReplaced ) &&
       
  1319                affectsActiveConfiguration )
       
  1320          {
       
  1321 #ifdef HSPS_LOG_ACTIVE  
       
  1322           if( iLogBus )
       
  1323               {            
       
  1324               iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleDefinitionRespositoryEvent(): - plugin replace occured." ) );
       
  1325               }
       
  1326 #endif           
       
  1327           if ( !iDefinitionRepository.Locked() )
       
  1328               {
       
  1329               PrepareAndCompleteRequestL( aRepositoryInfo, EhspsReplacePluginSuccess );
       
  1330               }
       
  1331          }
       
  1332           
       
  1333     // do not consume this event because there could be some other still waiting for it    
       
  1334     return EFalse;
       
  1335     }
       
  1336 
       
  1337 // -----------------------------------------------------------------------------
       
  1338 // ChspsClientRequestHandler::HandleCenRepChangeL()
       
  1339 // Handles events coming from CentralRepository.
       
  1340 // (other items were commented in a header).
       
  1341 // -----------------------------------------------------------------------------
       
  1342 //
       
  1343 void ChspsClientRequestHandler::HandleCenRepChangeL( const TUint32 aId )
       
  1344     {        
       
  1345     // 1. Check if another theme is activated
       
  1346     TInt themeUid(0);
       
  1347     TInt errorCode = iCentralRepository.Get( aId, themeUid );
       
  1348     if ( !errorCode )
       
  1349         {
       
  1350         if ( iActiveThemeUid != themeUid )
       
  1351             {
       
  1352 #ifdef HSPS_LOG_ACTIVE  
       
  1353             if( iLogBus )
       
  1354                 {
       
  1355                 iLogBus->LogText( _L( "ChspsClientRequestHandler::HandleCenRepChangeL(): - theme status change occurred." ) );
       
  1356                 }
       
  1357 #endif
       
  1358             
       
  1359             if ( !iDefinitionRepository.Locked() )
       
  1360                 {
       
  1361                 
       
  1362                 ThspsRepositoryInfo info( 
       
  1363                                    ThspsRepositoryEvent(EhspsODTActivated),
       
  1364                                    aId,
       
  1365                                    themeUid,
       
  1366                                    0,0,0,0,
       
  1367                                    0,0,
       
  1368                                    ETrue,
       
  1369                                    KNullDesC(),
       
  1370                                    ELangTest);  
       
  1371                                     
       
  1372                            
       
  1373                 
       
  1374                 PrepareAndCompleteRequestL( info, EhspsGetODTUpdateStatus );
       
  1375                 
       
  1376                 }
       
  1377             }
       
  1378         }
       
  1379     }
       
  1380     
       
  1381 // -----------------------------------------------------------------------------
       
  1382 // ChspsClientRequestHandler::CompleteRequestL()
       
  1383 // Completes client request. Writes hspsResult data back.
       
  1384 // (other items were commented in a header).
       
  1385 // -----------------------------------------------------------------------------
       
  1386 //  
       
  1387 void ChspsClientRequestHandler::CompleteRequestL(const ThspsServiceCompletedMessage aReturnMessage,
       
  1388                         RMessagePtr2& aMessagePtr, const TDesC8& /*aHeaderData*/ )
       
  1389     {
       
  1390     TInt errorCode = KErrNone;
       
  1391     RDesWriteStream writeBuf( iResultData );
       
  1392     CleanupClosePushL( writeBuf );
       
  1393     TRAP( errorCode, iResult->ExternalizeL( writeBuf ));
       
  1394     CleanupStack::PopAndDestroy();
       
  1395            
       
  1396     if ( !aMessagePtr.IsNull() ) 
       
  1397         {
       
  1398         if ( errorCode )
       
  1399             {
       
  1400             aMessagePtr.WriteL( 0, KNullDesC8, 0 );
       
  1401             }
       
  1402         else
       
  1403             {
       
  1404             aMessagePtr.WriteL( 0, iResultData, 0 );
       
  1405             }
       
  1406         aMessagePtr.Complete( aReturnMessage ); 
       
  1407         } 
       
  1408     }    
       
  1409     
       
  1410 // -----------------------------------------------------------------------------
       
  1411 // ChspsClientRequestHandler::CallGetODTPathL
       
  1412 // Retrieves a file path to the provided ODT instance
       
  1413 // -----------------------------------------------------------------------------
       
  1414 //
       
  1415 void ChspsClientRequestHandler::CallGetODTPathL( ChspsODT& aODT, TDes& aODTPath )
       
  1416     {
       
  1417 #ifdef _hsps_PERFORMANCE_TEST_
       
  1418     TTime start_time;
       
  1419     TBuf<KMaxHeaderDataLength8> tmp;
       
  1420     tmp.Format(
       
  1421         _L("ChspsClientRequestHandler::CallGetODTPathL(): -  getting path for theme %d .."), 
       
  1422         aODT.ThemeUid()
       
  1423         );
       
  1424     start_time = ChspsTimeMon::StartTiming( tmp ); 
       
  1425     ChspsTimeMon::PrintUserMem( _L("SERVER: - ready to get theme path.") );
       
  1426 #endif
       
  1427     
       
  1428     // retrieve specific ODT instance from the header cache
       
  1429     TInt errorCode = iThemeServer.GetConfigurationL( 
       
  1430             aODT.RootUid(), 
       
  1431             aODT.ThemeUid(),
       
  1432             aODT );        
       
  1433     if ( !errorCode )
       
  1434         {
       
  1435         // get path to the ODT file
       
  1436         iDefinitionRepository.GetResourcePathL( aODT, EResourceODT, aODTPath );
       
  1437         iLastSuccessThemeLoadTime.HomeTime();
       
  1438         
       
  1439 #ifdef _hsps_PERFORMANCE_TEST_ 
       
  1440         // calculating service time
       
  1441         tmp.Format(_L("ChspsClientRequestHandler::CallGetODTPathL(): - ODT ready."));      
       
  1442         ChspsTimeMon::StopTiming(start_time, tmp);
       
  1443         ChspsTimeMon::PrintUserMem( _L("SERVER: - theme file path ready.") );
       
  1444 #endif             
       
  1445         }
       
  1446     else
       
  1447         {        
       
  1448         // repository was unlocked but theme could not be found 
       
  1449 #ifdef HSPS_LOG_ACTIVE  
       
  1450         if( iLogBus )
       
  1451             {
       
  1452             iLogBus->LogText( _L( "ChspsClientRequestHandler::CallGetODTPathL(): - theme cannot be accessed." ) );
       
  1453             }
       
  1454 #endif
       
  1455         // default theme must be restored
       
  1456         iRestoreDefault = ETrue;
       
  1457         }    
       
  1458     
       
  1459     User::LeaveIfError( errorCode );
       
  1460     }
       
  1461    
       
  1462 // -----------------------------------------------------------------------------
       
  1463 // ChspsClientRequestHandler::RestoreDefaultL
       
  1464 // Restoring default theme after failed theme load because no active theme found.
       
  1465 // (other items were commented in a header).
       
  1466 // -----------------------------------------------------------------------------
       
  1467 //
       
  1468 void ChspsClientRequestHandler::RestoreDefaultL( ChspsODT& aOdt )
       
  1469     {
       
  1470     TInt errorCode = KErrNone;
       
  1471     ChspsMaintenanceHandler* mh = ChspsMaintenanceHandler::NewL(iThemeServer);
       
  1472     CleanupStack::PushL(mh);
       
  1473     ChspsODT* setmask = ChspsODT::NewL();
       
  1474     CleanupStack::PushL( setmask );
       
  1475     setmask->SetRootUid(iRootUid);
       
  1476     // lets make sure that all themes are in cache
       
  1477 #ifdef HSPS_LOG_ACTIVE  
       
  1478     if( iLogBus )
       
  1479         {
       
  1480         iLogBus->LogText( _L( "ChspsClientRequestHandler::RestoreDefaultL(): - updating cache." ) );
       
  1481         }
       
  1482 #endif
       
  1483     
       
  1484     iThemeServer.UpdateHeaderListCacheL();     
       
  1485     ThspsServiceCompletedMessage ret = mh->hspsRestoreDefault(*setmask, aOdt);
       
  1486     if ( ret == EhspsRestoreDefaultSuccess )
       
  1487         {
       
  1488         // inform for cache update to the repository so that everyone will know 
       
  1489         // about the change
       
  1490         ThspsRepositoryInfo info( EhspsCacheUpdate );
       
  1491         iDefinitionRepository.RegisterNotification( info );
       
  1492 
       
  1493 #ifdef HSPS_LOG_ACTIVE  
       
  1494         if( iLogBus )
       
  1495             {
       
  1496             iLogBus->LogText( _L( "ChspsClientRequestHandler::RestoreDefaultL(): - default theme restored." ) );
       
  1497             }
       
  1498 #endif        
       
  1499         }
       
  1500     else
       
  1501         {
       
  1502 #ifdef HSPS_LOG_ACTIVE  
       
  1503     if( iLogBus )
       
  1504         {
       
  1505         iLogBus->LogText( _L( "ChspsClientRequestHandler::RestoreDefaultL(): - failed." ) );
       
  1506         }
       
  1507 #endif
       
  1508         
       
  1509         errorCode = KErrNotFound;
       
  1510         }
       
  1511     iRestoreDefault = EFalse;
       
  1512     CleanupStack::PopAndDestroy( 2, mh ); 
       
  1513     User::LeaveIfError( errorCode );     
       
  1514     }
       
  1515        
       
  1516 // -----------------------------------------------------------------------------
       
  1517 // ChspsClientRequestHandler::RestoreValidThemeL
       
  1518 // 
       
  1519 // -----------------------------------------------------------------------------
       
  1520 void ChspsClientRequestHandler::RestoreValidThemeL(ChspsODT& aCorruptedOdt)    
       
  1521     {
       
  1522 
       
  1523     // Get current theme
       
  1524     ChspsODT* setmask = ChspsODT::NewL();
       
  1525     CleanupStack::PushL(setmask);
       
  1526     
       
  1527     setmask->SetRootUid( aCorruptedOdt.RootUid() );
       
  1528     setmask->SetThemeUid( aCorruptedOdt.ThemeUid() );
       
  1529 
       
  1530     if (aCorruptedOdt.Flags() & EhspsThemeStatusOperatorDefault)
       
  1531         {
       
  1532          // Need to delete corrupted operator theme to restore licensee default theme
       
  1533         setmask->SetFlags(EhspsThemeStatusClean);    
       
  1534         }
       
  1535 
       
  1536     ChspsODT* restoredOdt = ChspsODT::NewL();
       
  1537     CleanupStack::PushL(restoredOdt);
       
  1538                 
       
  1539     TInt errorCode = KErrNone;
       
  1540     ChspsMaintenanceHandler* mh = ChspsMaintenanceHandler::NewL(iThemeServer);
       
  1541     CleanupStack::PushL(mh);
       
  1542     iThemeServer.UpdateHeaderListCacheL();     
       
  1543     ThspsServiceCompletedMessage ret = mh->hspsRestoreDefault(*setmask, *restoredOdt);
       
  1544     if ( ret == EhspsRestoreDefaultSuccess )
       
  1545         {
       
  1546         // inform for cache update to the repository so that everyone will know 
       
  1547         // about the change
       
  1548         ThspsRepositoryInfo info( EhspsCacheUpdate );
       
  1549         iDefinitionRepository.RegisterNotification( info );
       
  1550         }
       
  1551     else
       
  1552         {
       
  1553         errorCode = KErrNotFound;
       
  1554         }
       
  1555 
       
  1556     iRestoreDefault = EFalse;
       
  1557     CleanupStack::PopAndDestroy( mh ); 
       
  1558     
       
  1559     CleanupStack::PopAndDestroy(restoredOdt);
       
  1560     
       
  1561     CleanupStack::PopAndDestroy(setmask);
       
  1562     
       
  1563     User::LeaveIfError( errorCode );     
       
  1564     }
       
  1565 
       
  1566 
       
  1567 //  End of File  
       
  1568