cdlcompilertoolkit/src/CdlTkWriteDll.cpp
changeset 0 f58d6ec98e88
child 1 b700e12870ca
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 #pragma warning (disable:4786)	// disable "identifier was truncated to '255' characters in the browser information" warning
       
    18 #include "CdlCompilerToolkit/CdlTkProcess.h"
       
    19 #include "CdlTkPriv.h"
       
    20 #include <fstream>
       
    21 #include <iomanip>
       
    22 #include <iostream>
       
    23 #include <sstream>
       
    24 using namespace std;
       
    25 
       
    26 namespace CdlCompilerToolkit {
       
    27 
       
    28 CCdlTkWriteDll::CCdlTkWriteDll(const CCdlTkDll& aDll)
       
    29 : iDll(aDll)
       
    30 	{
       
    31 	}
       
    32 
       
    33 CCdlTkWriteDll::~CCdlTkWriteDll()
       
    34 	{
       
    35 	}
       
    36 
       
    37 void CCdlTkWriteDll::Process()
       
    38 	{
       
    39 	WriteBldInf();
       
    40 	WriteMmp();
       
    41 	WriteMainCpp();
       
    42 	WriteInstanceIdHeader();
       
    43 	WriteEcomRss();
       
    44 	WriteEcomDetailRss();
       
    45 	}
       
    46 
       
    47 
       
    48 //
       
    49 // BLD.INF
       
    50 //
       
    51 
       
    52 const string KBldInf = "\
       
    53 /*\n\
       
    54 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n\
       
    55 * All rights reserved.\n\
       
    56 * This component and the accompanying materials are made available\n\
       
    57 * under the terms of  \"Eclipse Public License v1.0\"\n\
       
    58 * which accompanies this distribution, and is available\n\
       
    59 * at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n\
       
    60 *\n\
       
    61 * Initial Contributors:\n\
       
    62 * Nokia Corporation - initial contribution.\n\
       
    63 *\n\
       
    64 * Contributors:\n\
       
    65 *\n\
       
    66 * Description:\n\
       
    67 *\n\
       
    68 */\n\n\
       
    69 // This file was generated by:\n\
       
    70 // $CMDLINE\n\
       
    71 // It lists the makefile for a customisation DLL.\n\
       
    72 // It may be modified manually.\n\
       
    73 \n\
       
    74 PRJ_MMPFILES\n\
       
    75 $MMP_NAME\n";
       
    76 
       
    77 void CCdlTkWriteDll::WriteBldInf() const
       
    78 	{
       
    79 	string name = CdlTkUtil::OutputPath() + "bld.inf";
       
    80 	ofstream stream;
       
    81 	CCdlTkFileCleanup tempFile;
       
    82 	CdlTkUtil::OpenTempOutput(stream, tempFile);
       
    83 	stream << 
       
    84 		CdlTkUtil::Replace("$CMDLINE", CdlTkUtil::CommandLine(),
       
    85 		CdlTkUtil::Replace("$MMP_NAME", CdlTkUtil::ToLower(CdlTkUtil::StripPath(iDll.Name()+".mmp")), KBldInf));
       
    86 	stream.close();
       
    87 	CdlTkUtil::ExportFileIfWritable(tempFile, name);
       
    88 	}
       
    89 
       
    90 
       
    91 //
       
    92 // MMP
       
    93 //
       
    94 
       
    95 const string KMmp = "\
       
    96 /*\n\
       
    97 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n\
       
    98 * All rights reserved.\n\
       
    99 * This component and the accompanying materials are made available\n\
       
   100 * under the terms of \"Eclipse Public License v1.0\"\n\
       
   101 * which accompanies this distribution, and is available\n\
       
   102 * at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n\
       
   103 *\n\
       
   104 * Initial Contributors:\n\
       
   105 * Nokia Corporation - initial contribution.\n\
       
   106 *\n\
       
   107 * Contributors:\n\
       
   108 *\n\
       
   109 * Description:\n\
       
   110 *\n\
       
   111 */\n\n\
       
   112 // This file was generated by:\n\
       
   113 // $CMDLINE\n\
       
   114 // It contains the project definition for a customisation DLL.\n\
       
   115 // It may be modified manually.\n\
       
   116 #include <platform_paths.hrh>\n\
       
   117 \n\
       
   118 target           $UID.dll\n\
       
   119 targettype		 PLUGIN\n\
       
   120 UID 			 0x10009D8D 0x$UID\n\
       
   121 CAPABILITY       CAP_ECOM_PLUGIN\n\
       
   122 VENDORID         VID_DEFAULT\n\
       
   123 \n\
       
   124 SOURCEPATH       .\n\
       
   125 userinclude      .\n\
       
   126 systeminclude    .\n\
       
   127 MW_LAYER_SYSTEMINCLUDE\n\
       
   128 \n\
       
   129 source           $DLL_SRC_NAME.cpp\n\
       
   130 $SOURCE\
       
   131 \n\
       
   132 library          euser.lib\n\
       
   133 $LIBRARIES\
       
   134 \n\
       
   135 START RESOURCE	 $UID.rss\n\
       
   136 TARGET       $UID.rsc\n\
       
   137 END\n\
       
   138 START RESOURCE   $UID_cdl_detail.rss\n\
       
   139 TARGETPATH       resource\\cdl\n\
       
   140 END\n\
       
   141 \n\
       
   142 $EXTRA";
       
   143 
       
   144 const string KMmpSourceLine = "source           $NAME.cpp\n";
       
   145 const string KMmpLibLine = "library          $NAME\n";
       
   146 
       
   147 void CCdlTkWriteDll::WriteMmp() const
       
   148 	{
       
   149 	string name = CdlTkUtil::ToLower(CdlTkUtil::OutputPath() + iDll.Name() + ".mmp");
       
   150 	ofstream stream;
       
   151 	CCdlTkFileCleanup tempFile;
       
   152 	CdlTkUtil::OpenTempOutput(stream, tempFile);
       
   153 
       
   154 	string source;
       
   155 	for (CCdlTkDll::CInstances::const_iterator pName = iDll.Instances().begin(); pName != iDll.Instances().end(); ++pName)
       
   156 		CdlTkUtil::AppendString(source, CdlTkUtil::Replace("$NAME", CdlTkUtil::CorrectFilenameCase(*pName), KMmpSourceLine));
       
   157 
       
   158 	string libraries;
       
   159 	for (CCdlTkDll::CLibraries::const_iterator pLib = iDll.Libraries().begin(); pLib != iDll.Libraries().end(); ++pLib)
       
   160 		CdlTkUtil::AppendString(libraries, CdlTkUtil::Replace("$NAME", *pLib, KMmpLibLine));
       
   161 
       
   162 	CdlTkUtil::CReplaceSet mmpSet;
       
   163 	mmpSet.Add("$DLL_NAME", iDll.Name());
       
   164 	mmpSet.Add("$DLL_SRC_NAME", CdlTkUtil::CorrectFilenameCase(iDll.Name()));
       
   165 	mmpSet.Add("$UID", CdlTkUtil::IntToHexString(iDll.Uid()).substr(2));
       
   166 	mmpSet.Add("$SOURCE", source);
       
   167 	mmpSet.Add("$LIBRARIES", libraries);
       
   168 	mmpSet.Add("$EXTRA", iDll.ExtraMmp());
       
   169 	mmpSet.Add("$CMDLINE", CdlTkUtil::CommandLine());
       
   170 	string mmp = CdlTkUtil::MultiReplace(mmpSet, KMmp);
       
   171 
       
   172 	stream << mmp;
       
   173 	stream.close();
       
   174 
       
   175 	CdlTkUtil::ExportFileIfWritable(tempFile, name);
       
   176 	}
       
   177 
       
   178 
       
   179 //
       
   180 // CPP
       
   181 //
       
   182 
       
   183 const string KMainCpp = "\
       
   184 /*\n\
       
   185 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n\
       
   186 * All rights reserved.\n\
       
   187 * This component and the accompanying materials are made available\n\
       
   188 * under the terms of \"Eclipse Public License v1.0\"\n\
       
   189 * which accompanies this distribution, and is available\n\
       
   190 * at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n\
       
   191 *\n\
       
   192 * Initial Contributors:\n\
       
   193 * Nokia Corporation - initial contribution.\n\
       
   194 *\n\
       
   195 * Contributors:\n\
       
   196 *\n\
       
   197 * Description:\n\
       
   198 *\n\
       
   199 */\n\n\
       
   200 // This file was generated by:\n\
       
   201 // $CMDLINE\n\
       
   202 // This is the main source file for a customisation DLL.\n\
       
   203 // It may be modified manually.\n\
       
   204 \n\
       
   205 $INCLUDES\
       
   206 \n\
       
   207 CDL_ARRAY_START(SCdlCustomisation, KCdlData)\n\
       
   208 \t{\n\
       
   209 $INSTANCES\
       
   210 \t}\n\
       
   211 CDL_ARRAY_END(SCdlCustomisation, KCdlData);\n\
       
   212 \n\
       
   213 GLREF_D const SCdlMain KCdlMainExport =\n\
       
   214 \t{\n\
       
   215 \t$MAJOR_VER,\n\
       
   216 \t$MINOR_VER,\n\
       
   217 \t&KCdlData\n\
       
   218 \t};\n\
       
   219 \n\
       
   220 #include <ecom/ecom.h>\n\
       
   221 #include <ecom/implementationproxy.h>\n\
       
   222 \n\
       
   223 static TAny* MainExport()\n\
       
   224 	{\n\
       
   225 	return (TAny*)&KCdlMainExport;\n\
       
   226 	}\n\
       
   227 \n\
       
   228 const TImplementationProxy ImplementationTable[] =\n\
       
   229 	{\n\
       
   230 		{{$DLLUID}, ::MainExport}\n\
       
   231 	};\n\
       
   232 \n\
       
   233 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)\n\
       
   234 	{\n\
       
   235 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);\n\
       
   236 	return ImplementationTable;\n\
       
   237 	}\n\
       
   238 \n\
       
   239 \n";
       
   240 
       
   241 string KMainCppInclude = "#include \"$NAME.h\"\n";
       
   242 string KMainCppInstance = "\t\tCDL_CUSTOMISATION($CPP_NAME),\n";
       
   243 
       
   244 void CCdlTkWriteDll::WriteMainCpp() const
       
   245 	{
       
   246 	string name = CdlTkUtil::CorrectFilenameCase(CdlTkUtil::OutputPath() + iDll.Name() + ".cpp");
       
   247 	ofstream stream;
       
   248 	CCdlTkFileCleanup tempFile;
       
   249 	CdlTkUtil::OpenTempOutput(stream, tempFile);
       
   250 
       
   251 	string includes;
       
   252 	string instances;
       
   253 	for (CCdlTkDll::CInstances::const_iterator pName = iDll.Instances().begin(); pName != iDll.Instances().end(); ++pName)
       
   254 		{
       
   255 		CdlTkUtil::AppendString(includes, CdlTkUtil::Replace("$NAME", CdlTkUtil::ToLower(*pName), KMainCppInclude));
       
   256 		CdlTkUtil::AppendString(instances, CdlTkUtil::Replace("$CPP_NAME", CdlTkUtil::ToCpp(*pName), KMainCppInstance));
       
   257 		}
       
   258 
       
   259 	stringstream majorVer;
       
   260 	majorVer << KCdlCompilerMajorVersion;
       
   261 
       
   262 	stringstream minorVer;
       
   263 	minorVer << KCdlCompilerMinorVersion;
       
   264 
       
   265 	CdlTkUtil::CReplaceSet cppSet;
       
   266 	cppSet.Add("$MAJOR_VER", majorVer.str());
       
   267 	cppSet.Add("$MINOR_VER", minorVer.str());
       
   268 	cppSet.Add("$INCLUDES", includes);
       
   269 	cppSet.Add("$INSTANCES", instances);
       
   270 	cppSet.Add("$CMDLINE", CdlTkUtil::CommandLine());
       
   271 	cppSet.Add("$DLLUID", CdlTkUtil::IntToHexString(iDll.Uid()));
       
   272 	string cpp = CdlTkUtil::MultiReplace(cppSet, KMainCpp);
       
   273 
       
   274 	stream << cpp;
       
   275 	stream.close();
       
   276 
       
   277 	CdlTkUtil::ExportFileIfWritable(tempFile, name);
       
   278 	}
       
   279 
       
   280 //
       
   281 // Instance ID Header
       
   282 //
       
   283 
       
   284 const string KInstHeaderBody = "\
       
   285 /*\n\
       
   286 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n\
       
   287 * All rights reserved.\n\
       
   288 * This component and the accompanying materials are made available\n\
       
   289 * under the terms of \"Eclipse Public License v1.0\"\n\
       
   290 * which accompanies this distribution, and is available\n\
       
   291 * at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n\
       
   292 *\n\
       
   293 * Initial Contributors:\n\
       
   294 * Nokia Corporation - initial contribution.\n\
       
   295 *\n\
       
   296 * Contributors:\n\
       
   297 *\n\
       
   298 * Description:\n\
       
   299 *\n\
       
   300 */\n\n\
       
   301 // Header file for automatic instance id assignment for $DLL_NAME, generated by:\n\
       
   302 // $CMDLINE\n\
       
   303 #ifndef $DLL_NAME_INST_IDS\n\
       
   304 #define $DLL_NAME_INST_IDS\n\
       
   305 \n\
       
   306 $IDS\
       
   307 \n\
       
   308 #endif\n";
       
   309 
       
   310 const string KInstHeaderId = "#define $ID $NUM\n";
       
   311 
       
   312 void CCdlTkWriteDll::WriteInstanceIdHeader() const
       
   313 	{
       
   314 	string name = CdlTkUtil::ToLower(CdlTkUtil::OutputPath() + KDllInstHeader);
       
   315 	ofstream stream;
       
   316 	CCdlTkFileCleanup tempFile;
       
   317 	CdlTkUtil::OpenTempOutput(stream, tempFile);
       
   318 
       
   319 	int num = 0;
       
   320 	string ids;
       
   321 	for (CCdlTkDll::CInstances::const_iterator pName = iDll.Instances().begin(); pName != iDll.Instances().end(); ++pName)
       
   322 		{
       
   323 		string name = CCdlTkInstance::InstanceNameToDllInstanceName(*pName);
       
   324 		string id = CdlTkUtil::Replace("$ID", name, KInstHeaderId);
       
   325 		id = CdlTkUtil::Replace("$NUM", CdlTkUtil::IntToHexString(num), id);
       
   326 		CdlTkUtil::AppendString(ids, id);
       
   327 		num++;
       
   328 		}
       
   329 
       
   330 	CdlTkUtil::CReplaceSet headerSet;
       
   331 	headerSet.Add("$DLL_NAME", iDll.Name());
       
   332 	headerSet.Add("$IDS", ids);
       
   333 	headerSet.Add("$CMDLINE", CdlTkUtil::CommandLine());
       
   334 	string header = CdlTkUtil::MultiReplace(headerSet, KInstHeaderBody);
       
   335 
       
   336 	stream << header;
       
   337 	stream.close();
       
   338 
       
   339 	CdlTkUtil::ExportFileIfWritable(tempFile, name);
       
   340 	}
       
   341 
       
   342 const string KEComRss = "\
       
   343 /*\n\
       
   344 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n\
       
   345 * All rights reserved.\n\
       
   346 * This component and the accompanying materials are made available\n\
       
   347 * under the terms of \"Eclipse Public License v1.0\"\n\
       
   348 * which accompanies this distribution, and is available\n\
       
   349 * at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n\
       
   350 *\n\
       
   351 * Initial Contributors:\n\
       
   352 * Nokia Corporation - initial contribution.\n\
       
   353 *\n\
       
   354 * Contributors:\n\
       
   355 *\n\
       
   356 * Description:\n\
       
   357 *\n\
       
   358 */\n\n\
       
   359 #include <ecom/registryinfo.rh>\n\
       
   360 #include <cdlecom.hrh>\n\
       
   361 \n\
       
   362 CDL_ECOM_MAIN_REG_WITH_VERSION(0x$DLLUID, $DLLVER)\n";
       
   363 
       
   364 void CCdlTkWriteDll::WriteEcomRss() const
       
   365 	{
       
   366 	string dllUid = CdlTkUtil::IntToHexString(iDll.Uid()).substr(2);
       
   367 	string dllVer = CdlTkUtil::IntToString(iDll.Version());
       
   368 	string name = CdlTkUtil::ToLower(CdlTkUtil::OutputPath() + dllUid + ".rss");
       
   369 	ofstream stream;
       
   370 	CCdlTkFileCleanup tempFile;
       
   371 	CdlTkUtil::OpenTempOutput(stream, tempFile);
       
   372 
       
   373 	CdlTkUtil::CReplaceSet rssSet;
       
   374 	rssSet.Add("$DLLUID", dllUid);
       
   375 	rssSet.Add("$DLLVER", dllVer);
       
   376 	string rss = CdlTkUtil::MultiReplace(rssSet, KEComRss);
       
   377 
       
   378 	stream << rss;
       
   379 	stream.close();
       
   380 
       
   381 	CdlTkUtil::ExportFileIfWritable(tempFile, name);
       
   382 	}
       
   383 
       
   384 const string KEComDetailRss = "\
       
   385 /*\n\
       
   386 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n\
       
   387 * All rights reserved.\n\
       
   388 * This component and the accompanying materials are made available\n\
       
   389 * under the terms of \"Eclipse Public License v1.0\"\n\
       
   390 * which accompanies this distribution, and is available\n\
       
   391 * at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n\
       
   392 *\n\
       
   393 * Initial Contributors:\n\
       
   394 * Nokia Corporation - initial contribution.\n\
       
   395 *\n\
       
   396 * Contributors:\n\
       
   397 *\n\
       
   398 * Description:\n\
       
   399 *\n\
       
   400 */\n\n\
       
   401 #include <cdlecom.rh>\n\
       
   402 #include <cdlecom.hrh>\n\
       
   403 \n\
       
   404 $INCLUDES\
       
   405 \n\
       
   406 CDL_ECOM_REG_DETAIL_START\n\
       
   407 $INSTANCES\
       
   408 CDL_ECOM_REG_DETAIL_END\n";
       
   409 
       
   410 string KDetailRssInclude = "#include \"$NAME.hrh\"\n";
       
   411 string KDetailRssInstance = "\tCDL_ECOM_DETAIL_IMPL($CPP_NAME)\n";
       
   412 
       
   413 void CCdlTkWriteDll::WriteEcomDetailRss() const
       
   414 	{
       
   415 	string dllUid = CdlTkUtil::IntToHexString(iDll.Uid()).substr(2);
       
   416 	string name = CdlTkUtil::ToLower(CdlTkUtil::OutputPath() + dllUid + "_cdl_detail.rss");
       
   417 	ofstream stream;
       
   418 	CCdlTkFileCleanup tempFile;
       
   419 	CdlTkUtil::OpenTempOutput(stream, tempFile);
       
   420 
       
   421 	string includes;
       
   422 	string instances;
       
   423 	CCdlTkDll::CInstances::const_iterator begin = iDll.Instances().begin();
       
   424 	for (CCdlTkDll::CInstances::const_iterator pName = begin; pName != iDll.Instances().end(); ++pName)
       
   425 		{
       
   426 		string instance = (pName != begin) ? "," : "";
       
   427 		instance += CdlTkUtil::Replace("$CPP_NAME", CdlTkUtil::ToCpp(*pName), KDetailRssInstance);
       
   428 		CdlTkUtil::AppendString(instances, instance);
       
   429 		CdlTkUtil::AppendString(includes, CdlTkUtil::Replace("$NAME", CdlTkUtil::ToLower(*pName), KDetailRssInclude));
       
   430 		}
       
   431 
       
   432 	CdlTkUtil::CReplaceSet rssSet;
       
   433 	rssSet.Add("$INCLUDES", includes);
       
   434 	rssSet.Add("$INSTANCES", instances);
       
   435 	string rss = CdlTkUtil::MultiReplace(rssSet, KEComDetailRss);
       
   436 
       
   437 	stream << rss;
       
   438 	stream.close();
       
   439 
       
   440 	CdlTkUtil::ExportFileIfWritable(tempFile, name);
       
   441 	}
       
   442 
       
   443 }	// end of namespace CdlCompilerToolkit