contextframework/cfwplugins/cenrepsourceplugin/inc/cenreptrace.h
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2007-2007 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:  Trace definitions.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef SENSORTRACE_H
       
    20 #define SENSORTRACE_H
       
    21 
       
    22 #include <e32debug.h>
       
    23 #include <flogger.h>
       
    24 #include "cenreptraceconfiguration.hrh"
       
    25 
       
    26 //-----------------------------------------------------------------------------
       
    27 // Enable file trace macros
       
    28 //-----------------------------------------------------------------------------
       
    29 //
       
    30 #ifdef TRACE_INTO_FILE
       
    31 
       
    32 #include <flogger.h>
       
    33 #include <f32file.h>
       
    34 
       
    35     /**
       
    36     * Constants
       
    37     */
       
    38     _LIT( KDir, "contextframework" );
       
    39     _LIT( KFile, "cenrepsource_log.txt" );
       
    40     _LIT( KFullPath, "c:\\logs\\contextframework\\" );
       
    41 
       
    42     /**
       
    43     * Enables logging by creating the log folder.
       
    44     */
       
    45     LOCAL_C void EnableLog()
       
    46         {
       
    47         RFs fs;
       
    48         if( fs.Connect() == KErrNone )
       
    49             {
       
    50             fs.MkDirAll( KFullPath );
       
    51             fs.Close();
       
    52             }
       
    53         }
       
    54     #define ENABLE_LOG\
       
    55         {\
       
    56         EnableLog();\
       
    57         }
       
    58         
       
    59 #else//TRACE_INTO_FILE not defined
       
    60 
       
    61     #define ENABLE_LOG
       
    62 
       
    63 #endif//TRACE_INTO_FILE
       
    64  
       
    65 //-----------------------------------------------------------------------------
       
    66 // Error trace macros
       
    67 //-----------------------------------------------------------------------------
       
    68 //
       
    69 #ifdef ERROR_TRACE
       
    70 
       
    71     /**
       
    72     * Error trace definitions. Does not automatically log the error code!
       
    73     */
       
    74     #ifdef TRACE_INTO_FILE
       
    75 
       
    76         #define ERROR( aErr, aMsg )\
       
    77             {\
       
    78             if( aErr < KErrNone )\
       
    79                 {\
       
    80                 _LIT( KMsg, aMsg );\
       
    81                 RFileLogger::Write( KDir, KFile, EFileLoggingModeAppend, KMsg );\
       
    82                 }\
       
    83             }
       
    84         #define ERROR_1( aErr, aMsg, aP1 )\
       
    85             {\
       
    86             if( aErr < KErrNone )\
       
    87                 {\
       
    88                 _LIT( KMsg, aMsg );\
       
    89                 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, KMsg, aP1 );\
       
    90                 }\
       
    91             }
       
    92         #define ERROR_2( aErr, aMsg, aP1, aP2 )\
       
    93             {\
       
    94             if( aErr < KErrNone )\
       
    95                 {\
       
    96                 _LIT( KMsg, aMsg );\
       
    97                 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, KMsg, aP1, aP2 );\
       
    98                 }\
       
    99             }
       
   100         #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
       
   101             {\
       
   102             if( aErr < KErrNone )\
       
   103                 {\
       
   104                 _LIT( KMsg, aMsg );\
       
   105                 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, KMsg, aP1, aP2, aP3 );\
       
   106                 }\
       
   107             }
       
   108         #define ERROR_GEN( aMsg ) ERROR( KErrGeneral, aMsg )
       
   109         #define ERROR_GEN_1( aMsg, aP1 ) ERROR_1( KErrGeneral, aMsg, aP1 )
       
   110             
       
   111     #else//TRACE_INTO_FILE not defined
       
   112     
       
   113         #define ERROR( aErr, aMsg )\
       
   114             {\
       
   115             if( aErr < KErrNone )\
       
   116                 {\
       
   117                 _LIT( KMsg, aMsg ); RDebug::Print( KMsg );\
       
   118                 }\
       
   119             }
       
   120         #define ERROR_1( aErr, aMsg, aP1 )\
       
   121             {\
       
   122             if( aErr < KErrNone )\
       
   123                 {\
       
   124                 _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aP1 );\
       
   125                 }\
       
   126             }
       
   127         #define ERROR_2( aErr, aMsg, aP1, aP2 )\
       
   128             {\
       
   129             if( aErr < KErrNone )\
       
   130                 {\
       
   131                 _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aP1, aP2 );\
       
   132                 }\
       
   133             }
       
   134         #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
       
   135             {\
       
   136             if( aErr < KErrNone )\
       
   137                 {\
       
   138                 _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aP1, aP2, aP3 );\
       
   139                 }\
       
   140             }
       
   141         #define ERROR_GEN( aMsg ) ERROR( KErrGeneral, aMsg )
       
   142         #define ERROR_GEN_1( aMsg, aP1 ) ERROR_1( KErrGeneral, aMsg, aP1 )
       
   143     
       
   144     #endif//TRACE_INTO_FILE
       
   145 
       
   146 #else//ERROR_TRACE not defined
       
   147 
       
   148     #define ERROR( aErr, aMsg )
       
   149     #define ERROR_1( aErr, aMsg, aP1 )
       
   150     #define ERROR_2( aErr, aMsg, aP1, aP2 )
       
   151     #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )
       
   152     #define ERROR_GEN( aMsg )
       
   153     #define ERROR_GEN_1( aMsg, aP1 )
       
   154 
       
   155 #endif//ERROR_TRACE
       
   156 
       
   157 //-----------------------------------------------------------------------------
       
   158 // Info trace macros
       
   159 //-----------------------------------------------------------------------------
       
   160 //
       
   161 #ifdef INFO_TRACE
       
   162 
       
   163     /**
       
   164     * Info log message definitions.
       
   165     */
       
   166     #ifdef TRACE_INTO_FILE
       
   167     
       
   168         #define INFO( aMsg )\
       
   169             {\
       
   170             _LIT( KMsg, aMsg );\
       
   171             RFileLogger::Write( KDir, KFile, EFileLoggingModeAppend, KMsg );\
       
   172             }
       
   173         #define INFO_1( aMsg, aP1 )\
       
   174             {\
       
   175             _LIT( KMsg, aMsg );\
       
   176             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, KMsg, aP1 );\
       
   177             }
       
   178         #define INFO_2( aMsg, aP1, aP2 )\
       
   179             {\
       
   180             _LIT( KMsg, aMsg );\
       
   181             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, KMsg, aP1, aP2 );\
       
   182             }
       
   183         #define INFO_3( aMsg, aP1, aP2, aP3 )\
       
   184             {\
       
   185             _LIT( KMsg, aMsg );\
       
   186             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, KMsg, aP1, aP2, aP3 );\
       
   187             }
       
   188 
       
   189     #else//TRACE_INTO_FILE not defined
       
   190 
       
   191         #define INFO( aMsg )\
       
   192             {\
       
   193             _LIT( KMsg, aMsg ); RDebug::Print( KMsg );\
       
   194             }
       
   195         #define INFO_1( aMsg, aP1 )\
       
   196             {\
       
   197             _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aP1 );\
       
   198             }
       
   199         #define INFO_2( aMsg, aP1, aP2 )\
       
   200             {\
       
   201             _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aP1, aP2 );\
       
   202             }
       
   203         #define INFO_3( aMsg, aP1, aP2, aP3 )\
       
   204             {\
       
   205             _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aP1, aP2, aP3 );\
       
   206             }
       
   207 
       
   208     #endif//TRACE_INTO_FILE
       
   209         
       
   210 #else//INFO_TRACE not defined
       
   211 
       
   212     #define INFO( aMsg )
       
   213     #define INFO_1( aMsg, aP1 )
       
   214     #define INFO_2( aMsg, aP1, aP2 )
       
   215     #define INFO_3( aMsg, aP1, aP2, aP3 )
       
   216 
       
   217 #endif//INFO_TRACE
       
   218 
       
   219 //-----------------------------------------------------------------------------
       
   220 // Trace current client thread name and process id
       
   221 //-----------------------------------------------------------------------------
       
   222 //
       
   223 #ifdef CLIENT_TRACE
       
   224 
       
   225     #define CLIENT( aMessage )\
       
   226         {\
       
   227         RThread thread;\
       
   228         TInt err = aMessage.Client( thread );\
       
   229         if( err == KErrNone )\
       
   230             {\
       
   231             RProcess process;\
       
   232             err = thread.Process( process );\
       
   233             if( err == KErrNone )\
       
   234                 {\
       
   235                 TPtrC thredName( thread.Name() );\
       
   236                 TUid processUid( process.SecureId() );\
       
   237                 INFO_2( "Current client process UID: [%x], thread name: [%S]",\
       
   238                     processUid,\
       
   239                     &thredName );\
       
   240                 }\
       
   241             process.Close();\
       
   242             }\
       
   243         thread.Close();\
       
   244         }
       
   245 
       
   246 #else
       
   247 
       
   248     #define CLIENT( aMessage )
       
   249 
       
   250 #endif
       
   251 
       
   252 //-----------------------------------------------------------------------------
       
   253 // Function trace macros
       
   254 //-----------------------------------------------------------------------------
       
   255 //
       
   256 #ifdef FUNC_TRACE
       
   257 
       
   258     // Constants
       
   259     _LIT8( KEllipse, "(" );
       
   260 
       
   261     /**
       
   262     * Function logging definitions.
       
   263     */
       
   264     #ifdef TRACE_INTO_FILE
       
   265     
       
   266         #define FUNC( aMsg, aP1 )\
       
   267             {\
       
   268             _LIT8( KMsg, aMsg ); RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, KMsg, aP1 );\
       
   269             }\
       
   270     
       
   271     #else//TRACE_INTO_FILE not defined
       
   272     
       
   273         #define FUNC( aMsg, aP1 )\
       
   274             {\
       
   275             RDebug::Printf( aMsg, aP1 );\
       
   276             }\
       
   277     
       
   278     #endif//TRACE_INTO_FILE
       
   279         
       
   280     /**
       
   281     * Function trace helper class.
       
   282     */
       
   283     class TFuncLog
       
   284         {
       
   285         public:
       
   286             inline TFuncLog( const char* aFunc ): iFunc( (TUint8*)aFunc )
       
   287                 {
       
   288                 TInt pos = iFunc.Find( KEllipse );
       
   289                 if( pos != KErrNotFound )
       
   290                     {
       
   291                     iFunc.Set( iFunc.Left( iFunc.Find( KEllipse ) ) );
       
   292                     }
       
   293                 FUNC( "%S-START", &iFunc );
       
   294                 }
       
   295             inline ~TFuncLog()
       
   296                 {
       
   297                 FUNC( "%S-END", &iFunc );
       
   298                 }
       
   299             TPtrC8 iFunc;
       
   300         };
       
   301 
       
   302     #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ );
       
   303     
       
   304 #else//FUNC_TRACE not defined
       
   305 
       
   306     #define FUNC_LOG
       
   307 
       
   308 #endif//FUNC_TRACE
       
   309 
       
   310 //-----------------------------------------------------------------------------
       
   311 // Timestamp trace macros
       
   312 //-----------------------------------------------------------------------------
       
   313 //
       
   314 #ifdef TIMESTAMP_TRACE
       
   315 
       
   316     #ifdef TRACE_INTO_FILE
       
   317     
       
   318         #define TIMESTAMP( aCaption )\
       
   319             {\
       
   320             TTime t;\
       
   321             t.HomeTime();\
       
   322             TDateTime dt = t.DateTime();\
       
   323             _LIT( KMsg, aCaption );\
       
   324             _LIT( KFormat, "[TIMESTAMP] %S %d:%02d:%02d.%d us");\
       
   325             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, KFormat,\
       
   326                 &KMsg, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\
       
   327             }
       
   328 
       
   329     #else//TRACE_INTO_FILE not defined
       
   330     
       
   331         #define TIMESTAMP( aCaption )\
       
   332             {\
       
   333             TTime t;\
       
   334             t.HomeTime();\
       
   335             TDateTime dt = t.DateTime();\
       
   336             _LIT( KMsg, aCaption );\
       
   337             _LIT( KFormat, "[TIMESTAMP] %S %d:%02d:%02d.%d us");\
       
   338             RDebug::Print( KFormat,\
       
   339                 &KMsg, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\
       
   340             }
       
   341 
       
   342     #endif//TRACE_INTO_FILE
       
   343 
       
   344 #else//TIMESTAMP_TRACE not defined
       
   345 
       
   346     #define TIMESTAMP( aCaption )
       
   347 
       
   348 #endif//TIMESTAMP_TRACE
       
   349 
       
   350 #endif