realtimenetprots/sipfw/ClientResolver/common/inc/SIPCRLogs.inl
changeset 55 36ea1f90a3d8
parent 0 307788aac0a8
equal deleted inserted replaced
54:e4420734a2a0 55:36ea1f90a3d8
    23 
    23 
    24 /**
    24 /**
    25  @internalComponent
    25  @internalComponent
    26 */
    26 */
    27 
    27 
    28 #include <e32base.h>
       
    29 #include <e32svr.h>
       
    30 #include <utf.h>
       
    31 #include <flogger.h>
       
    32 #include <bautils.h>
       
    33 
       
    34 _LIT(KSipLogFileDir, "Sip");
       
    35 _LIT(KSipLogFileName, "SipLog.txt");
       
    36 _LIT(KSeparator, "---------------");
       
    37 _LIT(KSipLogPath, "C:\\logs\\sip\\");
       
    38 
       
    39 inline void SIPCRLog::Print(const TDesC16& aStr)
    28 inline void SIPCRLog::Print(const TDesC16& aStr)
    40 	{
    29 	{
    41 	_LIT( KLogFormat, "SIP Client Resolver: %S" );
    30     OstTraceExt1( TRACE_NORMAL, SIPCRLOG_PRINT_TEXT16, "SIP Client Resolver: %S", aStr );
    42 	TBuf<256> str;
       
    43 	str.Format( KLogFormat, &aStr );
       
    44     
       
    45 	if ( LogDirExists( KSipLogPath ) )
       
    46 		{
       
    47 		WriteToFile( str );
       
    48 		}
       
    49 	else
       
    50 		{
       
    51 		RDebug::RawPrint( str );
       
    52 		}
       
    53 	}
    31 	}
    54 
    32 
    55 inline void SIPCRLog::Print(const TDesC16& aStr, TInt aValue) 
    33 inline void SIPCRLog::Print(const TDesC16& aStr, TInt aValue) 
    56 	{
    34 	{
    57 	_LIT( KLogFormat, "SIP Client Resolver: %S: %d" );
    35     OstTraceExt2( TRACE_NORMAL, SIPCRLOG_PRINT_TEXT16_TINT, "SIP Client Resolver: %S: %d", aStr, aValue );
    58 	TBuf<256> str;
       
    59 	str.Format( KLogFormat, &aStr, aValue );
       
    60 	
       
    61 	if ( LogDirExists( KSipLogPath ) )
       
    62 		{
       
    63 		WriteToFile( str );
       
    64 		}
       
    65 	else
       
    66 		{
       
    67 		_LIT(KLogFormat, "SIP Client Resolver: %S: %d");
       
    68 		TBuf<256> str;
       
    69 		str.Format(KLogFormat, &aStr, aValue);
       
    70 		RDebug::RawPrint(str);
       
    71 		}
       
    72 	}
    36 	}
    73 
    37 
    74 inline void SIPCRLog::Print(const TDesC16& aStr1, const TDesC8& aStr2) 
    38 inline void SIPCRLog::Print(const TDesC16& aStr1, const TDesC8& aStr2) 
    75 	{
    39 	{
    76 	_LIT(KLogFormat, "SIP Client Resolver: %S: %S");
    40     OstTraceExt2( TRACE_NORMAL, SIPCRLOG_PRINT_TEXT16_TEXT8, "SIP Client Resolver: %S: %s", aStr1, aStr2 );
    77 	TBuf<100> str2;
       
    78 	CnvUtfConverter::ConvertToUnicodeFromUtf8(str2, aStr2);
       
    79 	TBuf<256> str;
       
    80 	str.Format(KLogFormat, &aStr1, &str2);
       
    81 	
       
    82 	if ( LogDirExists( KSipLogPath ) )
       
    83 		{
       
    84 		WriteToFile( str );
       
    85 		}
       
    86 	else
       
    87 		{
       
    88 		RDebug::RawPrint(str);    	
       
    89 		}
       
    90 	}
    41 	}
    91 
       
    92 inline TBool SIPCRLog::LogDirExists( const TDesC& aFolderName )
       
    93 	{
       
    94 	RFs fs;
       
    95 	TInt ret = fs.Connect();
       
    96 	
       
    97 	if ( ret != KErrNone )
       
    98 		{
       
    99 		fs.Close();
       
   100 		return EFalse;
       
   101 		}
       
   102 	
       
   103 	if ( aFolderName.Length() == 0 )
       
   104 		{
       
   105 		fs.Close();
       
   106 		return EFalse;
       
   107 		}
       
   108 	
       
   109 	TParse parse;
       
   110 	
       
   111 	TInt retcode = parse.SetNoWild( aFolderName, NULL, NULL );
       
   112  	
       
   113 	if ( retcode != KErrNone )
       
   114 		{
       
   115 		fs.Close();
       
   116 		return EFalse;
       
   117 		}
       
   118  			
       
   119 	if ( parse.NameOrExtPresent() )
       
   120 		{
       
   121 		if ( !fs.IsValidName( aFolderName ) )
       
   122 			{
       
   123 			fs.Close();
       
   124 			return EFalse;
       
   125 			}
       
   126 		}
       
   127  	
       
   128 	TPtrC dirName = parse.DriveAndPath();
       
   129 	RDir dir;
       
   130 	retcode = dir.Open( fs, dirName, 0 );
       
   131 	
       
   132 	if ( retcode == KErrNone )
       
   133 		{
       
   134 		dir.Close();
       
   135 		}
       
   136 	fs.Close();
       
   137 	
       
   138 	return ( retcode == KErrNone );
       
   139 	}
       
   140 
       
   141 inline void SIPCRLog::WriteToFile( const TDesC& aStr )
       
   142 	{
       
   143 	RFileLogger::Write( KSipLogFileDir, KSipLogFileName, 
       
   144 		EFileLoggingModeAppend, aStr );
       
   145 	RFileLogger::Write (KSipLogFileDir, KSipLogFileName, 
       
   146 		EFileLoggingModeAppend, KSeparator);		
       
   147 	}