uiresources_plat/cdl_api/inc/CdlExplorer.h
changeset 0 05e9090e2422
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 CDLPACKAGEEXPLORER_H
       
    18 #define CDLPACKAGEEXPLORER_H
       
    19 
       
    20 #include <CdlEngine.h>
       
    21 
       
    22 class CCdlRefs;
       
    23 
       
    24 /**
       
    25 * Enumeration used to indicate the result of comparing two customisation instances
       
    26 */
       
    27 enum TCdlInstanceComparison
       
    28 	{
       
    29 	ECdlInstancesNotComparable,
       
    30 	EFirstCdlInstanceBetter,
       
    31 	ESecondCdlInstanceBetter
       
    32 	};
       
    33 
       
    34 
       
    35 /**
       
    36 * Utilities for the CDL explorer system
       
    37 */
       
    38 class CdlExplorerUtils
       
    39 	{
       
    40 public:
       
    41 	/**
       
    42 	* Create a CCdlRefs containing a single reference to the instance passed in.
       
    43 	* @param aSingleInstance an instance whose reference will appear in the collection.
       
    44 	* @return a CCdlRefs containing a single reference to the instance passed in.
       
    45 	*/
       
    46 	IMPORT_C static CCdlRefs* CreateRefsLC(const CCdlInstance& aSingleInstance);
       
    47 	/**
       
    48 	* Create a CCdlRefs containing a collection of references which have come from a
       
    49 	* customisation instance. If any of the references do not give a DLL name, they take
       
    50 	* their DLL name from the instance provided.
       
    51 	* @param aHomeInstance a customisation instance which has provided the array of references
       
    52 	* @param aRefs a collection of references.
       
    53 	* @return a CCdlRefs containing the references supplied.
       
    54 	*/
       
    55 	IMPORT_C static CCdlRefs* CreateRefsLC(const CCdlInstance& aHomeInstance, const TCdlArray<TCdlRef>& aRefs);
       
    56 	};
       
    57 
       
    58 
       
    59 /**
       
    60 * Base class for CDL explorer classes. Has functionality for finding instances.
       
    61 */
       
    62 class CCdlInstanceExplorerBase : public CBase
       
    63 	{
       
    64 public:
       
    65 	/**
       
    66 	* destructor
       
    67 	*/
       
    68 	IMPORT_C ~CCdlInstanceExplorerBase();
       
    69 
       
    70 protected:
       
    71 	/**
       
    72 	* Finds customisation instances that implement a particular interface. The returned set is
       
    73 	* filtered so that invalid and less good instances are removed.
       
    74 	* @param aCdlUid the CDL interfaces UID to look for.
       
    75 	* @return An array of instances that implement the specified interface.
       
    76 	*/
       
    77 	IMPORT_C CArrayPtr<CCdlInstance>* FindLC(TUid aCdlUid);
       
    78 
       
    79 private:
       
    80 	void TryAddL(const TCdlRef& aRef, const CCdlInstance* aSubLayer, CArrayPtr<CCdlInstance>* aInstances);
       
    81 
       
    82 private:
       
    83 	virtual CCdlInstance* CreateInstanceLC(const TCdlRef& aRef, const CCdlInstance* aSubLayer) = 0;
       
    84 	virtual TCdlInstanceComparison CallCompare(const CCdlInstance& aFirst, const CCdlInstance& aSecond) const = 0;
       
    85 	virtual TBool CallIsValid(const CCdlInstance& aInstance) const = 0;
       
    86 
       
    87 private:
       
    88 	CCdlInstance* iSubLayer;		// owned, used as a sub-layer for all returned instances
       
    89 	};
       
    90 
       
    91 
       
    92 /**
       
    93 * Template class for creating explorers for specific CDL interfaces.
       
    94 * The template parameter must be the CInstance class from a particular CDL interfaces namespace.
       
    95 * This class uses inline virtual functions, which could result in a lot of code duplication
       
    96 * if instantiated in a public header. Therefore, this class should only ever be derived from and
       
    97 * instantiated inside a .cpp file where it is needed.
       
    98 */
       
    99 template<class T>
       
   100 class CCdlInstanceExplorer : public CCdlInstanceExplorerBase
       
   101 	{
       
   102 public:
       
   103 	/**
       
   104 	* Finds customisation instances of the type that this class is instantiated with.
       
   105 	* The returned set is filtered so that invalid and less good instances are removed.
       
   106 	* @return An array of instances of the type that this class is instantiated with.
       
   107 	*/
       
   108 	inline CArrayPtr<T>* FindLC();
       
   109 
       
   110 private:
       
   111 	inline CCdlInstance* CreateInstanceLC(const TCdlRef& aRef, const CCdlInstance* aSubLayer);
       
   112 	inline TCdlInstanceComparison CallCompare(const CCdlInstance& aFirst, const CCdlInstance& aSecond) const;
       
   113 	inline TBool CallIsValid(const CCdlInstance& aPackage) const;
       
   114 
       
   115 protected:	// These functions can be overridden to specialise explorer behavior
       
   116 	/**
       
   117 	* Virtual function for comparing two instances.
       
   118 	* Instances are comparable if they are alternative versions of the same implementation.
       
   119 	* Eg for different languages.
       
   120 	* If the instances are not related, they are not comparable.
       
   121 	* Compare should favor aFirst in case of a tie.
       
   122 	* @param aFirst The first instance to compare.
       
   123 	* @param aFirst The second instance to compare.
       
   124 	* @return The result of the comparison
       
   125 	*/
       
   126 	inline virtual TCdlInstanceComparison Compare(const T& aFirst, const T& aSecond) const;
       
   127 	/**
       
   128 	* Virtual function for checking the validity of an instance.
       
   129 	* Instantiations of the instance explorer may want to overide this to check that 
       
   130 	* instances meet certain requirements.
       
   131 	* @param aInstance The instance to check validity on
       
   132 	* @return ETrue if valid
       
   133 	*/
       
   134 	inline virtual TBool IsValid(const T& aInstance) const;
       
   135 	};
       
   136 
       
   137 
       
   138 /**
       
   139 *  Explorer class with added functionality for packages.
       
   140 */
       
   141 template<class T>
       
   142 class CCdlPackageExplorer : public CCdlInstanceExplorer<T>
       
   143 	{
       
   144 public:
       
   145 	/**
       
   146 	* Extracts the contents of a package into a CCdlRefs collection
       
   147 	* @param aPackage the package whose contents require extraction
       
   148 	* @return a CCdlRefs containing the contents of the package.
       
   149 	*/
       
   150 	inline CCdlRefs* CreateRefsLC(const T& aPackage);
       
   151 	};
       
   152 
       
   153 
       
   154 #include <CdlExplorer.inl>
       
   155 
       
   156 #endif