logsui/EngineSrc/CLogsGetEvent.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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 *     Implements interface for log event getting
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 // #include <PbkFields.hrh>
       
    22 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    23 #include <logengevents.h>
       
    24 #endif
       
    25 #include <logcli.h>
       
    26 #include <logview.h>
       
    27 #include <logviewchangeobserver.h>
       
    28 #include <featmgr.h>
       
    29 #include "CLogsGetEvent.h"
       
    30 #include "CLogsEventData.h"
       
    31 #include "CLogsEvent.h"
       
    32 #include "MLogsObserver.h"
       
    33 #include "CLogsEventGetter.h"
       
    34 #include "LogsApiConsts.h"  //additional event uids
       
    35 
       
    36 // EXTERNAL DATA STRUCTURES
       
    37 
       
    38 // EXTERNAL FUNCTION PROTOTYPES  
       
    39 
       
    40 // CONSTANTS
       
    41 
       
    42 // MACROS
       
    43 
       
    44 // LOCAL CONSTANTS AND MACROS
       
    45 
       
    46 // MODULE DATA STRUCTURES
       
    47 
       
    48 //========================================CLogsGetEventNotify=============================================
       
    49 //
       
    50 class CLogsGetEventNotify : public CActive, 
       
    51                             public MLogViewChangeObserver
       
    52     {
       
    53     public:
       
    54         /**
       
    55          * Symbian OS constructor. 
       
    56          *
       
    57          * @param aFsSession ref. to file server session
       
    58          * @param aGetEvent pointer to Logs reader
       
    59          * @return New instance of this class
       
    60          */
       
    61         static CLogsGetEventNotify* NewL
       
    62                                     (   RFs& aFsSession
       
    63                                     ,   CLogsGetEvent* aGetEvent
       
    64                                     );
       
    65 
       
    66         /**
       
    67          *  Destructor
       
    68          */
       
    69         ~CLogsGetEventNotify();
       
    70 
       
    71     private:
       
    72         /**
       
    73          * Default constructor. 
       
    74          */
       
    75         CLogsGetEventNotify();
       
    76 
       
    77         /**
       
    78          * Second phase constructor. 
       
    79          */
       
    80         void ConstructL();
       
    81 
       
    82         /**
       
    83          * C++ constructor. 
       
    84          *
       
    85          * @param aFsSession ref. to file server session
       
    86          * @param aGetEvent pointer to Logs reader
       
    87          */
       
    88         CLogsGetEventNotify( RFs& aFsSession, CLogsGetEvent* aGetEvent );
       
    89 
       
    90     public:
       
    91         /**
       
    92          *  Sets Log ID
       
    93          *  @param aId Log ID
       
    94          */
       
    95         void SetId( TLogId aId );
       
    96 
       
    97     private:
       
    98         /**
       
    99          *  Creates and returns a filter.
       
   100          *  Leaves filter object on cleanupstack.
       
   101          *
       
   102          *  @param  aFilterType     Filter type id.
       
   103          *
       
   104          *  @return  Pointer to created and configured filter.
       
   105          */
       
   106         CLogFilter* SetOneFilterLC( TUid aFilterType );
       
   107 
       
   108     public: // from MLogViewChangeObserver
       
   109         void HandleLogViewChangeEventAddedL
       
   110                         (   TLogId aId
       
   111                         ,   TInt aViewIndex
       
   112                         ,   TInt aChangeIndex
       
   113                         ,   TInt aTotalChangeCount
       
   114                         );
       
   115 
       
   116         void HandleLogViewChangeEventChangedL
       
   117                         (   TLogId aId
       
   118                         ,   TInt aViewIndex
       
   119                         ,   TInt aChangeIndex
       
   120                         ,   TInt aTotalChangeCount
       
   121                         );
       
   122 
       
   123         void HandleLogViewChangeEventDeletedL
       
   124                         (   TLogId aId
       
   125                         ,   TInt aViewIndex
       
   126                         ,   TInt aChangeIndex
       
   127                         ,   TInt aTotalChangeCount
       
   128                         );
       
   129 
       
   130     private: /// from CActive
       
   131         void DoCancel();
       
   132 
       
   133     protected: /// from CActive
       
   134         void RunL();
       
   135         TInt RunError(TInt aError);
       
   136 
       
   137     private: // data
       
   138         /// Own:
       
   139         TLogId              iId;
       
   140 
       
   141         /// Ref: File server session
       
   142         RFs&                iFsSession;
       
   143 
       
   144         /// Own:
       
   145         CLogsGetEvent*      iGetEvent;
       
   146         
       
   147         /// Own: Log client
       
   148         CLogClient*         iLogClient;
       
   149 
       
   150         /// Own:
       
   151         CLogViewEvent*      iEventView;
       
   152 
       
   153         /// Own: Filterlist
       
   154         CLogFilterList*     iFilterList;
       
   155     };
       
   156 //    
       
   157 //========================================CLogsGetEventNotify=============================================
       
   158 
       
   159     
       
   160     
       
   161 
       
   162 // LOCAL FUNCTION PROTOTYPES
       
   163 
       
   164 // ==================== LOCAL FUNCTIONS ====================
       
   165 
       
   166 // ================= MEMBER FUNCTIONS =======================
       
   167 
       
   168 CLogsGetEvent::CLogsGetEvent
       
   169     (   RFs& aFsSession
       
   170     ,   TLogsEventStrings& aStrings
       
   171     ,   MLogsObserver* aObserver
       
   172     )
       
   173     : CActive( EPriorityHigh )
       
   174     , iFsSession( aFsSession )
       
   175     , iStrings( aStrings )
       
   176     , iObserver( aObserver )
       
   177     , iState( EStateUndefined )
       
   178     , iStaticEmerg( ETrue )
       
   179     {
       
   180     }
       
   181 
       
   182 CLogsGetEvent* CLogsGetEvent::NewL
       
   183     (   RFs& aFsSession
       
   184     ,   TLogsEventStrings& aStrings
       
   185     ,   MLogsObserver* aObserver
       
   186     )
       
   187     {
       
   188     CLogsGetEvent* self = new (ELeave) CLogsGetEvent
       
   189                                         (   aFsSession
       
   190                                         ,   aStrings
       
   191                                         ,   aObserver
       
   192                                         );
       
   193     CleanupStack::PushL(self);
       
   194     self->ConstructL();
       
   195     CleanupStack::Pop();  // self
       
   196     return self;
       
   197     }
       
   198 
       
   199 void CLogsGetEvent::ConstructL()
       
   200     {
       
   201     iLogClient = CLogClient::NewL( iFsSession );
       
   202     iNotify = CLogsGetEventNotify::NewL( iFsSession, this );    
       
   203     iLogEvent = CLogEvent::NewL();
       
   204     CLogsEvent* event = CLogsEvent::NewLC( );      
       
   205     
       
   206     CleanupStack::Pop(); // event
       
   207     iEvent = event;
       
   208     iWrapper = CLogsEventGetter::NewL( );   
       
   209     
       
   210     if ( FeatureManager::FeatureSupported( KFeatureIdProtocolCdma ) )
       
   211         {
       
   212         iStaticEmerg = EFalse;
       
   213         }
       
   214         
       
   215     CActiveScheduler::Add( this );
       
   216     }
       
   217 
       
   218 CLogsGetEvent::~CLogsGetEvent()
       
   219     {
       
   220     Cancel();
       
   221     delete iLogClient;
       
   222     delete iLogEvent;
       
   223     delete iEvent;
       
   224     delete iWrapper;
       
   225     delete iNotify;
       
   226     }
       
   227 
       
   228 void CLogsGetEvent::Get( TLogId aId )
       
   229     {
       
   230     Cancel();
       
   231     iLogEvent->SetId( aId );
       
   232     iNotify->SetId( aId );
       
   233     iLogClient->GetEvent( *iLogEvent, iStatus ); //Get details from db.This is an asynchronous request
       
   234     iState = EStateActive;        
       
   235     SetActive();
       
   236     }
       
   237 
       
   238 const MLogsEventGetter* CLogsGetEvent::Event()
       
   239     {
       
   240     return iWrapper->Wrap( iEvent );
       
   241     }
       
   242 
       
   243 const CLogEvent* CLogsGetEvent::LogEvent() const
       
   244     {
       
   245     return iLogEvent;
       
   246     }
       
   247 
       
   248 void CLogsGetEvent::SetObserver( MLogsObserver* aObserver )
       
   249     {
       
   250     iObserver = aObserver;      //Observer to indicate when asynchronous retrieval is ok
       
   251     }
       
   252 
       
   253 void CLogsGetEvent::DoCancel()
       
   254     {      
       
   255     iLogClient->Cancel();
       
   256     }
       
   257 
       
   258 void CLogsGetEvent::RunL()
       
   259     {
       
   260     ConstructEventL( *iEvent, *iLogEvent );  
       
   261     iState = EStateFinished;    
       
   262     
       
   263     if( iObserver )
       
   264         {
       
   265         iObserver->StateChangedL( this ); //Indicate observer: Asynch retrieval is now done 
       
   266         }                                 // on CLogsDetailControlContainer::StateChangedL
       
   267     }
       
   268 
       
   269 TInt CLogsGetEvent::RunError(TInt aError)
       
   270     {
       
   271     if( aError == KErrAccessDenied )
       
   272         {
       
   273         return KErrNone;
       
   274         }
       
   275     else
       
   276         {
       
   277         return aError;
       
   278         }
       
   279     }
       
   280 
       
   281 TLogsState CLogsGetEvent::State() const
       
   282     {
       
   283     return iState;
       
   284     }
       
   285 
       
   286 void CLogsGetEvent::ConstructEventL( MLogsEvent& aDest, const CLogEvent& aSource )
       
   287     {
       
   288     aDest.InitializeEventL( aSource, iStrings, ELogsDetailModel );
       
   289     }
       
   290 
       
   291 
       
   292 //========================================CLogsGetEventNotify=============================================
       
   293 //
       
   294 CLogsGetEventNotify* CLogsGetEventNotify::NewL
       
   295     (   RFs& aFsSession
       
   296     ,   CLogsGetEvent* aGetEvent
       
   297     )
       
   298     {
       
   299     CLogsGetEventNotify* self = new (ELeave) CLogsGetEventNotify
       
   300                                             (   aFsSession
       
   301                                             ,   aGetEvent
       
   302                                             );
       
   303     CleanupStack::PushL( self );
       
   304     self->ConstructL();
       
   305     CleanupStack::Pop();
       
   306     return self;
       
   307     }
       
   308 
       
   309 CLogsGetEventNotify::CLogsGetEventNotify
       
   310     (   RFs& aFsSession
       
   311     ,   CLogsGetEvent* aGetEvent
       
   312     )
       
   313     : CActive( EPriorityStandard )
       
   314     , iFsSession( aFsSession )
       
   315     , iGetEvent( aGetEvent )
       
   316     {
       
   317     }
       
   318 
       
   319 void CLogsGetEventNotify::ConstructL()
       
   320     {
       
   321     iLogClient = CLogClient::NewL( iFsSession );
       
   322     iEventView = CLogViewEvent::NewL( *iLogClient, *this );
       
   323     iFilterList = new ( ELeave ) CLogFilterList;
       
   324     iFilterList->AppendL( SetOneFilterLC( KLogShortMessageEventTypeUid ) );
       
   325     CleanupStack::Pop();
       
   326     iFilterList->AppendL( SetOneFilterLC( KLogsEngMmsEventTypeUid ) );
       
   327     CleanupStack::Pop();
       
   328     iFilterList->AppendL( SetOneFilterLC( KLogCallEventTypeUid ) );
       
   329     CleanupStack::Pop();
       
   330     iFilterList->AppendL( SetOneFilterLC( KLogDataEventTypeUid ) );
       
   331     CleanupStack::Pop();
       
   332     iFilterList->AppendL( SetOneFilterLC( KLogFaxEventTypeUid ) );
       
   333     CleanupStack::Pop();
       
   334     iFilterList->AppendL( SetOneFilterLC( KLogPacketDataEventTypeUid ) );
       
   335     CleanupStack::Pop();
       
   336     iFilterList->AppendL( SetOneFilterLC( KLogsEngWlanEventTypeUid ) );
       
   337     CleanupStack::Pop();
       
   338     iFilterList->AppendL( SetOneFilterLC( KLogsEngPocInfoEventTypeUid ) );
       
   339     CleanupStack::Pop();
       
   340     
       
   341     CActiveScheduler::Add( this ); 
       
   342 
       
   343     TRAPD( err, iEventView->SetFilterL( *iFilterList, iStatus ) );
       
   344     if( err == KErrAccessDenied )
       
   345         {
       
   346         return;
       
   347         }
       
   348     User::LeaveIfError( err );
       
   349     SetActive();
       
   350     }
       
   351 
       
   352 CLogFilter* CLogsGetEventNotify::SetOneFilterLC( TUid aFilterType )
       
   353     {
       
   354     CLogFilter* filter = CLogFilter::NewL();
       
   355     CleanupStack::PushL( filter );
       
   356     filter->SetEventType( aFilterType );
       
   357     return filter;
       
   358     }
       
   359 
       
   360 CLogsGetEventNotify::~CLogsGetEventNotify()
       
   361     {
       
   362     Cancel();     
       
   363     delete iEventView;
       
   364     delete iLogClient;
       
   365     
       
   366     if( iFilterList )
       
   367         {
       
   368         iFilterList->ResetAndDestroy();
       
   369         delete iFilterList;
       
   370         iFilterList = NULL;
       
   371         }
       
   372     }
       
   373 
       
   374 void CLogsGetEventNotify::DoCancel()
       
   375     {     
       
   376     if( iEventView )
       
   377         {
       
   378         iEventView->Cancel();
       
   379         }
       
   380         
       
   381     if( iLogClient )
       
   382         {
       
   383         iLogClient->Cancel();
       
   384         }
       
   385     }
       
   386 
       
   387 void CLogsGetEventNotify::RunL()
       
   388     {
       
   389     }
       
   390 
       
   391 TInt CLogsGetEventNotify::RunError(TInt aError)
       
   392     {
       
   393     if( aError == KErrAccessDenied )
       
   394         {
       
   395         return KErrNone;
       
   396         }
       
   397     else
       
   398         {
       
   399         return aError;
       
   400         }
       
   401     }
       
   402 
       
   403 void CLogsGetEventNotify::HandleLogViewChangeEventAddedL
       
   404     (   TLogId /*aId*/
       
   405     ,   TInt /*aViewIndex*/
       
   406     ,   TInt /*aChangeIndex*/
       
   407     ,   TInt /*aTotalChangeCount*/
       
   408     )
       
   409     {  
       
   410     }
       
   411 
       
   412 void CLogsGetEventNotify::HandleLogViewChangeEventChangedL
       
   413     (   TLogId aId
       
   414     ,   TInt /*aViewIndex*/
       
   415     ,   TInt /*aChangeIndex*/
       
   416     ,   TInt aTotalChangeCount
       
   417     )
       
   418     {   
       
   419     if( aTotalChangeCount && ( iId == aId ) )
       
   420         {
       
   421         iGetEvent->Get( iId );
       
   422         }
       
   423     }
       
   424 
       
   425 void CLogsGetEventNotify::HandleLogViewChangeEventDeletedL
       
   426     (   TLogId /*aId*/
       
   427     ,   TInt /*aViewIndex*/
       
   428     ,   TInt /*aChangeIndex*/
       
   429     ,   TInt /*aTotalChangeCount*/
       
   430     )
       
   431     {    
       
   432     }
       
   433 
       
   434 void CLogsGetEventNotify::SetId( TLogId aId )
       
   435     {
       
   436     iId = aId;
       
   437     }
       
   438 //    
       
   439 //========================================CLogsGetEventNotify=============================================
       
   440 
       
   441     
       
   442     
       
   443 
       
   444 //  End of File