imgtools/imgcheck/src/reporter.cpp
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 2007-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 * Base for commandline or xml report generation.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalComponent
       
    23  @released
       
    24 */
       
    25 
       
    26 #include "reporter.h"
       
    27 
       
    28 /**
       
    29 Static variable as instance pointer
       
    30 
       
    31 @internalComponent
       
    32 @released
       
    33 */
       
    34 Reporter* Reporter::iInstance = KNull;
       
    35 
       
    36 /**
       
    37 Constructor: Reporter class
       
    38 Initilize the parameters to data members.
       
    39 
       
    40 @internalComponent
       
    41 @released
       
    42 */
       
    43 Reporter::Reporter(unsigned int aCmdOptions)
       
    44 :iInputOptions(aCmdOptions)
       
    45 {
       
    46 }
       
    47 
       
    48 
       
    49 /**
       
    50 Destructor: Reporter class 
       
    51 Release the objects. 
       
    52 
       
    53 @internalComponent
       
    54 @released
       
    55 */
       
    56 Reporter::~Reporter()
       
    57 {
       
    58 	iImgVsExeStatus.clear();
       
    59 }
       
    60 
       
    61 /**
       
    62 Function responsible to return the reference of iImgVsExeStatus
       
    63 
       
    64 @internalComponent
       
    65 @released
       
    66 
       
    67 @return - returns the reference of iImgVsExeStatus
       
    68 */
       
    69 ImgVsExeStatus& Reporter::GetContainerReference()
       
    70 {
       
    71 	return iImgVsExeStatus;
       
    72 }
       
    73 
       
    74 
       
    75 /**
       
    76 Function responsible to create the report instances.
       
    77 
       
    78 @internalComponent
       
    79 @released
       
    80 
       
    81 @param aReportType - report type either commandline or XML
       
    82 @param aXmlFile - if XML then pass the xml filename
       
    83 
       
    84 @return - return the new report instance created
       
    85 */
       
    86 Reporter* Reporter::Instance(unsigned int aCmdOptions)
       
    87 {
       
    88 	if(iInstance == KNull)
       
    89 	{
       
    90 		iInstance = new Reporter(aCmdOptions);
       
    91 		if(!iInstance)
       
    92 		{
       
    93 			throw ExceptionReporter(NOMEMORY, __FILE__, __LINE__);
       
    94 		}
       
    95 	}
       
    96 	return iInstance;
       
    97 }
       
    98 
       
    99 /**
       
   100 Function to delete the instance.
       
   101 
       
   102 @internalComponent
       
   103 @released
       
   104 */
       
   105 void Reporter::DeleteInstance()
       
   106 {
       
   107 	DELETE(iInstance);
       
   108 }
       
   109 
       
   110 
       
   111 /**
       
   112 Function responsible to create the report which is common for both the XML and command line output.
       
   113 
       
   114 @internalComponent
       
   115 @released
       
   116 
       
   117 @param aWriterList - Container which stores the report objects
       
   118 */
       
   119 void Reporter::CreateReport(const WriterPtrList& aWriterList)
       
   120 {
       
   121 	int wtrPtrLstCnt = aWriterList.size();
       
   122 	int attrCnt=0;
       
   123 	int serNo = 0;
       
   124 	ReportWriter* rptWriter = KNull;
       
   125 
       
   126 	// fetches the begin and end of the image and the related data from the integrated container
       
   127 	ImgVsExeStatus::iterator imgBegin;
       
   128 	ImgVsExeStatus::iterator imgEnd;
       
   129 
       
   130 	ExeVsMetaData::iterator exeBegin;
       
   131 	ExeVsMetaData::iterator exeEnd;
       
   132 	
       
   133 	if(IsAttributeAvailable())
       
   134 	{
       
   135 		while(wtrPtrLstCnt)
       
   136 		{
       
   137 			imgBegin = iImgVsExeStatus.begin();
       
   138 			imgEnd = iImgVsExeStatus.end();
       
   139 
       
   140 			rptWriter = aWriterList[wtrPtrLstCnt-1];
       
   141 			ExceptionReporter(GENERATINGREPORT, (char*)rptWriter->ReportType().c_str()).Log();
       
   142 			// starts the report
       
   143 			rptWriter->StartReport();
       
   144 			
       
   145 			while(imgBegin != imgEnd)
       
   146 			{
       
   147 				// starts the image
       
   148 				rptWriter->StartImage(imgBegin->first);
       
   149 
       
   150 				// fetches the begin and end of the executable container
       
   151 				ExeVsMetaData& exeAttStatus = imgBegin->second;
       
   152 				exeBegin = exeAttStatus.begin();
       
   153 				exeEnd = exeAttStatus.end();
       
   154 				serNo = 1;
       
   155 				while(exeBegin != exeEnd)
       
   156 				{
       
   157 					ExeAttList exeAttList = exeBegin->second.iExeAttList;
       
   158 					attrCnt = exeAttList.size();
       
   159 					if(attrCnt)
       
   160 					{
       
   161 						// starts the executable	
       
   162 						rptWriter->StartExecutable(serNo, exeBegin->first);
       
   163 					
       
   164 						while(attrCnt)
       
   165 						{
       
   166 							// writes the attributes
       
   167 							rptWriter->WriteExeAttribute(*exeAttList.front());
       
   168 							if(wtrPtrLstCnt == 1)
       
   169 							{
       
   170 								DELETE(exeAttList.front()); //If no more reports to be generated, delete it
       
   171 							}
       
   172 							exeAttList.pop_front();
       
   173 							--attrCnt;
       
   174 						}
       
   175 						// ends the executable
       
   176 						rptWriter->EndExecutable();	
       
   177 						++serNo;
       
   178 					}
       
   179 					++exeBegin;
       
   180 				}
       
   181 				++imgBegin;
       
   182 				// ends the image
       
   183 				rptWriter->EndImage();
       
   184 			}
       
   185 			rptWriter->WriteNote();
       
   186 			// ends the report
       
   187 			rptWriter->EndReport();
       
   188 			--wtrPtrLstCnt;
       
   189 		}
       
   190 		ExceptionReporter(REPORTGENERATION,"Success").Log();
       
   191 	}
       
   192 	else
       
   193 	{
       
   194 		if(iInputOptions & KE32Input)
       
   195 		{
       
   196 			ExceptionReporter(VALIDE32INPUT).Report();
       
   197 		}
       
   198 		else
       
   199 		{
       
   200 			ExceptionReporter(VALIDIMAGE).Report();
       
   201 		}
       
   202 	}
       
   203 }
       
   204 
       
   205 /**
       
   206 Function checks if the attributes are valid and are not blank.
       
   207 
       
   208 @internalComponent
       
   209 @released
       
   210 
       
   211 */
       
   212 bool Reporter::IsAttributeAvailable()
       
   213 {
       
   214 	ImgVsExeStatus::iterator imgBegin = iImgVsExeStatus.begin();
       
   215 	ImgVsExeStatus::iterator imgEnd = iImgVsExeStatus.end();
       
   216 
       
   217 	ExeVsMetaData::iterator exeBegin;
       
   218 	ExeVsMetaData::iterator exeEnd;
       
   219 
       
   220 	while(imgBegin != imgEnd)
       
   221 	{
       
   222 		ExeVsMetaData& exeVsMetaData = imgBegin->second;
       
   223 
       
   224 		exeBegin = exeVsMetaData.begin();
       
   225 		exeEnd = exeVsMetaData.end();
       
   226 		while(exeBegin != exeEnd)
       
   227 		{
       
   228 			if((exeBegin->second).iExeAttList.size() == 0)
       
   229 			{
       
   230 				++exeBegin;
       
   231 				continue;
       
   232 			}
       
   233 			else
       
   234 			{
       
   235 				return true;
       
   236 			}
       
   237 			++exeBegin;
       
   238 		}
       
   239 		++imgBegin;
       
   240 	}
       
   241 	return false;
       
   242 }