os/persistentdata/featuremgmt/featuremgr/src/serverexe/featmgrfeatureregistry.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/featuremgmt/featuremgr/src/serverexe/featmgrfeatureregistry.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,299 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +
    1.24 +#ifndef FEATMGRFEATUREREGISTRY_H
    1.25 +#define FEATMGRFEATUREREGISTRY_H
    1.26 +
    1.27 +//  INCLUDES
    1.28 +#include <e32svr.h>
    1.29 +#include <s32file.h>
    1.30 +#include <featmgr/featurecmn.h>
    1.31 +#include <featmgr/featureinfoplugin.h>
    1.32 +#include "featmgrfeatureentry.h"
    1.33 +#include "swilistener.h"
    1.34 +
    1.35 +// FORWARD DECLARATIONS
    1.36 +
    1.37 +// CLASS DECLARATION
    1.38 +
    1.39 +class MFeatMgrRegistryObserver
    1.40 +    {
    1.41 +    public:
    1.42 +        virtual void HandleFeatureChange( TFeatureServerEntry& aFeature, 
    1.43 +            TFeatureChangeType aType ) = 0;
    1.44 +    };
    1.45 +
    1.46 +// CLASS DECLARATION
    1.47 +NONSHARABLE_CLASS(CFeatMgrFeatureRegistry) : public CBase, MSWICallBack
    1.48 +    {
    1.49 +    private:
    1.50 +	
    1.51 +    	/* 
    1.52 +    	* Status for SWI which must be kept in memory in order for calls made to the new
    1.53 +    	* API functions SWIStart and SWIEnd can be related to actual installation/uninstallation.
    1.54 +    	* 
    1.55 +    	* ESWIOutOfMemory will inform FeatMgr that an out-of-memory condition has occurred during
    1.56 +    	* caching and/or memory pre-allocation for the new features to be added.
    1.57 +    	*/
    1.58 +    	enum TSWIStatus
    1.59 +	    	{
    1.60 +	    	ESWIComplete=0,
    1.61 +	    	ESWIInstalling,
    1.62 +	    	ESWIAborted,
    1.63 +	    	ESWIOutOfMemory 
    1.64 +	    	};
    1.65 +    	
    1.66 +	    /*
    1.67 +	    * Enumerations to identify the category of the operation to apply on the cached 
    1.68 +	    * features after SWI completes.
    1.69 +	    */
    1.70 +		enum TSWIOperationCat
    1.71 +			{ 
    1.72 +			ESWIAddFeat,
    1.73 +			ESWIDeleteFeat,
    1.74 +			ESWISetFeatAndData,
    1.75 +			ESWISetFeatData,
    1.76 +			ESWISetFeat
    1.77 +			};
    1.78 +		
    1.79 +		/*
    1.80 +		* The operation tuple to be cached
    1.81 +		*/
    1.82 +		struct TSWICachedOperation
    1.83 +			{
    1.84 +			TSWIOperationCat iCat;
    1.85 +			TFeatureServerEntry iFeatEntry;
    1.86 +			};
    1.87 +
    1.88 +    public:
    1.89 +        
    1.90 +        /**
    1.91 +        * Two-phased constructor.
    1.92 +        */
    1.93 +        static CFeatMgrFeatureRegistry* NewL( RFs& aFs, MFeatMgrRegistryObserver& aObserver );
    1.94 +
    1.95 +        /**
    1.96 +        * Destructor.
    1.97 +        */
    1.98 +        virtual ~CFeatMgrFeatureRegistry();
    1.99 +
   1.100 +    public:
   1.101 +           
   1.102 +        /**
   1.103 +        * Reads feature files.
   1.104 +        */
   1.105 +        void ReadFeatureFilesL();
   1.106 +
   1.107 +        /**
   1.108 +        * Reads runtime feature file.
   1.109 +        */
   1.110 +        void ReadRuntimeFeaturesL( TBool &aFeaturesReady );
   1.111 +
   1.112 +        /**
   1.113 +        * Merges features to common feature array from plugin.
   1.114 +        */
   1.115 +        void MergePluginFeaturesL( RArray<FeatureInfoCommand::TFeature>& aList );
   1.116 +
   1.117 +        /**
   1.118 +        * Merges features to common feature array from plugin.
   1.119 +        */
   1.120 +        void MergePluginFeaturesL( RFeatureArray& aList );
   1.121 +
   1.122 +        /**
   1.123 +        * Returns feature support status.
   1.124 +        */
   1.125 +        TInt IsFeatureSupported( TFeatureServerEntry& aFeature );
   1.126 +
   1.127 +        /**
   1.128 +        * Adds feature.
   1.129 +        * @param aFeature A reference to a client owned TFeatureEntry object
   1.130 +        * @param aProcessId The id of the process calling this function. This is needed to identify 
   1.131 +        * 					the executable launched by Software Installer (SWI) and cache its to-be
   1.132 +        * 					added features. The default value for aProcessId enables other clients to 
   1.133 +        * 					add features directly to the list (allowing backward compatibility).
   1.134 +        * When set to ETrue the function 
   1.135 +        */
   1.136 +        TInt AddFeature( TFeatureServerEntry& aFeature, TUint aProcessId = 0 );
   1.137 +
   1.138 +        /**
   1.139 +        * Deletes feature.
   1.140 +        */
   1.141 +        TInt DeleteFeature( TUid aFeature, TUint = 0 );
   1.142 +
   1.143 +        /**
   1.144 +        * Sets feature support status and optionally data.
   1.145 +        */
   1.146 +        TInt SetFeature( TUid aFeature, TInt aEnable, const TUint32 *aData = NULL, TUint = 0 );
   1.147 +
   1.148 +        /**
   1.149 +        * Lists supported features to array.
   1.150 +        */
   1.151 +        void SupportedFeaturesL( RFeatureUidArray& aSupportedFeatures );
   1.152 +
   1.153 +        /**
   1.154 +        * Returns number of supported features.
   1.155 +        */
   1.156 +        TInt NumberOfSupportedFeatures();
   1.157 +        
   1.158 +        /**
   1.159 +         * Make a backup of the feature list into member iFeatureListBackup, then reset 
   1.160 +         * the feature list iFeatureList.
   1.161 +		 *
   1.162 +		 * Leaves if there is an error during back up, with KErrNoMemory or any of the 
   1.163 +		 * other system-wide error codes.
   1.164 +         */ 
   1.165 +        void ResetFeaturesL();
   1.166 +        
   1.167 +        /**
   1.168 +		 * This function will handle the required notifications for new, deleted and changed features
   1.169 +		 * after a restore operation has taken place.
   1.170 +         */ 
   1.171 +        void HandleRestoredFeatureNotificationsL();
   1.172 +        
   1.173 +        /**
   1.174 +		 * Returns the fully qualified path and filename for the runtime feature data file.
   1.175 +         */ 
   1.176 +        TFileName GetFeaturesFilePathAndName( void );
   1.177 +
   1.178 +        /**
   1.179 +        * Indicates that SWI started. It takes the Id of the process calling it as a parameter.
   1.180 +        */
   1.181 +        TInt SWIStart(TUint);
   1.182 +        
   1.183 +        /**
   1.184 +        * Indicates that SWI ended. It takes the Id of the process calling it as a parameter.
   1.185 +        */
   1.186 +        TInt SWIEnd(TUint);
   1.187 +        
   1.188 +        /**
   1.189 +         * Add a new command to the cache.
   1.190 +         * 
   1.191 +         * @return error KErrArgument if the maximum number of cached features is reached.
   1.192 +         * 				 KErrNoMemory if there is no memory to create a new command to cached,
   1.193 +         * 							  or if an out-of-memory condition has occured during caching.
   1.194 +         */
   1.195 +         TInt SWICacheCommand(TSWIOperationCat aOptCat, TFeatureServerEntry aFeature);
   1.196 +        
   1.197 +        /**
   1.198 +        * Commit changes for the cached features into feature manager.
   1.199 +        */
   1.200 +        void CommitSWIFeatChanges();
   1.201 +        
   1.202 +        /**
   1.203 +        * Reset and clean up SWI-related states and member variables.
   1.204 +        */
   1.205 +        void SWIReset();
   1.206 +
   1.207 +        /*
   1.208 +        * Handle the case when SWI aborts.
   1.209 +        */
   1.210 +        void SWIAborted();
   1.211 +        
   1.212 +        /*
   1.213 +        * Virtual function from MSWICallBack.
   1.214 +        * It is fired when the timer runs out to indicate that SWI finished before a call to 
   1.215 +        * SWIEnd or the launched executable crashed or hanged. It will deal with rolling-back 
   1.216 +        * all cached changes. It is called after 15 seconds.
   1.217 +        */
   1.218 +        void SWITimedOut();
   1.219 +        
   1.220 +        /*
   1.221 +        * Return the status of the caching mechanism (started or not).
   1.222 +        */
   1.223 +        TBool SWICacheStarted();
   1.224 +        
   1.225 +        /*
   1.226 +        * Returns the status of the caching mechanism (successful, aborted, out-of-memory).
   1.227 +        */
   1.228 +        TBool SWICacheStatusOOM();
   1.229 +        
   1.230 +    private:
   1.231 +
   1.232 +        CFeatMgrFeatureRegistry( RFs& aFs, MFeatMgrRegistryObserver& aObserver );
   1.233 +        void ConstructL();
   1.234 +        
   1.235 +        TInt ReadFiles( const TDesC& aFilePath, CDir* aDir );
   1.236 +        void ReadFileL( const TDesC& aFilePath );
   1.237 +        void CompareFeatureListsL();
   1.238 +        void ReadFilesFromDirL( const TDesC& aDirName );
   1.239 +        void UpdateRuntimeFeaturesFileL( TFeatureServerEntry& aFeature, TFeatureChangeType aType );
   1.240 +
   1.241 +        TInt HandleChange( TFeatureServerEntry& aFeature, TFeatureChangeType aType );
   1.242 +        TInt ValidateFeature( TUid aFeature, TInt &aIndex );
   1.243 +        TInt SearchFeature( TUid aFeature );
   1.244 +        TInt EnableFeature( TUid aFeature );
   1.245 +        TInt DisableFeature( TUid aFeature );
   1.246 +        TBool IsFlagSet( TInt aIndex, TFeatureFlags aFlag );
   1.247 +        static TInt FindByUid( const TUid *aFeature, const TFeatureServerEntry& aItem );
   1.248 +        static TInt FindByUid( const TFeatureServerEntry& aFeature, 
   1.249 +        const TFeatureServerEntry& aItem );
   1.250 +        void ValidateHeaderL( RFileReadStream& stream, TUint32& count, TUint32& countDSRs );
   1.251 +        void WriteHeaderAndEntriesL( RFileWriteStream &aStream, RFeatureServerArray& aArray );
   1.252 +        void ValidateFeatureFlagL(TBitFlags32 aFlags);
   1.253 +        void ValidateRuntimeFeatureFlagL(TBitFlags32 aFlags);
   1.254 +        
   1.255 +     private:
   1.256 +        
   1.257 +        // Observer of feature changes
   1.258 +        MFeatMgrRegistryObserver& iObserver;
   1.259 +        // Array of features
   1.260 +        RArray<TFeatureServerEntry> iFeatureList;
   1.261 +        // Struct to contain information of default supported ranges
   1.262 +        class TDefaultRange
   1.263 +	        {
   1.264 +	        public:
   1.265 +    	        TUid iLowUid;
   1.266 +    	        TUid iHighUid;
   1.267 +	        };
   1.268 +        // Array of supported ranges
   1.269 +        RArray<TDefaultRange> iRangeList;
   1.270 +        // File server session
   1.271 +        RFs& iFs;
   1.272 +        
   1.273 +        // Array of features (backup up for BUR)
   1.274 +        RArray<TFeatureServerEntry> iFeatureListBackup;
   1.275 +
   1.276 +        // Flag to tell feature manager to cache newly modified features during SWI.
   1.277 +        TBool iSWICacheFeature;
   1.278 +        // Tracks the SWI status to check if an installation/uninstallation is in progress before 
   1.279 +        // starting caching.
   1.280 +        TSWIStatus iSWIStatus;
   1.281 +        // Array that holds the operations to apply on cached features when SWI ends.
   1.282 +        RArray<TSWICachedOperation> iSWICachedOperations;
   1.283 +        // Id of the process launched by SWI whose commands to feature manager are to be cached.
   1.284 +        TUint iSWIProcessId;
   1.285 +        // Listens to the SWI P&S property KSAUidSoftwareInstallKeyValue 
   1.286 +        CSWIListener* iSWIListener;
   1.287 +        // Timer to handle the situation when the launched exe by SWI manipulates features and then 
   1.288 +        // hangs/crashes, or a call to SWIEnd was not made.
   1.289 +        CSWITimer* iSWITimer;
   1.290 +        // Traces if an "out-of-memory" condition has occurred during caching. If so, FeatMgr will
   1.291 +        // not commit the cache when the installation is successful. It will be disregarded.
   1.292 +        TBool iOomOccured;
   1.293 +        // Counts the number of features allowed to be cached during SWI install/uninstall. 
   1.294 +        // The maximum is set to 50 (MAXSWIOPS)
   1.295 +        TInt iSWIOperations;
   1.296 +        // Counts how many AddFeature commands are cached during SWI
   1.297 +        TInt iAddFeatCount;
   1.298 +    };
   1.299 +
   1.300 +#endif      // FEATMGRFEATUREREGISTRY_H 
   1.301 +            
   1.302 +// End of File