lowlevellibsandfws/pluginfw/Framework/frame/RegistryData.h
changeset 31 ce057bb09d0b
child 45 4b03adbd26ca
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implements Registry data handling.
       
    15 // Registry structure...
       
    16 // iRegistrations
       
    17 // -> CDriveData					(Drive number 1)
       
    18 // -> CDllData						(Dll number 1)
       
    19 // |	 -> CInterfaceData				(Interface number 1)
       
    20 // |	|	 -> CImplementationData -> CImplementationInformation	(Implementation 1)
       
    21 // |	|	 -> CImplementationData -> CImplementationInformation	(Implementation 2)
       
    22 // |	 -> CInterfaceData			
       
    23 // -> CDllData						(Dll number 2)
       
    24 // -> CInterfaceData				(Interface number 1)
       
    25 // -> CImplementationData -> CImplementationInformation	(Implementation 1)
       
    26 // 
       
    27 //
       
    28 
       
    29 /**
       
    30  @code
       
    31  @endcode
       
    32 */
       
    33 
       
    34 #ifndef __REGISTRYDATA_H__
       
    35 #define __REGISTRYDATA_H__
       
    36 
       
    37 #include <e32base.h>
       
    38 #include <f32file.h>
       
    39 #include <barsread2.h> // RResourceReader
       
    40 #include <s32std.h>
       
    41 #include <s32file.h>
       
    42 #include <badesca.h>
       
    43 #include "clientrequest.h"
       
    44 #include <ecom/ecom.h>
       
    45 #include <ecom/ecomerrorcodes.h>
       
    46 #include <ecom/ecomresolverparams.h>
       
    47 #include <ecom/implementationinformation.h>
       
    48 #include <ecom/publicregistry.h>
       
    49 #include "EComEntry.h"
       
    50 #include "DiscovererObserver.h"
       
    51 #include "EComPerformance.h"
       
    52 #include "callback.h"
       
    53 
       
    54 /** 
       
    55 The index of the uid which is used for matching dlls 
       
    56 @internalComponent
       
    57 */
       
    58 const TInt KTEntryDllUniqueIdIndex = 2;
       
    59 
       
    60 /**
       
    61 Default path to Interface Implementation Collection resource files.
       
    62 @internalComponent
       
    63 */
       
    64 _LIT(KEComResourceFilePath,"\\resource\\plugins\\");
       
    65 
       
    66 /** The granularities of two arrays, iInterfaceImplIndex and
       
    67 iImplIndex, have huge impact on
       
    68 discovery time on boot up. Larger granularity does not
       
    69 always shorten discovery time. The two default granularities
       
    70 below are chosen empirically to optimize discovery time
       
    71 while as much as possible, not to waste too much memory.
       
    72 
       
    73 @internalComponent
       
    74 */
       
    75 const TInt KDefaultInterfaceImplIndexGranularity = 23;
       
    76 
       
    77 /** @internalComponent */
       
    78 const TInt KDefaultImplIndexGranularity = 29;
       
    79 
       
    80 // Forward declaration
       
    81 class CEComCachedDriveInfo;
       
    82 
       
    83 //
       
    84 // CRegistryData class
       
    85 
       
    86 /**
       
    87 @internalComponent
       
    88 class CRegistryData.
       
    89 This class manages the entire data of the registry.
       
    90 */
       
    91 class CRegistryData : public CBase
       
    92 	{
       
    93 public:
       
    94 	// Make the test State Accessor a friend
       
    95 	friend class TRegistryData_StateAccessor;
       
    96 	friend class CRegistrar;
       
    97 	
       
    98 	class CDriveData;
       
    99 	class CDllData;
       
   100 	class CInterfaceData;
       
   101 	class CImplementationData;	
       
   102 
       
   103 	// The implemented structure for the registry data 
       
   104 	typedef CRegistryData::CImplementationData* CImplementationDataPtr;
       
   105 	
       
   106 	typedef RArray<CImplementationDataPtr> RImplDataArray;
       
   107 	/** whether the implementation to be added to the registry data
       
   108 	is a newcomer, or upgrade of an existing implementation, or
       
   109 	downgrade of an existing implementation. 
       
   110  	*/
       
   111 	enum TInsertImplMode
       
   112 		{
       
   113 		EInsertImplUndefinedMode,
       
   114 		EInsertImplAsNewcomerOfInterface,
       
   115 		EInsertImplAsUpgradeOfExistingImpl,
       
   116 		EInsertImplAsUnusedImpl
       
   117 		};
       
   118 		
       
   119 public:	
       
   120 	static CRegistryData* NewL(RFs& aFs);
       
   121 
       
   122 	/** This overload is provided for ECom performance test to find
       
   123 	the optimum granularity settings.
       
   124 	@see CEComImplIndexPerfTest
       
   125 	*/
       
   126 	static CRegistryData* NewL(RFs& aFs, 
       
   127 		TInt aInterfaceImplIndexGranularity, TInt aImplIndexGranularity);
       
   128 
       
   129 	virtual ~CRegistryData();
       
   130 	void ListImplementationsL(TUid aInterfaceUid,
       
   131 							  RImplDataArray& aImplementationData) const;
       
   132 	TInt SetEnabledState(TUid aImplementationUid, TBool aState);
       
   133 	void TemporaryUninstallL(const TDriveUnit& aDrive);
       
   134 	void UndoTemporaryUninstallL(const TDriveUnit& aDrive);
       
   135 	TBool IsRegisteredWithDate(TUid aDllUid, 
       
   136 								const TTime& aModified, 
       
   137 								TBool& aUpdate, 
       
   138 								CDriveData* aDriveData);
       
   139 	void AddDllDataL(const TDriveUnit& aDrive, TInt aFoundDriveIndex, CDllData* aDllData);
       
   140 	void UpdateDllDataL(const TDriveUnit& aDrive,TInt aFoundDriveIndex, CDllData* aDllData);
       
   141 	void DiscoveriesBeginning() const;
       
   142 	void DiscoveriesCompleteL(TBool aSuccessful, TPluginProcessingTypeIdentifier aProcessingType, TBool& aHasRegistryChanged);
       
   143 	TBool IndexValid() const;
       
   144 	TInt GetImplementationDllInfoForServer(	const TCapabilitySet& aCapabilitySet,
       
   145 											const TUid aImplUid,
       
   146 											const TUid aInterfaceUid,
       
   147 											TEntry& aEntry,
       
   148 											CImplementationInformation*& aImplInfo,
       
   149 											TBool& aIsOnRWDrive) const;
       
   150 	TInt GetImplementationDllInfoForClientL(const TClientRequest& aClientRequest,
       
   151 											const TUid aImplUid,
       
   152 											const TUid aInterfaceUid,
       
   153 											TEntry& aEntry,
       
   154 											CImplementationInformation*& aImplInfo,
       
   155 											TBool aSecurityCheckNeeded)const;
       
   156 	TBool HasLanguageChanged() const;
       
   157 	TBool InsertIntoIndexL(CImplementationData* aImplPtr, TBool aCheckIsNeeded);
       
   158 	void RemoveFromIndexL(CDllData* aDllData) const;
       
   159 	TBool IsAnyDllRegisteredWithDriveL(const TDriveUnit& aDrive)const;
       
   160 	TInt FindDriveL(const TDriveUnit& aDrive, CDriveData*& aDriveData)const;
       
   161 	void SetDiscoveryFlagL(const TDriveUnit& aDriveUnit);
       
   162 	void LanguageChangedL(TBool& aLanguageChanged);
       
   163 	void SetImplUpgradeCallBack(const TCallBackWithArg& aCallBack);
       
   164 	
       
   165 #ifdef __ECOM_SERVER_PERFORMANCE__
       
   166 	void GetRegistryCountsL(TInt aType, RegistryCounts::TRegistryCounts& aCounts) const;
       
   167 #endif // __ECOM_SERVER_PERFORMANCE__
       
   168 
       
   169 private:
       
   170 	typedef RPointerArray<CDriveData> TRegistration;
       
   171 
       
   172 	/** 
       
   173 	Implementation structure containing the current in use implementation and
       
   174 	a list of unused implementations with the same uid held in the registry tree.
       
   175 	The unused list is used to allow efficient rollback to previous impl in the event
       
   176 	that the current impl is removed.
       
   177 	*/	
       
   178 	typedef struct TImplStruct
       
   179 		{
       
   180 		/** Constructor */
       
   181 		TImplStruct();
       
   182 		/** Resets iUnusedImpls*/
       
   183 		inline void Reset();
       
   184 		/** Comparer*/
       
   185 		static TInt CompareImplStructUid(const TImplStruct& aEntry1,const TImplStruct& aEntry2);
       
   186 		/** Comparer to search TImplStruct with just the Impl. UID */
       
   187 		static TInt CompareUidAgainstImplStruct(const TUid* aUid, const TImplStruct& aEntry);
       
   188 		/**
       
   189 		Current Impl. This is not held in an array with the unused implementations because the array is not
       
   190 		sorted. See comment for iUnusedImpls.
       
   191 		*/
       
   192 		CImplementationDataPtr iCurrentImpl;
       
   193 		/**
       
   194 		List of additional unused implementations. This list is not ordered as the processing required to sort
       
   195 		the list when adding is more than that required to determine which should be used on rollback.
       
   196 		Also this additional processing is not wanted during startup.
       
   197 		*/
       
   198 		RImplDataArray iUnusedImpls;
       
   199 		}TImplContainer;
       
   200 	
       
   201 	typedef RArray<TImplContainer> TImplContainerArray;
       
   202 
       
   203 	/** 
       
   204 	Interface used by all implementation index
       
   205 	*/
       
   206 	typedef struct TInterfaceStruct
       
   207 		{
       
   208 		/** Constructor */
       
   209 		TInterfaceStruct();
       
   210 		/** Resets iImplementationInfo */
       
   211 		inline void Reset();
       
   212 		/** Comparer*/
       
   213 		static TInt CompareInfUid(const TInterfaceStruct& aIndexEntry1,const TInterfaceStruct& aIndexEntry2);
       
   214 		/** Unique Id of this interface */
       
   215 		TUid	iInterfaceUid;
       
   216 		/** List of the implementations of this interface */
       
   217 		TImplContainerArray iImpData;
       
   218 		}TInterfaceIndex;
       
   219 
       
   220 private:
       
   221 	explicit CRegistryData(RFs& aFs, TInt aInterfaceImplIndexGranularity, TInt aImplIndexGranularity);
       
   222 	void ConstructL();
       
   223 
       
   224 	TInt IndexedFind(TUid aInterfaceUid) const;
       
   225 	static TBool MatchOnDrive(const CRegistryData::CDriveData& aIndexOne, 
       
   226 							  const CRegistryData::CDriveData& aIndexTwo);
       
   227 
       
   228 	TInt FindImplementation(const TUid aImplUid, const TUid aInterfaceUid, CImplementationData*& aImplData) const;
       
   229 	CImplementationData* SelectDuplicatedImpl(const CImplementationData* aImpl1, const CImplementationData* aImpl2) const;
       
   230 
       
   231 	void ValidateRegistryL();
       
   232 	
       
   233 	CImplementationData* SelectPreferredImplL(CImplementationData* aOldImpl,
       
   234 											CImplementationData* aNewImpl,
       
   235 											TBool& aLigitimateImpl,
       
   236 											TBool aCheckIsNeeded) const;
       
   237 
       
   238 	void FilterForLatestLegitimateImplL(TImplContainerArray& aIdxArray,
       
   239 										CImplementationData* aNewImpl,
       
   240 										TInsertImplMode& aInsertMode,
       
   241 										TInt&  aPosOfImplInArray,
       
   242 										TBool& aLigitimateImpl,
       
   243 										TBool aCheckIsNeeded);
       
   244 	void DeleteDllL(CDllData* aDllData) const;
       
   245 	void AddImplDataL(CDriveData* aDriveData);
       
   246 
       
   247 	void InsertImplInIndexesL(TInsertImplMode	aInsertMode,
       
   248 							  TInt				aIfPosInInterfaceImplIndex,
       
   249 							  TInterfaceIndex&  aNewIfIndexEl,
       
   250 							  TInt				aImplPosInContainerArray,
       
   251 							  CImplementationData* aNewImpl,
       
   252 							  TBool aLegitimateImpl);
       
   253 	static void ResetTInterfaceIndex(TAny* aObject);
       
   254 
       
   255 	/** Remove the pointer from iImplIndex based on the impl address*/
       
   256     TBool RemoveImplByAddrFromImplIndex(CImplementationData* aPtr) const;
       
   257 
       
   258     /** Used to restore the impIndex sanity in case of a leave */
       
   259 	static void RemoveImplFromImplIndexCleanUp(TAny* aPtr);
       
   260 	
       
   261 	/** Insert aNewImpl into iImplIndex. */
       
   262 	TInt InsertImplIntoImplIndex(CImplementationData* aNewImpl) const;
       
   263 	/** Store change in drive state - addition or removal*/
       
   264 	void DriveChanged(const TDriveUnit& aDrive, TBool aDriveRemoved);
       
   265 
       
   266 // Attributes / Properties
       
   267 private:
       
   268 	/** A reference to a connected file server instance */
       
   269 	RFs& iFs;
       
   270 	/** The flag to indicate that we are in the middle of discoveries and therefore
       
   271 	the index list is probably out of date */
       
   272 	mutable TBool iCurrentlyDiscovering;
       
   273 	/** A boolean, indicating if the language downgrade path has changed */
       
   274 	TBool iLanguageChanged;
       
   275 	/** The entire registration data */ 
       
   276 	TRegistration* iRegistrations;
       
   277 	/** The index of all registered implementations sorted by interface UID.*/
       
   278 	mutable RArray<TInterfaceIndex> iInterfaceImplIndex;
       
   279 	/** Index of all implementations available to clients sorted by
       
   280 	 Implementation UID.
       
   281 	 Majority of clients do not specify the interface UID in 
       
   282 	 their create requests. Thus ECOM needs this auxiliary index.
       
   283 	 Note that if multiple entries have the same Impl. UID, they are
       
   284 	 ordered by the interface UID.
       
   285 	*/
       
   286 	mutable RPointerArray<CImplementationData> iImplIndex;
       
   287 	/**Bitmap indicating any drives removed */
       
   288 	TInt iRemovedDrives;
       
   289 
       
   290 	TCallBackWithArg iImplUpgradeCallBack;
       
   291 
       
   292 public:
       
   293 	/** System Drive cache to allow access by CEComServer*/
       
   294 	TDriveNumber iSystemDrive;	
       
   295 
       
   296 	/** cached info on drivelist */
       
   297 	CEComCachedDriveInfo*  iCachedDriveInfo;	
       
   298 	};  // End of CRegistryData definition
       
   299 	
       
   300 
       
   301 //
       
   302 // CRegistryData::CImplementationData class
       
   303 /**
       
   304 This wrapper class is needed, to create a 2 way relationship between CInterfaceData and the public 
       
   305 CImplementationInformation objects. It holds a reference to an implementation and a reference to its 
       
   306 parent interface data. 
       
   307 @internalComponent
       
   308 */
       
   309 class CRegistryData::CImplementationData : public CBase
       
   310 	{
       
   311 public:
       
   312 	static CImplementationData* NewLC(CInterfaceData* aParent);
       
   313 	static CImplementationData* NewL(CInterfaceData* aParent,
       
   314 											TUid	aUid,
       
   315 											TInt	aVersion, 
       
   316 											HBufC*  aName,
       
   317 											HBufC8* aDataType,
       
   318 											HBufC8* aOpaqueData,
       
   319 											TDriveUnit aDrive,
       
   320 											TBool aRomOnly,
       
   321 											TBool aRomBased);
       
   322 	static CImplementationData* NewL(CInterfaceData* aParent,
       
   323 											TUid	aUid,
       
   324 											TInt	aVersion, 
       
   325 											HBufC*  aName,
       
   326 											HBufC8* aDataType,
       
   327 											HBufC8* aOpaqueData,
       
   328 											TDriveUnit aDrive,
       
   329 											TBool aRomOnly,
       
   330 											TBool aRomBased,
       
   331 											RExtendedInterfacesArray* aExtendedInterfaces);											
       
   332 	~CImplementationData();
       
   333 	void ExternalizeL(RWriteStream& aStore) const;
       
   334 	void InternalizeL(RReadStream& aStore);
       
   335 	static TInt CompareImplUid(const CImplementationData& aImpl1,const CImplementationData& aImpl2);
       
   336 	static TInt CompareImplUidIgnoreIfUid(const CImplementationData& aImpl1,const CImplementationData& aImpl2);
       
   337 	static TInt CompareUidAgainstImplData(const CImplementationData& aUid, const CImplementationData& aImplData);
       
   338 private:
       
   339 	CImplementationData(CInterfaceData* aParent);
       
   340 	void ConstructL(TUid	aUid,
       
   341 					TInt	aVersion, 
       
   342 					HBufC*  aName,
       
   343 					HBufC8* aDataType,
       
   344 					HBufC8* aOpaqueData,
       
   345 					TDriveUnit aDrive,
       
   346 					TBool aRomOnly,
       
   347 					TBool aRomBased);
       
   348 	void ConstructL(TUid	aUid,
       
   349 					TInt	aVersion, 
       
   350 					HBufC*  aName,
       
   351 					HBufC8* aDataType,
       
   352 					HBufC8* aOpaqueData,
       
   353 					TDriveUnit aDrive,
       
   354 					TBool aRomOnly,
       
   355 					TBool aRomBased,
       
   356 					RExtendedInterfacesArray* aExtendedInterfaces);				
       
   357 public:
       
   358 	/** A pointer to the implementation */
       
   359 	CImplementationInformation* iImplInfo;
       
   360 	/**Pointer to the parent CInterfaceData */
       
   361 	CInterfaceData* iParent;
       
   362 	};
       
   363 
       
   364 //
       
   365 // CRegistryData::CInterfaceData class
       
   366 
       
   367 /**
       
   368 This class manages the entire data for an interface of a dll.
       
   369 @internalComponent
       
   370 */
       
   371 class CRegistryData::CInterfaceData : public CBase
       
   372 	{
       
   373 public:
       
   374 	static CInterfaceData* NewLC(CDllData* aParent);
       
   375 	static CInterfaceData* NewLC(TUid aInterfaceUid, CDllData* aParent);
       
   376 	~CInterfaceData();
       
   377 	void AddL(const CImplementationData* aImplementation);
       
   378 	void SetInterfaceUid(TUid aInterfaceUid);
       
   379 	void ExternalizeL(RWriteStream& aStore) const;
       
   380 	void InternalizeL(RReadStream& aStore);
       
   381 private:
       
   382 	CInterfaceData(CDllData* aParent);
       
   383 	CInterfaceData(TUid aInterfaceUid,CDllData* aParent);
       
   384 	void ConstructL();
       
   385 public:
       
   386 	/** The interface UID */
       
   387 	TUid		iInterfaceUid;
       
   388 	/** The implementations related to this interface */
       
   389 	RPointerArray<CImplementationData>* iImplementations;
       
   390 	/** Pointer to the parent DLL data */
       
   391 	CDllData* iParent;
       
   392 	};	// End CRegistryData::CInterfaceData
       
   393 
       
   394 /**
       
   395 @internalComponent
       
   396 */
       
   397 typedef RPointerArray<CRegistryData::CInterfaceData> RInterfaceList ;
       
   398 
       
   399 //
       
   400 // CRegistryData::CDllData class
       
   401 
       
   402 /**
       
   403 This class manages the entire data of a registered dll.
       
   404 @internalComponent
       
   405 */
       
   406 class CRegistryData::CDllData : public CBase
       
   407 	{
       
   408 public:
       
   409 	static CDllData* NewLC( CDriveData* iParent);//
       
   410 	static CDllData* NewLC(const TDesC& aDllName,const TTime& aDllModTime,const TUid& aSecondUid,const TUid& aThirdUid, CDriveData* iParent);
       
   411 	~CDllData();
       
   412 	void AddL(const CInterfaceData* aInterface);
       
   413 	void ExternalizeL(RWriteStream& aStore) const;
       
   414 	void InternalizeL(RReadStream& aStore);
       
   415 	void PopulateAnEntry(TEntry& aEntry) const;
       
   416 	TBool ProcessSecurityCheckL();
       
   417 	TBool SaveSecurityInfoL();
       
   418 	void SetResourceExtL(const TDesC& aExt);
       
   419 private:
       
   420 	CDllData( CDriveData* iParent);//
       
   421 	void ConstructL();//
       
   422 	/** See CDllData* NewLC */
       
   423 	void ConstructL(const TDesC& aDllName,const TTime& aDllModTime,const TUid& aSecondUid,const TUid& aThirdUid);
       
   424 
       
   425 public:
       
   426 	/** Information on the DLL */
       
   427 	CEComEntry* iDllEntry;
       
   428 	/** The list of interfaces within the dll */
       
   429 	RInterfaceList*	iIfList;
       
   430 	/** Capability set of this dll */
       
   431 	TCapabilitySet iCapSet;
       
   432 	/** A flag to tell if the DLL's security has been previously checked or not.*/
       
   433 	TBool iSecurityChecked;
       
   434 	/** A pointer to the parent drive data. */
       
   435 	CDriveData* iParent;
       
   436 	/** The VendorId of the DLL. */
       
   437 	TVendorId iVid;
       
   438 	/** The plugin resource file extension  - not set for plugins residing on RO Internal drives*/
       
   439 	HBufC* iRscFileExtension;
       
   440 	}; // End CRegistryData::CDllData
       
   441 
       
   442 /**
       
   443 @internalComponent
       
   444 */
       
   445 typedef RPointerArray<CRegistryData::CDllData> TDll ;
       
   446 
       
   447 //
       
   448 // CRegistryData::CDriveData class
       
   449 
       
   450 /**
       
   451 This class manages the entire data of a registered dll.
       
   452 */
       
   453 class CRegistryData::CDriveData : public CBase
       
   454 	{
       
   455 public:
       
   456 	static CDriveData* NewLC(TDriveUnit aDrive,CRegistryData* aParent);
       
   457 	~CDriveData();
       
   458 	void AddL(const CDllData* aDll);
       
   459 	void ExternalizeL(RFs& aFs,const TDesC& aDatFileName);
       
   460 	void InternalizeL(RFs& aFs,const TDesC& aDatFileName);
       
   461 	TInt FindDllIndex(const TUid aDllUid) const;
       
   462 private:
       
   463 	void DoInternalizeL(RFs& aFs, const TDesC& aFileName);
       
   464 	CDriveData(TDriveUnit aDrive,CRegistryData* aParent);
       
   465 	void ConstructL();
       
   466 
       
   467 public:
       
   468 	/** A reference to the drive. */
       
   469 	TDriveUnit	iDrive;
       
   470 	/** The list of Interface Implementation Collections upon the drive */
       
   471 	TDll*		iDllList;
       
   472 	/** The registry data. */
       
   473     CRegistryData* iParent;
       
   474     /**indicate the drive has change */
       
   475     TBool iDriveChanged;
       
   476     /**indiacate the registry data on the drive has changed */
       
   477     TBool iRegistryChanged;
       
   478 
       
   479 	}; // End CRegistryData::CDriveData
       
   480 
       
   481 void CRegistryData::TInterfaceIndex::Reset()
       
   482  	{
       
   483  	TInt count = iImpData.Count();
       
   484  	while(count > 0)
       
   485  		{
       
   486  		--count;
       
   487  		iImpData[count].Reset();
       
   488  		}
       
   489  	iImpData.Reset();
       
   490    	}
       
   491 
       
   492 void CRegistryData::TImplContainer::Reset()
       
   493  	{
       
   494  	iUnusedImpls.Reset();
       
   495    	}
       
   496 
       
   497     
       
   498     class TCleanupImplIndexEntry
       
   499         {
       
   500         public:
       
   501         TCleanupImplIndexEntry(CRegistryData* aRegData, CRegistryData::CImplementationData* aImpl)
       
   502         : iRegistryData(aRegData), iImplEntry(aImpl)   
       
   503         {}
       
   504         CRegistryData*         iRegistryData;
       
   505         CRegistryData::CImplementationData*   iImplEntry;
       
   506         };
       
   507 #endif //__REGISTRYDATA_H__