contextframework/cfw/inc/cfscriptengine/CFScriptHandler.h
changeset 0 2e3d3ce01487
child 4 0fdb7f6b0309
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2002-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:  CCFScriptHandler class declaration.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CFSCRIPTHANDLER_H
       
    20 #define C_CFSCRIPTHANDLER_H
       
    21 
       
    22 #include <f32file.h>
       
    23 #include <badesca.h>
       
    24 #include <GMXMLParser.h>
       
    25 
       
    26 #include "CFScriptEngineInterface.h"
       
    27 #include "cfstarterobserver.h"
       
    28 #include "CFSecurityChecker.h"
       
    29 #include "cfstateobserver.h"
       
    30 #include "cfscriptinfo.h"
       
    31 #include "cfstartereventhandler.h"
       
    32 
       
    33 class MCFActionHandler;
       
    34 class MCFExtendedContextInterface;
       
    35 class CCFScript;
       
    36 class CCFOperationPluginManager;
       
    37 
       
    38 /**
       
    39  * ScriptHandler implementing the main public interface for ScriptEngine
       
    40  * functionality.
       
    41  *
       
    42  * @lib CFScriptEngine
       
    43  * @since Series 60 2.6
       
    44  */
       
    45 NONSHARABLE_CLASS( CCFScriptHandler ):
       
    46 public CBase,
       
    47 public MCFScriptEngineInterface,
       
    48 public MCFStarterObserver,
       
    49 public MMDXMLParserObserver,
       
    50 public MMDXMLParserDataProvider,
       
    51 public MCFStateObserver
       
    52     {
       
    53 public: // Constructors and destructor
       
    54 
       
    55     IMPORT_C static CCFScriptHandler* NewL(
       
    56         MCFExtendedContextInterface& aCF,
       
    57         RFs& aFs,
       
    58         MCFActionHandler& aScriptEventListener,
       
    59         MCFSecurityChecker& aSecurityChecker );
       
    60     IMPORT_C static CCFScriptHandler* NewLC(
       
    61         MCFExtendedContextInterface& aCF,
       
    62         RFs& aFs,
       
    63         MCFActionHandler& aScriptEventListener,
       
    64         MCFSecurityChecker& aSecurityChecker );
       
    65 
       
    66     IMPORT_C ~CCFScriptHandler();
       
    67 
       
    68 public: // From base classes
       
    69 
       
    70     // @see MCFScriptEngineInterface
       
    71     TInt RemoveScriptById( TInt aScriptId, const RThread& aOwner );
       
    72 
       
    73     // @see MCFScriptEngineInterface
       
    74     TInt RemoveScriptsBySession( const MCFActionHandler& aSession );
       
    75 
       
    76     // @see MCFScriptEngineInterface
       
    77     TInt RemoveScriptByName( const TDesC& aScriptName,
       
    78         const TUid& aOwnerUid );
       
    79 
       
    80     // @see MCFScriptEngineInterface
       
    81     TInt RemoveScriptByUid( const TUid& aUid );
       
    82 
       
    83     // @see MCFScriptEngineInterface
       
    84     TInt AddScript( const TDesC& aName,
       
    85         const TDesC8& aScript,
       
    86         const TUid& aOwner,
       
    87         const RThread& aOwnerThread,
       
    88         MCFActionHandler& aActionHandler,
       
    89         MCFScriptOwner* aScriptOwner );
       
    90 
       
    91     // @see MCFScriptEngineInterface
       
    92     TInt NumberOfScriptsByOwner( const TUid& aOwner );
       
    93 
       
    94     // @see MCFScriptEngineInterface
       
    95     TInt NumberOfScripts();
       
    96 
       
    97     // @see MCFScriptEngineInterface
       
    98     TInt ScriptLength( TInt aScriptId );
       
    99 
       
   100     // @see MCFScriptEngineInterface
       
   101     const RArray<TInt>& GetEveryScriptId();
       
   102 
       
   103     // @see MCFScriptEngineInterface
       
   104     const RArray<TInt>& GetEveryScriptIdByOwner(
       
   105         const TUid& aScriptOwner );
       
   106 
       
   107     // @see MCFScriptEngineInterface
       
   108     TInt UpdateScript( TInt aScriptID,
       
   109         const RThread& aOwnerThread,
       
   110         const TDesC8& aUpdatedScript,
       
   111         MCFScriptOwner* aScriptOwner );
       
   112 
       
   113     // @see MCFScriptEngineInterface
       
   114     TInt SaveScript( const TDesC8& aScript, TInt aScriptId,
       
   115         const TUid& aOwnerUid );
       
   116 
       
   117     // @see MCFScriptEngineInterface
       
   118     TInt DeleteScriptByName( const TDesC& aScriptName,
       
   119         const TUid& aOwnerUid );
       
   120 
       
   121     // @see MCFScriptEngineInterface
       
   122     TInt DeleteScriptByUid( const TUid& aUid );
       
   123 
       
   124     // @see MCFScriptEngineInterface
       
   125     TBool AlreadyExists( const TDesC& aScriptName,
       
   126         const TUid& aOwnerUid,
       
   127         TInt& aScriptId ) const;
       
   128 
       
   129     // @see MCFScriptEngineInterface
       
   130     void CleanupPersistentDataByName( const TDesC& aScriptName,
       
   131         const TUid& aOwnerUid );
       
   132 
       
   133     // @see MCFScriptEngineInterface
       
   134     void CleanupPersistentDataByUid( const TUid& aOwnerUid );
       
   135 
       
   136     // @see MCFScriptEngineInterface
       
   137     TInt RestoreRomScript( TInt aScriptId, const TUid& aOwnerUid,
       
   138         const RThread& aClient );
       
   139 
       
   140     // @see MCFScriptEngineInterface
       
   141     TInt IsUpgradeAllowed( const TDesC& aName,
       
   142         const TDesC8& aScript,
       
   143         const TUid& aOwner,
       
   144         const RThread& aOwnerThread,
       
   145         MCFActionHandler& aActionHandler );
       
   146         
       
   147     // @see MCFScriptEngineInterface
       
   148     TInt RemoveScriptByProviderUid( const TUid& aProviderUid, TBool aRollback );
       
   149     
       
   150     // @see MCFScriptEngineInterface
       
   151     void RollbackScripts();
       
   152     
       
   153     // @see MCFScriptEngineInterface
       
   154     void DeregisterScriptOwner( MCFScriptOwner* aScriptOwner );
       
   155 
       
   156     // @see MCFStarterObserver
       
   157     void InitializePhaseL( CCFPhaseBase::TCFPhaseId aPhaseId );
       
   158 
       
   159     // @see MMDXMLParserObserver
       
   160     void ParseFileCompleteL();
       
   161 
       
   162     // @see MMDXMLParserDataProvider
       
   163     void GetData( TPtrC8& aPtr, TRequestStatus& aStatus );
       
   164 
       
   165     // @see MMDXMLParserDataProvider
       
   166     void Disconnect();
       
   167 
       
   168     // from MCFStateObserver
       
   169     void UpdatePlugInsL();
       
   170 
       
   171         // @see MCFStarterObserver
       
   172         void SetEventHandler( MCFStarterEventHandler& /*aEventHandler*/ );
       
   173 
       
   174 private:
       
   175 
       
   176     CCFScriptHandler( MCFExtendedContextInterface& aCF,
       
   177         RFs& aFs,
       
   178         MCFActionHandler& aScriptEventListener,
       
   179         MCFSecurityChecker& aSecurityChecker );
       
   180     void ConstructL();
       
   181 
       
   182 private: // New functions
       
   183 
       
   184     /**
       
   185      * This method does actual adding to file store and calls
       
   186      * AddScriptToArrayL
       
   187      * to add script to internal array. It may leave.
       
   188      * @since Series 60 2.6
       
   189      * @param aName is script's name, filename or client thread's secure id.
       
   190      * @param aScript is a new script to be added.
       
   191      * @param aOwner is the owner's unique Uid.
       
   192      * @param aOwnerThread Thread of the owner process.
       
   193      * @param aActionHandler Action handler.
       
   194      * @param aDoSecurityCheck Defines if a security check is needed.
       
   195      * @param aScriptId If set then this same script id is given to the script.
       
   196      * @return script Id given to the script by the handler.
       
   197      * 	Returned value is > 0, otherwise error occurred.
       
   198      */
       
   199     TInt AddScriptL( const TDesC& aName,
       
   200         const TDesC8& aScript,
       
   201         const TUid& aOwner,
       
   202         const RThread& aOwnerThread,
       
   203         MCFActionHandler& aActionHandler,
       
   204         TBool aDoSecurityCheck,
       
   205         MCFScriptOwner* aScriptOwner,
       
   206         TInt aScriptId = KErrNotFound );
       
   207 
       
   208     // Initilizes device starting phase
       
   209     void InitDeviceStartingPhaseL();
       
   210 
       
   211     // Initializes device started phase
       
   212     void InitDeviceStartedPhaseL();
       
   213 
       
   214     // Complete file path
       
   215     void CompleteFilePath( TDes& aFileName );
       
   216 
       
   217     // Loads script from file
       
   218     HBufC8* LoadScriptFromFile( const TDesC& aFilePath );
       
   219 
       
   220     // Get scripts by Uid
       
   221     void GetScriptsByUid( const TUid& aUid,
       
   222         RPointerArray<CCFScript>& aArray ) const;
       
   223 
       
   224     // Create a ram file path for a script
       
   225     HBufC* ScriptFilePath( CCFScriptInfo& aInfo ) const;
       
   226 
       
   227     // Create a ram file path for a script
       
   228     HBufC* ScriptFilePath( const TDesC& aName, const TUid& aOwnerUid ) const;
       
   229 
       
   230     // Create a ram file path for a script
       
   231     void ScriptFilePath( CCFScriptInfo& aInfo, TDes& aFile ) const;
       
   232 
       
   233     // Saves a script
       
   234     TInt DoSave( const TDesC& aFileName, const TDesC8& aScript );
       
   235     
       
   236     // Loads a script
       
   237     TInt DoLoad( const TDesC& aFilePath );
       
   238     
       
   239     // Get script uid and name from file path
       
   240     void ParseUidAndName( const TDesC& aFilePath,
       
   241         TUid& aUid, TPtrC& aName ) const;
       
   242     
       
   243     // Create a new script object
       
   244     CCFScript* CreateScriptL( const TDesC& aName,
       
   245         const TDesC8& aScript,
       
   246         const TUid& aOwner,
       
   247         const RThread& aOwnerThread,
       
   248         MCFActionHandler& aActionHandler,
       
   249         TBool aDoSecurityCheck,
       
   250         MCFScriptOwner* aScriptOwner,
       
   251         TInt aScriptId );
       
   252         
       
   253     // Rollback a script based on existing script info
       
   254     void RollbackScriptL( const CCFScriptInfo& aInfo, const TDesC& aFilePath );
       
   255     
       
   256     // Resolves script ids by owner session
       
   257     void NotifyScriptIds( MCFScriptOwner* aScriptOwner );
       
   258     
       
   259     // Adds a script information in rollback array
       
   260     void AddRollbackInfoL( CCFScript& aScript );
       
   261     
       
   262     // Deletes a script file from system drive
       
   263     TInt DeleteScriptFile( const TDesC& aFilePath, const TUid& aOwnerUid );
       
   264 
       
   265 private: // Data
       
   266 
       
   267     enum EInternalParserDataProvidingState
       
   268         {
       
   269         KInit = 0,
       
   270         KDataSent,
       
   271         KDone,
       
   272         KError
       
   273         };
       
   274 
       
   275     // Internal state of the parser data providing.
       
   276     EInternalParserDataProvidingState iParserDataProvidingState;
       
   277 
       
   278     // unique Id assigned to new script
       
   279     TInt iNextId;
       
   280 
       
   281     // Own: Scripts
       
   282     RPointerArray<CCFScript> iScripts;
       
   283 
       
   284     // Own: Script ids
       
   285     RArray<TInt> iScriptIds;
       
   286 
       
   287     // Loaded scripts in starting phase
       
   288     RPointerArray<CCFScript> iLoadedScripts;
       
   289 
       
   290     // XML DOM parser.
       
   291     CMDXMLParser* iParser;
       
   292 
       
   293     // Data provider's data for the parser that is valid during AddScriptL.
       
   294     TPtrC8 iParserData;
       
   295 
       
   296     // Wait for DOM parser to complete.
       
   297     CActiveSchedulerWait* iWaitParsing;
       
   298 
       
   299     // Ref: Context manager
       
   300     MCFExtendedContextInterface& iCF;
       
   301 
       
   302     // Ref: File server session
       
   303     RFs& iFs;
       
   304 
       
   305     // Ref: Script event listener
       
   306     MCFActionHandler& iScriptEventListener;
       
   307 
       
   308     // Ref: Security checker
       
   309     MCFSecurityChecker& iSecurityChecker;
       
   310 
       
   311     // Own: Operation plugin manager
       
   312     CCFOperationPluginManager* iOperationPluginManager;
       
   313 
       
   314     // Default Rom drive letter
       
   315     TChar iDefaultRomDrive;
       
   316 
       
   317     // Default system drive
       
   318     TChar iDefaultSystemDrive;
       
   319     
       
   320     // Script which is being updated
       
   321     CCFScript* iUpdatedScript;
       
   322     
       
   323     // Script info array for rollback
       
   324     RScriptInfoArray iRollbackList;
       
   325     };
       
   326 
       
   327 #endif // C_CFSCRIPTHANDLER_H
       
   328