qtecomplugins/xqecom/main.cpp
changeset 8 71781823f776
parent 5 453da2cfceef
child 11 06b8e2af4411
equal deleted inserted replaced
5:453da2cfceef 8:71781823f776
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 * 
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not, 
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
       
    19 *
       
    20 */
       
    21 
       
    22 #include <QString>
       
    23 #include <QStringList>
       
    24 #include <QFile>
       
    25 #include <QIODevice>
       
    26 #include <QTextStream>
       
    27 #include <QDateTime>
       
    28 #include <QFileInfo>
       
    29 
       
    30 #define IMPLEMENTATION_UID_LIT "KQtEcomPluginImplementationUid"
       
    31 
       
    32 void runRSSFileGenerator(QStringList params)
       
    33 {
       
    34     QString appName = params[1];
       
    35 	QString uid3 = params[2];
       
    36 	QString interfacename = params[3];
       
    37 	QString configuration = params[4];
       
    38 	QString configurationFile = params[5];
       
    39 	
       
    40 	QString rssFilename = appName;
       
    41     rssFilename.append(QString::fromLatin1(".rss"));
       
    42 
       
    43     QFile ft(rssFilename);
       
    44 	if(!ft.exists()){
       
    45 		if(ft.open(QIODevice::WriteOnly)) {
       
    46 			QTextStream t(&ft);
       
    47 
       
    48 			t << "// ==============================================================================" << endl;
       
    49 	        t << "// Generated by xqecom on " << QDateTime::currentDateTime().toString() << endl;
       
    50 	        t << "// This file is generated by xqecom and should not be modified by the user." << endl;
       
    51 			t << "//  Name        : " << rssFilename << endl;
       
    52 			t << "//  Part of     : " << endl;
       
    53 			t << "//  Description : Fixes common plugin symbols to known ordinals" << endl;
       
    54 			t << "//  Version     : " << endl;
       
    55 			t << "//" << endl;
       
    56 			t << "// ==============================================================================" << "\n" << endl;
       
    57 			t << endl;
       
    58 
       
    59 	        if (interfacename.isEmpty()) {
       
    60 	            interfacename = QString(appName).append(QString::fromLatin1(".dll"));
       
    61 	        }
       
    62 			
       
    63 	        QTextStream configStream;
       
    64 	        QFile cfgFile;
       
    65 			
       
    66 			if (!configurationFile.isEmpty()) {
       
    67 				cfgFile.setFileName(configurationFile);
       
    68 				if (cfgFile.open(QIODevice::ReadOnly)) {
       
    69 					configStream.setDevice( &cfgFile );
       
    70 				} else {
       
    71 					printf("Not generated: ");
       
    72 					printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
    73 					printf(" - Cannot open file: %s\n", configurationFile.toLocal8Bit().data());						
       
    74 					ft.remove();
       
    75 					return;
       
    76 				}
       
    77 	        } else {
       
    78 				configStream.setString( &configuration, QIODevice::ReadOnly );
       
    79 	        }
       
    80 
       
    81 			
       
    82 	        t << "#include <registryinfov2.rh>" << endl << endl;
       
    83 	        t << "#include <xqtecom.hrh>" << endl << endl;
       
    84 	        t << "#include <ecomstub_" << uid3 << ".hrh>" << endl << endl;
       
    85 	        t << "RESOURCE REGISTRY_INFO theInfo" << endl << "{" << endl;
       
    86 	        t << "resource_format_version = RESOURCE_FORMAT_VERSION_2;" << endl;
       
    87 	        t << "dll_uid = " << uid3 << ";" << endl;
       
    88 	        t << "interfaces =" << endl << "\t{" << endl << "\tINTERFACE_INFO" << endl << "\t\t{" << endl;
       
    89 	        t << "\t\tinterface_uid = KQtEcomPluginInterfaceUID;" << endl;
       
    90 	        t << "\t\timplementations =" << endl << "\t\t\t{" << endl;
       
    91 	        t << "\t\t\tIMPLEMENTATION_INFO" << endl << "\t\t\t\t{" << endl;
       
    92 	        t << "\t\t\t\timplementation_uid = " << IMPLEMENTATION_UID_LIT << ";" << endl;
       
    93 	        t << "\t\t\t\tversion_no = 1;" << endl;
       
    94 	        t << "\t\t\t\tdisplay_name = \"" << appName+QString(QString::fromLatin1(".dll")) << "\";" << endl;
       
    95 	        t << "\t\t\t\t// SERVICE.INTERFACE_NAME" << endl;
       
    96 	        t << "\t\t\t\tdefault_data = \"" << interfacename << "\";" << endl;
       
    97 	        t << "\t\t\t\t// SERVICE.CONFIGURATION" << endl;
       
    98 	        t << "\t\t\t\topaque_data = \""; 
       
    99 			while( !configStream.atEnd() ) {
       
   100 				configStream.skipWhiteSpace();
       
   101 				t << configStream.readLine( 255 ).replace(QString::fromLatin1("\""), QString::fromLatin1("\\\""));
       
   102 			};
       
   103 			t << "\";" << endl;
       
   104 	        t << "\t\t\t\t}" << endl << "\t\t\t};" << endl << "\t\t}" << endl << "\t};" << endl << "}" << endl;
       
   105 			printf("Generated: ");
       
   106 			printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
   107 			printf("\n");
       
   108 	    }else{
       
   109 			printf("Not generated: ");
       
   110 			printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
   111 			printf(" - Error %d\n",ft.error());
       
   112 		}
       
   113 	}else{
       
   114 		printf("Not generated: ");
       
   115 		printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
   116 		printf(" - File exists\n");					
       
   117 	}
       
   118 }
       
   119 
       
   120 void runXQPkgGenerator(QStringList params)
       
   121 {
       
   122     QString appName = params[1];
       
   123     QString uid3=params[2];
       
   124 	
       
   125     QString outputFileName=appName+QString(QString::fromLatin1(".pkg"));
       
   126 
       
   127     QFile ft(outputFileName);
       
   128 	if(!ft.exists()){
       
   129 	    if(ft.open(QIODevice::WriteOnly)) {
       
   130 	        QTextStream t(&ft);
       
   131 	        t << "// ============================================================================" << endl;
       
   132 	        t << "// Generated by xqecom on " << QDateTime::currentDateTime().toString() << endl;
       
   133 	        t << "// This file is generated by xqecom and should not be modified by the user." << endl;
       
   134 	        t << "// ============================================================================" << endl;
       
   135 	        t << endl;
       
   136 	        t << "; Language" << endl;
       
   137 	        t << "&EN" << endl;
       
   138 	        t << endl;
       
   139 	        t << "; SIS header: name, uid, version" << endl;
       
   140 	        t << "#{"<< appName <<"},(" << uid3 << "),1,0,0" << endl;
       
   141 	        t << endl;
       
   142 	        t << "; Localised Vendor name" << endl;
       
   143 	        t << "%{\"Nokia, Qt Software\"}" << endl;
       
   144 	        t << endl;
       
   145 	        t << "; Unique Vendor name" << endl;
       
   146 	        t << ":\"Nokia, Qt Software\"" << endl;
       
   147 	        t << endl;
       
   148 	        t << "; Dependencies" << endl;
       
   149 	        t << "[0x101F7961],0,0,0,{\"S60ProductID\"}" << endl;
       
   150 	        t << "[0x102032BE],0,0,0,{\"S60ProductID\"}" << endl;
       
   151 	        t << "[0x102752AE],0,0,0,{\"S60ProductID\"}" << endl;
       
   152 	        t << "[0x1028315F],0,0,0,{\"S60ProductID\"}" << endl;
       
   153 	        t << "(0x2001E61C), 4, 5, 0, {\"QtLibs pre-release\"}" << endl;
       
   154 	        t << endl;
       
   155 	        t << ";files" << endl;
       
   156 	        t << "\"\\epoc32\\release\\armv5\\urel\\"<< appName <<".dll\"    - \"!:\\sys\\bin\\"<< appName <<".dll\"" << endl;
       
   157 	        t << "\"\\epoc32\\data\\Z\\resource\\plugins\\"<< appName <<".rsc\" - \"!:\\resource\\plugins\\"<< appName <<".rsc\"" << endl;
       
   158 			printf("Generated: ");
       
   159 			printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
   160 			printf("\n");
       
   161 	    }else{
       
   162 			printf("Not generated: ");
       
   163 			printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
   164 			printf(" - Error %d\n",ft.error());
       
   165 		}
       
   166 	}else{
       
   167 		printf("Not generated: ");
       
   168 		printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
   169 		printf(" - File exists\n");					
       
   170 	}
       
   171 }
       
   172 
       
   173 void runXQIbyGenerator(QStringList params)
       
   174 {
       
   175     QString appName = params[1];
       
   176 	
       
   177     QString outputFileName=appName+QString(QString::fromLatin1(".iby"));
       
   178 	QString headerGuard = appName+QString(QString::fromLatin1("_IBY"));
       
   179 	headerGuard=headerGuard.toUpper();
       
   180 
       
   181     QFile ft(outputFileName);
       
   182 	if(!ft.exists()){
       
   183 	    if(ft.open(QIODevice::WriteOnly)) {
       
   184 	        QTextStream t(&ft);
       
   185 	        t << "// ============================================================================" << endl;
       
   186 	        t << "// Generated by xqecom on " << QDateTime::currentDateTime().toString() << endl;
       
   187 	        t << "// This file is generated by xqecom and should not be modified by the user." << endl;
       
   188 	        t << "// ============================================================================" << endl;
       
   189 	        t << endl;
       
   190 	        t << "#ifndef " << headerGuard << endl;
       
   191 	        t << "#define " << headerGuard << endl;
       
   192 	        t << endl;
       
   193 	        t << "#include <bldvariant.hrh>" << endl;
       
   194 	        t << endl;
       
   195 			t << "ECOM_PLUGIN( " << appName << ".dll, " << appName << ".rsc )" << endl;
       
   196 	        t << endl;
       
   197 	        t << "#endif //" << headerGuard << endl;
       
   198 			printf("Generated: ");
       
   199 			printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
   200 			printf("\n");
       
   201 	    }else{
       
   202 			printf("Not generated: ");
       
   203 			printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
   204 			printf(" - Error %d\n",ft.error());
       
   205 		}
       
   206 	}else{
       
   207 		printf("Not generated: ");
       
   208 		printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
   209 		printf(" - File exists\n");					
       
   210 	}
       
   211 }
       
   212 
       
   213 void runXQStubGenerator(QStringList params)
       
   214 {
       
   215     QString appName = params[1];
       
   216     QString uid3 = params[2];	
       
   217 	
       
   218 	QString outputHeaderFileName=QString::fromLatin1("ecomstub_") + uid3 + QString::fromLatin1(".hrh");
       
   219 	QString outputSourceFileName=QString::fromLatin1("ecomstub_") + uid3 + QString::fromLatin1(".cpp");
       
   220 	QString headerGuard = QString::fromLatin1("ECOMSTUB_%1_HRH").arg(uid3);
       
   221 
       
   222     QFile fth(outputHeaderFileName);
       
   223 	if(!fth.exists()){
       
   224 	    if(fth.open(QIODevice::WriteOnly)) {
       
   225 	        QTextStream t(&fth);
       
   226 	        t << "// ============================================================================" << endl;
       
   227 	        t << "// Generated by xqecom on " << QDateTime::currentDateTime().toString() << endl;
       
   228 	        t << "// This file is generated by xqecom and should not be modified by the user." << endl;
       
   229 	        t << "// ============================================================================" << endl;
       
   230 	        t << endl;
       
   231 			t << "#ifndef " << headerGuard << endl;
       
   232 			t << "#define " << headerGuard << endl;
       
   233 			
       
   234 			t << "#define " << IMPLEMENTATION_UID_LIT << " " << uid3 << endl;
       
   235 			t << "#endif //" << headerGuard << endl;
       
   236 			printf("Generated: ");
       
   237 			printf((QFileInfo(fth).absoluteFilePath()).toLocal8Bit().data() );
       
   238 			printf("\n");
       
   239 	    }else{
       
   240 			printf("Not generated: ");
       
   241 			printf((QFileInfo(fth).absoluteFilePath()).toLocal8Bit().data() );
       
   242 			printf(" - Error %d\n",fth.error());
       
   243 		}
       
   244 	}else{
       
   245 		printf("Not generated: ");
       
   246 		printf((QFileInfo(fth).absoluteFilePath()).toLocal8Bit().data() );
       
   247 		printf(" - File exists\n");					
       
   248 	}
       
   249 	
       
   250     QFile ft(outputSourceFileName);
       
   251 	if(!ft.exists()){
       
   252 	    if(ft.open(QIODevice::WriteOnly)) {
       
   253 	        QTextStream t(&ft);
       
   254 	        t << "// ============================================================================" << endl;
       
   255 	        t << "// Generated by xqecom on " << QDateTime::currentDateTime().toString() << endl;
       
   256 	        t << "// This file is generated by xqecom and should not be modified by the user." << endl;
       
   257 	        t << "// ============================================================================" << endl;
       
   258 	        t << endl;
       
   259 	        
       
   260 			t << "#include <xqplugin.h>" << endl;
       
   261 	        t << "#include <" << outputHeaderFileName << ">" << endl;
       
   262 	        t << "#include <ecom/implementationproxy.h>" << endl;
       
   263 	        t << "XQ_PLUGIN_ECOM_HEADER(" << appName << ")" << endl;
       
   264 	        //t << "const TImplementationProxy implementationTable[] = \n\t{\n\tIMPLEMENTATION_PROXY_ENTRY( " << IMPLEMENTATION_UID_LIT << ", C" 
       
   265 			
       
   266 			t << "const TImplementationProxy implementationTable[] = \n\t{\n\tIMPLEMENTATION_PROXY_ENTRY(" << uid3 << ", C" 
       
   267 			  << appName
       
   268 	          <<"Factory::NewL)\n\t};" << endl << endl;
       
   269 			  
       
   270 	        t << "EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)"
       
   271 	          << endl <<"\t{\n\taTableCount = sizeof( implementationTable ) / sizeof( TImplementationProxy );"
       
   272 	          << endl <<"\treturn implementationTable;"
       
   273 	          << endl <<"\t}" << endl;
       
   274 			printf("Generated: ");
       
   275 			printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
   276 			printf("\n");
       
   277 	    }else{
       
   278 			printf("Not generated: ");
       
   279 			printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
   280 			printf(" - Error %d\n",ft.error());
       
   281 		}
       
   282 	}else{
       
   283 		printf("Not generated: ");
       
   284 		printf((QFileInfo(ft).absoluteFilePath()).toLocal8Bit().data() );
       
   285 		printf(" - File exists\n");					
       
   286 	}
       
   287 }
       
   288 
       
   289 int main(int argc, char *argv[])
       
   290 {
       
   291     QStringList params;
       
   292     for (int i=0 ; i < argc ; i++) {
       
   293         params << QString::fromLatin1(argv[i]);
       
   294 //		printf(argv[i]);
       
   295 //		printf("\n");
       
   296 //		fprintf(stderr, "%s\n",argv[i]);
       
   297    }
       
   298 	if (params.count() < 6) {
       
   299         fprintf(stderr, "xqecom error: invalid parameters(%d)! ",params.count());
       
   300         fprintf(stderr, "Usage: xqecom <app name> <uid3> <interface name> <configuration> <configuration-filename>\n");
       
   301         return 1;
       
   302     }
       
   303 	
       
   304 	if ( !params[2].startsWith(QString::fromLatin1("0x")) ){ //fix uid if incorrect
       
   305 		params[2].insert( 0, QString::fromLatin1("0x"));
       
   306 	}
       
   307 
       
   308     printf("xqecom:\n");
       
   309 	runRSSFileGenerator(params);
       
   310 	runXQPkgGenerator(params);
       
   311 	runXQIbyGenerator(params);
       
   312 	runXQStubGenerator(params);
       
   313 	
       
   314 	printf("\n");	
       
   315 	return 0;
       
   316 }