realtimenetprots/sipfw/ClientResolver/common/inc/SIPCRLogs.inl
changeset 0 307788aac0a8
child 55 36ea1f90a3d8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2005-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:
       
    15 * Name          : SIPCRLogs.inl
       
    16 * Part of       : SIP Client Resolver
       
    17 * Version       :  
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 /**
       
    25  @internalComponent
       
    26 */
       
    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)
       
    40 	{
       
    41 	_LIT( KLogFormat, "SIP Client Resolver: %S" );
       
    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 	}
       
    54 
       
    55 inline void SIPCRLog::Print(const TDesC16& aStr, TInt aValue) 
       
    56 	{
       
    57 	_LIT( KLogFormat, "SIP Client Resolver: %S: %d" );
       
    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 	}
       
    73 
       
    74 inline void SIPCRLog::Print(const TDesC16& aStr1, const TDesC8& aStr2) 
       
    75 	{
       
    76 	_LIT(KLogFormat, "SIP Client Resolver: %S: %S");
       
    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 	}
       
    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 	}