realtimenetprots/sipfw/ProfileAgent/Profile/Inc/SipProfileLog.inl
changeset 55 36ea1f90a3d8
parent 17 bfe1f539b721
equal deleted inserted replaced
54:e4420734a2a0 55:36ea1f90a3d8
    18 * Macros for logging
    18 * Macros for logging
    19 * Version     : 1.0
    19 * Version     : 1.0
    20 *
    20 *
    21 */
    21 */
    22 
    22 
    23 
       
    24 #include <flogger.h>
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <bautils.h>
       
    28 #include <utf.h>
       
    29 
       
    30 _LIT(KSipLogFileDir, "Sip");
       
    31 _LIT(KSipLogFileName, "SipLog.txt");
       
    32 _LIT(KSipLogPath, "C:\\logs\\sip\\");
       
    33 _LIT(KSeparator, "---------------");
       
    34 
       
    35 inline void TSIPProfileDebug::Print(const TDesC16& aStr) 
    23 inline void TSIPProfileDebug::Print(const TDesC16& aStr) 
    36 	{
    24 	{
    37 	_LIT(KProfileFormat, "SIPProfile: %S");
    25     OstTraceExt1( TRACE_NORMAL, TSIPPROFILEDEBUG_PRINT, "SIPProfile: %S", aStr );
    38 	TBuf<256> str;
       
    39 
       
    40 	str.Format(KProfileFormat, &aStr);
       
    41 		
       
    42 	WriteLog( str );
       
    43 	}
    26 	}
    44 
    27 
    45 
    28 
    46 inline void TSIPProfileDebug::Print(const TDesC16& aStr1, const TDesC16& aStr2) 
    29 inline void TSIPProfileDebug::Print(const TDesC16& aStr1, const TDesC16& aStr2) 
    47 	{
    30 	{
    48 	_LIT(KProfileFormat, "SIPProfile: %S, %S");
    31     OstTraceExt2( TRACE_NORMAL, TSIPPROFILEDEBUG_PRINT_TWO_ARG, "SIPProfile: %S, %S", aStr1, aStr2 );
    49 	TBuf<256> str;
       
    50 
       
    51 	str.Format(KProfileFormat, &aStr1, &aStr2);
       
    52 		
       
    53 	WriteLog( str );
       
    54 	}
    32 	}
    55 
    33 
    56 
    34 
    57 inline void TSIPProfileDebug::Print(const TDesC16& aStr, TUint32 aValue) 
    35 inline void TSIPProfileDebug::Print(const TDesC16& aStr, TUint32 aValue) 
    58 	{
    36 	{
    59 	_LIT(KProfileFormat, "SIPProfile: %S, %d");
    37     OstTraceExt2( TRACE_NORMAL, DUP1_TSIPPROFILEDEBUG_PRINT, "SIPProfile: %S, %u", aStr, aValue );
    60 	TBuf<256> str;
       
    61 
       
    62 	str.Format(KProfileFormat, &aStr, aValue);
       
    63 		
       
    64 	WriteLog( str );
       
    65 	}
    38 	}
    66 
    39 
    67 inline void TSIPProfileDebug::Print(const TDesC16& aStr, TUint32 aValue1,
    40 inline void TSIPProfileDebug::Print(const TDesC16& aStr, TUint32 aValue1,
    68 	TUint32 aValue2) 
    41 	TUint32 aValue2) 
    69 	{
    42 	{
    70 	_LIT(KProfileFormat, "SIPProfile: %S, %d, %d");
    43     OstTraceExt3( TRACE_NORMAL, DUP2_TSIPPROFILEDEBUG_PRINT, "SIPProfile: %S, %u, %u", aStr, aValue1, aValue2 );
    71 	TBuf<256> str;
       
    72 
       
    73 	str.Format(KProfileFormat, &aStr, aValue1, aValue2);
       
    74 		
       
    75 	WriteLog( str );
       
    76 	}
    44 	}
    77 
    45 
    78 
    46 
    79 inline void TSIPProfileDebug::Print(const TDesC16& aStr, TUint32 aValue1, 
    47 inline void TSIPProfileDebug::Print(const TDesC16& aStr, TUint32 aValue1, 
    80 	TUint32 aValue2, TUint32 aValue3) 
    48 	TUint32 aValue2, TUint32 aValue3) 
    81 	{
    49 	{
    82 	_LIT(KProfileFormat, "SIPProfile: %S, %d, %d, %d");
    50     OstTraceExt4( TRACE_NORMAL, DUP3_TSIPPROFILEDEBUG_PRINT, "SIPProfile: %S, %u, %u, %u", aStr, aValue1, aValue2, aValue3 );
    83 	TBuf<256> str;
       
    84 
       
    85 	str.Format(KProfileFormat, &aStr, aValue1, aValue2, aValue3);
       
    86 		
       
    87 	WriteLog( str );
       
    88 	}
    51 	}
    89 
    52 
    90 
    53 
    91 inline void TSIPProfileDebug::Print(const TDesC16& aStr1, const TDesC8& aStr2) 
    54 inline void TSIPProfileDebug::Print(const TDesC16& aStr1, const TDesC8& aStr2) 
    92 	{
    55 	{
    93 	_LIT(KProfileFormat, "SIPProfile: %S, %S");
    56     OstTraceExt2( TRACE_NORMAL, DUP4_TSIPPROFILEDEBUG_PRINT, "SIPProfile: %S, %s", aStr1, aStr2 );
    94 	TBuf<100> str2;
       
    95 	CnvUtfConverter::ConvertToUnicodeFromUtf8(str2, aStr2);
       
    96 	TBuf<256> str;
       
    97 
       
    98 	str.Format(KProfileFormat, &aStr1, &str2);
       
    99 		
       
   100 	WriteLog( str );
       
   101 	}
    57 	}
   102 
       
   103 inline TBool TSIPProfileDebug::LogDirExists( const TDesC& aFolderName )
       
   104 	{
       
   105 	RFs fs;
       
   106 	TInt ret = fs.Connect();
       
   107 	
       
   108 	if ( ret != KErrNone )
       
   109 		{
       
   110 		fs.Close();
       
   111 		return EFalse;
       
   112 		}
       
   113 	
       
   114 	if ( aFolderName.Length() == 0 )
       
   115 		{
       
   116 		fs.Close();
       
   117 		return EFalse;
       
   118 		}
       
   119 	
       
   120 	TParse parse;
       
   121 	
       
   122 	TInt retcode = parse.SetNoWild( aFolderName, NULL, NULL );
       
   123  	
       
   124 	if ( retcode != KErrNone )
       
   125 		{
       
   126 		fs.Close();
       
   127 		return EFalse;
       
   128 		}
       
   129  			
       
   130 	if ( parse.NameOrExtPresent() )
       
   131 		{
       
   132 		if ( !fs.IsValidName( aFolderName ) )
       
   133 			{
       
   134 			fs.Close();
       
   135 			return EFalse;
       
   136 			}
       
   137 		}
       
   138  	
       
   139 	TPtrC dirName = parse.DriveAndPath();
       
   140 	RDir dir;
       
   141 	retcode = dir.Open( fs, dirName, 0 );
       
   142 	
       
   143 	if ( retcode == KErrNone )
       
   144 		{
       
   145 		dir.Close();
       
   146 		}
       
   147 	fs.Close();
       
   148 	
       
   149 	return ( retcode == KErrNone );
       
   150 	}
       
   151 
       
   152 inline void TSIPProfileDebug::WriteToFile( const TDesC& aStr )
       
   153 	{
       
   154 	RFileLogger::Write ( KSipLogFileDir, KSipLogFileName, 
       
   155 		EFileLoggingModeAppend, aStr );
       
   156 	RFileLogger::Write (KSipLogFileDir, KSipLogFileName, 
       
   157 		EFileLoggingModeAppend, KSeparator);		
       
   158 	}
       
   159 	
       
   160 inline void TSIPProfileDebug::WriteLog( const TDesC& aStr )
       
   161 	{
       
   162 	if ( LogDirExists( KSipLogPath ) )
       
   163 		{
       
   164 		WriteToFile( aStr );
       
   165 		}
       
   166 	else
       
   167 		{
       
   168 		RDebug::RawPrint( aStr );
       
   169 		}
       
   170 	}