vpnengine/dmadipsecvpn/src/dmadeventlog.cpp
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2000 - 2006 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: Implementation of TDmAdEventLog.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <utf.h>
       
    20 #include <barsread.h>
       
    21 #include "vpnlogger.h"
       
    22 
       
    23 //#include <vpnmanagementui.rsg>
       
    24 //#include <avkon.rsg>
       
    25 
       
    26 #include "dmadeventlog.h"
       
    27 
       
    28 // "dd/mm/yyyy0"
       
    29 const TInt KDmAdMaxLengthTextDateString = 11;               
       
    30 
       
    31 void TDmAdEventLog::DeleteLogL(void)
       
    32     {
       
    33     TRACE("TDmAdEventLog::DeleteLogL");
       
    34     
       
    35     CEventViewer* eventViewer = CEventViewer::NewL();
       
    36     CleanupStack::PushL(eventViewer);
       
    37     User::LeaveIfError(eventViewer->DeleteLogFile());
       
    38     CleanupStack::PopAndDestroy(); //eventViewer
       
    39     }
       
    40 
       
    41 void TDmAdEventLog::EventLogL(CBufBase& aEventLog)
       
    42     {
       
    43     
       
    44     TRACE("TDmAdEventLog::EventLogL");
       
    45 /*
       
    46    _LIT(KResourceFileVpnLog, "\\resource\\vpnmanagementui.rsc");
       
    47    _LIT(KResourceFileAvkon, "\\resource\\avkon.rsc");
       
    48 */
       
    49 
       
    50     CEventViewer* eventViewer = 0;
       
    51     TRAPD(err, eventViewer = CEventViewer::NewL());
       
    52     if (err == KErrNotFound)
       
    53         {
       
    54         return;
       
    55         }
       
    56     User::LeaveIfError(err);
       
    57     CleanupStack::PushL(eventViewer);
       
    58 
       
    59    RFs fs;
       
    60    CleanupClosePushL(fs);
       
    61    User::LeaveIfError(fs.Connect());
       
    62 
       
    63    RResourceFile resourceFileVpnLog;
       
    64    CleanupClosePushL(resourceFileVpnLog);
       
    65 
       
    66    RResourceFile resourceFileAvkon;
       
    67    CleanupClosePushL(resourceFileAvkon);
       
    68 
       
    69    //OpenResourceFileL(fs, resourceFileVpnLog, KResourceFileVpnLog);
       
    70    //OpenResourceFileL(fs, resourceFileAvkon, KResourceFileAvkon);
       
    71    
       
    72     TEventProperties eventProperties;
       
    73     HBufC* eventText = NULL;
       
    74       
       
    75     TInt ret = eventViewer->GetMostRecentEvent(eventText, eventProperties);
       
    76     while (ret == KErrNone)
       
    77         {
       
    78         CleanupStack::PushL(eventText);
       
    79 
       
    80         TBuf<2 * KDmAdMaxLengthTextDateString + 3> timeBuf;
       
    81         FormatTimeL(resourceFileAvkon, timeBuf, eventProperties.iTimeStamp);
       
    82         
       
    83         HBufC* categoryText = CategoryTextLC(resourceFileVpnLog, eventProperties.iCategory);
       
    84         
       
    85         _LIT(KDmAdCr, "\n");
       
    86         _LIT(KDmAdSpace, " ");
       
    87         HBufC* messageText = HBufC::NewLC(timeBuf.Length() +
       
    88                                           KDmAdCr().Length() +
       
    89                                           categoryText->Length() +
       
    90                                           KDmAdSpace().Length() +
       
    91                                           eventText->Length() +
       
    92                                           KDmAdCr().Length());
       
    93         messageText->Des().Copy(timeBuf);
       
    94         messageText->Des().Append(KDmAdCr);
       
    95         messageText->Des().Append(*categoryText);
       
    96         messageText->Des().Append(KDmAdSpace); 
       
    97         messageText->Des().Append(*eventText);
       
    98         messageText->Des().Append(KDmAdCr);
       
    99 
       
   100         HBufC8* messageText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L(*messageText);
       
   101         CleanupStack::PushL(messageText8);
       
   102         aEventLog.InsertL(aEventLog.Size(), *messageText8);
       
   103                 
       
   104         CleanupStack::PopAndDestroy(4); // messageText8, messageText, categoryText, eventText
       
   105 
       
   106         ret = eventViewer->GetPreviousEvent(eventText, eventProperties);
       
   107         }
       
   108     CleanupStack::PopAndDestroy(4); //resourceFileAvkon, resourceFileVpnLog, fs, eventViewer
       
   109     }
       
   110 
       
   111 void TDmAdEventLog::FormatTimeL(RResourceFile& aResourceFile, TDes& aDateTimeText, TTime aTime)
       
   112     {
       
   113     TRACE("TDmAdEventLog::FormatTimeL");
       
   114     
       
   115     (void)aResourceFile;
       
   116    _LIT(KDmAdDateFromat, "%D%M%Y%/0%1%/1%2%/2%3%/3");
       
   117    _LIT(KDmAdTimeFromat, "%-B%:0%J%:1%T%:3%+B");
       
   118 
       
   119      // Date
       
   120    HBufC* dateFormat = KDmAdDateFromat().AllocLC();
       
   121     //HBufC* dateFormat = ReadResourceLC(aResourceFile, R_QTN_DATE_USUAL_WITH_ZERO);
       
   122     //HBufC* dateFormat = StringLoader::LoadLC(R_QTN_DATE_USUAL_WITH_ZERO);
       
   123     TBuf<KDmAdMaxLengthTextDateString> dateString;
       
   124     aTime.FormatL(dateString, *dateFormat);
       
   125     CleanupStack::PopAndDestroy(); //dateFormat
       
   126 
       
   127     // Time
       
   128     dateFormat = KDmAdTimeFromat().AllocLC();
       
   129     //dateFormat = ReadResourceLC(aResourceFile, R_QTN_TIME_USUAL_WITH_ZERO);
       
   130     //dateFormat = StringLoader::LoadLC(R_QTN_TIME_USUAL_WITH_ZERO);
       
   131     TBuf<KDmAdMaxLengthTextDateString> timeString;
       
   132     aTime.FormatL(timeString, *dateFormat);
       
   133     CleanupStack::PopAndDestroy(); //dateFormat
       
   134       
       
   135     TBuf<2 * KDmAdMaxLengthTextDateString + 3> timeBuf;
       
   136 
       
   137     /*
       
   138     TTime now;
       
   139     now.HomeTime();
       
   140     if ( (now.YearsFrom(aTime).Int() > 0) ||
       
   141         (aTime.DayNoInYear() < now.DayNoInYear()))
       
   142         {
       
   143         timeBuf.Append(dateString);
       
   144         _LIT(KDmAdSpaceHyphenSpace, " - ");
       
   145         timeBuf.Append(KDmAdSpaceHyphenSpace);
       
   146         }
       
   147     */
       
   148 
       
   149     timeBuf.Append(dateString);
       
   150     _LIT(KDmAdSpaceHyphenSpace, " - ");
       
   151     timeBuf.Append(KDmAdSpaceHyphenSpace);
       
   152         
       
   153     timeBuf.Append(timeString);
       
   154     aDateTimeText = timeBuf;
       
   155     }
       
   156 
       
   157 HBufC* TDmAdEventLog::CategoryTextLC(RResourceFile& aResourceFile, TLogCategory2 aCategory)
       
   158     {
       
   159     (void)aResourceFile;
       
   160     HBufC* categoryText = NULL;
       
   161     _LIT(KDmAdInfo, "Information:");
       
   162     _LIT(KDmAdWarning, "Warning:");
       
   163     _LIT(KDmAdError, "Error:");
       
   164     
       
   165     if (aCategory == ELogInfo)
       
   166         {
       
   167         categoryText = KDmAdInfo().AllocLC();
       
   168         //categoryText = ReadResourceLC(aResourceFile, R_VPN_DETAIL_LOG_ENTRY_INFO);
       
   169         //categoryText = StringLoader::LoadLC(R_VPN_DETAIL_LOG_ENTRY_INFO);
       
   170         }
       
   171     else if (aCategory == ELogWarning)
       
   172         {
       
   173         categoryText = KDmAdWarning().AllocLC();
       
   174         //categoryText = ReadResourceLC(aResourceFile, R_VPN_DETAIL_LOG_ENTRY_WARNING);
       
   175         //categoryText = StringLoader::LoadLC(R_VPN_DETAIL_LOG_ENTRY_WARNING);
       
   176         }
       
   177     else // ELogError (or ELogDebug)
       
   178         {
       
   179         categoryText = KDmAdError().AllocLC();
       
   180         //categoryText = ReadResourceLC(aResourceFile, R_VPN_DETAIL_LOG_ENTRY_ERROR);
       
   181         //categoryText = StringLoader::LoadLC(R_VPN_DETAIL_LOG_ENTRY_ERROR);
       
   182         }
       
   183     return categoryText;
       
   184     }
       
   185     
       
   186 void TDmAdEventLog::OpenResourceFileL(RFs& aFs, RResourceFile& aResourceFile, const TDesC& aFilename)
       
   187    {
       
   188    TRACE("TDmAdEventLog::OpenResourceFileL");
       
   189    
       
   190    TFileName resourceFileName;
       
   191    TFileName dllName;
       
   192 
       
   193    Dll::FileName(dllName);
       
   194    TBuf<2> drive = dllName.Left(2); // always z: for ... ?
       
   195    
       
   196    resourceFileName.Copy(drive);
       
   197    resourceFileName.Append(aFilename);
       
   198    
       
   199    aResourceFile.OpenL(aFs, resourceFileName);
       
   200    aResourceFile.ConfirmSignatureL();
       
   201    }
       
   202 
       
   203 HBufC* TDmAdEventLog::ReadResourceLC(RResourceFile& aResourceFile, TInt aMsgId)
       
   204    {
       
   205    HBufC8* resourceBuf = aResourceFile.AllocReadLC(aMsgId);
       
   206 
       
   207    TResourceReader resourceReader;
       
   208    resourceReader.SetBuffer(resourceBuf);
       
   209 
       
   210    HBufC* textDataBuf = HBufC::NewL(resourceBuf->Length());
       
   211    resourceReader.Read((void*)textDataBuf->Ptr(), resourceBuf->Length());
       
   212    textDataBuf->Des().SetLength(resourceBuf->Length()/2);
       
   213    
       
   214    CleanupStack::PopAndDestroy(); // resourceBuf
       
   215    CleanupStack::PushL(textDataBuf);
       
   216    return textDataBuf;
       
   217    }