secureswitools/swisistools/source/scrtool/main.cpp
changeset 0 ba25891c3a9e
child 50 c6e8afe0ba85
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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 the License "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 
       
    18 
       
    19 #include "dblayer.h"
       
    20 #include "xmlparser.h"
       
    21 #include "logs.h"
       
    22 #include "exception.h"
       
    23 #include "options.h"
       
    24 
       
    25 #include <iostream>
       
    26 #include <string>
       
    27 #include <memory>
       
    28 
       
    29 typedef std::vector<std::string>::iterator StringIterator;
       
    30 typedef std::vector<XmlDetails::TScrEnvironmentDetails> EnvDetails;
       
    31 typedef std::vector<std::string> SchemaDetails;
       
    32 
       
    33 
       
    34 int main (int argc, char** argv) 
       
    35 	{
       
    36 	int returnCode = 0;
       
    37 
       
    38 	try
       
    39 		{
       
    40 		const char* epocRoot = getenv("EPOCROOT");
       
    41 		if(NULL == epocRoot)
       
    42 			{
       
    43 			throw CException("EPOCROOT environment variable not specified.", ExceptionCodes::EEnvNotSpecified);
       
    44 			}
       
    45 		std::string epocRootStr(epocRoot); 
       
    46 		
       
    47 		COptions options(argc, argv);
       
    48 
       
    49 		std::string logFileName(options.GetLogFileName());
       
    50 		std::auto_ptr<CLogger> logger(new CLogger(logFileName, options.GetLogLevel()));
       
    51 		
       
    52 		std::string dllPath = "sqlite3.dll";
       
    53 		std::auto_ptr<CDbLayer> db( new CDbLayer(dllPath, options.GetDbFileName()));
       
    54 		std::auto_ptr<CScrXmlParser> xmlParser( new CScrXmlParser());
       
    55 
       
    56 		if(options.IsDbAbsent())
       
    57 			{
       
    58 			std::string dbFileName = epocRootStr + "epoc32\\tools\\create_db.xml";
       
    59 			std::auto_ptr<SchemaDetails> schema(xmlParser->ParseDbSchema(dbFileName));
       
    60 			db->CreateScrDatabase(*schema);
       
    61 			}
       
    62 
       
    63 		std::vector<std::string> xmlFileNames = options.GetEnvFileNames();
       
    64 		for(StringIterator xmlIter=xmlFileNames.begin(); xmlIter != xmlFileNames.end(); ++xmlIter)
       
    65 			{
       
    66 			std::auto_ptr<EnvDetails> envDetails(xmlParser->GetEnvironmentDetails(*xmlIter));
       
    67 			db->PopulateScrDatabase(*envDetails);
       
    68 			}
       
    69 		
       
    70 		if(options.IsPreProvisionInfoAvailable())
       
    71 			{
       
    72 			std::string preProvFileName = options.GetPrePovisionFileName();
       
    73 			XmlDetails::TScrPreProvisionDetail preProvisionDetailList = xmlParser->GetPreProvisionDetails(preProvFileName);
       
    74 			db->PopulatePreProvisionDetails(preProvisionDetailList);
       
    75 			}
       
    76 		}
       
    77 	catch(CException& aException)
       
    78 		{
       
    79 		const std::string& exc = aException.GetMessageA();
       
    80 		returnCode = aException.GetCode();
       
    81 		std::cout << "Exception caught::" << exc << std::endl;
       
    82 		std::cout << "Error Code::" << returnCode << std::endl;
       
    83 		}
       
    84 		
       
    85 	return returnCode;
       
    86 	}
       
    87 
       
    88