perfsrv/analyzetool/commandlineengine/inc/CATBase.h
changeset 51 98307c651589
equal deleted inserted replaced
42:0ff24a8f6ca2 51:98307c651589
       
     1 /*
       
     2 * Copyright (c) 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 "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:  Defines CATBase "utility" class.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef __CATBASE_H__
       
    19 #define __CATBASE_H__
       
    20 
       
    21 #include "../inc/ATCommonDefines.h"
       
    22 
       
    23 /**
       
    24 * This class implements lot of utility type of functions used all around atool project.
       
    25 * All functions are static so they can be used without inheritance of this class. But still
       
    26 * this is a base class of almost all others.
       
    27 */
       
    28 class CATBase
       
    29 {
       
    30 public:
       
    31 	
       
    32 	/**
       
    33 	* Constructor
       
    34 	*/
       
    35 	CATBase();
       
    36 
       
    37 	/**
       
    38 	* Destructor
       
    39 	*/
       
    40 	virtual ~CATBase(void);
       
    41 
       
    42 public:
       
    43 	
       
    44 	/**
       
    45 	* FilterExtraSpaces
       
    46 	* Filters/replaces multiple continuous spaces with single. Won't leave
       
    47 	* spaces in start or end of string.
       
    48 	* @param sString to filter.
       
    49 	* @return void.
       
    50 	*/
       
    51 	static void FilterExtraSpaces( string& sString );
       
    52 
       
    53 	/**
       
    54 	* Convert hex value in string to signed decimal.
       
    55 	* @param sHex
       
    56 	* @param iDec
       
    57 	* @return true if successful
       
    58 	*/
       
    59 	static bool hexToDec( string& sHex, int& iDec );
       
    60 
       
    61 	/**
       
    62 	* Convert hex value in string to unsigned decimal
       
    63 	* @param sHex
       
    64 	* @param iDec
       
    65 	* @return true if successful
       
    66 	*/
       
    67 	static bool hexToDec( string& sHex, unsigned int& iDec );
       
    68 
       
    69 	/**
       
    70 	* Convert hex value in string to unsigned long.
       
    71 	* @param sHex
       
    72 	* @param ulDec
       
    73 	* @return true if successful
       
    74 	*/
       
    75 	static bool hexToDec( string& sHex, unsigned long& ulDec );
       
    76 
       
    77 	/**
       
    78 	* Convert hex value in string to unsigned long long.
       
    79 	* @param sHex
       
    80 	* @param ullDec
       
    81 	* @return true if successful
       
    82 	*/
       
    83 	static bool hexToDec( string& sHex, unsigned long long& ullDec );
       
    84 
       
    85 	/**
       
    86 	* Convert hex value to integer
       
    87 	* @param value
       
    88 	* @return unsigned long
       
    89 	*/
       
    90 	static unsigned long _httoi(const TCHAR *value);
       
    91 
       
    92 	/**
       
    93 	* Convert integer to hex string.
       
    94 	* @param i
       
    95 	* @return hex string
       
    96 	*/
       
    97 	static string NumberToHexString( unsigned int i );
       
    98 
       
    99 	/**
       
   100 	* Convert long to hex string.
       
   101 	* @param i
       
   102 	* @return hex string
       
   103 	*/
       
   104 	static string NumberToHexString( unsigned long i );
       
   105 
       
   106 	/**
       
   107 	* Helper function checks is given character hex.
       
   108 	* @param value value to check.
       
   109 	* @return true if value is hex char.
       
   110 	*/
       
   111 	static bool IsHexCharacter(const TCHAR *value);
       
   112 
       
   113 	/**
       
   114 	* Parse string to vector of strings using
       
   115 	* separator. (Tokenizer with delimeter).
       
   116 	* @param sInput string to split
       
   117 	* @char separator
       
   118 	* return vector<string>
       
   119 	*/
       
   120 	static vector<string> ParseStringToVector( const string& sInput, char separator );
       
   121 
       
   122 	/**
       
   123 	* Remove spaces and tabulatures from beginning and
       
   124 	* end of given string.
       
   125 	* @param sInput String to trim.
       
   126 	*/
       
   127 	static void TrimString( string& sInput );
       
   128 
       
   129 	/**
       
   130 	* Searches files with given extension from path.
       
   131 	* @param pPathAndExt path with extension
       
   132 	* @return string filename
       
   133 	*/
       
   134 	static string GetFileNameUsingExt( const char* pPathAndExt );
       
   135 
       
   136 	/**
       
   137 	* Changes all BackSlash characters to Slash character from string.
       
   138 	* @param sInput String including backslashes.
       
   139 	* @return String without backslashes.
       
   140 	*/
       
   141 	static string ChangeSlashToBackSlash( string sInput );
       
   142 
       
   143 	/**
       
   144 	* Changes given string to uppercase
       
   145 	* @param sInput
       
   146 	*/
       
   147 	static void ChangeToUpper( string& sInput );
       
   148 
       
   149 	/**
       
   150 	* Converts any uppercase letter to lowercase.
       
   151 	*
       
   152 	* @param sInput Reference to string.
       
   153 	*/
       
   154 	static void ChangeToLower( string& sInput );
       
   155 
       
   156 	/**
       
   157 	* Filter string out of unwanted characters. The list of allowed
       
   158 	* characters is defined in CFILTERSTRING.
       
   159 	* @param sString string to filter.
       
   160 	* @return filtered string.
       
   161 	*/
       
   162 	static string FilterString( const string& sString );
       
   163 
       
   164 	/**
       
   165 	* Removes path and extension from given filename string
       
   166 	* @param sFileName
       
   167 	* @param bReverseFindExt if true extension will be looked starting from end
       
   168 	* @return string
       
   169 	*/
       
   170 	static string RemovePathAndExt( string sFileName, bool bReverseFindExt = false );
       
   171 
       
   172 	/**
       
   173 	* Returns time  stamp in microseconds parsed from start of trace message
       
   174 	* @param sLineStart
       
   175 	* @return int
       
   176 	*/
       
   177 	unsigned __int64 ParseTimeStamp( string sLineStart );
       
   178 
       
   179 	/**
       
   180 	* Check if given file exists.
       
   181 	* @param pFilename Pointer to file name.
       
   182 	* @return False If file does not exists.
       
   183 	*/
       
   184 	static bool FileExists( const char* pFilename );
       
   185 
       
   186 	/**
       
   187 	* Check if given file is flagged read only.
       
   188 	* @param pFileName pointer to file name
       
   189 	* @return true if read only flag set.
       
   190 	*/
       
   191 	static bool IsFileReadOnly( const char* pFileName );
       
   192 
       
   193 	/**
       
   194 	* Set file read only.
       
   195 	* @param pFileName Pointer to file name
       
   196 	* @return true if successful.
       
   197 	*/
       
   198 	static bool SetFileReadOnly( const char* pFileName );
       
   199 
       
   200 	/**
       
   201 	* Set file writable (remove read only flag).
       
   202 	*
       
   203 	* @param pFilename Pointer to file name.
       
   204 	* @return true if successful.
       
   205 	*/
       
   206 	static bool SetFileWritable( const char* pFileName );
       
   207 
       
   208 	/**
       
   209 	* Copy file to given path
       
   210 	* @param sFile
       
   211 	* @param sToPath
       
   212 	* @return true if successful
       
   213 	*/
       
   214 	static bool FileCopyToPath(const string& sFile, const string& sToPath);
       
   215 
       
   216 	/**
       
   217 	* Move file to given path
       
   218 	* @param sFile File to be moved
       
   219 	* @param sToPath path where to move file
       
   220 	* @return true if successful
       
   221 	*/
       
   222 	static bool FileMoveToPath(const string& sFile, const string& sToPath);
       
   223 
       
   224 	/**
       
   225 	* Delete file
       
   226 	* Note! if file does not exists no error message is displayed
       
   227 	* but function returns false
       
   228 	* @param sFile File to be deleted
       
   229 	* @param bPrint display messages or not, default true
       
   230 	* @return true if successful
       
   231 	*/
       
   232 	static bool FileDelete(const string& sFile, bool bPrint = true );
       
   233     
       
   234 	/**
       
   235 	* Delete dir
       
   236 	* Note! if dir does not exists no error message is displayed
       
   237 	* but function returns false.
       
   238 	* This function wont delete directory if string does not contain
       
   239 	* AT_TEMP...
       
   240 	* @param sDir Directory to be deleted
       
   241 	* @param bPrint display message or not, default true
       
   242 	* @return true if successful
       
   243 	*/
       
   244 	static bool DirDelete(const string& sDir, bool bPrint = true );
       
   245 
       
   246 	/**
       
   247 	* Create dir
       
   248 	* Note! if dir cannot be created no error message is displayed
       
   249 	* but function returns false.
       
   250 	* @param sDir Directory to be deleted
       
   251 	* @param pPrint display message or not, default true
       
   252 	* @return true if successful
       
   253 	*/
       
   254 	static bool DirCreate(const string& sDir, bool pPrint = true );
       
   255 
       
   256 	/**
       
   257 	* Create temp path string for given
       
   258 	* mmpfile (full path+mmpname)
       
   259 	* @param sMmpFileWithPath
       
   260 	* @return string containing full path to
       
   261 	* AnalyzeTool temporary directory
       
   262 	*/
       
   263 	static string CreateTempPath(const string& sMmpFileWithPath);
       
   264 
       
   265 	/**
       
   266 	* Search files with extensions from given path.
       
   267 	* @param pPathAndExt path with extension definition
       
   268 	* @param bPrintErrors do print errors?
       
   269 	* @param sErrorLog errors
       
   270 	* @return true if found.
       
   271 	*/
       
   272 	static bool SearchFileWithExtension( const char* pPathAndExt, bool bPrintErrors, string& sErrorLog );
       
   273 
       
   274 	/**
       
   275 	* Helper function to parse filename or path from given string
       
   276 	* @param bFileName if true returns filename otherwise the path
       
   277 	* @param sInput string where to get path or filename
       
   278 	* @return string filename or path
       
   279 	*/
       
   280 	static string GetPathOrFileName( bool bFileName, string sInput );
       
   281 
       
   282 	/**
       
   283 	* Function returns string from begin of given string until next space,
       
   284 	* characters until next space are removed from sInput string.
       
   285 	*
       
   286 	* @param sInput Line where data is separated with spaces.
       
   287 	* @param bEraseFromInput If true characters before space will be removed.
       
   288 	* @return string String until next space.
       
   289 	*/
       
   290 	static string GetStringUntilNextSpace( string& sInput, bool bEraseFromInput = true );
       
   291 
       
   292 	/**
       
   293 	* Function returns string from begin of given string until next atool's main id <AT>,
       
   294 	* characters until next space are removed from sInput string.
       
   295 	*
       
   296 	* @param sInput Line which contains main id.
       
   297 	* @param bEraseFromInput If true characters before main id will be removed.
       
   298 	* @return string String until main id.
       
   299 	*/
       
   300 	static string GetStringUntilMainId( string& sInput, bool bEraseFromInput = true );
       
   301 
       
   302 	/**
       
   303 	* Convert unix path to windows
       
   304 	* @param sPath
       
   305 	*/
       
   306 	static void ConvertUnixPathToWin( string& sPath );
       
   307 
       
   308 	/**
       
   309 	* Create Temporary AT Cpp file
       
   310 	* @param sId unique id to add in file name
       
   311 	* @param sPath where to create
       
   312 	* @param sS60FileName of the logging file
       
   313 	* @param sS60FilePath of the logging file
       
   314 	* @param iLogOption logging mode
       
   315 	* @param iIsDebug build type
       
   316 	* @param iAllocCallStackSize
       
   317 	* @param iFreeCallStackSize
       
   318 	* @return true if successful
       
   319 	*/
       
   320 	static bool CreateTemporaryCpp( const string& sId
       
   321 								 ,const string& sPath
       
   322 								 ,const string& sS60FileName
       
   323 								 ,const string& sS60FilePath
       
   324 								 ,int iLogOption
       
   325 								 ,int iIsDebug
       
   326 								 ,int iAllocCallStackSize
       
   327 								 ,int iFreeCallStackSize );
       
   328 	/**
       
   329 	* Acquire a list of files in given directory
       
   330 	* @param sDirectory can end to \ or x but not to *
       
   331 	* @param bListDirs if true directories will be listed as well, default false
       
   332 	* @param bAddPathToFile if true given sDirectory path is added to file string, default false
       
   333 	* @return vector<string> list of files in folder
       
   334 	*/
       
   335 	static vector<string> DirList(const string& sDirectory, bool bListDirs = false, bool bAddPathToFile = false);
       
   336 
       
   337 	/**
       
   338 	* Get extension from given "file" string
       
   339 	* returns string after last . if any otherwise returns same
       
   340 	* what was given
       
   341 	* @param sString 
       
   342 	* @return string string after last '.' if no '.' returns given string
       
   343 	*/
       
   344 	static string GetExtension(const string& sString);
       
   345 
       
   346 	/**
       
   347 	* Convert TCHAR pointer to string
       
   348 	* @param charArray to convert
       
   349 	* @return string
       
   350 	*/
       
   351 	static string ConvertTCHARtoString(TCHAR* charArray);
       
   352 
       
   353 	/**
       
   354 	* if given string contains two dots '.' this will remove
       
   355 	* all characters after first '.'
       
   356 	*/
       
   357 	static void RemoveAllAfterDotIfTwoDots(string& sString);
       
   358 
       
   359 	/**
       
   360 	* checks given file is it data file
       
   361 	* @param sFile
       
   362 	* @return true if it is datafile
       
   363 	*/
       
   364 	static bool IsDataFile( string sFile );
       
   365 
       
   366 	/**
       
   367 	* checks given file is it binary log file
       
   368 	* @param sFile
       
   369 	* @return true if it is binary logfile
       
   370 	*/
       
   371 	static bool IsBinaryLogFile( string sFile );
       
   372 
       
   373 	/**
       
   374 	* Parses a path string containing ".." to a valid
       
   375 	* path without relations. If given string does
       
   376 	* not contain relations it will not be changed
       
   377 	* @param sPathString
       
   378 	* @return void
       
   379 	*/
       
   380 	static void ParseRelativePathString(string& sPathString);
       
   381 
       
   382 	/**
       
   383 	* Remove relative path ".." from string
       
   384 	* @param sString string to remove from
       
   385 	* @param iDots index of ".."
       
   386 	* @return void
       
   387 	*/
       
   388 	static void RemoveRelativePath(string& sString, size_t iDots);
       
   389 
       
   390 	/**
       
   391 	* Check if given directory exists.
       
   392 	*
       
   393 	* @param pDirname Pointer to directory name.
       
   394 	* @return False If directory does not exists.
       
   395 	*/	
       
   396 	static bool DirectoryExists( const char* pDirname );
       
   397 
       
   398 	/**
       
   399 	* Checks from constant array is this targettype
       
   400 	* unsupported by AT
       
   401 	* @param sTargetType type to check
       
   402 	* @return true if it is supported by atool
       
   403 	*/
       
   404 	static bool IsTargetTypeSupported(string sTargetType);
       
   405 
       
   406 	/**
       
   407 	* Checks from constant array is this targettype
       
   408 	* kernel side.
       
   409 	* @param sTargetType type to check
       
   410 	* @return true if it is kernel type
       
   411 	*/
       
   412 	static bool IsTargetTypeKernelSide(string sTargetType);
       
   413 
       
   414 	/**
       
   415 	* Check is given variant defined in environment.(SBS v.1)
       
   416 	* @param sEpocroot
       
   417 	* @param sVariantName
       
   418 	* @return true if it is.
       
   419 	*/
       
   420 	static bool CheckVariant( const string& sEpocroot, const string& sVariantName );
       
   421 
       
   422 	/**
       
   423 	* Check has the environment defined "DEFAULT" variant
       
   424 	* @param sEpocRoot
       
   425 	* @return true if it is
       
   426 	*/
       
   427 	static  bool IsDefaultVariant( const string& sEpocRoot );
       
   428 
       
   429 	/**
       
   430 	* Check is all character ascii
       
   431 	* @param pInput pointer to characters
       
   432 	* @param iLength length of the string
       
   433 	* @return true if all character are ascii
       
   434 	*/
       
   435 	static bool IsAscii( const char* pInput, const unsigned int iLength );
       
   436 
       
   437 	/**
       
   438 	* Get current environments epocroot.
       
   439 	* @param sEpocRoot value is stored in this if successful.
       
   440 	* @return true if successful.
       
   441 	*/
       
   442 	static bool GetEpocRoot( string& sEpocRoot );
       
   443 };
       
   444 #endif