logsui/EngineSrc/CLogsBaseReader.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 Logs reader. Common functionality.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <logcli.h>
       
    22 #include "CLogsBaseReader.h"
       
    23 #include "MLogsObserver.h"
       
    24 #include "CLogsEvent.h"
       
    25 #include "MLogsEventArray.h"
       
    26 #include "LogsEngConsts.h"
       
    27 #include <featmgr.h>
       
    28 #include "CLogsEventData.h"
       
    29 #include "CLogsEngine.h"
       
    30 
       
    31 
       
    32 // CONSTANTS
       
    33 const TInt KDeleteCountInit = -1;
       
    34 
       
    35 // CONSTANTS FOR DEBUGGING
       
    36 #ifdef _DEBUG
       
    37 _LIT(KPanicMsg,"CLogsBaseReader");
       
    38 #endif
       
    39 
       
    40 // ----------------------------------------------------------------------------
       
    41 // CLogsBaseReader::CLogsBaseReader
       
    42 // ----------------------------------------------------------------------------
       
    43 //
       
    44 CLogsBaseReader::CLogsBaseReader( 
       
    45     RFs& aFsSession, 
       
    46     MLogsEventArray& aEventArray, 
       
    47     TLogsEventStrings& aStrings,
       
    48     TLogsModel aModelId,
       
    49     MLogsObserver* aObserver,
       
    50     CLogsEngine* aLogsEngineRef
       
    51      ) :
       
    52         CActive( EPriorityStandard ),
       
    53         iFsSession( aFsSession ),
       
    54         iEventArray( aEventArray ),
       
    55         iStrings( aStrings ),
       
    56         iObserver( aObserver ),
       
    57         iLogsEngineRef( aLogsEngineRef ),
       
    58         iPhase( EInitial ),
       
    59         iModelId( aModelId ),
       
    60         iIndex( 0 ),
       
    61         iInterrupted( EFalse ),
       
    62         iState( EStateUndefined ),
       
    63         iDirty( ETrue ),
       
    64         iActivated( EFalse ),
       
    65         iDeleteChangeCount( KDeleteCountInit ),
       
    66         iStaticEmerg( ETrue )
       
    67     {
       
    68     }
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // CLogsBaseReader::~CLogsBaseReader
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 CLogsBaseReader::~CLogsBaseReader()
       
    75     {
       
    76     Cancel();
       
    77     }
       
    78 
       
    79 // ----------------------------------------------------------------------------
       
    80 // CLogsBaseReader::BaseConstructL
       
    81 // ----------------------------------------------------------------------------
       
    82 //
       
    83 void CLogsBaseReader::BaseConstructL()
       
    84     {
       
    85     iLogClientRef = iLogsEngineRef->CLogClientRef();     
       
    86     
       
    87     if ( FeatureManager::FeatureSupported( KFeatureIdProtocolCdma ) )
       
    88         {
       
    89         iStaticEmerg = EFalse;
       
    90         }
       
    91     }
       
    92 
       
    93 
       
    94 // ----------------------------------------------------------------------------
       
    95 // CLogsBaseReader::IsInterrupted
       
    96 // ----------------------------------------------------------------------------
       
    97 //
       
    98 TBool CLogsBaseReader::IsInterrupted() const
       
    99     {
       
   100     return iInterrupted;
       
   101     }
       
   102 
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // CLogsBaseReader::Interrupt
       
   106 // ----------------------------------------------------------------------------
       
   107 //
       
   108 void CLogsBaseReader::Interrupt()
       
   109     {
       
   110     if( iPhase != EInitial && iPhase != EDone )    
       
   111         {
       
   112         iInterrupted = ETrue;
       
   113         iState = EStateInterrupted;
       
   114         }
       
   115     else if( iPhase == EDone )
       
   116         {
       
   117         iState = EStateInterrupted;
       
   118         iPhase = EFilter;
       
   119         }
       
   120     }
       
   121 
       
   122 // ----------------------------------------------------------------------------
       
   123 // CLogsBaseReader::State
       
   124 // ----------------------------------------------------------------------------
       
   125 //
       
   126 TLogsState CLogsBaseReader::State() const
       
   127     {
       
   128     return iState;
       
   129     }
       
   130 
       
   131 // ----------------------------------------------------------------------------
       
   132 // CLogsBaseReader::NextL
       
   133 // ----------------------------------------------------------------------------
       
   134 //
       
   135 void CLogsBaseReader::NextL()
       
   136     {
       
   137     if( ! iInterrupted )
       
   138         {
       
   139         if( DoNextL() ) //Implemented in  derived reader
       
   140             {
       
   141             iState = EStateActive;
       
   142             SetActive();
       
   143             }
       
   144         else
       
   145             {
       
   146             iState = EStateFinished;
       
   147             ReadingFinishedL();
       
   148             if( iObserver )
       
   149                 {
       
   150                 iObserver->StateChangedL( this );
       
   151                 }
       
   152             }
       
   153         }
       
   154     }
       
   155 
       
   156 // ----------------------------------------------------------------------------
       
   157 // CLogsBaseReader::SetObserver
       
   158 // ----------------------------------------------------------------------------
       
   159 //
       
   160 void CLogsBaseReader::SetObserver( MLogsObserver* aObserver )
       
   161     {
       
   162     iObserver = aObserver;
       
   163     }
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // CLogsBaseReader::ContinueL
       
   167 // ----------------------------------------------------------------------------
       
   168 //
       
   169 void CLogsBaseReader::ContinueL()
       
   170     {
       
   171     iInterrupted = EFalse;
       
   172     
       
   173     if( ! IsActive() )
       
   174         {
       
   175         NextL();
       
   176         }
       
   177     }
       
   178 
       
   179 
       
   180 // ----------------------------------------------------------------------------
       
   181 // CLogsBaseReader::DoCancel
       
   182 // ----------------------------------------------------------------------------
       
   183 //
       
   184 void CLogsBaseReader::DoCancel()   //From CActive
       
   185     {
       
   186     iPhase = EInitial;
       
   187     iState = EStateUndefined;
       
   188     iLogClientRef->Cancel();  
       
   189     }
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // CLogsBaseReader::RunL
       
   193 // ----------------------------------------------------------------------------
       
   194 //
       
   195 void CLogsBaseReader::RunL()
       
   196     {
       
   197     
       
   198     if( iStatus != KErrNone )   
       
   199         {
       
   200         iState = EStateError;
       
   201         if( iObserver )
       
   202             {
       
   203             iObserver->StateChangedL( this ); 
       
   204             }
       
   205         }
       
   206     else
       
   207         {
       
   208         switch( iPhase )
       
   209             {
       
   210             case EFilter:
       
   211                 if( ViewCountL() == 0 )
       
   212                     {
       
   213                     iEventArray.Reset();
       
   214                     iPhase = EDone;
       
   215                     }
       
   216                 break;
       
   217 
       
   218             case ERead:
       
   219                 {
       
   220                 const CLogEvent& sourceEvent = Event();
       
   221 
       
   222                 //If operator notifies voicemail using proprietary CPHS-message there is no number.
       
   223                 //Sms stack is logging it using number="CPHS" so we need to skip those entries (NSIA-6SP9GC).
       
   224                 _LIT(kCphs, "CPHS");
       
   225                 const TDesC& nbr = sourceEvent.Number();
       
   226                 
       
   227                 if( nbr == kCphs ) 
       
   228                     {
       
   229                     break;
       
   230                     }
       
   231 
       
   232                 if( iEventArray.Count() <= iIndex )     //Append new entry to event array
       
   233                     { 
       
   234                     // create new event 
       
   235                     CLogsEvent* event = CLogsEvent::NewLC(); 
       
   236                     // Event() reads current event from Logs database
       
   237                     ConstructEventL( *event, sourceEvent ); //dest, source
       
   238                     // Append to end of array, when reading array first time
       
   239                     iEventArray.AppendL( *event );      //Ownership transferred
       
   240                     CleanupStack::Pop( event );    
       
   241                     }
       
   242                 else                                    //Rewrite new entry on top of an old entry in event array
       
   243                     {
       
   244                     //Event() reads current event from Logs database
       
   245                     ConstructEventL( ( iEventArray.At( iIndex ) ), sourceEvent );  //dest, source                    
       
   246                     }
       
   247 
       
   248                 // read duplicate counts if missed list and we're in phase of reading of the counts too.
       
   249                 if( iModelId == ELogsMissedModel &&
       
   250                     iReadMissedDuplicateCounts )
       
   251                     {
       
   252                     iPhase = EDuplicate; 
       
   253                     }
       
   254                 else
       
   255                     {
       
   256                     ++iIndex;
       
   257                     }
       
   258 
       
   259                 if( iIndex >= ViewCountL() )
       
   260                     {
       
   261                     iPhase = EDone;
       
   262                     }            
       
   263                 break;
       
   264                 }
       
   265 
       
   266             case EDuplicate:
       
   267 
       
   268                 iPhase = ERead;
       
   269 
       
   270                 iEventArray.At( iIndex ).SetDuplicates(                     //Retrieve duplicate count just retrieved in 
       
   271                             static_cast<TInt8>( DuplicateCountL() + 1 ) );  //in call of NextL() 
       
   272                 ++iIndex;
       
   273 
       
   274                 if( iIndex >= ViewCountL() )
       
   275                     {
       
   276                     iPhase = EDone;
       
   277                     }
       
   278                 break;
       
   279 
       
   280             case EInitial: // flow-through
       
   281             case EDone:
       
   282             default:
       
   283                 break;
       
   284             }   //end switch
       
   285 
       
   286         if( iPhase == EDone )
       
   287             {
       
   288             //All events read
       
   289             if( iModelId == ELogsMissedModel && !iReadMissedDuplicateCounts )  
       
   290                 {
       
   291                 //Finish first phase of reading missed calls, 
       
   292                 iReadMissedDuplicateCounts = ETrue;
       
   293                 iState = EStateSemiFinished; //in order avoid scrollbar flicker etc in UI when StateChangedL is called                
       
   294                 
       
   295                 if( iObserver )
       
   296                     {
       
   297                     iObserver->StateChangedL( this ); 
       
   298                     }
       
   299                 //Then immediately continue rereading missed calls now including the missed counts too
       
   300                 StartL(); 
       
   301                 }
       
   302             else
       
   303                 {
       
   304                 //Reading finished
       
   305                 ReadingFinishedL();    
       
   306                 iState = EStateFinished; //Inform UI etc all reading is now done
       
   307 
       
   308                 if( iObserver )
       
   309                     {
       
   310                     iObserver->StateChangedL( this );
       
   311                     }
       
   312                 }
       
   313             }
       
   314         else
       
   315             {
       
   316             //Continue to next event
       
   317             if( iObserver )
       
   318                 {
       
   319                 iObserver->StateChangedL( this );
       
   320                 }
       
   321             NextL();
       
   322             }
       
   323         }   //endif
       
   324     }
       
   325 
       
   326 // ----------------------------------------------------------------------------
       
   327 // CLogsBaseReader::RunError
       
   328 // ----------------------------------------------------------------------------
       
   329 //
       
   330 TInt CLogsBaseReader::RunError(TInt aError)
       
   331     {
       
   332     if( aError == KErrAccessDenied )
       
   333         {
       
   334         return KErrNone;
       
   335         }
       
   336     else
       
   337         {
       
   338         return aError;
       
   339         }
       
   340     }
       
   341 
       
   342 // ----------------------------------------------------------------------------
       
   343 // CLogsBaseReader::ReadingFinishedL
       
   344 // ----------------------------------------------------------------------------
       
   345 //
       
   346 void CLogsBaseReader::ReadingFinishedL()
       
   347     {
       
   348     CheckArrayLengthL();
       
   349     }
       
   350 
       
   351 // ----------------------------------------------------------------------------
       
   352 // CLogsBaseReader::CheckArrayLengthL
       
   353 //
       
   354 // If there are old items in the end of iEventArray that are not part of what was just read from db,
       
   355 // get rid of those. This is called when data is (re)read from db.
       
   356 // ----------------------------------------------------------------------------
       
   357 //
       
   358 void CLogsBaseReader::CheckArrayLengthL()
       
   359     {
       
   360     TInt count( ViewCountL() );   //Item count in Log db view
       
   361     
       
   362     for( TInt i = iEventArray.Count(); i > count; i-- )
       
   363         {
       
   364         iEventArray.Delete( i - 1 );
       
   365         }
       
   366         
       
   367     iEventArray.Compress();
       
   368     }
       
   369 
       
   370 
       
   371 // ----------------------------------------------------------------------------
       
   372 // CLogsBaseReader::DuplicateCountL
       
   373 // ----------------------------------------------------------------------------
       
   374 //
       
   375 TInt CLogsBaseReader::DuplicateCountL() const
       
   376     {
       
   377     return 0;
       
   378     }
       
   379 
       
   380 // ----------------------------------------------------------------------------
       
   381 // CLogsBaseReader::HandleLogViewChangeEventAddedL
       
   382 //
       
   383 // Called by Log Database engine when it notifies us that it has added an event to database
       
   384 // ----------------------------------------------------------------------------
       
   385 //
       
   386 void CLogsBaseReader::HandleLogViewChangeEventAddedL( 
       
   387     TLogId /*aId*/, 
       
   388     TInt /*aViewIndex*/, 
       
   389     TInt /*aChangeIndex*/, 
       
   390     TInt aTotalChangeCount )
       
   391     {
       
   392     //Comment: HandleLogViewChangeEventAddedL seems to be called only once (and aTotalChangeCount is 1) even if 
       
   393     //there are multiple entries added to database in a batch. This seems to happen at least in wins emulator in Symbian 80a_200432.
       
   394     //If problems in this area or changed behaviour, we need to consider same kind of optimization to here as is in 
       
   395     //HandleLogViewChangeEventDeletedL
       
   396 
       
   397     iDeleteChangeCount = KDeleteCountInit;   //-1   
       
   398     HandleViewChangeL( aTotalChangeCount );
       
   399     }
       
   400 
       
   401 // ----------------------------------------------------------------------------
       
   402 // CLogsBaseReader::HandleLogViewChangeEventChangedL
       
   403 //
       
   404 // Called by Log Database engine when it notifies us that it has changed an event in the database
       
   405 // ----------------------------------------------------------------------------
       
   406 //
       
   407 void CLogsBaseReader::HandleLogViewChangeEventChangedL( 
       
   408     TLogId /*aId*/, 
       
   409     TInt /*aViewIndex*/, 
       
   410     TInt /*aChangeIndex*/, 
       
   411     TInt aTotalChangeCount )
       
   412     {
       
   413     iDeleteChangeCount = KDeleteCountInit;  //-1
       
   414     HandleViewChangeL( aTotalChangeCount );
       
   415     }
       
   416 
       
   417 // ----------------------------------------------------------------------------
       
   418 // CLogsBaseReader::HandleLogViewChangeEventDeletedL
       
   419 //
       
   420 // Called by Log Database engine when it notifies us that it has deleted an event in the database
       
   421 // ----------------------------------------------------------------------------
       
   422 //
       
   423 void CLogsBaseReader::HandleLogViewChangeEventDeletedL( 
       
   424     TLogId /*aId*/, 
       
   425     TInt /*aViewIndex*/, 
       
   426     TInt /*aChangeIndex*/, 
       
   427     TInt aTotalChangeCount )
       
   428     {
       
   429     //In order to prevent to re-reading the database multiple times, we call HandleViewChangeL only once. This is
       
   430     //because HandleLogViewChangeEventDeletedL is called as many times as is the number of entries are deleted e.g. when 
       
   431     //deleteting old entries from database happens. However, aTotalChangeCount contains total number of deletions in
       
   432     //a batch, so we can optimize the call to HandleViewChangeL to happen only even if we're called multiple times.
       
   433     
       
   434     //Note that CLogsEngine::StateChangedL is called by Logs engine when recent list entry has been deleted from db (it starts
       
   435     //rereading of view data from db)
       
   436 
       
   437     if( aTotalChangeCount == 1 || ( aTotalChangeCount != iDeleteChangeCount ) )
       
   438         {
       
   439         iDeleteChangeCount = aTotalChangeCount;
       
   440         HandleViewChangeL( aTotalChangeCount );  
       
   441         }  
       
   442     }
       
   443 
       
   444 // ----------------------------------------------------------------------------
       
   445 // CLogsBaseReader::HandleViewChangeL
       
   446 // ----------------------------------------------------------------------------
       
   447 //
       
   448 void CLogsBaseReader::HandleViewChangeL( TInt aTotalChangeCount )
       
   449     {
       
   450     if( aTotalChangeCount > 0 )
       
   451         {
       
   452         iDirty = ETrue;
       
   453         }
       
   454 
       
   455     if( iActivated  && iDirty )
       
   456         {
       
   457         StartL();                
       
   458         } 
       
   459     }
       
   460 
       
   461 
       
   462 // ----------------------------------------------------------------------------
       
   463 // CLogsBaseReader::ActivateL
       
   464 // ----------------------------------------------------------------------------
       
   465 //
       
   466 void CLogsBaseReader::ActivateL()  //Overridden method in derived classes may leave, that's why
       
   467     {                              // name of this function indicates that this may leave.
       
   468     iActivated = ETrue;
       
   469     iReadMissedDuplicateCounts = EFalse;//ETrue: Read missed calls including duplicate counts.    
       
   470                                         //EFalse: Read missed calls view twice, first without duplicate counts,
       
   471                                         //then again including duplicate counts (EMSH-6JDFBV).
       
   472     }
       
   473 
       
   474 // ----------------------------------------------------------------------------
       
   475 // CLogsBaseReader::DeActivate
       
   476 // ----------------------------------------------------------------------------
       
   477 //
       
   478 void CLogsBaseReader::DeActivate( )
       
   479     {
       
   480     iActivated = EFalse;
       
   481     }
       
   482 
       
   483 // ----------------------------------------------------------------------------
       
   484 // CLogsBaseReader::IsDirty
       
   485 // ----------------------------------------------------------------------------
       
   486 //
       
   487 TBool CLogsBaseReader::IsDirty() const
       
   488     {
       
   489     return iDirty;
       
   490     }
       
   491 
       
   492 // ----------------------------------------------------------------------------
       
   493 // CLogsBaseReader::SetDirty
       
   494 // ----------------------------------------------------------------------------
       
   495 //
       
   496 void CLogsBaseReader::SetDirty()
       
   497     {
       
   498     iDirty = ETrue;
       
   499     }
       
   500 
       
   501 // ----------------------------------------------------------------------------
       
   502 // CLogsBaseReader::BaseConstructEventL
       
   503 // ----------------------------------------------------------------------------
       
   504 //
       
   505 void CLogsBaseReader::BaseConstructEventL( 
       
   506     MLogsEvent& aDest, 
       
   507     const CLogEvent& aSource )
       
   508     {
       
   509     aDest.InitializeEventL( aSource, iStrings, iModelId );
       
   510     }
       
   511