imgtools/imgcheck/src/depreporter.cpp
changeset 0 044383f39525
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 * Reports Executable Dependency
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalComponent
       
    23  @released
       
    24 */
       
    25 #include "depreporter.h"
       
    26 
       
    27 /**
       
    28 Constructor: DepReporter class
       
    29 Initilize the parameters to data members.
       
    30 
       
    31 @internalComponent
       
    32 @released
       
    33 
       
    34 @param aMap		   - Reference to map data
       
    35 @param aReportType - Reference to report type.
       
    36 @param aXmlFile	   - Pointer to xml file name.
       
    37 */
       
    38 DepReporter::DepReporter(const StringVsMapOfExeVsDep& aMap, const unsigned int& aReportType, const char* aXmlFile)
       
    39 : Reporter(aReportType,aXmlFile), iReportData(aMap)
       
    40 {
       
    41 }
       
    42 
       
    43 
       
    44 /**
       
    45 Destructor: DepReporter class
       
    46 
       
    47 @internalComponent
       
    48 @released
       
    49 */
       
    50 DepReporter::~DepReporter()
       
    51 {
       
    52 }
       
    53 
       
    54 
       
    55 /**
       
    56 Generates the Report of mentioned type.
       
    57 
       
    58 Checks the validty of input data.
       
    59 Construct the report objects(Based on options).
       
    60 Traverse the Map and generate the report.
       
    61 
       
    62 @internalComponent
       
    63 @released
       
    64 
       
    65 @return Status - returns the status of the depreporter.
       
    66 				 'true' - for sucessful completion of the report.
       
    67 */
       
    68 bool DepReporter::CreateReport()
       
    69 {
       
    70 	try
       
    71 	{
       
    72 		// Check for the empty map.
       
    73 		if (iReportData.empty() != 0)
       
    74 		{
       
    75 			throw ExceptionReporter(NODATATOREPORT);
       
    76 		}
       
    77 	 	// Check for valid Xml filename for report generation.
       
    78 		if (iReportType & XML_REPORT)
       
    79 		{
       
    80 			if (iXmlFileName.size() <= 0)
       
    81 			{
       
    82 				throw ExceptionReporter(XMLNAMENOTVALID);
       
    83 			}
       
    84 		}
       
    85 		ConstructReportObjects();
       
    86 		ProcessMapData();
       
    87 	}
       
    88 	catch (ExceptionReporter& aErrorReport)
       
    89 	{
       
    90 		throw aErrorReport;
       
    91 	}
       
    92 	return true;
       
    93 }
       
    94 
       
    95 
       
    96 /**
       
    97 Traverse the map and Creates the report.
       
    98 Both rom and rofs image is supported.
       
    99 
       
   100 @internalComponent
       
   101 @released
       
   102 */
       
   103 void DepReporter::ProcessMapData(void)
       
   104 {
       
   105 	StringVsMapOfExeVsDep::const_iterator aIterMapBegin = iReportData.begin();
       
   106 	StringVsMapOfExeVsDep::const_iterator aIterMapEnd = iReportData.end();
       
   107 	const ExeNamesVsDepMapData* exeNamesVsDepMapDataAddress = 0;
       
   108 	ExeNamesVsDepMapData::const_iterator aIterExeNameBegin;
       
   109 	ExeNamesVsDepMapData::const_iterator aIterExeNameEnd;
       
   110 	const NameVsDepStatusData* nameVsDepStatusDataAddress = 0;
       
   111 	NameVsDepStatusData::const_iterator aIterNameVsDepBegin;
       
   112 	NameVsDepStatusData::const_iterator aIterNameVsDepEnd;
       
   113 
       
   114 	ConstructReport(KReportStart);
       
   115 	
       
   116 	for (; aIterMapBegin != aIterMapEnd ; ++aIterMapBegin)
       
   117 	{
       
   118 		//If no dependency data found don't display the empty report
       
   119 		if(((*aIterMapBegin).second).size() == 0)
       
   120 		{
       
   121 			ExceptionReporter(NOMISSINGDEPS, (char*)(*aIterMapBegin).first.c_str()).Report();
       
   122 			continue;
       
   123 		}
       
   124 		ConstructReport(KReportStartElementHeader,aIterMapBegin->first);
       
   125 		exeNamesVsDepMapDataAddress = &aIterMapBegin->second;
       
   126 		if(exeNamesVsDepMapDataAddress->empty() != 0)
       
   127 		{
       
   128 			ConstructReport(KReportEndElementHeader);
       
   129 			continue; 
       
   130 		}
       
   131 		aIterExeNameBegin = exeNamesVsDepMapDataAddress->begin();
       
   132 		aIterExeNameEnd = exeNamesVsDepMapDataAddress->end();
       
   133 
       
   134 		// Traverse the executable.
       
   135 		for( ; aIterExeNameBegin != aIterExeNameEnd ; ++aIterExeNameBegin)
       
   136 		{
       
   137 		
       
   138 			ConstructReport(KReportStartExecutable,"",aIterExeNameBegin->first);
       
   139 			nameVsDepStatusDataAddress = &aIterExeNameBegin->second;
       
   140 			if(nameVsDepStatusDataAddress->empty() != 0)
       
   141 			{
       
   142 			ConstructReport(KReportEndExecutable);
       
   143 			continue; 
       
   144 			}
       
   145 			aIterNameVsDepBegin = nameVsDepStatusDataAddress->begin();
       
   146 			aIterNameVsDepEnd = nameVsDepStatusDataAddress->end();
       
   147 
       
   148 			// Traverse the dependencies.
       
   149 			for(; aIterNameVsDepBegin != aIterNameVsDepEnd ; ++aIterNameVsDepBegin)
       
   150 			{
       
   151 				ConstructReport(KReportWriteDependency,"",
       
   152 						"", aIterNameVsDepBegin->first,
       
   153 						aIterNameVsDepBegin->second);
       
   154 			}
       
   155 			ConstructReport(KReportEndExecutable);
       
   156 		}
       
   157 		ConstructReport(KReportEndElementHeader);
       
   158 		ConstructReport(KReportWriteNote);
       
   159 	}
       
   160 	ConstructReport(KReportEnd);
       
   161 }
       
   162 
       
   163 
       
   164 /**
       
   165 Writes the Report sections to the report objects.
       
   166 
       
   167 @internalComponent
       
   168 @released
       
   169 
       
   170 @param aReportSection - Reference to Report section
       
   171 @param aImageName	  - Reference to Image Name string.
       
   172 @param aExeName	      - Reference to Executable string.
       
   173 @param aDepName		  - Reference to Dependency Name string.
       
   174 @param aDepStatus	  - Reference to Dependency Status string.
       
   175 */
       
   176 void DepReporter::ConstructReport(EReportSection aReportSection, const String& aImageName,
       
   177 								  const String& aExeName, const String& aDepName,
       
   178 								  const String& aDepStatus)
       
   179 {
       
   180 	ReportWriter* iReportBasePointer = 0;
       
   181 	int count = iReportObjectList.size();
       
   182 	while(count)
       
   183 	{
       
   184 		iReportBasePointer = (ReportWriter*)iReportObjectList[count-1];
       
   185 		switch(aReportSection)
       
   186 		{
       
   187 			// Start Report document.
       
   188 			case KReportStart	:
       
   189 				iReportBasePointer->StartReport();
       
   190 				break;
       
   191 
       
   192 			// End Report document.
       
   193 			case KReportEnd	:
       
   194 				iReportBasePointer->EndReport();
       
   195 				break;
       
   196 
       
   197 			// Start element header info.
       
   198 			case KReportStartElementHeader	:
       
   199 				iReportBasePointer->StartElementHeader(aImageName);
       
   200 				iReportBasePointer->WriteImageHeader(KCmdDependencyHeader);
       
   201 				break;
       
   202 
       
   203 			// End element header info.
       
   204 			case KReportEndElementHeader :	
       
   205 				iReportBasePointer->EndElementHeader();
       
   206 				break;
       
   207 
       
   208 			// Start Executable info.
       
   209 			case KReportStartExecutable :	
       
   210 				iReportBasePointer->StartExecutable(aExeName);
       
   211 				break;
       
   212 
       
   213 			// End Executable info.
       
   214 			case KReportEndExecutable :	
       
   215 				iReportBasePointer->EndExecutable();
       
   216 				break;
       
   217 
       
   218 			// Write element details
       
   219 			case KReportWriteDependency	:	
       
   220 				iReportBasePointer->WriteElementDependencies(aDepName, aDepStatus);
       
   221 				break;
       
   222 
       
   223 			// Write a note about unknown dependency
       
   224 			case KReportWriteNote :
       
   225 				iReportBasePointer->WriteNote();
       
   226 				break;
       
   227 
       
   228 			// Do nothing..
       
   229 			default	:	
       
   230 				break;
       
   231 		}
       
   232 	--count;
       
   233 	}
       
   234 }