usbclasses/usbphoneasmodem/classimplementation/atplugin/src/atcmdpam_debug.cpp
changeset 34 7858bc6ead78
parent 31 dfdd8240f7c8
child 35 9d8b04ca6939
equal deleted inserted replaced
31:dfdd8240f7c8 34:7858bc6ead78
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implements Debug API for phone as modem at extension plugin
       
    15 // 
       
    16 //
       
    17 
       
    18 // INCLUDES
       
    19 #include <e32std.h>
       
    20 #include <eikapp.h>
       
    21 #include <eikdoc.h>
       
    22 #include <atcodec.h>
       
    23 #include <AknNoteWrappers.h>
       
    24 #include <flogger.h>
       
    25 #include "atcmdpam_debug.h"
       
    26 #ifdef ATCMDPAM_DEBUG_TRACES
       
    27 #pragma message( "Traces enabled" )
       
    28 #endif // ATCMDPAM_DEBUG_TRACES
       
    29 #ifdef ATCMDPAM_DEBUG_BTTRACES
       
    30 #include <btlog.h>
       
    31 #endif // ATCMDPAM_DEBUG_BTTRACES
       
    32 // CONSTANTS
       
    33 #ifdef ATCMDPAM_DEBUG_TRACES
       
    34 _LIT( KDebugFile, "atcmdpam.txt" );
       
    35 _LIT( KDebugDir, "atcmdpam" );
       
    36 _LIT( KATDebugFile, "log.txt" );
       
    37 _LIT( KATDebugDir, "atcmdpam" );
       
    38 #endif // ATCMDPAM_DEBUG_TRACES
       
    39 
       
    40 // ============================= LOCAL FUNCTIONS  =============================
       
    41 
       
    42 /**
       
    43  Debug str
       
    44  */
       
    45 #ifdef ATCMDPAM_DEBUG_TRACES
       
    46 TText* DEBUG_STR( TDes* aStr )
       
    47     {
       
    48     if ( aStr )
       
    49         {
       
    50         return DEBUG_STR( *aStr );
       
    51         }
       
    52     else
       
    53         {
       
    54         return const_cast<TText*>( _L( "" ).Ptr() );
       
    55         }
       
    56     }
       
    57 
       
    58 /**
       
    59  Debug str
       
    60  */
       
    61 TText16* DEBUG_STR( TDes16& aStr )
       
    62     {
       
    63     if ( aStr.Length() < aStr.MaxLength() )
       
    64         {
       
    65         aStr.ZeroTerminate();
       
    66         }
       
    67     TText16* txt = const_cast<TText16*>( aStr.Ptr() );
       
    68 
       
    69     return txt;
       
    70     }
       
    71 
       
    72 /**
       
    73  Debug str
       
    74  */
       
    75 TText8* DEBUG_STR( TDes8& aStr )
       
    76     {
       
    77     if ( aStr.Length() < aStr.MaxLength() )
       
    78         {
       
    79         aStr.ZeroTerminate();
       
    80         }
       
    81     TText8* txt = const_cast<TText8*>( aStr.Ptr() );
       
    82 
       
    83     return txt;
       
    84     }
       
    85 
       
    86 /**
       
    87  Debug str
       
    88  */
       
    89 TText* DEBUG_STR( TPtr aStr )
       
    90     {
       
    91     if ( aStr.Length() < aStr.MaxLength() )
       
    92         {
       
    93         aStr.ZeroTerminate();
       
    94         }
       
    95     TText* txt = const_cast<TText*>( aStr.Ptr() );
       
    96 
       
    97     return txt;
       
    98     }
       
    99 
       
   100 /**
       
   101  Debug str
       
   102  */
       
   103 TText* DEBUG_STR( HBufC* aStr )
       
   104     {
       
   105     if ( aStr )
       
   106         {
       
   107         return DEBUG_STR( aStr->Des() );
       
   108         }
       
   109     else
       
   110         {
       
   111         return const_cast<TText*>( _L( "" ).Ptr() );
       
   112         }
       
   113     }
       
   114 
       
   115 /**
       
   116  Debug str
       
   117  */
       
   118 TText* DEBUG_STR( TDesC* aStr )
       
   119     {
       
   120     if ( aStr )
       
   121         {
       
   122         TText* txt = const_cast<TText*>( aStr->Ptr() );
       
   123         return txt;
       
   124         }
       
   125     else
       
   126         {
       
   127         return const_cast<TText*>( _L( "" ).Ptr() );
       
   128         }
       
   129     }
       
   130 
       
   131 /**
       
   132  Debug str
       
   133  */
       
   134 TText* DEBUG_STR( const TDes& aStr )
       
   135     {
       
   136     return DEBUG_STR( const_cast<TDes&>( aStr ) );
       
   137     }
       
   138 
       
   139 /**
       
   140  Debug str
       
   141  */
       
   142 TText8* DEBUG_STR( const TDes8& aStr )
       
   143     {
       
   144     return DEBUG_STR( const_cast<TDes8&>( aStr ) );
       
   145     }
       
   146 
       
   147 /**
       
   148  Debug str
       
   149  */
       
   150 TText* DEBUG_STR( const TPtrC& aStr )
       
   151     {
       
   152     return const_cast<TText*>( aStr.Ptr() );
       
   153     }
       
   154 
       
   155 /**
       
   156  Debug str
       
   157  */
       
   158 TText* DEBUG_STR( const TDesC& aStr )
       
   159     {
       
   160     return const_cast<TText*>( aStr.Ptr() );
       
   161     }
       
   162 
       
   163 /**
       
   164  Debug str
       
   165  */
       
   166 TText8* DEBUG_STR( const TDesC8& aStr )
       
   167     {
       
   168     return const_cast<TText8*>( aStr.Ptr() );
       
   169     }
       
   170 
       
   171 // ============================= MEMBER FUNCTIONS =============================
       
   172 
       
   173 /**
       
   174  Ignore overflow
       
   175  */
       
   176 void TOverflowTruncate::Overflow( TDes16& /* aDes */)
       
   177     {
       
   178     return;
       
   179     }
       
   180 
       
   181 /**
       
   182  Ignore overflow
       
   183  */
       
   184 void TOverflowTruncate8::Overflow( TDes8& /* aDes */)
       
   185     {
       
   186     return;
       
   187     }
       
   188 
       
   189 /**
       
   190  Debug print
       
   191  (static)
       
   192  */
       
   193 #ifndef ATCMDPAM_DEBUG_NOFLOGGER
       
   194 void CATCmdPAMDebug::Print( TRefByValue<const TDesC> aFmt,... )
       
   195     {
       
   196     TOverflowTruncate overflow;
       
   197     VA_LIST list;
       
   198     VA_START( list,aFmt );
       
   199     TBuf<256> buf;
       
   200     buf.AppendFormatList( aFmt, list, &overflow );
       
   201 
       
   202     // Output to IDE
       
   203     RDebug::Print( buf );
       
   204 
       
   205     // Output to file
       
   206     RFileLogger::WriteFormat( KDebugDir,
       
   207             KDebugFile,
       
   208             EFileLoggingModeAppend,
       
   209             buf
       
   210     );
       
   211 
       
   212 #ifdef ATCMDPAM_DEBUG_BTTRACES
       
   213     BTLog::Print( buf );
       
   214 #endif // ATCMDPAM_DEBUG_BTTRACES
       
   215     return;
       
   216     }
       
   217 #endif // !ATCMDPAM_DEBUG_NOFLOGGER
       
   218 
       
   219 /**
       
   220  Debug print
       
   221  (static)
       
   222  */
       
   223 #ifndef ATCMDPAM_DEBUG_NOFLOGGER
       
   224 void CATCmdPAMDebug::Print8( TRefByValue<const TDesC8> aFmt,... )
       
   225     {
       
   226     TOverflowTruncate8 overflow8;
       
   227     VA_LIST list;
       
   228     VA_START( list,aFmt );
       
   229     TBuf8<256> buf8;
       
   230     buf8.AppendFormatList( aFmt, list, &overflow8 );
       
   231 
       
   232     HBufC* buf = HBufC::New( buf8.Length() + 1 );
       
   233     if ( buf )
       
   234         {
       
   235         buf->Des().Copy( buf8 );
       
   236         buf->Des().ZeroTerminate();
       
   237         CATCmdPAMDebug::Print( buf->Des() );
       
   238         delete buf;
       
   239         }
       
   240 
       
   241     return;
       
   242     }
       
   243 #endif // !ATCMDPAM_DEBUG_NOFLOGGER
       
   244 
       
   245 /**
       
   246  Debug message
       
   247  (static, may leave)
       
   248  */
       
   249 #ifdef ATCMDPAM_DEBUG_INFORMATION_NOTE_MESSAGES
       
   250 void CATCmdPAMDebug::NoteL( TPtrC aNote )
       
   251     {
       
   252     CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue );
       
   253     (void) note->ExecuteLD( aNote );
       
   254 
       
   255     return;
       
   256     }
       
   257 #endif // ATCMDPAM_DEBUG_INFORMATION_NOTE_MESSAGES
       
   258 
       
   259 /**
       
   260  Debug print
       
   261  (static)
       
   262  */
       
   263 void CATCmdPAMDebug::ATLog( CATCommand& aCmd )
       
   264     {
       
   265     TBuf8<CATCommand::EMaxCmdSize> buf;
       
   266     const TInt err = aCmd.Des( buf );
       
   267     if ( !err )
       
   268         {
       
   269         // Output to file
       
   270         RFileLogger::WriteFormat( KATDebugDir, 
       
   271                                   KATDebugFile, 
       
   272                                   EFileLoggingModeAppend, 
       
   273                                   buf 
       
   274                                 );
       
   275         }
       
   276 
       
   277     return;
       
   278     }
       
   279 #endif // ATCMDPAM_DEBUG_TRACES
       
   280 
       
   281 // ========================= OTHER EXPORTED FUNCTIONS =========================
       
   282 
       
   283 //  End of File