uitools_plat/cdl_api/inc/CdlCompilerToolkit/CdlTkInstance.h
changeset 0 f58d6ec98e88
equal deleted inserted replaced
-1:000000000000 0:f58d6ec98e88
       
     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 CDLTKINSTANCE_H
       
    18 #define CDLTKINSTANCE_H
       
    19 #pragma warning (disable:4786)	// disable "identifier was truncated to '255' characters in the browser information" warning
       
    20 
       
    21 #include <CdlCompilerToolkit/CdlTkInterface.h>
       
    22 #include <vector>
       
    23 #include <set>
       
    24 
       
    25 namespace CdlCompilerToolkit {
       
    26 
       
    27 class CCdlTkDll;
       
    28 class CCdlTkInstance;
       
    29 
       
    30 const int KCdlTkGetInstanceIdFromHostDll = -1;
       
    31 
       
    32 /**
       
    33 * The implementation of a single API from a CDL interface.
       
    34 */
       
    35 class CCdlTkImplementation
       
    36 	{
       
    37 public:
       
    38 	/**
       
    39     * constructor
       
    40     * @param aInstance the customisation instance to which this implementation belongs
       
    41 	* @param aApi the API that this implements
       
    42     */
       
    43 	CCdlTkImplementation(const CCdlTkInstance& aInstance, const CCdlTkApi& aApi);
       
    44 	/**
       
    45     * destructor
       
    46     */
       
    47 	~CCdlTkImplementation();
       
    48 
       
    49 	/**
       
    50     * Get the implementation's definition.
       
    51     * @return the implementation's definition.
       
    52     */
       
    53 	std::string Definition() const;
       
    54 	/**
       
    55     * Set the implementation's definition.
       
    56     * @param aDefn the implementation's definition.
       
    57     */
       
    58 	void SetDefinition(const std::string& aDefn);
       
    59 	/**
       
    60     * Set the implementation's definition to be that defined by the data type translations
       
    61 	* provided by the interface.
       
    62     */
       
    63 	void SetTemplateDefinition();
       
    64 	/**
       
    65     * Get a pointer reference for the implementation.
       
    66     * @return a pointer reference for the implementation.
       
    67     */
       
    68 	std::string PointerReference() const;
       
    69 	/**
       
    70     * Set a pointer reference for the implementation.
       
    71     * @param aPtr a pointer reference for the implementation.
       
    72     */
       
    73 	void SetPointerReference(const std::string& aPtr);
       
    74 	/**
       
    75     * Set the implementation's pointer reference to be that defined by the data type translations
       
    76 	* provided by the interface.
       
    77     */
       
    78 	void SetTemplatePointerReference();
       
    79 
       
    80 	/**
       
    81     * Set both the definition and pointer reference to be that defined by the data type 
       
    82 	* translations provided by the interface.
       
    83     */
       
    84 	void SetTemplate();
       
    85 	/**
       
    86     * Set an empty definition and NULL pointer reference
       
    87     */
       
    88 	void SetNull();
       
    89 
       
    90 	/**
       
    91     * Get the customisation instance to which this implementation belongs
       
    92     * @return the customisation instance to which this implementation belongs
       
    93     */
       
    94 	const CCdlTkInstance& Instance() const;
       
    95 	/**
       
    96     * Get the API which this implementation implements
       
    97     * @return the API which this implementation implements
       
    98     */
       
    99 	const CCdlTkApi& Api() const;
       
   100 	/**
       
   101     * Get the name of the implementation, which is also the name of API that this implements
       
   102     * @return the name of the implementation
       
   103     */
       
   104 	const std::string& Name() const;
       
   105 
       
   106 private:
       
   107 	const CCdlTkDataTypeTranslation* GetTranslation(const std::string& aType, std::string& aTypeVar);
       
   108 
       
   109 private:
       
   110 	const CCdlTkInstance& iInstance;
       
   111 	const CCdlTkApi& iApi;
       
   112 	std::string iDefn;
       
   113 	std::string iPtr;
       
   114 	};
       
   115 
       
   116 /**
       
   117 * A collection of implementations of the APIs in an API list. There is one implementation
       
   118 * for each API and they appear in the same order as the API list.
       
   119 */
       
   120 class CCdlTkImplementations
       
   121 	{
       
   122 private:
       
   123 	typedef std::vector<CCdlTkImplementation*> CImpl;
       
   124 
       
   125 public:
       
   126 	/**
       
   127     * constructor
       
   128     * @param aInstance the customisation instance to which these implementations belong
       
   129 	* @param aApiList the APIs that define what implementations appear in this collection
       
   130     */
       
   131 	CCdlTkImplementations(const CCdlTkInstance& aInstance, const CCdlTkApiList& aApiList);
       
   132 	/**
       
   133     * destructor
       
   134     */
       
   135 	~CCdlTkImplementations();
       
   136 
       
   137 	/**
       
   138     * Find an implementation by name
       
   139     * @param aName the name of the implemntation to find
       
   140     * @return the implmentation, or NULL if none is found
       
   141     */
       
   142 	CCdlTkImplementation* Find(const std::string& aName) const;
       
   143 	/**
       
   144     * Set all implementations to be null.
       
   145     */
       
   146 	void ClearAll();
       
   147 	/**
       
   148     * Set all implementations to have the template definition and pointer reference syntax
       
   149 	* defined by the data type translations from the interface.
       
   150     */
       
   151 	void TemplateAll();
       
   152 
       
   153 public:
       
   154 	// iterator interface
       
   155 	/**
       
   156     * The iterator type
       
   157     */
       
   158 	typedef CImpl::iterator iterator;
       
   159 	/**
       
   160     * The const iterator type
       
   161     */
       
   162 	typedef CImpl::const_iterator const_iterator;
       
   163 	/**
       
   164     * begin iterator
       
   165     */
       
   166 	iterator begin() { return iImpl.begin(); }
       
   167 	/**
       
   168     * begin iterator
       
   169     */
       
   170 	const_iterator begin() const { return iImpl.begin(); }
       
   171 	/**
       
   172     * end iterator
       
   173     */
       
   174 	iterator end() { return iImpl.end(); }
       
   175 	/**
       
   176     * end iterator
       
   177     */
       
   178 	const_iterator end() const { return iImpl.end(); }
       
   179 
       
   180 private:
       
   181 	CImpl iImpl;
       
   182 	};
       
   183 
       
   184 
       
   185 /**
       
   186 * a customisation instance
       
   187 */
       
   188 class CCdlTkInstance
       
   189 	{
       
   190 public:
       
   191 	/**
       
   192     * constructor
       
   193     * @param aInterface the CDL interface that this instance implements
       
   194     */
       
   195 	CCdlTkInstance(const CCdlTkInterface& aInterface);
       
   196 	/**
       
   197     * destructor
       
   198     */
       
   199 	~CCdlTkInstance();
       
   200 
       
   201 	/**
       
   202     * Get the implementations that make up this instance
       
   203     * @return the implementations that make up this instance
       
   204     */
       
   205 	CCdlTkImplementations& Impl();
       
   206 	/**
       
   207     * Get the implementations that make up this instance
       
   208     * @return the implementations that make up this instance
       
   209     */
       
   210 	const CCdlTkImplementations& Impl() const;
       
   211 	/**
       
   212     * Set all implementations to be null.
       
   213     */
       
   214 	void ClearAllImplementations();
       
   215 	/**
       
   216     * Set all implementations to have the template definition and pointer reference syntax
       
   217 	* defined by the data type translations from the interface.
       
   218     */
       
   219 	void TemplateAllImplementations();
       
   220 
       
   221 	/**
       
   222     * Set the name of this customisation instance
       
   223     * @param aName the name of this customisation instance
       
   224     */
       
   225 	void SetName(const std::string& aName);
       
   226 	/**
       
   227     * Get the name of this customisation instance
       
   228     * @return the name of this customisation instance
       
   229     */
       
   230 	const std::string& Name() const;
       
   231 	/**
       
   232     * Get an identifier for this customisation instance that its
       
   233 	* host DLL can use to identify it.
       
   234     * @return the fully qualified name of this customisation instance
       
   235     */
       
   236 	std::string DllInstanceName() const;
       
   237 	/**
       
   238     * Turn an instance name into an identifier that a DLL can use to set
       
   239 	* the instance id.
       
   240 	* @param aName the instance name
       
   241     * @return the DLL instance id string
       
   242     */
       
   243 	static std::string InstanceNameToDllInstanceName(const std::string& aName);
       
   244 
       
   245 	/**
       
   246     * Set the id of this customisation instance to be got from the host DLL. 
       
   247 	* The id is used to distinguish this instance from others in a customisation DLL.
       
   248 	* Getting the id from the host DLL optimised the lookup process.
       
   249 	* Note, the instance is automatically created with the this id. So, this
       
   250 	* function only needs to be used if the id has been previously set to another
       
   251 	* value.
       
   252     */
       
   253 	void SetId();
       
   254 	/**
       
   255     * Set the id of this customisation instance. 
       
   256 	* The id is used to distinguish this instance from others in a customisation DLL.
       
   257 	* This function does not generate as efficient code as SetId()
       
   258     * @param aId the id of this customisation instance
       
   259     */
       
   260 	void SetId(int aId);
       
   261 	/**
       
   262     * Get the id of this customisation instance. 
       
   263 	* The id is used to distinguish this instance
       
   264 	* from others in a customisation DLL.
       
   265     * @return the id of this customisation instance, which may be
       
   266 	* KCdlTkGetInstanceIdFromHostDll if the id is to come from the host DLL.
       
   267     */
       
   268 	int Id() const;
       
   269 
       
   270 	/**
       
   271     * Get the interface that this instance implements.
       
   272     * @return the interface that this instance implements.
       
   273     */
       
   274 	const CCdlTkInterface& Interface() const;
       
   275 
       
   276 	/**
       
   277     * Set the extra C++ section for this instance. This may add any extra C++ code required
       
   278 	* by the API implementations. For instance, helper functions or #includes
       
   279     * @param aExtra the extra C++ section for this instance
       
   280     */
       
   281 	void SetExtraCpp(const std::string& aExtra);
       
   282 	/**
       
   283     * Get the extra C++ section for this instance. This may be extra C++ code required
       
   284 	* by the API implementations. For instance, helper functions or #includes
       
   285     * @return the extra C++ section for this instance
       
   286     */
       
   287 	const std::string& ExtraCpp() const;
       
   288 
       
   289 private:
       
   290 	const CCdlTkInterface& iInterface;
       
   291 	CCdlTkImplementations iImpl;
       
   292 	std::string iName;
       
   293 	int iId;
       
   294 	std::string iExtraCpp;
       
   295 	};
       
   296 
       
   297 
       
   298 /**
       
   299 * A customisation instance that implements a CDL package interface.
       
   300 * a CDL package interface is one that contains the following API:
       
   301 *   TCdlArray<TCdlRef> contents;
       
   302 */
       
   303 class CCdlTkPackage : public CCdlTkInstance
       
   304 	{
       
   305 private:
       
   306 	class CRef
       
   307 		{
       
   308 	public:
       
   309 		CRef();
       
   310 		const std::string& LocalInstanceName() const;
       
   311 		void SetLocalInstanceName(const std::string& aLocalInstanceName);
       
   312 		int Id() const;
       
   313 		void SetId(int aId);
       
   314 		int Uid() const;
       
   315 		void SetUid(int aUid);
       
   316 		const std::string& DllName() const;
       
   317 		void SetDllName(const std::string& aDllName);
       
   318 		const std::string& DllSourcePath() const;
       
   319 		void SetDllSourcePath(const std::string& aDllSourcePath);
       
   320 		const std::string& DllInstName() const;
       
   321 		void SetDllInstName(const std::string& aDllInstName);
       
   322 
       
   323 	private:
       
   324 		std::string iLocalInstanceName;
       
   325 		int iId;
       
   326 		int iUid;
       
   327 		std::string iDllName;
       
   328 		std::string iDllSourcePath;
       
   329 		std::string iDllInstName;
       
   330 		};
       
   331 
       
   332 	typedef std::vector<CRef> CRefs;
       
   333 
       
   334 public:
       
   335 	/**
       
   336     * constructor
       
   337     * @param aInterface the CDL package interface that this package implements
       
   338     */
       
   339 	CCdlTkPackage(const CCdlTkInterface& aInterface);
       
   340 	/**
       
   341     * destructor
       
   342     */
       
   343 	~CCdlTkPackage();
       
   344 	
       
   345 	/**
       
   346     * Adds a customisation instance which will appear in the same DLL as this package
       
   347     * @param aInstance a customisation instance to be referenced by this package
       
   348     */
       
   349 	void AddLocalContent(const CCdlTkInstance& aInstance);
       
   350 	/**
       
   351     * Adds a customisation instance which will appear in the same DLL as this package
       
   352     * @param aLocalInstanceName a customisation instance name to be referenced by this package
       
   353     */
       
   354 	void AddLocalContent(const std::string& aLocalInstanceName);
       
   355 	/**
       
   356     * Adds a customisation instance which will appear in another DLL to this package
       
   357     * @param aInstance the instance to add to this package
       
   358 	* @param aDll the DLL that the instance appears in.
       
   359 	* @param aDllSourcePath the path to the source code for the DLL that 
       
   360 	* the instance appears in. This may be an empty string if the instance
       
   361 	* has an instance id other than KCdlTkGetInstanceIdFromHostDll, or if the
       
   362 	* instance appears in the same DLL as this package.
       
   363     */
       
   364 	void AddContent(const CCdlTkInstance& aInstance, const CCdlTkDll& aDll, const std::string& aDllSourcePath);
       
   365 	/**
       
   366     * Adds a customisation instance which may appear in another DLL to this package
       
   367     * @param aId the id of the customisation instance.
       
   368     * @param aUid the UID of the customisation instance's interface
       
   369     * @param aDllName the DLL in which the customisation instance appears. This may be
       
   370 	* an empty string if the instance appears in the same DLL as this package.
       
   371     */
       
   372 	void AddContent(int aId, int aUid, const std::string& aDllName);
       
   373 	/**
       
   374     * Adds a customisation instance which appears in another DLL created by the
       
   375 	* CDL compiler, and whose source is available.
       
   376     * @param aInstanceName the customisation instance name used in the other DLL
       
   377     * @param aDllSourcePath the path to the other DLLs source
       
   378     * @param aDllName the name of the other DLL
       
   379     */
       
   380 	void AddExternalContent(const std::string& aInstanceName, const std::string& aDllSourcePath, const std::string& aDllName);
       
   381 
       
   382 private:
       
   383 	const CRefs& Contents() const;
       
   384 	void GenerateImpl();
       
   385 	void AddIncludesAndBuildDllSet(std::string& aDefn, std::set<std::string>& aDllNames);
       
   386 	void AddDllNameLits(std::string& aDefn, std::set<std::string>& aDllNames);
       
   387 	void AddContents(std::string& aDefn);
       
   388 
       
   389 private:
       
   390 	CRefs iContents;
       
   391 	CCdlTkImplementation* iContentsImpl;	// not owned, can't be initialised until base class is constructed
       
   392 	};
       
   393 
       
   394 
       
   395 /**
       
   396 * a customisation DLLs contents and build information
       
   397 */
       
   398 class CCdlTkDll
       
   399 	{
       
   400 public:
       
   401 	/**
       
   402     * a collection of customisation instance names that will appear in the DLL
       
   403     */
       
   404 	typedef std::vector<std::string> CInstances;
       
   405 	/**
       
   406     * a collection of libraries that the DLL needs to link to
       
   407     */
       
   408 	typedef std::vector<std::string> CLibraries;
       
   409 
       
   410 public:
       
   411 	/**
       
   412     * constructor
       
   413     */
       
   414 	CCdlTkDll();
       
   415 	/**
       
   416     * destructor
       
   417     */
       
   418 	~CCdlTkDll();
       
   419 	
       
   420 	/**
       
   421     * Adds a customisation instance to the DLL
       
   422     * @param aInstance a customisation instance
       
   423     */
       
   424 	void AddInstance(const CCdlTkInstance& aInstance);
       
   425 	/**
       
   426     * Adds a customisation instance to the DLL
       
   427     * @param aInstanceName the name of a customisation instance
       
   428     */
       
   429 	void AddInstance(const std::string& aInstanceName);
       
   430 	/**
       
   431     * Gets the collection of customisation instances that appear in this DLL
       
   432     * @return the collection of customisation instances that appear in this DLL
       
   433     */
       
   434 	const CInstances& Instances() const;
       
   435 	
       
   436 	/**
       
   437     * Set the name of the DLL
       
   438     * @param aName the name of the DLL
       
   439     */
       
   440 	void SetName(const std::string& aName);
       
   441 	/**
       
   442     * Get the name of the DLL
       
   443     * @return the name of the DLL
       
   444     */
       
   445 	const std::string& Name() const;
       
   446 
       
   447 	/**
       
   448     * Set the UID of the DLL
       
   449     * @param aUid the UID of the DLL
       
   450     */
       
   451 	void SetUid(int aUid);
       
   452 	/**
       
   453     * Get the UID of the DLL
       
   454     * @return the UID of the DLL
       
   455     */
       
   456 	int Uid() const;
       
   457 
       
   458 	/**
       
   459     * Set the version of the DLL
       
   460     * @param aVersion the version number of the DLL
       
   461     */
       
   462 	void SetVersion(int aVersion);
       
   463 	/**
       
   464     * Get the version number of the DLL
       
   465     * @return the version number of the DLL
       
   466     */
       
   467 	int Version() const;
       
   468 
       
   469 	/**
       
   470     * Add a library name to the DLL
       
   471     * @param aLibName a library name
       
   472     */
       
   473 	void AddLibrary(const std::string& aLibName);
       
   474 	/**
       
   475     * Get the collection of libraries that this DLL links to
       
   476     * @return the collection of libraries that this DLL links to
       
   477     */
       
   478 	const CLibraries& Libraries() const;
       
   479 	/**
       
   480     * Get the collection of libraries that this DLL links to
       
   481     * @return the collection of libraries that this DLL links to
       
   482     */
       
   483 	CLibraries& Libraries();
       
   484 
       
   485 	/**
       
   486     * Set any extra MMP file content that the DLL needs
       
   487     * @param aExtraMmp extra MMP file content that the DLL needs
       
   488     */
       
   489 	void SetExtraMmp(const std::string& aExtraMmp);
       
   490 	/**
       
   491     * Get the extra MMP file content that has been set for the DLL
       
   492     * @return the extra MMP file content that has been set for the DLL
       
   493     */
       
   494 	const std::string& ExtraMmp() const;
       
   495 
       
   496 private:
       
   497 	std::string iName;
       
   498 	int iUid;
       
   499 	CInstances iInstances;
       
   500 	CLibraries iLibraries;
       
   501 	std::string iExtraMmp;
       
   502 	std::set<std::string> iUniqueInstances;
       
   503 	int iVersion;
       
   504 	};
       
   505 
       
   506 
       
   507 }	// end of namespace CdlCompilerToolkit
       
   508 
       
   509 #endif