email/alwaysonlineemailplugin/src/AlwaysOnlineEmailLoggingTools.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 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: 
       
    15 *     Class for more comprehensive logging features
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "AlwaysOnlineEmailLoggingTools.h"
       
    21 
       
    22 #ifdef AO_LOGGING_TOOLS_ON
       
    23 
       
    24 // ----------------------------------------------------------------------------
       
    25 // AOLogT()
       
    26 // Constructor
       
    27 // ----------------------------------------------------------------------------
       
    28 #ifndef AO_LOG_USE_RBUF 
       
    29 AOLogT::AOLogT( const TDesC& _aolFunc ) : 
       
    30     iAoFunc( _aolFunc ), iAoLogBuf( KAOLogToolInFunc )
       
    31     {
       
    32     if (DoFilter(AoLogInOut)) 
       
    33         {
       
    34         AOLogT::WriteAoLog(iAoLogBuf);   
       
    35         iAoLogBuf.Append(iAoFunc);
       
    36         AOLogT::WriteAoLog(iAoLogBuf);
       
    37         }
       
    38     }
       
    39 
       
    40 #else
       
    41 AOLogT::AOLogT( const TDesC& _aolFunc ) : iAoFunc( _aolFunc )
       
    42     {
       
    43     if ( iAoLogBuf.Create(KAOLoggingToolsBuffer) )
       
    44         {
       
    45         AOLogT::WriteAoLog(KAOLogError);
       
    46         }
       
    47     else
       
    48         {
       
    49         if (DoFilter(EAoLogInOut)) 
       
    50             {
       
    51             iAoLogBuf.Append( KAOLogToolInFunc );
       
    52             iAoLogBuf.Append(iAoFunc);
       
    53             AOLogT::WriteAoLog(iAoLogBuf);
       
    54             }
       
    55         }
       
    56     }
       
    57 #endif
       
    58     
       
    59 // ----------------------------------------------------------------------------
       
    60 // ~AOLogT()
       
    61 // Destructor
       
    62 // ----------------------------------------------------------------------------
       
    63 AOLogT::~AOLogT()
       
    64     {
       
    65     if (DoFilter(EAoLogInOut)) 
       
    66         {
       
    67         // write function exit to log
       
    68         iAoLogBuf.Zero();
       
    69         iAoLogBuf.Append( KAOLogToolOutFunc );
       
    70         iAoLogBuf.Append( iAoFunc );
       
    71         iAoLogBuf.Append(' ');
       
    72         AOLogT::WriteAoLog( iAoLogBuf );
       
    73         }
       
    74 #ifdef AO_LOG_USE_RBUF
       
    75     iAoLogBuf.Close();
       
    76 #endif
       
    77     }
       
    78     
       
    79 // ----------------------------------------------------------------------------
       
    80 // WriteContext()
       
    81 //
       
    82 // ----------------------------------------------------------------------------
       
    83 void AOLogT::WriteContext( const TDesC& _aolMsg, TAoValueCat valCat, TInt _aolVal )
       
    84     {
       
    85     iAoLogBuf.Zero();
       
    86     // append function name
       
    87     iAoLogBuf.Append( iAoFunc );
       
    88     // append space
       
    89     iAoLogBuf.Append(' ');
       
    90     iAoLogBuf.Append( _aolMsg );
       
    91     AOLogT::WriteAoLog( iAoLogBuf, valCat, _aolVal );
       
    92     }
       
    93     
       
    94 // ----------------------------------------------------------------------------
       
    95 // WriteContext()
       
    96 //
       
    97 // ----------------------------------------------------------------------------
       
    98 void AOLogT::WriteContext( const TDesC& _aolMsg )
       
    99     {
       
   100     iAoLogBuf.Zero();
       
   101     // append function name
       
   102     iAoLogBuf.Append( iAoFunc );
       
   103     iAoLogBuf.Append(' ');
       
   104     iAoLogBuf.Append( _aolMsg );
       
   105     AOLogT::WriteAoLog( iAoLogBuf );
       
   106     }
       
   107     
       
   108 // ----------------------------------------------------------------------------
       
   109 // WriteContextNum()
       
   110 //
       
   111 // ----------------------------------------------------------------------------
       
   112 void AOLogT::WriteContextNum( const TDesC& _aolMsg, TInt aNum )
       
   113     {
       
   114     iAoLogBuf.Zero();
       
   115     iAoLogBuf.Append( iAoFunc );
       
   116     iAoLogBuf.Append(' ');
       
   117     iAoLogBuf.Append( _aolMsg );
       
   118     iAoLogBuf.Append(' ');
       
   119     iAoLogBuf.AppendNum( aNum );
       
   120     AOLogT::WriteAoLog( iAoLogBuf );
       
   121     }
       
   122 // ----------------------------------------------------------------------------
       
   123 // WriteContextDes()
       
   124 //
       
   125 // ----------------------------------------------------------------------------
       
   126 void AOLogT::WriteContextDes( const TDesC& _aolMsg, const TDesC& aDes )
       
   127     {
       
   128     iAoLogBuf.Zero();
       
   129     //check that message will not be oversize and cause panic. 4 is for
       
   130     //appented extra spaces etc.
       
   131     if ( ( iAoFunc.Length() + _aolMsg.Length() + aDes.Length() + 4 ) < // CSI: 47 # see comment above
       
   132         iAoLogBuf.MaxLength() )
       
   133         {
       
   134         iAoLogBuf.Append( iAoFunc );
       
   135         iAoLogBuf.Append(' ');
       
   136         iAoLogBuf.Append( _aolMsg );
       
   137         iAoLogBuf.Append(' ');
       
   138         iAoLogBuf.Append( aDes );
       
   139         }
       
   140     else
       
   141         {
       
   142         iAoLogBuf.Append( KAOLogError );
       
   143         }
       
   144     AOLogT::WriteAoLog( iAoLogBuf );
       
   145     }
       
   146 // ----------------------------------------------------------------------------
       
   147 // WriteContextDes8()
       
   148 //
       
   149 // ----------------------------------------------------------------------------
       
   150 void AOLogT::WriteContextDes8( const TDesC& _aolMsg, const TDesC8& aDes8 )
       
   151     {
       
   152     //check that there is enough room for log message 4 is for extra spaces etc
       
   153     if ( ( iAoFunc.Length() + aDes8.Length() + _aolMsg.Length() + 4 ) // CSI: 47 # see comment above
       
   154         < iAoLogBuf.MaxLength() )
       
   155         {
       
   156         //copy 8 bit descriptor
       
   157         iAoLogBuf.Copy( aDes8 );
       
   158         //insert function name to first of message
       
   159         iAoLogBuf.Insert( 0, iAoFunc );
       
   160         //then insert message
       
   161         iAoLogBuf.Insert( iAoFunc.Length()-1, _aolMsg );
       
   162         }
       
   163     else
       
   164         {
       
   165         iAoLogBuf.Zero();
       
   166         iAoLogBuf.Append( KAOLogError );
       
   167         }
       
   168     AOLogT::WriteAoLog( iAoLogBuf );
       
   169     }
       
   170 
       
   171 // ----------------------------------------------------------------------------
       
   172 // WriteAoL()
       
   173 // static
       
   174 // ----------------------------------------------------------------------------
       
   175 void AOLogT::WriteAoLog( const TDesC& _aolMsg )
       
   176     {
       
   177     RFileLogger::Write(KAOEmailLogToolsDir, KAOEmailLogToolsFile, 
       
   178         EFileLoggingModeAppend, _aolMsg);
       
   179     }
       
   180 
       
   181 // ----------------------------------------------------------------------------
       
   182 // WriteAoLogFormat()
       
   183 // static
       
   184 // ----------------------------------------------------------------------------    
       
   185 void AOLogT::WriteAoLogFormat( const TDesC& _aolMsgFor, TInt aNum )
       
   186     {
       
   187     RFileLogger::WriteFormat(KAOEmailLogToolsDir, KAOEmailLogToolsFile, 
       
   188         EFileLoggingModeAppend, _aolMsgFor, aNum);
       
   189     }
       
   190     
       
   191 // ----------------------------------------------------------------------------
       
   192 // WriteAoL()
       
   193 // static
       
   194 // ----------------------------------------------------------------------------
       
   195 void AOLogT::WriteAoLog( TDes& _aolMsg, TAoValueCat _valCat, TInt _aolVal )
       
   196     {
       
   197     //pointer to map value table
       
   198     const AOMapVal* tableptr = NULL;
       
   199 
       
   200     // set correct table pointer represented in _valCat
       
   201     switch ( _valCat )
       
   202         {
       
   203         case EAoMailPluginStates:
       
   204             tableptr = EMailPluginStatesTable;
       
   205             break;
       
   206         case EAoManagerServerCommands:
       
   207             tableptr = TManagerServerCommandsTable;
       
   208             break;
       
   209         case EAoMsvSessionEvent:
       
   210             tableptr = TMsvSessionEventTable;
       
   211             break;
       
   212         case EAoNormalError:
       
   213             tableptr = NormalErrorTable;
       
   214             break;
       
   215         case EAoLastValue:
       
   216         default:
       
   217             break;
       
   218         }
       
   219     
       
   220     //space to message
       
   221     _aolMsg.Append(' ');
       
   222     
       
   223     if ( tableptr )
       
   224         {
       
   225         // add integer name to log message
       
   226         AOLogT::AddMapValue( _aolMsg, _aolVal, tableptr );
       
   227         }
       
   228     else 
       
   229         {
       
   230         // if correct table was not found add error message to log
       
   231         _aolMsg.Append( KAOMapError );
       
   232         }
       
   233     
       
   234     // write log 
       
   235     AOLogT::WriteAoLog( _aolMsg );
       
   236     }
       
   237     
       
   238 // ----------------------------------------------------------------------------
       
   239 // AddMapValue()
       
   240 // static
       
   241 // ----------------------------------------------------------------------------
       
   242 void AOLogT::AddMapValue( TDes& _aMapVal, 
       
   243     TInt _aVal, const AOMapVal _mapTable[] )
       
   244     {
       
   245     // taple index
       
   246     TInt ind = 0;
       
   247     
       
   248     // lop while correct integer is found or last table end is achieved
       
   249     while ( _mapTable[ind]._numVal != _aVal &&          // CSI: 2 # can't check length
       
   250         _mapTable[ind]._numVal != AO_LAST_MAP_VALUE )   // CSI: 2 # can't check length
       
   251         {
       
   252         ++ind;
       
   253         }
       
   254     
       
   255     // adds string to log message, table contains TText null terminated strings
       
   256     TPtrC mapPtr( _mapTable[ind]._strVal );     // CSI: 2 # can't check length
       
   257     _aMapVal.Append( mapPtr );
       
   258     }
       
   259     
       
   260 // ----------------------------------------------------------------------------
       
   261 // DoFilter()
       
   262 // static
       
   263 // ----------------------------------------------------------------------------  
       
   264 TBool AOLogT::DoFilter( TInt aFilter )
       
   265     {
       
   266     return ( aFilter & KAoLoggingToolsFilter );
       
   267     }
       
   268 
       
   269 #endif //AO_LOGGING_TOOLS_ON
       
   270