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