email/mail/UtilsSrc/MailLog.h
changeset 79 2981cb3aa489
parent 0 72b543305e3a
equal deleted inserted replaced
25:84d9eb65b26f 79:2981cb3aa489
       
     1 /*
       
     2 * Copyright (c) 2002 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 *     Logging class
       
    16 *     
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #ifndef MAILLOG_H
       
    23 #define MAILLOG_H
       
    24 
       
    25 /////////////////////////////////////////////////////////////////////////////
       
    26 // #Defines that control printing of additional information to debug stream.
       
    27 /////////////////////////////////////////////////////////////////////////////
       
    28 
       
    29 // INCLUDES
       
    30 
       
    31 #include "MailLogDef.h"
       
    32 #include <e32std.h>
       
    33 
       
    34 // DEFINES
       
    35 
       
    36 #ifdef MAIL_ENABLE_LOGGING
       
    37 #define LOGHANDLESIZE(v) MailLog::LogHandleSize(v);
       
    38 #define LOGHEAP() MailLog::LogHeap();
       
    39 #define LOG(s) MailLog::Log(_L(s))						// CSI: 78 # Have to use a _L macro
       
    40 #define LOG1(s, v) MailLog::Log( _L(s), v )				// CSI: 78 # Have to use a _L macro
       
    41 #define LOG2(s, v1, v2) MailLog::Log( _L(s), v1, v2 )	// CSI: 78 # Have to use a _L macro
       
    42 #define LOGPARAM_ONLY( x ) x
       
    43 #else
       
    44 #define LOGHANDLESIZE(v)
       
    45 #define LOGHEAP()
       
    46 #define LOG(s)
       
    47 #define LOG1(s, v)
       
    48 #define LOG2(s, v1, v2)
       
    49 #define LOGPARAM_ONLY( x )
       
    50 #endif // MAIL_ENABLE_LOGGING
       
    51 
       
    52 #ifdef MAIL_ENABLE_UNIT_TEST
       
    53 #define UNIT_TEST(ClassName) friend class ClassName;
       
    54 #else 
       
    55 #define UNIT_TEST(ClassName)
       
    56 #endif
       
    57 
       
    58 /**
       
    59  * Asserts and checks that statement doesn't allocate any memory. If
       
    60  * allocation happens evaluates failed.
       
    61  * 2147483647 KMaxTInt
       
    62  */
       
    63 #ifdef MAIL_ENABLE_ALLOC_TEST 
       
    64 #define MAIL_ALLOC_TEST(statement) \
       
    65     { TInt err(KErrNoMemory); TInt i(1); \
       
    66     while( err != KErrNone && i <= KMaxTInt ) \
       
    67         {__UHEAP_FAILNEXT(i); \
       
    68         LOG2("MAIL_ALLOC_TEST_FAILNEXT: %d err:%d", i, err); \
       
    69         TRAP(err, statement); \
       
    70         if(err==KLeaveExit) \
       
    71             User::Leave(err); \
       
    72         __UHEAP_RESET; \
       
    73         i += 1; \
       
    74         } \
       
    75     }
       
    76 #else
       
    77 
       
    78 /**
       
    79  * Release version of macro. Just executes statement.
       
    80  */
       
    81 #define MAIL_ALLOC_TEST(statement) statement
       
    82 
       
    83 #endif // MAIL_ENABLE_ALLOC_TEST
       
    84 
       
    85 
       
    86 // DATA TYPES
       
    87 
       
    88 
       
    89 // CLASS DECLARATION
       
    90 
       
    91 /**
       
    92 * Class offers logging functionality.
       
    93 */
       
    94 #ifdef MAIL_ENABLE_LOGGING
       
    95 class RFile;
       
    96 class MailLog
       
    97     {
       
    98 
       
    99     public:
       
   100     	static void LogHandleSize( RFile aFile );
       
   101         /**
       
   102         * Log the heap.
       
   103         */
       
   104         static void LogHeap();
       
   105         
       
   106         /**
       
   107         * Log the message.
       
   108 		* @param aText text to be written to log.
       
   109         */
       
   110         static void Log( TRefByValue<const TDesC> aText, ... );
       
   111         
       
   112 
       
   113     private: // constructor
       
   114         
       
   115 		/// Prohibited default constructor
       
   116 		MailLog();
       
   117 
       
   118 		/// Prohibited copy constructor
       
   119 		MailLog( const MailLog& );
       
   120     
       
   121 		/// Prohibited assignment operator
       
   122 		MailLog& operator=( const MailLog& );
       
   123     };
       
   124 
       
   125 #endif // MAIL_ENABLE_LOGGING
       
   126 
       
   127 #endif // MAILLOG_H
       
   128 
       
   129 //  End of File