supl/locationsuplfw/utilities/src/epos_csupltrace.cpp
changeset 0 667063e416a2
child 19 02ba3f1733c6
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2005 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 *     Provides functionality to write trace output to debug output (serial
       
    16 *     port in ARMI case) or predefined file.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include   <bautils.h>
       
    24 #include   "epos_csupltrace.h"
       
    25 
       
    26 // CONSTANTS
       
    27 #ifdef _DEBUG
       
    28 _LIT(KPosTraceLogFile, "epostracelog.txt");
       
    29 _LIT(KPosTraceLogDir, "epos"); // Relative to C:\Logs
       
    30 const TInt KMaxTraceLength = 1024;
       
    31 #endif
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 //
       
    38 
       
    39 CSuplTrace::CSuplTrace()
       
    40     {
       
    41     }
       
    42 
       
    43 // Two-phased constructor.
       
    44 EXPORT_C CSuplTrace* CSuplTrace::NewL()
       
    45     {
       
    46     CSuplTrace* self = new (ELeave) CSuplTrace;
       
    47     CleanupStack::PushL(self);
       
    48     self->ConstructL();
       
    49     CleanupStack::Pop(self);
       
    50     return self;
       
    51     }
       
    52 
       
    53 EXPORT_C CSuplTrace* CSuplTrace::NewL(
       
    54     const TDesC& aTraceLogDir,
       
    55     const TDesC& aTraceLogFile)
       
    56     {
       
    57     CSuplTrace* self = new (ELeave) CSuplTrace;
       
    58     CleanupStack::PushL(self);
       
    59     self->ConstructL(aTraceLogDir, aTraceLogFile);
       
    60     CleanupStack::Pop(self);
       
    61     return self;
       
    62     }
       
    63 
       
    64 // Destructor
       
    65 EXPORT_C CSuplTrace::~CSuplTrace()
       
    66     {
       
    67 #ifdef _DEBUG
       
    68     delete iTraceDir;
       
    69     delete iTraceFile;
       
    70 #endif
       
    71     }
       
    72 
       
    73 // EPOC default constructor can leave.
       
    74 void CSuplTrace::ConstructL()
       
    75     {
       
    76 #ifdef _DEBUG
       
    77     iTraceDir = KPosTraceLogDir().AllocL();
       
    78     iTraceFile = KPosTraceLogFile().AllocL();
       
    79 #endif
       
    80     }
       
    81 
       
    82 
       
    83 #ifdef _DEBUG
       
    84 
       
    85 void CSuplTrace::ConstructL(
       
    86     const TDesC& aTraceLogDir,
       
    87     const TDesC& aTraceLogFile)
       
    88     {
       
    89     iTraceDir = aTraceLogDir.AllocL();
       
    90     iTraceFile = aTraceLogFile.AllocL();
       
    91     }
       
    92 
       
    93 #else
       
    94 
       
    95 void CSuplTrace::ConstructL(
       
    96     const TDesC& /*aTraceLogDir*/,
       
    97     const TDesC& /*aTraceLogFile*/)
       
    98     {
       
    99     }
       
   100 
       
   101 #endif
       
   102 
       
   103 // ---------------------------------------------------------
       
   104 // CSuplTrace::TraceL
       
   105 // (other items were commented in a header).
       
   106 // ---------------------------------------------------------
       
   107 //
       
   108 
       
   109 #ifdef _DEBUG
       
   110 
       
   111 EXPORT_C void CSuplTrace::TraceL(
       
   112     const TDesC& aDescription,
       
   113     const TDesC& aFilename,
       
   114     const TInt aLineNumber)
       
   115     {
       
   116     _LIT(KPosTraceLogFormatNormal , "[EPos/0x%LX]: %S (%d): %S");
       
   117     const TInt KPosTraceLogFormatNormalExtraChars = 40;
       
   118 
       
   119     RProcess process;
       
   120 
       
   121     HBufC* buf = HBufC::NewL(
       
   122         aDescription.Length() +
       
   123         aFilename.Length() +
       
   124         KPosTraceLogFormatNormalExtraChars);
       
   125 
       
   126     buf->Des().Format(KPosTraceLogFormatNormal,
       
   127         process.Id().Id(),
       
   128         &aFilename,
       
   129         aLineNumber,
       
   130         &aDescription);
       
   131     
       
   132     RFileLogger::Write( *iTraceDir, *iTraceFile, EFileLoggingModeAppend, *buf);
       
   133     RDebug::RawPrint(*buf);
       
   134     
       
   135     delete buf;
       
   136     }
       
   137 
       
   138 EXPORT_C void CSuplTrace::Log( 
       
   139     const TDesC& aTraceLogDir,
       
   140     const TDesC& aTraceLogFile,
       
   141     TRefByValue<const TDesC> aFmt, ... )
       
   142     {
       
   143     VA_LIST list;
       
   144     VA_START( list, aFmt );
       
   145 
       
   146     RProcess process;
       
   147     HBufC* buf = HBufC::New( KMaxTraceLength );
       
   148     if ( buf )
       
   149     	{
       
   150     	TPtr ptr( buf->Des() );
       
   151         _LIT( KPrefix, "[EPos/0x%LX]: ");
       
   152         ptr.Format( KPrefix, process.Id().Id() );
       
   153 	    ptr.AppendFormatList( aFmt, list );
       
   154 	
       
   155 	    RDebug::RawPrint( ptr );
       
   156 	    RFileLogger::Write( aTraceLogDir, aTraceLogFile, EFileLoggingModeAppend, ptr );
       
   157 
       
   158 	    delete buf;
       
   159     	}
       
   160     }
       
   161 
       
   162 #else
       
   163 
       
   164 EXPORT_C void CSuplTrace::TraceL(
       
   165     const TDesC& /*aDescription*/,
       
   166     const TDesC& /*aFilename*/,
       
   167     const TInt /*aLineNumber*/)
       
   168     {
       
   169     }
       
   170 
       
   171 EXPORT_C void CSuplTrace::Log( 
       
   172     const TDesC& /*aTraceLogDir*/,
       
   173     const TDesC& /*aTraceLogFile*/,
       
   174     TRefByValue<const TDesC> /*aFmt*/, ... )
       
   175     {
       
   176     }
       
   177 
       
   178 #endif
       
   179 
       
   180 //  End of File