inc/ScreensaverUtils.h
changeset 14 8a173132b0aa
parent 2 058b1fc1663a
equal deleted inserted replaced
2:058b1fc1663a 14:8a173132b0aa
     1 /*
       
     2 * Copyright (c) 2003 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:   Screensaver utilities collection
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_SCREENSAVERUTILS_H
       
    20 #define C_SCREENSAVERUTILS_H
       
    21 
       
    22 // ========== LOGGING MACROS ===============================
       
    23 
       
    24 #ifdef USE_LOGGER
       
    25 
       
    26 #include <e32std.h>
       
    27 #include <e32def.h>
       
    28 #include <eikenv.h>
       
    29 #include <flogger.h>
       
    30 
       
    31 
       
    32 /* logging macros usage:
       
    33 
       
    34 // set logging on in mmp file...
       
    35 MACRO USE_LOGGER
       
    36 #ifdef WINS
       
    37 MACRO USE_RDEBUG
       
    38 #endif
       
    39 
       
    40 
       
    41 void CTestAppUi::ConstructL()
       
    42 {
       
    43 // creates log directory and log file on app startup.
       
    44 // prints starting banner...
       
    45 SCRLOGGER_CREATE;
       
    46 
       
    47 // entering to function...
       
    48 SCRLOGGER_ENTERFN("ConstructL()");
       
    49 
       
    50 TInt number = 42;
       
    51 TFileName file;
       
    52 file = "something" ....
       
    53 
       
    54 // print variable number of parameters...
       
    55 // Note: use _L macro for format string!
       
    56 SCRLOGGER_WRITEF(_L("SCR: number = %d, file = %S"), number, &file);
       
    57 
       
    58 // print just a string (no _L macro here!)
       
    59 SCRLOGGER_WRITE("Hello world!");
       
    60 
       
    61 // leave from function...
       
    62 SCRLOGGER_LEAVEFN("ConstructL()");
       
    63 }
       
    64 
       
    65 CTestAppUi::~CTestAppUi()
       
    66 {
       
    67 // print app exit banner when application exits.
       
    68 SCRLOGGER_DELETE;
       
    69 }
       
    70 
       
    71 */
       
    72 
       
    73 #ifdef USE_RDEBUG
       
    74 
       
    75 _LIT(KSCRLogBanner, "Screensaver log start");
       
    76 _LIT(KSCRLogEnterFn, "SCR: enter --> %S");
       
    77 _LIT(KSCRLogLeaveFn, "SCR: leave <-- %S");
       
    78 _LIT(KSCRLogWrite, "SCR: %S");
       
    79 _LIT(KSCRLogTag, "SCR: ");
       
    80 _LIT(KSCRLogExit, "Screensaver log end");
       
    81 _LIT(KSCRLogTimeFormatString, "%H:%T:%S:%*C2");
       
    82 
       
    83 #define SCRLOGGER_CREATE             {RDebug::Print(KSCRLogBanner);}
       
    84 #define SCRLOGGER_DELETE             {RDebug::Print(KSCRLogExit);}
       
    85 #define SCRLOGGER_ENTERFN(a)         {_LIT(temp, a); RDebug::Print(KSCRLogEnterFn, &temp);}
       
    86 #define SCRLOGGER_LEAVEFN(a)         {_LIT(temp, a); RDebug::Print(KSCRLogLeaveFn, &temp);}
       
    87 #define SCRLOGGER_WRITE(a)           {_LIT(temp, a); RDebug::Print(KSCRLogWrite, &temp);}
       
    88 #define SCRLOGGER_WRITE_TIMESTAMP(a) {_LIT(temp, a); TTime time; time.HomeTime(); TBuf<256> buffer; time.FormatL(buffer, KSCRLogTimeFormatString); buffer.Insert(0, temp); buffer.Insert(0, KSCRLogTag); RDebug::Print(buffer); }
       
    89 #define SCRLOGGER_WRITEF             RDebug::Print
       
    90 
       
    91 #else
       
    92 
       
    93 _LIT(KSCRLogDir, "SCR");
       
    94 _LIT(KSCRLogFile, "SCR.txt");
       
    95 _LIT8(KSCRLogBanner, "Screensaver log start");
       
    96 _LIT8(KSCRLogEnterFn, "SCR: -> %S");
       
    97 _LIT8(KSCRLogLeaveFn, "SCR: <- %S");
       
    98 _LIT8(KSCRLogExit, "Screensaver log end");
       
    99 _LIT(KSCRLogTimeFormatString, "%H:%T:%S:%*C2");
       
   100 
       
   101 #define SCRLOGGER_CREATE             {FCreate();}
       
   102 #define SCRLOGGER_DELETE             {RFileLogger::Write(KSCRLogDir, KSCRLogFile, EFileLoggingModeAppend, KSCRLogExit);}
       
   103 #define SCRLOGGER_ENTERFN(a)         {_LIT8(temp, a); RFileLogger::WriteFormat(KSCRLogDir, KSCRLogFile, EFileLoggingModeAppend, KSCRLogEnterFn, &temp);}
       
   104 #define SCRLOGGER_LEAVEFN(a)         {_LIT8(temp, a); RFileLogger::WriteFormat(KSCRLogDir, KSCRLogFile, EFileLoggingModeAppend, KSCRLogLeaveFn, &temp);}
       
   105 #define SCRLOGGER_WRITE(a)           {_LIT(temp, a); RFileLogger::Write(KSCRLogDir, KSCRLogFile, EFileLoggingModeAppend, temp);}
       
   106 #define SCRLOGGER_WRITE_TIMESTAMP(a) {_LIT(temp, a); TTime time; time.HomeTime(); TBuf<256> buffer; time.FormatL(buffer, KSCRLogTimeFormatString); buffer.Insert(0, temp); RFileLogger::Write(KSCRLogDir, KSCRLogFile, EFileLoggingModeAppend, buffer); }
       
   107 #define SCRLOGGER_WRITEF             FPrint
       
   108 
       
   109 inline void FPrint(const TRefByValue<const TDesC> aFmt, ...)
       
   110     {
       
   111     VA_LIST list;
       
   112     VA_START(list, aFmt);
       
   113     RFileLogger::WriteFormat(KSCRLogDir, KSCRLogFile, EFileLoggingModeAppend, aFmt, list);
       
   114     }
       
   115 
       
   116 inline void FPrint(const TDesC& aDes)
       
   117     {
       
   118     RFileLogger::WriteFormat(KSCRLogDir, KSCRLogFile, EFileLoggingModeAppend, aDes);
       
   119     }
       
   120 
       
   121 inline void FHex(const TUint8* aPtr, TInt aLen)
       
   122     {
       
   123     RFileLogger::HexDump(KSCRLogDir, KSCRLogFile, EFileLoggingModeAppend, 0, 0, aPtr, aLen);
       
   124     }
       
   125 
       
   126 inline void FHex(const TDesC8& aDes)
       
   127     {
       
   128     FHex(aDes.Ptr(), aDes.Length());
       
   129     }
       
   130 
       
   131 inline void FCreate()
       
   132     {
       
   133     TFileName path(_L("c:\\logs\\"));
       
   134     path.Append(KSCRLogDir);
       
   135     path.Append(_L("\\"));
       
   136     RFs& fs = CEikonEnv::Static()->FsSession();
       
   137     fs.MkDirAll(path);
       
   138     RFileLogger::WriteFormat(KSCRLogDir, KSCRLogFile, EFileLoggingModeOverwrite, KSCRLogBanner);
       
   139     }
       
   140 
       
   141 #endif // USE_RDEBUG
       
   142 
       
   143 #else // USE_LOGGER
       
   144 
       
   145 inline void FPrint(const TRefByValue<const TDesC> /*aFmt*/, ...) { };
       
   146 
       
   147 #define SCRLOGGER_CREATE
       
   148 #define SCRLOGGER_DELETE
       
   149 #define SCRLOGGER_ENTERFN(a)
       
   150 #define SCRLOGGER_LEAVEFN(a)
       
   151 #define SCRLOGGER_WRITE(a)
       
   152 #define SCRLOGGER_WRITEF 1 ? ((void)0) : FPrint
       
   153 #define SCRLOGGER_WRITE_TIMESTAMP(a)
       
   154 
       
   155 #endif // USE_LOGGER
       
   156 
       
   157 #endif // C_SCREENSAVERUTILS_H