lowlevellibsandfws/pluginfw/Framework/frame/RegistryData.h
changeset 0 e4d67989cc36
child 17 ef2ebc87518f
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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 */
       
   256 	TBool RemoveImplFromImplIndex(CImplementationData* aPtr) const;
       
   257 	/** Insert aNewImpl into iImplIndex. */
       
   258 	TInt InsertImplIntoImplIndex(CImplementationData* aNewImpl) const;
       
   259 	/** Store change in drive state - addition or removal*/
       
   260 	void DriveChanged(const TDriveUnit& aDrive, TBool aDriveRemoved);
       
   261 
       
   262 // Attributes / Properties
       
   263 private:
       
   264 	/** A reference to a connected file server instance */
       
   265 	RFs& iFs;
       
   266 	/** The flag to indicate that we are in the middle of discoveries and therefore
       
   267 	the index list is probably out of date */
       
   268 	mutable TBool iCurrentlyDiscovering;
       
   269 	/** A boolean, indicating if the language downgrade path has changed */
       
   270 	TBool iLanguageChanged;
       
   271 	/** The entire registration data */ 
       
   272 	TRegistration* iRegistrations;
       
   273 	/** The index of all registered implementations sorted by interface UID.*/
       
   274 	mutable RArray<TInterfaceIndex> iInterfaceImplIndex;
       
   275 	/** Index of all implementations available to clients sorted by
       
   276 	 Implementation UID.
       
   277 	 Majority of clients do not specify the interface UID in 
       
   278 	 their create requests. Thus ECOM needs this auxiliary index.
       
   279 	 Note that if multiple entries have the same Impl. UID, they are
       
   280 	 ordered by the interface UID.
       
   281 	*/
       
   282 	mutable RPointerArray<CImplementationData> iImplIndex;
       
   283 	/**Bitmap indicating any drives removed */
       
   284 	TInt iRemovedDrives;
       
   285 
       
   286 	TCallBackWithArg iImplUpgradeCallBack;
       
   287 
       
   288 public:
       
   289 	/** System Drive cache to allow access by CEComServer*/
       
   290 	TDriveNumber iSystemDrive;	
       
   291 
       
   292 	/** cached info on drivelist */
       
   293 	CEComCachedDriveInfo*  iCachedDriveInfo;	
       
   294 	};  // End of CRegistryData definition
       
   295 	
       
   296 
       
   297 //
       
   298 // CRegistryData::CImplementationData class
       
   299 /**
       
   300 This wrapper class is needed, to create a 2 way relationship between CInterfaceData and the public 
       
   301 CImplementationInformation objects. It holds a reference to an implementation and a reference to its 
       
   302 parent interface data. 
       
   303 @internalComponent
       
   304 */
       
   305 class CRegistryData::CImplementationData : public CBase
       
   306 	{
       
   307 public:
       
   308 	static CImplementationData* NewLC(CInterfaceData* aParent);
       
   309 	static CImplementationData* NewL(CInterfaceData* aParent,
       
   310 											TUid	aUid,
       
   311 											TInt	aVersion, 
       
   312 											HBufC*  aName,
       
   313 											HBufC8* aDataType,
       
   314 											HBufC8* aOpaqueData,
       
   315 											TDriveUnit aDrive,
       
   316 											TBool aRomOnly,
       
   317 											TBool aRomBased);
       
   318 	static CImplementationData* NewL(CInterfaceData* aParent,
       
   319 											TUid	aUid,
       
   320 											TInt	aVersion, 
       
   321 											HBufC*  aName,
       
   322 											HBufC8* aDataType,
       
   323 											HBufC8* aOpaqueData,
       
   324 											TDriveUnit aDrive,
       
   325 											TBool aRomOnly,
       
   326 											TBool aRomBased,
       
   327 											RExtendedInterfacesArray* aExtendedInterfaces);											
       
   328 	~CImplementationData();
       
   329 	void ExternalizeL(RWriteStream& aStore) const;
       
   330 	void InternalizeL(RReadStream& aStore);
       
   331 	static TInt CompareImplUid(const CImplementationData& aImpl1,const CImplementationData& aImpl2);
       
   332 	static TInt CompareImplUidIgnoreIfUid(const CImplementationData& aImpl1,const CImplementationData& aImpl2);
       
   333 	static TInt CompareUidAgainstImplData(const CImplementationData& aUid, const CImplementationData& aImplData);
       
   334 private:
       
   335 	CImplementationData(CInterfaceData* aParent);
       
   336 	void ConstructL(TUid	aUid,
       
   337 					TInt	aVersion, 
       
   338 					HBufC*  aName,
       
   339 					HBufC8* aDataType,
       
   340 					HBufC8* aOpaqueData,
       
   341 					TDriveUnit aDrive,
       
   342 					TBool aRomOnly,
       
   343 					TBool aRomBased);
       
   344 	void ConstructL(TUid	aUid,
       
   345 					TInt	aVersion, 
       
   346 					HBufC*  aName,
       
   347 					HBufC8* aDataType,
       
   348 					HBufC8* aOpaqueData,
       
   349 					TDriveUnit aDrive,
       
   350 					TBool aRomOnly,
       
   351 					TBool aRomBased,
       
   352 					RExtendedInterfacesArray* aExtendedInterfaces);				
       
   353 public:
       
   354 	/** A pointer to the implementation */
       
   355 	CImplementationInformation* iImplInfo;
       
   356 	/**Pointer to the parent CInterfaceData */
       
   357 	CInterfaceData* iParent;
       
   358 	};
       
   359 
       
   360 //
       
   361 // CRegistryData::CInterfaceData class
       
   362 
       
   363 /**
       
   364 This class manages the entire data for an interface of a dll.
       
   365 @internalComponent
       
   366 */
       
   367 class CRegistryData::CInterfaceData : public CBase
       
   368 	{
       
   369 public:
       
   370 	static CInterfaceData* NewLC(CDllData* aParent);
       
   371 	static CInterfaceData* NewLC(TUid aInterfaceUid, CDllData* aParent);
       
   372 	~CInterfaceData();
       
   373 	void AddL(const CImplementationData* aImplementation);
       
   374 	void SetInterfaceUid(TUid aInterfaceUid);
       
   375 	void ExternalizeL(RWriteStream& aStore) const;
       
   376 	void InternalizeL(RReadStream& aStore);
       
   377 private:
       
   378 	CInterfaceData(CDllData* aParent);
       
   379 	CInterfaceData(TUid aInterfaceUid,CDllData* aParent);
       
   380 	void ConstructL();
       
   381 public:
       
   382 	/** The interface UID */
       
   383 	TUid		iInterfaceUid;
       
   384 	/** The implementations related to this interface */
       
   385 	RPointerArray<CImplementationData>* iImplementations;
       
   386 	/** Pointer to the parent DLL data */
       
   387 	CDllData* iParent;
       
   388 	};	// End CRegistryData::CInterfaceData
       
   389 
       
   390 /**
       
   391 @internalComponent
       
   392 */
       
   393 typedef RPointerArray<CRegistryData::CInterfaceData> RInterfaceList ;
       
   394 
       
   395 //
       
   396 // CRegistryData::CDllData class
       
   397 
       
   398 /**
       
   399 This class manages the entire data of a registered dll.
       
   400 @internalComponent
       
   401 */
       
   402 class CRegistryData::CDllData : public CBase
       
   403 	{
       
   404 public:
       
   405 	static CDllData* NewLC( CDriveData* iParent);//
       
   406 	static CDllData* NewLC(const TDesC& aDllName,const TTime& aDllModTime,const TUid& aSecondUid,const TUid& aThirdUid, CDriveData* iParent);
       
   407 	~CDllData();
       
   408 	void AddL(const CInterfaceData* aInterface);
       
   409 	void ExternalizeL(RWriteStream& aStore) const;
       
   410 	void InternalizeL(RReadStream& aStore);
       
   411 	void PopulateAnEntry(TEntry& aEntry) const;
       
   412 	TBool ProcessSecurityCheckL();
       
   413 	TBool SaveSecurityInfoL();
       
   414 	void SetResourceExtL(const TDesC& aExt);
       
   415 private:
       
   416 	CDllData( CDriveData* iParent);//
       
   417 	void ConstructL();//
       
   418 	/** See CDllData* NewLC */
       
   419 	void ConstructL(const TDesC& aDllName,const TTime& aDllModTime,const TUid& aSecondUid,const TUid& aThirdUid);
       
   420 
       
   421 public:
       
   422 	/** Information on the DLL */
       
   423 	CEComEntry* iDllEntry;
       
   424 	/** The list of interfaces within the dll */
       
   425 	RInterfaceList*	iIfList;
       
   426 	/** Capability set of this dll */
       
   427 	TCapabilitySet iCapSet;
       
   428 	/** A flag to tell if the DLL's security has been previously checked or not.*/
       
   429 	TBool iSecurityChecked;
       
   430 	/** A pointer to the parent drive data. */
       
   431 	CDriveData* iParent;
       
   432 	/** The VendorId of the DLL. */
       
   433 	TVendorId iVid;
       
   434 	/** The plugin resource file extension  - not set for plugins residing on RO Internal drives*/
       
   435 	HBufC* iRscFileExtension;
       
   436 	}; // End CRegistryData::CDllData
       
   437 
       
   438 /**
       
   439 @internalComponent
       
   440 */
       
   441 typedef RPointerArray<CRegistryData::CDllData> TDll ;
       
   442 
       
   443 //
       
   444 // CRegistryData::CDriveData class
       
   445 
       
   446 /**
       
   447 This class manages the entire data of a registered dll.
       
   448 */
       
   449 class CRegistryData::CDriveData : public CBase
       
   450 	{
       
   451 public:
       
   452 	static CDriveData* NewLC(TDriveUnit aDrive,CRegistryData* aParent);
       
   453 	~CDriveData();
       
   454 	void AddL(const CDllData* aDll);
       
   455 	void ExternalizeL(RFs& aFs,const TDesC& aDatFileName);
       
   456 	void InternalizeL(RFs& aFs,const TDesC& aDatFileName);
       
   457 	TInt FindDllIndex(const TUid aDllUid) const;
       
   458 private:
       
   459 	void DoInternalizeL(RFs& aFs, const TDesC& aFileName);
       
   460 	CDriveData(TDriveUnit aDrive,CRegistryData* aParent);
       
   461 	void ConstructL();
       
   462 
       
   463 public:
       
   464 	/** A reference to the drive. */
       
   465 	TDriveUnit	iDrive;
       
   466 	/** The list of Interface Implementation Collections upon the drive */
       
   467 	TDll*		iDllList;
       
   468 	/** The registry data. */
       
   469     CRegistryData* iParent;
       
   470     /**indicate the drive has change */
       
   471     TBool iDriveChanged;
       
   472     /**indiacate the registry data on the drive has changed */
       
   473     TBool iRegistryChanged;
       
   474 
       
   475 	}; // End CRegistryData::CDriveData
       
   476 
       
   477 void CRegistryData::TInterfaceIndex::Reset()
       
   478  	{
       
   479  	TInt count = iImpData.Count();
       
   480  	while(count > 0)
       
   481  		{
       
   482  		--count;
       
   483  		iImpData[count].Reset();
       
   484  		}
       
   485  	iImpData.Reset();
       
   486    	}
       
   487 
       
   488 void CRegistryData::TImplContainer::Reset()
       
   489  	{
       
   490  	iUnusedImpls.Reset();
       
   491    	}
       
   492 
       
   493 #endif //__REGISTRYDATA_H__