vpnengine/eventviewer/inc/eventviewer2.h
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2003-2009 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: Log File Handler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __EVENTVIEWER2__
       
    20 #define __EVENTVIEWER2__
       
    21 
       
    22 #include <gdi.h>
       
    23 #include <e32base.h>
       
    24 #include <e32std.h>
       
    25 #include <f32file.h>
       
    26 #include <barsc.h>
       
    27 #include <bautils.h>
       
    28 
       
    29 ////////////////////////////////////////////////////////
       
    30 // Literals
       
    31 ////////////////////////////////////////////////////////
       
    32 #include "eventmediatorapi.h"
       
    33 
       
    34 #define LOG_ELEM_TRAILER_LTH  12
       
    35 #define LOG_ELEM_HEADER_LTH   32
       
    36 #define KBYTES_TO_BYTES     1024
       
    37 //efine ELEM_HEADER_LTH     8
       
    38 #define FILE_BEGIN          0    
       
    39 #define END_MARK_1          0xefbeadde
       
    40 #define END_MARK_2          0xeeabedfe
       
    41 #define LOG_FILE_ID         0x474F4C45    // ELOG
       
    42 
       
    43 
       
    44 /////////////////////////////////////////////////////////////////
       
    45 //  Enumeration of log event categories.
       
    46 ////////////////////////////////////////////////////////////////
       
    47 
       
    48 enum TLogCategory2
       
    49    {
       
    50    ELogInfo,
       
    51    ELogWarning,
       
    52    ELogError,
       
    53    ELogDebug
       
    54    };
       
    55 
       
    56 
       
    57 /////////////////////////////////////////////////////////
       
    58 // TEventProperties - data to be returned with the event
       
    59 // text to the caller
       
    60 /////////////////////////////////////////////////////////
       
    61 struct TEventProperties
       
    62 
       
    63 {
       
    64     TUint32       iSourceComponent; // Uid of source component
       
    65     TTime         iTimeStamp;       // 64 bit time stamp                           
       
    66     TLogCategory2 iCategory;        // Info, Warning, Error, Debug 
       
    67     TUint32       iMsgId;           // MsgId in localization file
       
    68     TUint32       iEventNumber;     // Event number
       
    69 };
       
    70 
       
    71 
       
    72 /////////////////////////////////////////////////////////
       
    73 // Packed File Header
       
    74 /////////////////////////////////////////////////////////
       
    75 class TFileHeader
       
    76 {
       
    77     public: // Methods
       
    78         inline TInt32 GetFileId()                const {return ((TInt32)(u.iData32[0]));};
       
    79         inline TInt32 GetPositionOfNextFree()    const {return ((TInt32)(u.iData32[1]));};
       
    80         inline TInt32 GetPositionOfWrapping()    const {return ((TInt32)(u.iData32[2]));};
       
    81         inline TInt32 GetCurrEventNumber()       const {return ((TInt32)(u.iData32[3]));};
       
    82 
       
    83     private: 
       
    84         union
       
    85             {
       
    86             TUint32 iData32[4];
       
    87             } u;
       
    88 };
       
    89 
       
    90 
       
    91 
       
    92 /////////////////////////////////////////////////////////
       
    93 // Unpacked File Header
       
    94 /////////////////////////////////////////////////////////
       
    95 
       
    96 class TUnpackedFileHeader
       
    97     {
       
    98     public:
       
    99         TUint32                 iFileId;    // ELOG
       
   100         TUint32                 iPositionOfNextFree;
       
   101         TUint32                 iPositionOfWrapping;
       
   102         TUint32                 iCurrEventNumber;
       
   103     };
       
   104 
       
   105 /////////////////////////////////////////////////////////
       
   106 // Packed Log Element
       
   107 ///////////////////////////////////////////////////////
       
   108 class TLogElem
       
   109     {
       
   110     public: // Methods
       
   111     inline TInt32        GetEventLength()           const {return ((TInt32)(u.iData32[0]));};
       
   112     inline TInt32        GetEventNumber()           const {return ((TInt32)(u.iData32[1]));};
       
   113     inline TInt64        GetTimeStamp()             const
       
   114         {
       
   115         return MAKE_TINT64(u.iData32[3], u.iData32[2]);;
       
   116         };
       
   117     inline TInt32        GetSourceComponent()       const {return ((TInt32)(u.iData32[4]));};
       
   118     inline TLogCategory2 GetCategory()              const {return ((TLogCategory2)(u.iData32[5]));};
       
   119     inline TInt32        GetMsgId()                 const {return ((TInt32)(u.iData32[6]));};
       
   120     inline TInt32        GetDescrCount()            const {return ((TInt32)(u.iData32[7]));};
       
   121 
       
   122 private: 
       
   123     union
       
   124         {
       
   125         TUint32 iData32[8];
       
   126         } u;
       
   127     };
       
   128 
       
   129 /////////////////////////////////////////////////////////
       
   130 // Unpacked Log Element         
       
   131 /////////////////////////////////////////////////////////
       
   132 
       
   133 class TUnpackedLogElem
       
   134 {
       
   135     public:
       
   136         TUint32                 iEventLength;             
       
   137         TUint32                 iEventNumber;             
       
   138         TInt64                  iTimeStamp;               
       
   139         TUint32                 iSourceComponent;         
       
   140         TLogCategory2           iCategory;                
       
   141         TUint32                 iMsgId;                   
       
   142         TUint32                 iDescrCount;              
       
   143 };
       
   144 
       
   145 /////////////////////////////////////////////////////////
       
   146 // Packed Log Element trailer
       
   147 /////////////////////////////////////////////////////////
       
   148 class TLogElemTrailer
       
   149 {
       
   150     public: // Methods
       
   151         inline TInt32 GetEndMark1()              const {return ((TInt32)(u.iData32[0]));};
       
   152         inline TInt32 GetEndMark2()              const {return ((TInt32)(u.iData32[1]));};
       
   153         inline TInt32 GetEventLength()           const {return ((TInt32)(u.iData32[2]));};
       
   154 
       
   155     private: 
       
   156         union
       
   157             {
       
   158             TUint32 iData32[3];
       
   159             } u;
       
   160 };
       
   161 
       
   162 /////////////////////////////////////////////////////////
       
   163 // Unpacked Element trailer
       
   164 /////////////////////////////////////////////////////////
       
   165 
       
   166 class TUnpackedLogElemTrailer
       
   167 {
       
   168     public:
       
   169         TUint32                 iEndMark1;
       
   170         TUint32                 iEndMark2;               
       
   171         TUint32                 iEventLength;           
       
   172 };
       
   173 
       
   174 
       
   175 /////////////////////////////////////////////////////////
       
   176 // EventViewer  Class
       
   177 /////////////////////////////////////////////////////////
       
   178 class CEventViewer : public CBase
       
   179 {
       
   180 
       
   181 
       
   182     //
       
   183     // EventViewer API in EventViewer.cpp
       
   184     //
       
   185     public: 
       
   186         IMPORT_C static CEventViewer* NewL();
       
   187         IMPORT_C ~CEventViewer();
       
   188         void ConstructL();
       
   189 
       
   190         IMPORT_C TInt GetMostRecentEvent (HBufC*&                            aEventText,
       
   191                                           TEventProperties&                   aEventProperties);
       
   192 
       
   193         IMPORT_C TInt GetNextEvent       (HBufC*&                            aEventText,
       
   194                                           TEventProperties&                   aEventProperties);
       
   195 
       
   196         IMPORT_C TInt GetPreviousEvent   (HBufC*&                            aEventText,
       
   197                                           TEventProperties&                   aEventProperties);
       
   198 
       
   199         IMPORT_C TInt GetEventUsingEventNumber(
       
   200                                          HBufC*&                            aEventText,
       
   201                                          TUint32                             aEventNumber,        
       
   202                                          TEventProperties&                   aEventProperties);
       
   203 
       
   204         IMPORT_C TInt GetOldestEvent     (HBufC*&                            aEventText,
       
   205                                           TEventProperties&                   aEventProperties);
       
   206 
       
   207         IMPORT_C TInt DeleteLogFile();
       
   208 
       
   209     //
       
   210     // EventViewer internal functions in EventViewer.cpp
       
   211     //
       
   212     private: 
       
   213         TInt GetRequestedEvent( HBufC*&              aEventText,
       
   214                                 TEventProperties&     aEventProperties,
       
   215                                 TUint32               aEventNumber,
       
   216                                 TInt                  aMethodId);
       
   217 
       
   218         TInt GetRequestedEventL( HBufC*&              aEventText,
       
   219                                 TEventProperties&     aEventProperties,
       
   220                                 TUint32               aEventNumber,
       
   221                                 TInt                  aMethodId);
       
   222 
       
   223     //
       
   224     // EventViewer internal functions in LogFileHandler.cpp
       
   225     //
       
   226     private:
       
   227         TInt OpenLogFile();
       
   228         void CloseLogFile();
       
   229         void TakeCopyOfFileHeader(TUnpackedFileHeader& asrc,
       
   230                                   TUnpackedFileHeader& adest);
       
   231         void OpenResourceFileL();
       
   232         
       
   233         TInt ReadWholeLogFileToMemoryBuffer();
       
   234         TInt ReadLogFileHeader();
       
   235         TInt CopyPackedFileHeaderToUnpackedObject( TDesC8& aFileHeader);
       
   236         TBool IsLogFileModified();
       
   237         TInt EventLookup(TUint32 aEventNumber);
       
   238         TInt GetStartPositionOfLogElem(TUint32 aEndOfLogElemPosition,    
       
   239                                        TUint32* aLogElemPosition);       
       
   240         void CopyPackedLogElemToUnpackedObject(TUint32 iPositionOfCurrLogElem);
       
   241         HBufC*  SearchEventTextL( TUint32 aMsgId);
       
   242         HBufC*  ModifyEventText(HBufC* aEventTextSrc,
       
   243                                  TUint32 aDescrCount,         // Count of descriptor elements
       
   244                                  TUint32 aDescrDataPosition); // Descriptors: lth data lth data.... 
       
   245         HBufC*   FormatEvent(TInt aDescrCount,                // Count of lth/data pairs 
       
   246                              const TDesC8&  aDescrList,       // lth lth ... data data ... 
       
   247                              const TDesC&   aEventString);    // string got from localisation file
       
   248         TInt     AnalyseConvSpec(
       
   249                                  const TDesC& SourceBuf,     //    
       
   250                                  TInt&     aOffset,         // offset of conversion spec element
       
   251                                  TUint32&  aConvType,       // U or N (KConvTypex)
       
   252                                  TUint32&  aSeqNumber);     // Seq number included to conv spec elem
       
   253         HBufC*  GetDescriptorData (
       
   254                                    TUint32 aDescrCount,         // Count of lth/data pairs
       
   255                                    const TDesC8& aDescrList,    // lth lth ... data data ...
       
   256                                    TUint32 aConvType,           // KConvTypeN or KConvTypeU
       
   257                                    TUint32 aDescrNumber);       // Seq number of lth/data pair
       
   258         TInt    BufferAppend(HBufC*& aDestBuf,
       
   259                              const TDesC& aString);
       
   260 
       
   261         void    DoDeleteLogFileL();                             // In LogFileHandler.cpp
       
   262 
       
   263     private:
       
   264         RFs                         iFS;
       
   265         REventMediator              iEventMediator;
       
   266         TUnpackedFileHeader         iCurrFileHeader;
       
   267         TUnpackedFileHeader         iPreviousFileHeader;
       
   268         TUnpackedLogElem            iUnpackedLogElem;
       
   269         TUnpackedLogElemTrailer     iLogElemTrailer;
       
   270         TUint32                     iRequestedEventNumber;
       
   271         HBufC8*                     iLogFileBuf;
       
   272         TInt                        iLogFileSize;
       
   273         TInt                        iWrappingOccured;
       
   274         TUint32                     iPositionOfCurrLogElem;
       
   275         RResourceFile               iResourceFile;
       
   276         HBufC*                      iResultBuf;    // Formatted event is build to this buffer 
       
   277         
       
   278     //
       
   279     // Current API call parameters
       
   280     //
       
   281     HBufC** iEventText;
       
   282     TEventProperties* iEventProperties;
       
   283 };
       
   284 #endif