imgtools/imgcheck/src/imgcheckmanager.cpp
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 2008-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 * ImgCheckManager controller class Controls the instantiation and 
       
    16 * operations of ImageReader, Checker, Reporter and ReportWriter.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23  @internalComponent
       
    24  @released
       
    25 */
       
    26 
       
    27 #include "imgcheckmanager.h"
       
    28 #include "romreader.h"
       
    29 #include "rofsreader.h"
       
    30 #include "dirreader.h"
       
    31 #include "depchecker.h"
       
    32 #include "sidchecker.h"
       
    33 #include "vidchecker.h"
       
    34 #include "dbgflagchecker.h"
       
    35 
       
    36 /**
       
    37 Constructor initializes command line handler pointer.
       
    38 Which can be used by any tool which is derived from this class.
       
    39 
       
    40 @internalComponent
       
    41 @released
       
    42 
       
    43 @param aCmdPtr - command line handler pointer
       
    44 */
       
    45 ImgCheckManager::ImgCheckManager(CmdLineHandler* aCmdPtr)
       
    46 :iCmdLine(aCmdPtr)
       
    47 {
       
    48 	iReporter = Reporter::Instance(iCmdLine->ReportFlag());
       
    49 	iNoRomImage = true; 
       
    50 }
       
    51 
       
    52 /**
       
    53 Destructor traverses through the imagereader list and delets the same
       
    54 
       
    55 @internalComponent
       
    56 @released
       
    57 */
       
    58 ImgCheckManager::~ImgCheckManager()
       
    59 {
       
    60 	while(iImageReaderList.size() > 0)
       
    61 	{
       
    62 		DELETE(iImageReaderList.back());
       
    63 		iImageReaderList.pop_back();
       
    64 	}
       
    65 	while(iCheckerList.size() > 0)
       
    66 	{
       
    67 		DELETE(iCheckerList.back());
       
    68 		iCheckerList.pop_back();
       
    69 	}
       
    70 	while(iWriterList.size() > 0)
       
    71 	{
       
    72 		DELETE(iWriterList.back())
       
    73 		iWriterList.pop_back();
       
    74 	}
       
    75 	Reporter::DeleteInstance();
       
    76 	iCmdLine = 0;
       
    77 }
       
    78 
       
    79 /**
       
    80 Function responsible to read the header and directory section.
       
    81 
       
    82 @internalComponent
       
    83 @released
       
    84 
       
    85 @param aImageName - image name
       
    86 @param aImageType - image type
       
    87 */
       
    88 void ImgCheckManager::Process(ImageReader* aImageReader)
       
    89 {
       
    90 	ExceptionReporter(READINGIMAGE,(char*)aImageReader->ImageName().c_str()).Log();
       
    91 	aImageReader->ReadImage();
       
    92 	aImageReader->ProcessImage();
       
    93 	if(!aImageReader->ExecutableAvailable())
       
    94 	{
       
    95 		throw ExceptionReporter(NOEXEPRESENT);
       
    96 	}
       
    97 }
       
    98 
       
    99 /**
       
   100 Function responsible to 
       
   101 1. get the image names one by one. 
       
   102 2. Identify the image type and Create respective Reader objects.
       
   103 3. Identify the required validations and create respective Instances.
       
   104 4. Identify the required Writers and create respective instances.
       
   105 
       
   106 @internalComponent
       
   107 @released
       
   108 */
       
   109 void ImgCheckManager::CreateObjects(void)
       
   110 {
       
   111 	unsigned int imgCnt = iCmdLine->NoOfImages();
       
   112 	String imgName;
       
   113 	
       
   114 	while(imgCnt > 0)
       
   115 	{	
       
   116 		imgName = iCmdLine->NextImageName();
       
   117 		--imgCnt;
       
   118 		HandleImage(imgName);
       
   119 	}
       
   120 
       
   121 	Checker* checkerPtr = KNull;
       
   122 	unsigned int checks = iCmdLine->EnabledValidations();
       
   123 	unsigned short int bitPos = 1;
       
   124 	while(bitPos)
       
   125 	{
       
   126 		if(bitPos & checks)
       
   127 		{
       
   128 			switch(bitPos)
       
   129 			{
       
   130 			case EDep:
       
   131 				checkerPtr = new DepChecker(iCmdLine, iImageReaderList,iNoRomImage);
       
   132 				break;
       
   133 			case ESid:
       
   134 				checkerPtr = new SidChecker(iCmdLine, iImageReaderList);
       
   135 				break;
       
   136 			case EVid:
       
   137 				checkerPtr = new VidChecker(iCmdLine, iImageReaderList);
       
   138 				break;
       
   139 			case EDbg:
       
   140 				checkerPtr = new DbgFlagChecker(iCmdLine, iImageReaderList);
       
   141 				break;
       
   142 			}
       
   143 			if(checkerPtr == KNull)
       
   144 			{
       
   145 				throw ExceptionReporter(NOMEMORY, __FILE__, __LINE__);
       
   146 			}
       
   147 			iCheckerList.push_back(checkerPtr);
       
   148 		}
       
   149 		bitPos <<= 1; //Shift one bit left
       
   150 	}
       
   151 
       
   152 	unsigned int rptFlag = iCmdLine->ReportFlag();
       
   153 	ReportWriter* rptWriter = KNull;
       
   154 	if(!( rptFlag & QuietMode))
       
   155 	{
       
   156 		rptWriter = new CmdLineWriter(rptFlag);
       
   157 		InsertWriter(rptWriter);
       
   158 	}
       
   159 	if(iCmdLine->ReportFlag() & KXmlReport)
       
   160 	{
       
   161 		rptWriter = new XmlWriter(iCmdLine->XmlReportName(), iCmdLine->Command());
       
   162 		InsertWriter(rptWriter);
       
   163 	}
       
   164 }
       
   165 
       
   166 /**
       
   167 Function responsible to insert the ReprtWriter into iWriterList
       
   168 
       
   169 @internalComponent
       
   170 @released
       
   171 */
       
   172 void ImgCheckManager::InsertWriter(ReportWriter* aWriter)
       
   173 {
       
   174 	if(aWriter == KNull)
       
   175 	{
       
   176 		throw ExceptionReporter(NOMEMORY, __FILE__, __LINE__);
       
   177 	}
       
   178 	iWriterList.push_back(aWriter);
       
   179 }
       
   180 
       
   181 /**
       
   182 Function responsible to initiate the enabled validations
       
   183 
       
   184 @internalComponent
       
   185 @released
       
   186 */
       
   187 void ImgCheckManager::Execute(void)
       
   188 {
       
   189 	unsigned int cnt = 0;
       
   190 	ImgVsExeStatus& imgVsExeStatus = iReporter->GetContainerReference();
       
   191 	while(cnt < iCheckerList.size())
       
   192 	{
       
   193 		iCheckerList[cnt++]->Check(imgVsExeStatus);
       
   194 	}
       
   195 }
       
   196 
       
   197 /**
       
   198 Function responsible to write the validated data into Reporter.
       
   199 
       
   200 @internalComponent
       
   201 @released
       
   202 */
       
   203 void ImgCheckManager::FillReporterData(void)
       
   204 {
       
   205 	
       
   206 	ImgVsExeStatus& imgVsExeStatus = iReporter->GetContainerReference();
       
   207 	ImgVsExeStatus::iterator imgBegin = imgVsExeStatus.begin();
       
   208 	ImgVsExeStatus::iterator imgEnd = imgVsExeStatus.end();
       
   209 	
       
   210 	ExeVsMetaData::iterator exeBegin;
       
   211 	ExeVsMetaData::iterator exeEnd;
       
   212 
       
   213 
       
   214 	while(imgBegin != imgEnd)
       
   215 	{
       
   216 		ExeVsMetaData& exeVsMetaData = imgBegin->second;
       
   217 		exeBegin = exeVsMetaData.begin();
       
   218 		exeEnd = exeVsMetaData.end();
       
   219 		while(exeBegin != exeEnd)
       
   220 		{
       
   221 			ExeContainer& exeContainer = (*exeBegin).second;
       
   222 
       
   223 			unsigned int cnt = 0;
       
   224 			while(cnt < iCheckerList.size())
       
   225 			{
       
   226 				iCheckerList[cnt++]->PrepareAndWriteData(&exeContainer);
       
   227 			}
       
   228 			++exeBegin;
       
   229 		}
       
   230 		++imgBegin;
       
   231 	}
       
   232 }
       
   233 
       
   234 /**
       
   235 Function responsible to start report generation. This function invokes the Reporter's
       
   236 CreateReport function by passing iWriterList as argument.
       
   237 
       
   238 @internalComponent
       
   239 @released
       
   240 
       
   241 @return - returns the return value of Reporter::CreateReport function.
       
   242 */
       
   243 void ImgCheckManager::GenerateReport(void)
       
   244 {
       
   245 	iReporter->CreateReport(iWriterList);
       
   246 }
       
   247 
       
   248 /** 
       
   249 Function to identify the image type and read the header and file and/or directory entries.
       
   250 
       
   251 @internalComponent
       
   252 @released
       
   253 
       
   254 @param aImageName - image name received as part of command line
       
   255 @param EImageType - type of the input image
       
   256 */
       
   257 void ImgCheckManager::HandleImage(const String& aImageName, EImageType aImageType)
       
   258 {
       
   259 	unsigned int rptFlag = iCmdLine->ReportFlag();
       
   260 	if(rptFlag & KE32Input)
       
   261 	{
       
   262 		aImageType = DirReader::EntryType((char*)aImageName.c_str());
       
   263 	}
       
   264 	else if(aImageType == EUnknownImage)
       
   265 	{
       
   266 		aImageType = ImageReader::ReadImageType(aImageName);
       
   267 	}
       
   268 	ImageReader* imgReader = KNull;
       
   269 
       
   270 	switch(aImageType)
       
   271 	{
       
   272 	case ERomImage:
       
   273 		iNoRomImage = false;
       
   274 	case ERomExImage:
       
   275 		imgReader = new RomReader((char*)aImageName.c_str(), aImageType);
       
   276 		break;
       
   277 
       
   278 	case ERofsImage:
       
   279 	case ERofsExImage:
       
   280 		imgReader = new RofsReader((char*)aImageName.c_str(), aImageType);
       
   281 		break;
       
   282 
       
   283 	case EE32Directoy:
       
   284 		imgReader = new DirReader((char*)aImageName.c_str());
       
   285 		break;
       
   286 	
       
   287 	case EE32File:
       
   288 		imgReader = new E32Reader((char*)aImageName.c_str());
       
   289 		break;
       
   290 
       
   291 	case EUnknownImage:
       
   292 		throw ExceptionReporter(UNKNOWNIMAGETYPE, (char*)aImageName.c_str());
       
   293 		break;
       
   294 
       
   295 	case EE32InputNotExist:
       
   296 		throw ExceptionReporter(E32INPUTNOTEXIST, (char*)aImageName.c_str());
       
   297 		break;
       
   298 	}
       
   299 	if(imgReader == KNull)
       
   300 	{
       
   301 		throw ExceptionReporter(NOMEMORY, __FILE__, __LINE__);
       
   302 	}
       
   303 	Process(imgReader);
       
   304 	iImageReaderList.push_back(imgReader);
       
   305 }