imgtools/imgcheck/src/exceptionimplementation.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 * This class is used to log and/or display the error, warning and status
       
    16 * messages. This is a sigleton class.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23  @internalComponent
       
    24  @released
       
    25 */
       
    26 
       
    27 #include "exceptionimplementation.h"
       
    28 
       
    29 enum MessageArraySize{MAX=42};
       
    30 
       
    31 /**
       
    32 Message objects are created and these objects holds the error, warning and status
       
    33 message required by imgcheck tool.
       
    34 
       
    35 @internalComponent
       
    36 @released
       
    37 */
       
    38 struct Messages MessageArray[MAX]=
       
    39 {
       
    40 	{UNKNOWNIMAGETYPE, "Error: Image Type Unknown: '%s'"},
       
    41 	{UNKNOWNPREFIX,"Error: Option has Un-Known Prefix: '%s'"},
       
    42 	{VALUEEXPECTED,"Error: Value expected for option: '%s'"},
       
    43 	{VALUENOTEXPECTED,"Error: Value not expected for option: '%s'"},
       
    44 	{UNKNOWNOPTION,"Error: Unknown option: '%s'"},
       
    45 	{QUIETMODESELECTED,"Error: Quiet mode selected while not generating XML report"},
       
    46 	{NOIMAGE,"Error: No images specified in the input"},
       
    47 	{NOROMIMAGE,"Warning: ROM image not passed"},
       
    48 	{XMLOPTION,"Warning: XML file name specified while not generating XML report"},
       
    49 	{NOMEMORY,"Error:%s:%d: Insuffient program memory"},
       
    50 	{FILENAMETOOBIG,"Error:'%s':%d: Improper File Name Size"},
       
    51 	{XMLNAMENOTVALID,"Error: Not a valid Xml File name"},
       
    52 	{REPORTTYPEINVALID,"Error: Not a valid report type"},
       
    53 	{FILEOPENFAIL,"Error:%s:%d: Cannot Open file: '%s'"},
       
    54 	{XSLCREATIONFAILED,"Warning:%s:%d: Unable to Create XSL file: '%s'"},
       
    55 	{UNEXPECTEDNUMBEROFVALUE, "Error: Unexpected number of values received for option: '%s'"},
       
    56 	{INVALIDVIDVALUE, "Error: Invalid VID value: '%s'"},
       
    57 	{UNKNOWNSUPPRESSVAL, "Error: Unknown suppress value: '%s'"},
       
    58 	{ALLCHECKSSUPPRESSED, "Error: All Validations suppressed"},
       
    59 	{SUPPRESSCOMBINEDWITHVIDVAL, "Warning: VID values received but VID validation suppressed"},
       
    60 	{SIDALLCOMBINEDWITHSID, "Warning: --sidall option received but SID validation suppressed"},
       
    61 	{DATAOVERFLOW, "Overflow: Input value '%s'"},
       
    62 	{VALIDIMAGE, "Success: Image(s) are valid"},
       
    63 	{IMAGENAMEALREADYRECEIVED, "Warning: Image '%s' passed in multiple times, first one is considered and rest are ignored."},
       
    64 	{UNKNOWNDBGVALUE , "Error: Invalid value is passed to --dbg, expected values are TRUE or FALSE."},
       
    65 	{ONLYSINGLEDIRECTORYEXPECTED , "Error: Only single directory should be passed as input when E32Input is enabled."},
       
    66 	{INVALIDDIRECTORY , "Error: Invalid directory or E32 file received as E32Input."},
       
    67 	{INCORRECTVALUES , "Warning: The status reported for Dependency and SID check may not be correct in E32 input mode."},
       
    68 	{NOVALIDATIONSENABLED , "Error: No validations are enabled."},
       
    69 	{NOEXEPRESENT, "Error: No valid executables are present"},
       
    70 	{E32INPUTNOTEXIST, "Error: Invalid E32 input '%s'"},
       
    71 	{VALIDE32INPUT, "Success: E32 executable(s) are validated"},
       
    72 	// Add the New Error and warning messages above this line
       
    73 	{GATHERINGDEPENDENCIES,"Gathering dependencies for '%s'"},
       
    74 	{WRITINGINTOREPORTER,"'%s' Checker writing data into Reporter"},
       
    75 	{COLLECTDEPDATA,"Collecting dependency data for '%s'"},
       
    76 	{NOOFEXECUTABLES,"No of executables in '%s': %d"},
       
    77 	{NOOFHEXECUTABLES,"No of hidden executables in '%s': %d"},
       
    78 	{READINGIMAGE,"Reading image: '%s'"},
       
    79 	{GATHERINGIDDATA,"Gathering %s data for '%s'"},
       
    80 	{GENERATINGREPORT,"Generating '%s' Report"},
       
    81 	{REPORTGENERATION,"Report generation %s"},
       
    82 	//Add the new status informations below this line
       
    83 	{NODISKSPACE,"Error: No enough disk space for %s"}
       
    84 };
       
    85 
       
    86 /**
       
    87 Static variables used to construct singleton class are initialized
       
    88 
       
    89 @internalComponent
       
    90 @released
       
    91 */
       
    92 unsigned int ExceptionImplementation::iCmdFlag = 0;
       
    93 ExceptionImplementation* ExceptionImplementation::iInstance = KNull;
       
    94 
       
    95 /**
       
    96 Static function provides the way to get the instance of ExceptionImplementation
       
    97 class. It takes aCmdFlag as argument, this argument contains the specified 
       
    98 commandline options and this flag is used to display the status information to 
       
    99 standard output upon receiving verbose mode flag.
       
   100 
       
   101 @internalComponent
       
   102 @released
       
   103 
       
   104 @param aCmdFlag - has all the options received in commandline.
       
   105 
       
   106 @return - returns the instance
       
   107 */
       
   108 ExceptionImplementation* ExceptionImplementation::Instance(unsigned int aCmdFlag)
       
   109 {
       
   110 	if(iInstance == KNull)
       
   111 	{
       
   112 		iCmdFlag = aCmdFlag;
       
   113 		iInstance = new ExceptionImplementation();
       
   114 	}
       
   115 	return iInstance;
       
   116 }
       
   117 
       
   118 /**
       
   119 Static function to delete the instance.
       
   120 
       
   121 @internalComponent
       
   122 @released
       
   123 */
       
   124 void ExceptionImplementation::DeleteInstance()
       
   125 {
       
   126 	DELETE(iInstance);
       
   127 }
       
   128 
       
   129 /**
       
   130 Constructor opens the output stream and traverses through MessageArray objects to 
       
   131 initialize iMessage map. This map is used later to log the messages.
       
   132 
       
   133 @internalComponent
       
   134 @released
       
   135 */
       
   136 ExceptionImplementation::ExceptionImplementation()
       
   137 :iMsgIndex(0)
       
   138 {
       
   139 	iLogStream.open(gLogFileName.c_str(),Ios::out);
       
   140 	int i;
       
   141 	for(i = 0; i < MAX; i++)
       
   142 	{
       
   143 		iMessage.insert(std::make_pair(MessageArray[i].iIndex,MessageArray[i].iMessage));
       
   144 	}
       
   145 }
       
   146 
       
   147 /**
       
   148 Destructor closes the output stream opened during construction.
       
   149 
       
   150 @internalComponent
       
   151 @released
       
   152 */
       
   153 ExceptionImplementation::~ExceptionImplementation()
       
   154 {
       
   155 	iLogStream.close();
       
   156 }
       
   157 
       
   158 /**
       
   159 Function returns the message equivalent to the recived enum value.
       
   160 
       
   161 @internalComponent
       
   162 @released
       
   163 
       
   164 @param aMsgIndex - enum value
       
   165 */
       
   166 String& ExceptionImplementation::Message(const int aMsgIndex)
       
   167 {
       
   168 	iMsgIndex = aMsgIndex;
       
   169 	return iMessage[aMsgIndex];
       
   170 }
       
   171 
       
   172 /**
       
   173 Function to log the error, warning and status information.
       
   174 Irrespective of the messgae type all the messages are logged into the imgcheck 
       
   175 logfile. The warning and error messages are needed to be displayed on the command
       
   176 prompt always. But the status information is displayed at standard output only if
       
   177 the verbose mode is selected by the user.
       
   178 
       
   179 @internalComponent
       
   180 @released
       
   181 
       
   182 @param aMsgIndex - enum value
       
   183 */
       
   184 void ExceptionImplementation::Log(const String aMsg)
       
   185 {
       
   186 	iLogStream <<  aMsg.c_str() << "\n";
       
   187     
       
   188 	if(iCmdFlag & KVerbose)
       
   189 	{
       
   190 		cout << aMsg.c_str() << endl;
       
   191 	}
       
   192 }
       
   193 
       
   194 /**
       
   195 Function to report the error and warning information.
       
   196 Irrespective of the messgae type all the messages are logged into the imgcheck 
       
   197 logfile. The warning and error messages are needed to be displayed on the command
       
   198 prompt always. 
       
   199 
       
   200 @internalComponent
       
   201 @released
       
   202 
       
   203 @param aMsgIndex - enum value
       
   204 */
       
   205 void ExceptionImplementation::Report(const String aMsg)
       
   206 {
       
   207 	iLogStream <<  aMsg.c_str() << "\n";
       
   208 	if(aMsg.find("Success") != String::npos)
       
   209 	{
       
   210 		cout << aMsg.c_str() << endl;
       
   211 	}
       
   212 	else
       
   213 	{
       
   214 		cerr << aMsg.c_str() << endl;
       
   215 	}
       
   216 }