imgtools/imgcheck/src/depchecker.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 * DepChecker class is responsible to Validate the dependencies existence and put the  
       
    16 * prepared data into Reporter.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23  @internalComponent
       
    24  @released
       
    25 */
       
    26 
       
    27 #include "depchecker.h"
       
    28 
       
    29 /** 
       
    30 Constructor intializes the iHashPtr and iHiddenExeHashPtr members.
       
    31 
       
    32 @internalComponent
       
    33 @released
       
    34 
       
    35 @param aCmdInput - pointer to a processed CmdLineHandler object
       
    36 @param aImageReaderList - List of ImageReader insatance pointers
       
    37 */
       
    38 DepChecker::DepChecker(CmdLineHandler* aCmdPtr, ImageReaderPtrList& aImageReaderList, bool aNoRomImage) 
       
    39 :Checker(aCmdPtr, aImageReaderList), iNoRomImage(aNoRomImage)
       
    40 {
       
    41 	iHashPtr = new HashTable(KHashTableSize); 
       
    42 	iHiddenExeHashPtr = new HashTable(KHiddenExeHashSize);
       
    43 }
       
    44 
       
    45 /** 
       
    46 Destructor deletes the imagereader objects and hash tables.
       
    47 
       
    48 @internalComponent
       
    49 @released
       
    50 */
       
    51 DepChecker::~DepChecker()
       
    52 {
       
    53 	DELETE(iHiddenExeHashPtr);
       
    54 	DELETE(iHashPtr);
       
    55 	iAddressVsExeName.clear();
       
    56 }
       
    57 
       
    58 /**
       
    59 Fucntion responsible to
       
    60 1. Prepare the ROM and ROFS image executable List
       
    61 2. Gather Dependencies of all executables present in the ROFS image
       
    62 3. Prepare the input data for Reporter
       
    63 
       
    64 @internalComponent
       
    65 @released
       
    66 
       
    67 @param ImgVsExeStatus - Global integrated container which contains image, exes and attribute value status.
       
    68 */
       
    69 void DepChecker::Check(ImgVsExeStatus& aImgVsExeStatus)
       
    70 {
       
    71 	unsigned int imgCnt = 0;
       
    72 	RomImagePassed();
       
    73 	String imageName;
       
    74 	ExeNamesVsDepListMap::iterator exeBegin;
       
    75 	ExeNamesVsDepListMap::iterator exeEnd;
       
    76 	while(imgCnt < iImageReaderList.size())
       
    77 	{
       
    78 		imageName = iImageReaderList[imgCnt]->ImageName();
       
    79 		PrepareImageExeList(iImageReaderList[imgCnt]);
       
    80 		//Gather dependencies of all the images.
       
    81 		ExceptionReporter(GATHERINGDEPENDENCIES, (char*)imageName.c_str()).Log();
       
    82 		ExeNamesVsDepListMap& depMap = iImageReaderList[imgCnt]->GatherDependencies();
       
    83 		exeBegin = depMap.begin();
       
    84 		exeEnd = depMap.end();
       
    85 		while(exeBegin != exeEnd)
       
    86 		{
       
    87 			StringList& list = exeBegin->second;
       
    88 			aImgVsExeStatus[imageName][exeBegin->first].iIdData = KNull;
       
    89 			aImgVsExeStatus[imageName][exeBegin->first].iDepList = list;
       
    90 			++exeBegin;
       
    91 		}
       
    92 		++imgCnt;
       
    93 	}
       
    94 }
       
    95 
       
    96 /**
       
    97 Function responsible to
       
    98 1. Prepare the ExecutableList
       
    99 2. Put the received Excutable list into HASH table, this data will be used later 
       
   100    to identify the dependencies existense.
       
   101 
       
   102 @internalComponent
       
   103 @released
       
   104 
       
   105 @param aImageReader - ImageReader instance pointer.
       
   106 */
       
   107 void DepChecker::PrepareImageExeList(ImageReader* aImageReader)
       
   108 {
       
   109 	aImageReader->PrepareExecutableList();
       
   110 	StringList aExeList = aImageReader->GetExecutableList();
       
   111 	iHashPtr->InsertStringList(aExeList); //Put executable names into Hash
       
   112 	/**
       
   113 	In ROM if any file is hidden then its entry is not placed in the directory 
       
   114 	section of the image during image building time. But still the entry data is 
       
   115 	already resolved and ready for xip. So this entry is marked here as Unknown
       
   116 	Dependency and its status is Hidden.
       
   117 	*/
       
   118 	StringList hiddenExeList = aImageReader->GetHiddenExeList();
       
   119 	iHiddenExeHashPtr->Insert(KUnknownDependency); //ROm Specific and only once
       
   120 	iHiddenExeHashPtr->InsertStringList(hiddenExeList);
       
   121 	DeleteHiddenExeFromExecutableList(aImageReader, hiddenExeList);
       
   122 	String imgName = aImageReader->ImageName();
       
   123 	ExceptionReporter(NOOFEXECUTABLES, (char*)imgName.c_str(), aExeList.size()).Log();
       
   124 	ExceptionReporter(NOOFHEXECUTABLES, (char*)imgName.c_str(), hiddenExeList.size()).Log();
       
   125 }
       
   126 
       
   127 /**
       
   128 Function responsible to delete the hidden executables from iExecutableList.
       
   129 In ROFS image, if a file is hidden then its duplicate entry is created to say it is
       
   130 hidden. But the other entry is already placed in the executable list and it is 
       
   131 available in iHashPtr Hash table. So this needs to be deleted form iHashPtr, then only
       
   132 it is possible to get the status "Hidden" for such executables.
       
   133 
       
   134 @internalComponent
       
   135 @released
       
   136 
       
   137 @param aImageReader - ImageReader instance pointer.
       
   138 @param aHiddenExeList - List containing the hidden exe's.
       
   139 */
       
   140 void DepChecker::DeleteHiddenExeFromExecutableList(ImageReader* /*aImageReader*/, StringList& aHiddenExeList)
       
   141 {
       
   142 	StringList::iterator begin = aHiddenExeList.begin();
       
   143 	StringList::iterator end = aHiddenExeList.end();
       
   144 	while(begin != end)
       
   145 	{
       
   146 		iHashPtr->Delete(*begin);
       
   147 		++begin;
       
   148 	}
       
   149 }
       
   150 
       
   151 /**
       
   152 Function responsible to prepare the data input for Report Generator.
       
   153 Traverses through all the images to identify the executables dependency status.
       
   154 
       
   155 @internalComponent
       
   156 @released
       
   157 
       
   158 @param aExeContainer - Global integrated container which contains all the attribute, values and the status.
       
   159 */
       
   160 void DepChecker::PrepareAndWriteData(ExeContainer* aExeContainer)
       
   161 {
       
   162 	ExeAttribute* exeAtt;
       
   163 	StringList& depList = aExeContainer->iDepList;
       
   164 	StringList::iterator depBegin = depList.begin();
       
   165 	StringList::iterator depEnd = depList.end();
       
   166 	while(depBegin != depEnd)
       
   167 	{
       
   168 		String status;
       
   169 		if(!iNoCheck)
       
   170 		{
       
   171 			CollectDependencyStatus((*depBegin), status);
       
   172 		
       
   173 			if(status == String(KStatusNo))
       
   174 			{
       
   175 				if(iHiddenExeHashPtr->IsAvailable(*depBegin))
       
   176 				{
       
   177 					status.assign(KStatusHidden);
       
   178 				}
       
   179 			}
       
   180 			//Include only missing dependencies by default
       
   181 			if(!iAllExecutables && (status != String(KStatusNo)))
       
   182 			{
       
   183 				++depBegin;
       
   184 				continue;
       
   185 			}
       
   186 		}
       
   187 		exeAtt = new ExeAttribute;
       
   188 		if(exeAtt == KNull)
       
   189 		{
       
   190 			throw ExceptionReporter(NOMEMORY, __FILE__, __LINE__);
       
   191 		}
       
   192 		exeAtt->iAttName = KDependency;
       
   193 		exeAtt->iAttValue = *depBegin;
       
   194 		if(!iNoCheck)
       
   195 		{
       
   196 			exeAtt->iAttStatus = status;
       
   197 		}
       
   198 		else
       
   199 		{
       
   200 			exeAtt->iAttStatus = KNull;
       
   201 		}
       
   202 		aExeContainer->iExeAttList.push_back(exeAtt);
       
   203 		++depBegin;
       
   204 	}
       
   205 }
       
   206 
       
   207 /**
       
   208 Function responsible to Get the dependency status for one executable at instant.
       
   209 Check for the existence of executable in the Hash table which is created while
       
   210 preparing executable list.
       
   211 
       
   212 @internalComponent
       
   213 @released
       
   214 
       
   215 @param aString - Individual dependency name. (input)
       
   216 @param aStatus - Dependency status.(for output)
       
   217 */
       
   218 void DepChecker::CollectDependencyStatus(String& aString, String& aStatus) const
       
   219 {
       
   220 	if(iHashPtr->IsAvailable(aString))
       
   221 	{
       
   222 		aStatus.assign(KStatusYes);
       
   223 		return;
       
   224 	}
       
   225 	aStatus.assign(KStatusNo);
       
   226 }
       
   227 
       
   228 /**
       
   229 Function responsible to display the no rom image warning.
       
   230 While checking for dependency if ROM image is not passed and only ROFS is passed then 
       
   231 there is a chance that most of the executables dependencies will not be available.
       
   232 Hence this warning is raised.
       
   233 
       
   234 @internalComponent
       
   235 @released
       
   236 */
       
   237 void DepChecker::RomImagePassed(void) const
       
   238 {
       
   239 	if(iNoRomImage)
       
   240 	{
       
   241 		ExceptionReporter(NOROMIMAGE).Report();
       
   242 	}
       
   243 }