analyzetool/commandlineengine/src/CATBase.cpp
branchRCL_3
changeset 49 7fdc9a71d314
parent 19 da2cedce4920
child 59 8ad140f3dd41
equal deleted inserted replaced
46:e26895079d7c 49:7fdc9a71d314
   142 // -----------------------------------------------------------------------------
   142 // -----------------------------------------------------------------------------
   143 string CATBase::GetPathOrFileName( bool bFileName, string sInput )
   143 string CATBase::GetPathOrFileName( bool bFileName, string sInput )
   144 {
   144 {
   145 	LOG_LOW_FUNC_ENTRY("CATBase::GetPathOrFileName");
   145 	LOG_LOW_FUNC_ENTRY("CATBase::GetPathOrFileName");
   146 	string sRet;
   146 	string sRet;
   147 	size_t iPos = sInput.size();
   147 	size_t iPos = sInput.size()-1;
   148 
   148 
   149 	sInput = ChangeSlashToBackSlash( sInput );
   149 	sInput = ChangeSlashToBackSlash( sInput );
   150 
   150 
   151 	//Find character '\' starting from end of string
   151 	//Find character '\' starting from end of string
   152 	while( iPos > 0 && sInput[iPos] != '\\' )
   152 	while( iPos > 0 && sInput[iPos] != '\\' )
   226 	}
   226 	}
   227 	return sTemp;
   227 	return sTemp;
   228 }
   228 }
   229 
   229 
   230 // -----------------------------------------------------------------------------
   230 // -----------------------------------------------------------------------------
       
   231 // CATBase::GetStringUntilMainId
       
   232 // Function returns string from begin of given string until next atool's main id <AT>,
       
   233 // characters until next main id are removed from sInput string.
       
   234 // -----------------------------------------------------------------------------
       
   235 string CATBase::GetStringUntilMainId( string& sInput, bool bEraseFromInput )
       
   236 {
       
   237 	LOG_LOW_FUNC_ENTRY("CATBase::GetStringUntilMainId");
       
   238 	string sTemp( sInput );
       
   239 	size_t iSize = sTemp.find(MAIN_ID);
       
   240 	if( iSize != string::npos )
       
   241 	{
       
   242 		sTemp.resize( iSize );
       
   243 		if( bEraseFromInput )
       
   244 			sInput.erase( 0, (iSize) );
       
   245 	}
       
   246 	else
       
   247 	{
       
   248 		if ( bEraseFromInput )
       
   249 			sInput.clear();
       
   250 	}
       
   251 	return sTemp;
       
   252 }
       
   253 
       
   254 // -----------------------------------------------------------------------------
   231 // CATBase::ChangeSlashToBackSlash
   255 // CATBase::ChangeSlashToBackSlash
   232 // Function changes all BackSlash characters to Slash character from
   256 // Function changes all BackSlash characters to Slash character from
   233 // given string.
   257 // given string.
   234 // -----------------------------------------------------------------------------
   258 // -----------------------------------------------------------------------------
   235 string CATBase::ChangeSlashToBackSlash( string sInput )
   259 string CATBase::ChangeSlashToBackSlash( string sInput )
   241 		{
   265 		{
   242 			sInput[i] = '\\';
   266 			sInput[i] = '\\';
   243 		}
   267 		}
   244 	}
   268 	}
   245 	return sInput;
   269 	return sInput;
       
   270 }
       
   271 
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CATBase::ParseTimeStamp
       
   275 // Function returns time parsed from start of trace message
       
   276 // -----------------------------------------------------------------------------
       
   277 unsigned __int64 CATBase::ParseTimeStamp( string sLineStart )
       
   278 {
       
   279 	unsigned __int64 iTime(0);
       
   280 
       
   281 	int iHours(0), iMinutes(0), iSeconds(0), iMiliseconds(0), iMicroseconds(0);
       
   282 	int iErr(0), iRet(0);
       
   283 
       
   284 	TrimString( sLineStart );
       
   285 	string sTimeString = GetStringUntilNextSpace( sLineStart );
       
   286 
       
   287 	// Get time
       
   288 	int iPos = sTimeString.find( ":" );
       
   289 	if( iPos != string::npos ) // ':' found, this is timestamp from fastTrace/traceViewer 
       
   290 	{
       
   291 		// possible formats 
       
   292 		// hh:mm:ss - seconds (ft)
       
   293         // hh:mm:ss:mmm - miliseconds (ft/tw)
       
   294 		// hh:mm:ss:mmmmmm - microseconds (ft/tw)
       
   295 		// hh:mm:ss:nnnnnnnnn - nanoseconds (ft) - ignore last 3digits
       
   296 
       
   297 		iRet = sscanf_s( sTimeString.c_str(), "%d:%d:%d.%3d%3d", &iHours, &iMinutes, &iSeconds, &iMiliseconds, &iMicroseconds );
       
   298 		if( iRet == 5 || iRet == 4 )
       
   299 		{
       
   300 			// get microseconds
       
   301 			iTime = ( ( ( iHours*60 + iMinutes )*60 + iSeconds )*1000 + iMiliseconds )*1000 + iMicroseconds;
       
   302 		}
       
   303 		else
       
   304 		{
       
   305 			iErr = true;
       
   306 		}
       
   307 	}
       
   308 	else if( sTimeString.find( "." ) != string::npos ) // epoc timestamp in format ssss.mmm
       
   309 	{
       
   310 		iRet = sscanf_s( sTimeString.c_str(), "%d.%d", &iSeconds, &iMiliseconds );
       
   311 		if( iRet == 2 )
       
   312 		{
       
   313 			// get microseconds
       
   314 			iTime = ( ( ( iHours*60 + iMinutes )*60 + iSeconds )*1000 + iMiliseconds )*1000 + iMicroseconds;
       
   315 		}
       
   316 		else
       
   317 		{
       
   318 			iErr = true;
       
   319 		}
       
   320 	}
       
   321 	else // timestamp in microseconds from binary log file or from ft
       
   322 	{
       
   323 		iRet = sscanf_s( sTimeString.c_str(), "%016I64x", &iTime);
       
   324 		if( iRet == 1 )
       
   325 		{
       
   326 		}
       
   327 		else
       
   328 		{
       
   329 			iErr = true;
       
   330 		}
       
   331 	}
       
   332 
       
   333 	if( iErr )
       
   334 		cout << "Error, can not read timestamp.\n";
       
   335 
       
   336 	return iTime;
   246 }
   337 }
   247 
   338 
   248 // -----------------------------------------------------------------------------
   339 // -----------------------------------------------------------------------------
   249 // CATBase::FileExists
   340 // CATBase::FileExists
   250 // Check if given file exists.
   341 // Check if given file exists.
   874 // CATBase::CreateTemporaryCpp
   965 // CATBase::CreateTemporaryCpp
   875 // -----------------------------------------------------------------------------
   966 // -----------------------------------------------------------------------------
   876 bool CATBase::CreateTemporaryCpp( const string& sId,
   967 bool CATBase::CreateTemporaryCpp( const string& sId,
   877 								 const string& sPath
   968 								 const string& sPath
   878 								 ,const string& sS60FileName
   969 								 ,const string& sS60FileName
       
   970 								 ,const string& sS60FilePath
   879 								 ,int iLogOption
   971 								 ,int iLogOption
   880 								 ,int iIsDebug
   972 								 ,int iIsDebug
   881 								 ,int iAllocCallStackSize
   973 								 ,int iAllocCallStackSize
   882 								 ,int iFreeCallStackSize )
   974 								 ,int iFreeCallStackSize )
   883 {
   975 {
   909 	out << "\nconst TInt ATTempAllocCallStackSize(" << iAllocCallStackSize << ");";
  1001 	out << "\nconst TInt ATTempAllocCallStackSize(" << iAllocCallStackSize << ");";
   910 	// Free call stack
  1002 	// Free call stack
   911 	out << "\nconst TInt ATTempFreeCallStackSize(" << iFreeCallStackSize << ");";
  1003 	out << "\nconst TInt ATTempFreeCallStackSize(" << iFreeCallStackSize << ");";
   912 	// Log file name
  1004 	// Log file name
   913 	out << "\n_LIT( ATTempLogFileName, \"" << sS60FileName << "\" );";
  1005 	out << "\n_LIT( ATTempLogFileName, \"" << sS60FileName << "\" );";
       
  1006 	// Log file path
       
  1007 	out << "\n_LIT( ATTempLogFilePath, \"" << sS60FilePath << "\" );";
   914 	// Version number
  1008 	// Version number
   915 	out << "\n_LIT( ATTempVersion, \"" << ATOOL_COMPATIBILITY_STRING << "\" );";
  1009 	out << "\n_LIT( ATTempVersion, \"" << ATOOL_COMPATIBILITY_STRING << "\" );";
   916 	// Variable functions use enumeration values that are defined in memoryhook (customuser.h)
  1010 	// Variable functions use enumeration values that are defined in memoryhook (customuser.h)
   917 	// We use constants here so that we don't need to include the header file, wich
  1011 	// We use constants here so that we don't need to include the header file, wich
   918 	// might cause problems.
  1012 	// might cause problems.
   922             ELogFileName = 1,   
  1016             ELogFileName = 1,   
   923             EVersion = 2 ,
  1017             EVersion = 2 ,
   924             ELogOption = 3,
  1018             ELogOption = 3,
   925             EDebug = 4,
  1019             EDebug = 4,
   926             EAllocCallStackSize = 5,
  1020             EAllocCallStackSize = 5,
   927             EFreeCallStackSize = 6
  1021             EFreeCallStackSize = 6,
       
  1022 			ELogFilePath = 7
   928             };
  1023             };
   929 */
  1024 */
   930 	out << "\nTInt GetInt( const TUint8 aType )";
  1025 	out << "\nTInt GetInt( const TUint8 aType )";
   931 	out << "\n{";
  1026 	out << "\n{";
   932 	out << "\nswitch( aType )";
  1027 	out << "\nswitch( aType )";
   942 	out << "\n{";
  1037 	out << "\n{";
   943 	out << "\nswitch( aType )";
  1038 	out << "\nswitch( aType )";
   944 	out << "\n{";
  1039 	out << "\n{";
   945 	out << "\ncase 1: return ATTempLogFileName();";
  1040 	out << "\ncase 1: return ATTempLogFileName();";
   946 	out << "\ncase 2: return ATTempVersion();";
  1041 	out << "\ncase 2: return ATTempVersion();";
       
  1042 	out << "\ncase 7: return ATTempLogFilePath();";
   947 	out << "\ndefault: return KNullDesC();";
  1043 	out << "\ndefault: return KNullDesC();";
   948 	out << "\n}";
  1044 	out << "\n}";
   949 	out << "\n}";
  1045 	out << "\n}";
   950 
  1046 
   951 	/** Todo: Old way of separate functions, these here for backup support and to ease testing. */
  1047 	/** Todo: Old way of separate functions, these here for backup support and to ease testing. */
   953 
  1049 
   954 	out << "\n_LIT( KFileName, \"";
  1050 	out << "\n_LIT( KFileName, \"";
   955 	out << sS60FileName;
  1051 	out << sS60FileName;
   956 	out << "\" );\n";
  1052 	out << "\" );\n";
   957 
  1053 
       
  1054 	out << "\n_LIT( KFilePath, \"";
       
  1055 	out << sS60FilePath;
       
  1056 	out << "\" );\n";
       
  1057 
   958 	// Hardcoded version number for support.
  1058 	// Hardcoded version number for support.
   959 	out << "\n/* The AnalyzeTool version number used. */";
  1059 	out << "\n/* The AnalyzeTool version number used. */";
   960 	out << "\n_LIT( KAtoolVersion, \"1.7.5;1.9.1\" );\n";
  1060 	out << "\n_LIT( KAtoolVersion, \"1.7.6;1.10.0\" );\n";
   961 
  1061 
   962 	out << "\nconst TFileName LogFileName()";
  1062 	out << "\nconst TFileName LogFileName()";
   963 	out << "\n    {";
  1063 	out << "\n    {";
   964 	out << "\n    return TFileName( KFileName() );";
  1064 	out << "\n    return TFileName( KFileName() );";
       
  1065 	out << "\n    }";
       
  1066 
       
  1067 	out << "\nconst TPath LogFilePath()";
       
  1068 	out << "\n    {";
       
  1069 	out << "\n    return TPath( KFilePath() );";
   965 	out << "\n    }";
  1070 	out << "\n    }";
   966 
  1071 
   967 	out << "\nTUint32 AllocCallStackSize()";
  1072 	out << "\nTUint32 AllocCallStackSize()";
   968 	out << "\n    {";
  1073 	out << "\n    {";
   969 	out << "\n    return TUint32( ";
  1074 	out << "\n    return TUint32( ";
  1032 		return true;
  1137 		return true;
  1033 	else
  1138 	else
  1034 		return false;
  1139 		return false;
  1035 }
  1140 }
  1036 
  1141 
       
  1142 // -----------------------------------------------------------------------------
       
  1143 // CATBase::IsBinaryLogFile
       
  1144 // -----------------------------------------------------------------------------
       
  1145 bool CATBase::IsBinaryLogFile( string sFile )
       
  1146 {
       
  1147 	LOG_FUNC_ENTRY("CATBase::IsDataFile");
       
  1148 	// Check that sFile not empty
       
  1149 	if ( sFile.empty() || sFile.length() < 1 )
       
  1150 		return false;
       
  1151 
       
  1152 	// Temporary line char array.
       
  1153 	char cLineFromFile[MAX_LINE_LENGTH];
       
  1154 	//Open file
       
  1155 	ifstream in( sFile.c_str() );
       
  1156 
       
  1157 	//File open ok?
       
  1158 	if( !in.good() )
       
  1159 		return false;
       
  1160 
       
  1161 	//Read all lines
       
  1162 	in.getline( cLineFromFile, MAX_LINE_LENGTH );
       
  1163 
       
  1164 	string sLineFromFile( cLineFromFile );
       
  1165 	in.close();
       
  1166 
       
  1167 	if( sLineFromFile.find( "ATOOL_BINARY_FILE_VERSION" ) != string::npos )
       
  1168 		return true;
       
  1169 	else
       
  1170 		return false;
       
  1171 }
  1037 
  1172 
  1038 // -----------------------------------------------------------------------------
  1173 // -----------------------------------------------------------------------------
  1039 // CATBase::ParseStringToVector
  1174 // CATBase::ParseStringToVector
  1040 // -----------------------------------------------------------------------------
  1175 // -----------------------------------------------------------------------------
  1041 vector<string> CATBase::ParseStringToVector( const string& sInput, char separator )
  1176 vector<string> CATBase::ParseStringToVector( const string& sInput, char separator )