upnpavcontrolpoint/avcpengine/inc/upnpmdebug.h
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /** @file
       
     2 * Copyright (c) 2002-2004 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:  Debug printing to a log file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_UPNPMDEBUG_H
       
    20 #define C_UPNPMDEBUG_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32std.h>
       
    24 
       
    25 #ifdef _DEBUG
       
    26 #include <flogger.h>
       
    27 #include "upnpmydebug.h"
       
    28 
       
    29 // Take care that the correct upnpmydebug.h will be included
       
    30 // In upnpmydebug.h in your module inc directory,
       
    31 // define your application-specific configuration like this:
       
    32 // ----------------------------------------------------------
       
    33 // Debug file - debug output is disabled if the parent dir does not exist
       
    34 // _LIT(KDebugFileName, "C:\\logs\\remotefileengine\\remotefileengine.txt");
       
    35 
       
    36 // Replace the current debug file - if not defined appends to the file
       
    37 #ifndef APPEND_TO_DEBUG_FILE
       
    38 #define REPLACE_DEBUG_FILE
       
    39 #endif
       
    40 
       
    41 // Maximum formatted size resulting from a single DEBUG* call
       
    42 #ifndef MAX_DEBUG_STRING_LENGTH
       
    43 #define MAX_DEBUG_STRING_LENGTH 4096
       
    44 #endif
       
    45 // ----------------------------------------------------------
       
    46 
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 static void DoOutput(TDesC8& aData);
       
    50 
       
    51 static void DebugStringNarrowL(const char* aFmt, ...)
       
    52     {
       
    53     VA_LIST args;
       
    54     VA_START(args, aFmt);
       
    55     
       
    56     TPtrC8 fmt(reinterpret_cast<const unsigned char *>(aFmt));
       
    57     HBufC8* buf = HBufC8::NewLC(MAX_DEBUG_STRING_LENGTH);
       
    58     buf->Des().FormatList(fmt, args);
       
    59     buf->Des().Append('\n');
       
    60     DoOutput(*buf);
       
    61     CleanupStack::PopAndDestroy(buf);
       
    62        
       
    63     VA_END(args);
       
    64     }
       
    65 
       
    66 static void DebugStringWideL(const char* aFmt, ...)
       
    67     {
       
    68     VA_LIST args;
       
    69     VA_START(args, aFmt);
       
    70     
       
    71     TPtrC8 fmt(reinterpret_cast<const unsigned char *>(aFmt));
       
    72     HBufC* fmt16 = HBufC::NewLC(fmt.Length());
       
    73     fmt16->Des().Copy(fmt);
       
    74     HBufC* buf = HBufC::NewLC(MAX_DEBUG_STRING_LENGTH);
       
    75     buf->Des().FormatList(*fmt16, args);
       
    76     buf->Des().Append('\n');
       
    77     HBufC8* buf8 = HBufC8::NewLC(buf->Length());
       
    78     buf8->Des().Copy(*buf);
       
    79     DoOutput(*buf8);
       
    80     CleanupStack::PopAndDestroy(3); // fmt16, buf, buf8
       
    81 
       
    82     VA_END(args);
       
    83     }
       
    84 
       
    85 static void DebugBufferL(const TDesC8& aBuf)
       
    86     {
       
    87     DebugStringNarrowL("\"%S\"", &aBuf);
       
    88     }
       
    89 
       
    90 static void DebugBufferL(const TDesC& aBuf)
       
    91     {
       
    92     DebugStringWideL("\"%S\"", &aBuf);
       
    93     }
       
    94 
       
    95 static void DebugTimeL(const TTime& aTime)
       
    96     {
       
    97     TBuf<64> dateTimeString;
       
    98     _LIT(KDateString, "%E%D%X%N%Y %1 %2 %3");
       
    99     aTime.FormatL(dateTimeString, KDateString);
       
   100     DebugBufferL(dateTimeString);
       
   101     _LIT(KTimeString, "%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B");
       
   102     aTime.FormatL(dateTimeString, KTimeString);
       
   103     DebugBufferL(dateTimeString);
       
   104     }
       
   105 
       
   106 static void DoOutput(TDesC8& aData)
       
   107     {
       
   108     RFileLogger::Write(KDebugDirName,
       
   109                        KDebugFileName,
       
   110                        EFileLoggingModeAppend,
       
   111                        aData);
       
   112     }
       
   113 #endif    
       
   114 
       
   115 // MACROS
       
   116 // If you output one or more narrow descriptors by using '%S',
       
   117 //    use DEBUGSTRING8
       
   118 // else if you output one or more unicode descriptors by using '%S',
       
   119 //    use DEBUGSTRING16
       
   120 // else
       
   121 //    use DEBUGSTRING
       
   122 //
       
   123 // Narrow and unicode cannot be mixed in a single DEBUGSTRINGx call.
       
   124 
       
   125 #ifdef _DEBUG
       
   126 #define DEBUGINIT() DebugInit()
       
   127 #define DEBUGINITSUSPENDED() DebugInit(ETrue)
       
   128 #define DEBUGENABLE() SetDebugEnabled(ETrue)
       
   129 #define DEBUGDISABLE() SetDebugEnabled(EFalse)
       
   130 #define DEBUGSUSPEND() SetDebugSuspended(ETrue)
       
   131 #define DEBUGCONTINUE() SetDebugSuspended(EFalse)
       
   132 #define DEBUGSTRING(x) DebugStringNarrowL x
       
   133 #define DEBUGSTRING8(x) DebugStringNarrowL x
       
   134 #define DEBUGSTRING16(x) DebugStringWideL x
       
   135 #define DEBUGBUFFER(x) DebugBufferL x
       
   136 #define DEBUGTIME(x) DebugTimeL x
       
   137 #else
       
   138 #define DEBUGINIT()
       
   139 #define DEBUGINITSUSPENDED()
       
   140 #define DEBUGENABLE()
       
   141 #define DEBUGDISABLE()
       
   142 #define DEBUGSUSPEND()
       
   143 #define DEBUGCONTINUE()
       
   144 #define DEBUGSTRING(x)
       
   145 #define DEBUGSTRING8(x)
       
   146 #define DEBUGSTRING16(x)
       
   147 #define DEBUGBUFFER(x)
       
   148 #define DEBUGTIME(x)
       
   149 #endif
       
   150 
       
   151 #endif // C_MUPNPDEBUG_H
       
   152 
       
   153 // End of File