layouts/cdl/CdlEngine/inc/CCdlEngine.h
changeset 0 05e9090e2422
child 54 08459e712984
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 #ifndef CCDLENGINE_H
       
    18 #define CCDLENGINE_H
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <e32hashtab.h>
       
    22 #include "CdlLibrary.h"
       
    23 #include "CdlCustomisation.h"
       
    24 #include "CdlClient.h"
       
    25 #include "CdlRefs.h"
       
    26 #include "CdlChangeObserver.h"
       
    27 #include "CdlPanic.h"
       
    28 
       
    29 class CCdlEngine;
       
    30 
       
    31 /**
       
    32 * Utility functions for importing and exporting descriptors
       
    33 */
       
    34 class CdlUtils
       
    35 	{
       
    36 public:
       
    37 	/**
       
    38 	* Copy aLen bytes of data from aBuf to aData and move aBuf on.
       
    39 	*/
       
    40 	static void Extract(TPtrC8& aBuf, TDes8& aData, TInt aLen);
       
    41 
       
    42 	/**
       
    43 	* Add aText to aBuf, growing aBuf exponentially as necessary.
       
    44 	* This exponential growth waste on average 1/3 extra space, but it reduces run time
       
    45 	* from O(n^2) to O(nLog(n))
       
    46 	* This function assumes aBuf is on top of the cleanup stack. The LDC ending means
       
    47 	* that it may leave, it may destroy the object on the cleanup stack and it may
       
    48 	* place a new object on the cleanup stack.
       
    49 	*/
       
    50 	static void AppendLDC(HBufC8*& aBuf, const TDesC8& aText);
       
    51 	
       
    52 	/**
       
    53 	* Templated function for extracting T-classes from a descriptor, using TPckg.
       
    54 	*/
       
    55 	template<class T>
       
    56 	inline static void Extract(TPtrC8& aBuf, T& aData)
       
    57 		{ TPckg<T> pckg(aData); Extract(aBuf, pckg, pckg.MaxLength()); }
       
    58 	};
       
    59 
       
    60 /**
       
    61 * CDL engine base class.
       
    62 * This has the reference counting and library manager functionality.
       
    63 * The CDL server uses this class to provide the engine functionality it needs.
       
    64 */
       
    65 NONSHARABLE_CLASS(CCdlEngineBase) : public CBase
       
    66 	{
       
    67 public:
       
    68 	static CCdlEngineBase* Static();
       
    69 	static CCdlEngineBase* NewLC();
       
    70 	static CCdlEngineBase* InstanceLC(TBool& aPushed);
       
    71 
       
    72 	~CCdlEngineBase();
       
    73 	void IncRefCount();
       
    74 	void DecRefCount();
       
    75 
       
    76 	virtual CCdlRefCollection* FileContentsLC(const TDesC& aLibName);
       
    77 	CCdlLibManager* LibMan() const;
       
    78 	virtual TInt IsPluginInRom(const TDesC& aFileName, TBool& aIsInRom) const;
       
    79 	virtual TInt PluginDrive(const TDesC& aFileName, TDriveUnit& aDrive) const;
       
    80 
       
    81 protected:
       
    82 	CCdlEngineBase();
       
    83 	void ConstructL();
       
    84 
       
    85 private:
       
    86 	TInt iRefCount;
       
    87 	CCdlLibManager* iLibMan;		// owned
       
    88 	};
       
    89 
       
    90 /**
       
    91 * The client side CDL engine.
       
    92 * This adds all the customisation management functionality over the base class.
       
    93 */
       
    94 NONSHARABLE_CLASS(CCdlEngine) : public CCdlEngineBase
       
    95 	{
       
    96 public:
       
    97 	static CCdlEngine* Static();
       
    98 	static CCdlEngine* NewLC();
       
    99 	static CCdlEngine* InstanceLC(TBool& aPushed);
       
   100 	static CCdlEngine& Instance();
       
   101 
       
   102 	~CCdlEngine();
       
   103 
       
   104 	TAny* GetData(TUid aCdlUid, TInt aApiId) const;
       
   105 	TCdlEngineFunc* GetFunction(TUid aCdlUid, TInt aApiId) const;
       
   106 
       
   107 	void RequireCustomisationL(const SCdlInterface* aInterfaceParams);
       
   108 	void LoadCustomisationL(const TCdlRef& aRef);
       
   109 	TBool IsCustomisationStarted(const SCdlInterface* aInterfaceParams) const;
       
   110 
       
   111 	const CCdlInstance& CustomisationInstance(TUid aCdlUid) const;
       
   112 	const TCdlRef& LastAccessedRef(TUid aCdlUid) const;
       
   113 	void FileNameRelativeToLastAccessedInstance(TUid aCdlUid, TFileName& aFileName) const;
       
   114 	TInt LastApiId() const;
       
   115 	inline void SetLastApiId(TInt aLastApiId) const;
       
   116 
       
   117 	CCdlRefs* FindInstancesLC(TUid aCdlUid) const;
       
   118 	CCdlNames* FindCustomisationFilesLC() const;
       
   119 	CCdlRefs* AllAvailableRefsLC() const;
       
   120 	TInt* LastApiRefL(TUid aCdlUid);
       
   121 
       
   122 	void SetLocalStateL(const CCdlRefs& aState);
       
   123 	void SetGlobalStateL(const CCdlRefs& aState);
       
   124 	CCdlRefs* LocalStateLC(const CCdlUids& aCdlUids) const;
       
   125 	CCdlRefs* GlobalStateLC(const CCdlUids& aCdlUids) const;
       
   126 
       
   127 	void EnableGlobalCustomisationL(const CCdlUids& aCdlUids, TBool aEnabled);
       
   128 	void StartGlobalCustomisationL();
       
   129 	
       
   130 	void AddCustomisationChangeObserverL(MCdlChangeObserver* aObserver, TUid aUid);
       
   131 	void AddGeneralChangeObserverL(MCdlChangeObserver* aObserver);
       
   132 	void RemoveChangeObserver(MCdlChangeObserver* aObserver);
       
   133 
       
   134 	void HandleGlobalCustomisationChangeL(TInt aSize);
       
   135 	void HandleAvailableRefsChangeL();
       
   136 
       
   137 	
       
   138 	// from CCdlEngineBase
       
   139 	virtual CCdlRefCollection* FileContentsLC(const TDesC& aLibName);
       
   140 	virtual TInt IsPluginInRom(const TDesC& aFileName, TBool& aIsInRom) const;
       
   141 	virtual TInt PluginDrive(const TDesC& aFileName, TDriveUnit& aDrive) const;
       
   142 
       
   143 private:
       
   144 	CCdlEngine();
       
   145 	void ConstructL();
       
   146 
       
   147 	CCdlCustomisationStack* Lookup(TUid aCdlUid) const;
       
   148 	CCdlCustomisationStack& LookupP(TUid aCdlUid) const;
       
   149 	CCdlRefs* GlobalStateLC(TInt aSize) const;
       
   150 	void DoSetLocalStateL(const CCdlRefs& aState, CCdlUids& aChangedUids);
       
   151 	CCdlCustomisationStack* LookupOrCreateL(TUid aCdlUid);
       
   152 	const CCdlInstance* LastAccessedInstance(TUid aCdlUid) const;
       
   153 	void AddLocalStateToRefs(TUid aUid, CCdlRefs* aState) const;
       
   154 
       
   155 private:
       
   156 	friend class CdlEngine;	// for optimised GetFunction()
       
   157 	typedef RHashMap<TUint32, CCdlCustomisationStack*> CCdlCustomisations;
       
   158 	CCdlCustomisations iCustomisations;			// contained CCdlCustomisationStacks are owned
       
   159 	//mutable CCdlCustomisationStack* iLastStack;	// not owned thru this pointer
       
   160 	RCdlSession iServer;
       
   161 	CCdlUids iGloballyCustomised;
       
   162 	CCdlChangeMonitor* iChangeMonitor;			// owned
       
   163 	CCdlChangeObservers iObservers;
       
   164 	//CCdlCustomisationStack** iBeginCust;
       
   165 	//CCdlCustomisationStack** iEndCust;
       
   166 	mutable TInt iLastApiId;
       
   167 	};
       
   168 
       
   169 
       
   170 /**
       
   171 * Wrapper around a CDL DLL, to access it's contents as a CCdlRefCollection
       
   172 */
       
   173 NONSHARABLE_CLASS(CCdlLibraryContentsImp) : public CCdlRefCollection
       
   174 	{
       
   175 public:
       
   176 	static CCdlLibraryContentsImp* NewLC(const TDesC& aLibName, CCdlEngineBase* aEngine);
       
   177 	~CCdlLibraryContentsImp();
       
   178 
       
   179 	TInt CountRefs() const;
       
   180 	TCdlRef Ref(TInt aIndex) const;
       
   181 
       
   182 private:
       
   183 	void ConstructL(CCdlEngineBase* aEngine, const TDesC& aLibName);
       
   184 
       
   185 private:
       
   186 	RCdlLibRef iLib;
       
   187 	TCdlArray<SCdlCustomisation> iContent;
       
   188 	};
       
   189 
       
   190 
       
   191 void CCdlEngine::SetLastApiId(TInt aLastApiId) const
       
   192 	{
       
   193 	iLastApiId = aLastApiId;
       
   194 	}
       
   195 
       
   196 #endif