locationdataharvester/mylocationlogger/inc/mylocationlogger.h
branchRCL_3
changeset 17 1fc85118c3ae
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
       
     1 /*
       
     2 * Copyright (c) 2010 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 *
       
    16 */
       
    17 
       
    18 #ifndef MYLOCATIONLOGGER_H
       
    19 #define MYLOCATIONLOGGER_H
       
    20 #include <e32base.h> 
       
    21 #include <e32std.h> 
       
    22 #include <e32des8.h>
       
    23 #include <e32svr.h>
       
    24 #include "mylocloggingconfiguration.h"
       
    25 _LIT( KLogsDir, "Mylocation");
       
    26 _LIT( KLogFileName, "Mylocation.log");
       
    27 
       
    28 /*
       
    29  We have 3 possible logging methods:
       
    30 
       
    31  set MYLOC_LOGGING_METHOD to 0 to get no logging at all
       
    32  set MYLOC_LOGGING_METHOD to 1 to get logging via RDebug::Print
       
    33  set MYLOC_LOGGING_METHOD to 2 to get logging to log file
       
    34 
       
    35  Switching on/off is done in the Configuration file (MyLocLoggingConfiguration.h)
       
    36  */
       
    37 
       
    38 #if ( defined (_MYLOCLOGGING) )
       
    39 #if ( defined (_MYLOC_LOGGING_TO_FILE))
       
    40 #define MYLOC_LOGGING_METHOD 2
       
    41 #else
       
    42 #define MYLOC_LOGGING_METHOD 1
       
    43 #endif
       
    44 #else
       
    45 #define MYLOC_LOGGING_METHOD 0
       
    46 #endif
       
    47 
       
    48 #if (MYLOC_LOGGING_METHOD==0)
       
    49 #define MYLOCLOGSTRING(C)
       
    50 #define MYLOCLOGSTRING1(C, X)
       
    51 #define MYLOCLOGSTRING2(C, X, Y)
       
    52 #define MYLOCLOGSTRING3(C, X, Y, Z)
       
    53 #define MYLOCLOGSTRING4(C, X, Y, Z, A)
       
    54 #endif
       
    55 #if (MYLOC_LOGGING_METHOD==1)
       
    56 #define MYLOCLOGSTRING(C)                RDebug::Print(_L(C));
       
    57 #define MYLOCLOGSTRING1(C, X)            RDebug::Print(_L(C),X);
       
    58 #define MYLOCLOGSTRING2(C, X, Y)         RDebug::Print(_L(C),X, Y);
       
    59 #define MYLOCLOGSTRING3(C, X, Y, Z)      RDebug::Print(_L(C),X, Y, Z);
       
    60 #define MYLOCLOGSTRING4(C, X, Y, Z, A)   RDebug::Print(_L(C),X, Y, Z, A);
       
    61 #endif
       
    62 #if (MYLOC_LOGGING_METHOD==2)
       
    63 #ifndef __COMMSDEBUGUTILITY_H__
       
    64 #define __COMMSDEBUGUTILITY_H__
       
    65 #include <flogger.h>
       
    66 #endif
       
    67 
       
    68 
       
    69 #define MYLOCLOGSTRING(C)                {_LIT(tempLogDes,C);RFileLogger::WriteFormat(KLogsDir(),KLogFileName(), EFileLoggingModeAppend, tempLogDes());}
       
    70 #define MYLOCLOGSTRING1(C, X)            {_LIT(tempLogDes,C);RFileLogger::WriteFormat(KLogsDir(),KLogFileName(), EFileLoggingModeAppend, TRefByValue<const TDesC>(tempLogDes()),X);}
       
    71 #define MYLOCLOGSTRING2(C, X, Y)         {_LIT(tempLogDes,C);RFileLogger::WriteFormat(KLogsDir(),KLogFileName(), EFileLoggingModeAppend, TRefByValue<const TDesC>(tempLogDes()),X,Y);}
       
    72 #define MYLOCLOGSTRING3(C, X, Y, Z)      {_LIT(tempLogDes,C);RFileLogger::WriteFormat(KLogsDir(),KLogFileName(), EFileLoggingModeAppend, TRefByValue<const TDesC>(tempLogDes()),X,Y,Z);}
       
    73 #define MYLOCLOGSTRING4(C, X, Y, Z, A)   {_LIT(tempLogDes,C);RFileLogger::WriteFormat(KLogsDir(),KLogFileName(), EFileLoggingModeAppend, TRefByValue<const TDesC>(tempLogDes()),X,Y,Z,A);}
       
    74 #endif
       
    75 
       
    76 /*
       
    77  *Trace implementation
       
    78  * Description:
       
    79  * Macro definition file for logging.
       
    80  */
       
    81 
       
    82 #if !(MYLOC_LOGGING_METHOD == 0)
       
    83 #ifdef __cplusplus
       
    84 
       
    85 // define the following macro to enable call stack trace.
       
    86 #define FUNCTION_ETRY_EXIT
       
    87 
       
    88 const TInt KMaxLogLength = 256;
       
    89 class CLogFunctionEntryExit : public CBase
       
    90 {
       
    91 public:
       
    92     CLogFunctionEntryExit(const char* aFunctionName, const TInt aLineNo) :
       
    93         iFunctionName(aFunctionName)
       
    94     {
       
    95     #if (MYLOC_LOGGING_METHOD == 2)
       
    96             iBuffer = HBufC8::New(KMaxLogLength);
       
    97             if (iBuffer != NULL)
       
    98             {
       
    99                 TPtr8 buf = iBuffer->Des();
       
   100                 buf.Copy((const TUint8 *) aFunctionName);
       
   101                 _LIT8(KFormat,"=> %S [%02d])");
       
   102                 RFileLogger::WriteFormat(KLogsDir(), KLogFileName(),
       
   103                         EFileLoggingModeAppend, TRefByValue<const TDesC8> (
       
   104                                 KFormat()), &buf, aLineNo);
       
   105             }
       
   106     #else                
       
   107             RDebug::Printf("=> %s [%02d])", iFunctionName, aLineNo);
       
   108     #endif                
       
   109         }
       
   110         ~CLogFunctionEntryExit()
       
   111         {
       
   112     #if (MYLOC_LOGGING_METHOD == 2)
       
   113             TPtr8 buf = iBuffer->Des();
       
   114             _LIT8(KFormat,"<= %S");
       
   115             RFileLogger::WriteFormat(KLogsDir(), KLogFileName(),
       
   116                     EFileLoggingModeAppend, TRefByValue<const TDesC8> (KFormat()),
       
   117                     &buf);
       
   118             delete iBuffer;
       
   119     #else            
       
   120             RDebug::Printf("<= %s", iFunctionName);
       
   121     #endif            
       
   122         }
       
   123 private:
       
   124         const char* iFunctionName;
       
   125     #if (MYLOC_LOGGING_METHOD == 2)
       
   126         HBufC8* iBuffer;
       
   127     #endif
       
   128 };
       
   129 
       
   130 #ifdef FUNCTION_ETRY_EXIT
       
   131 // track
       
   132 #pragma message ("MyLocation Call stack trace - ENABLE")
       
   133 #define __TRACE_CALLSTACK CLogFunctionEntryExit functionEtryExit(__PRETTY_FUNCTION__,__LINE__)
       
   134 #endif
       
   135 #endif // __cplusplus
       
   136 #endif //
       
   137 #ifndef __TRACE_CALLSTACK
       
   138 // don't track function enter and exit
       
   139 #pragma message ("MyLocation Call stack trace - DISABLE")
       
   140 #define __TRACE_CALLSTACK
       
   141 #endif
       
   142 
       
   143 #endif //MYLOCATIONLOGGER_H