analyzetool/commandlineengine/src/CATBase.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 49 7fdc9a71d314
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
   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()-1;
   147 	size_t iPos = sInput.size();
   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 // -----------------------------------------------------------------------------
       
   255 // CATBase::ChangeSlashToBackSlash
   231 // CATBase::ChangeSlashToBackSlash
   256 // Function changes all BackSlash characters to Slash character from
   232 // Function changes all BackSlash characters to Slash character from
   257 // given string.
   233 // given string.
   258 // -----------------------------------------------------------------------------
   234 // -----------------------------------------------------------------------------
   259 string CATBase::ChangeSlashToBackSlash( string sInput )
   235 string CATBase::ChangeSlashToBackSlash( string sInput )
   265 		{
   241 		{
   266 			sInput[i] = '\\';
   242 			sInput[i] = '\\';
   267 		}
   243 		}
   268 	}
   244 	}
   269 	return sInput;
   245 	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;
       
   337 }
   246 }
   338 
   247 
   339 // -----------------------------------------------------------------------------
   248 // -----------------------------------------------------------------------------
   340 // CATBase::FileExists
   249 // CATBase::FileExists
   341 // Check if given file exists.
   250 // Check if given file exists.
   965 // CATBase::CreateTemporaryCpp
   874 // CATBase::CreateTemporaryCpp
   966 // -----------------------------------------------------------------------------
   875 // -----------------------------------------------------------------------------
   967 bool CATBase::CreateTemporaryCpp( const string& sId,
   876 bool CATBase::CreateTemporaryCpp( const string& sId,
   968 								 const string& sPath
   877 								 const string& sPath
   969 								 ,const string& sS60FileName
   878 								 ,const string& sS60FileName
   970 								 ,const string& sS60FilePath
       
   971 								 ,int iLogOption
   879 								 ,int iLogOption
   972 								 ,int iIsDebug
   880 								 ,int iIsDebug
   973 								 ,int iAllocCallStackSize
   881 								 ,int iAllocCallStackSize
   974 								 ,int iFreeCallStackSize )
   882 								 ,int iFreeCallStackSize )
   975 {
   883 {
  1001 	out << "\nconst TInt ATTempAllocCallStackSize(" << iAllocCallStackSize << ");";
   909 	out << "\nconst TInt ATTempAllocCallStackSize(" << iAllocCallStackSize << ");";
  1002 	// Free call stack
   910 	// Free call stack
  1003 	out << "\nconst TInt ATTempFreeCallStackSize(" << iFreeCallStackSize << ");";
   911 	out << "\nconst TInt ATTempFreeCallStackSize(" << iFreeCallStackSize << ");";
  1004 	// Log file name
   912 	// Log file name
  1005 	out << "\n_LIT( ATTempLogFileName, \"" << sS60FileName << "\" );";
   913 	out << "\n_LIT( ATTempLogFileName, \"" << sS60FileName << "\" );";
  1006 	// Log file path
       
  1007 	out << "\n_LIT( ATTempLogFilePath, \"" << sS60FilePath << "\" );";
       
  1008 	// Version number
   914 	// Version number
  1009 	out << "\n_LIT( ATTempVersion, \"" << ATOOL_COMPATIBILITY_STRING << "\" );";
   915 	out << "\n_LIT( ATTempVersion, \"" << ATOOL_COMPATIBILITY_STRING << "\" );";
  1010 	// Variable functions use enumeration values that are defined in memoryhook (customuser.h)
   916 	// Variable functions use enumeration values that are defined in memoryhook (customuser.h)
  1011 	// We use constants here so that we don't need to include the header file, wich
   917 	// We use constants here so that we don't need to include the header file, wich
  1012 	// might cause problems.
   918 	// might cause problems.
  1016             ELogFileName = 1,   
   922             ELogFileName = 1,   
  1017             EVersion = 2 ,
   923             EVersion = 2 ,
  1018             ELogOption = 3,
   924             ELogOption = 3,
  1019             EDebug = 4,
   925             EDebug = 4,
  1020             EAllocCallStackSize = 5,
   926             EAllocCallStackSize = 5,
  1021             EFreeCallStackSize = 6,
   927             EFreeCallStackSize = 6
  1022 			ELogFilePath = 7
       
  1023             };
   928             };
  1024 */
   929 */
  1025 	out << "\nTInt GetInt( const TUint8 aType )";
   930 	out << "\nTInt GetInt( const TUint8 aType )";
  1026 	out << "\n{";
   931 	out << "\n{";
  1027 	out << "\nswitch( aType )";
   932 	out << "\nswitch( aType )";
  1037 	out << "\n{";
   942 	out << "\n{";
  1038 	out << "\nswitch( aType )";
   943 	out << "\nswitch( aType )";
  1039 	out << "\n{";
   944 	out << "\n{";
  1040 	out << "\ncase 1: return ATTempLogFileName();";
   945 	out << "\ncase 1: return ATTempLogFileName();";
  1041 	out << "\ncase 2: return ATTempVersion();";
   946 	out << "\ncase 2: return ATTempVersion();";
  1042 	out << "\ncase 7: return ATTempLogFilePath();";
       
  1043 	out << "\ndefault: return KNullDesC();";
   947 	out << "\ndefault: return KNullDesC();";
  1044 	out << "\n}";
   948 	out << "\n}";
  1045 	out << "\n}";
   949 	out << "\n}";
  1046 
   950 
  1047 	/** Todo: Old way of separate functions, these here for backup support and to ease testing. */
   951 	/** Todo: Old way of separate functions, these here for backup support and to ease testing. */
  1049 
   953 
  1050 	out << "\n_LIT( KFileName, \"";
   954 	out << "\n_LIT( KFileName, \"";
  1051 	out << sS60FileName;
   955 	out << sS60FileName;
  1052 	out << "\" );\n";
   956 	out << "\" );\n";
  1053 
   957 
  1054 	out << "\n_LIT( KFilePath, \"";
       
  1055 	out << sS60FilePath;
       
  1056 	out << "\" );\n";
       
  1057 
       
  1058 	// Hardcoded version number for support.
   958 	// Hardcoded version number for support.
  1059 	out << "\n/* The AnalyzeTool version number used. */";
   959 	out << "\n/* The AnalyzeTool version number used. */";
  1060 	out << "\n_LIT( KAtoolVersion, \"1.7.6;1.10.0\" );\n";
   960 	out << "\n_LIT( KAtoolVersion, \"1.7.5;1.9.1\" );\n";
  1061 
   961 
  1062 	out << "\nconst TFileName LogFileName()";
   962 	out << "\nconst TFileName LogFileName()";
  1063 	out << "\n    {";
   963 	out << "\n    {";
  1064 	out << "\n    return TFileName( KFileName() );";
   964 	out << "\n    return TFileName( KFileName() );";
  1065 	out << "\n    }";
       
  1066 
       
  1067 	out << "\nconst TPath LogFilePath()";
       
  1068 	out << "\n    {";
       
  1069 	out << "\n    return TPath( KFilePath() );";
       
  1070 	out << "\n    }";
   965 	out << "\n    }";
  1071 
   966 
  1072 	out << "\nTUint32 AllocCallStackSize()";
   967 	out << "\nTUint32 AllocCallStackSize()";
  1073 	out << "\n    {";
   968 	out << "\n    {";
  1074 	out << "\n    return TUint32( ";
   969 	out << "\n    return TUint32( ";
  1137 		return true;
  1032 		return true;
  1138 	else
  1033 	else
  1139 		return false;
  1034 		return false;
  1140 }
  1035 }
  1141 
  1036 
  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 }
       
  1172 
  1037 
  1173 // -----------------------------------------------------------------------------
  1038 // -----------------------------------------------------------------------------
  1174 // CATBase::ParseStringToVector
  1039 // CATBase::ParseStringToVector
  1175 // -----------------------------------------------------------------------------
  1040 // -----------------------------------------------------------------------------
  1176 vector<string> CATBase::ParseStringToVector( const string& sInput, char separator )
  1041 vector<string> CATBase::ParseStringToVector( const string& sInput, char separator )