logsui/logsserviceextension/src/clogspresencetablemanager.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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:  Used to collect various presence related information for the
       
    15 *                extension.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "clogspresencetablemanager.h"
       
    23 #include "clogspresenceindextableentry.h"
       
    24 #include "clogspresencestatustableentry.h"
       
    25 #include "clogsextlogidpresidmapping.h"
       
    26 #include "MLogsEventGetter.h"
       
    27 #include "logsextconsts.h"
       
    28 #include "MLogsModel.h"
       
    29 #include "simpledebug.h"
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // NewL
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CLogsPresenceTableManager* CLogsPresenceTableManager::NewL()
       
    36     {
       
    37     CLogsPresenceTableManager* self = CLogsPresenceTableManager::NewLC();
       
    38     CleanupStack::Pop( self );
       
    39     return self;
       
    40     }
       
    41 
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // NewLC
       
    45 // ---------------------------------------------------------------------------
       
    46 //    
       
    47 CLogsPresenceTableManager* CLogsPresenceTableManager::NewLC()
       
    48     {
       
    49     CLogsPresenceTableManager* self = new( ELeave ) CLogsPresenceTableManager;
       
    50     CleanupStack::PushL( self );
       
    51     self->ConstructL();
       
    52     return self;
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // Destructor
       
    57 // ---------------------------------------------------------------------------
       
    58 //    
       
    59 CLogsPresenceTableManager::~CLogsPresenceTableManager()
       
    60     {
       
    61     _LOG("CLogsPresenceTableManager::~CLogsPresenceTableManager: begin")
       
    62    
       
    63     iPresenceStatusTable.ResetAndDestroy();
       
    64     iPresenceIndexTable.ResetAndDestroy();
       
    65     iLogIdPresIdMappingArray.ResetAndDestroy();
       
    66     
       
    67     _LOG("CLogsPresenceTableManager::~CLogsPresenceTableManager: end")
       
    68     }
       
    69 
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // ConstructL
       
    73 // ---------------------------------------------------------------------------
       
    74 //    
       
    75 void CLogsPresenceTableManager::ConstructL()
       
    76     {
       
    77     _LOG("CLogsPresenceTableManager::ConstructL(): begin")    
       
    78     _LOG("CLogsPresenceTableManager::ConstructL(): end")
       
    79     }
       
    80 
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Constructor
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CLogsPresenceTableManager::CLogsPresenceTableManager():
       
    87     iPresenceStatusTable( KPresenceTableManagerGranularity ),
       
    88     iPresenceIndexTable( KPresenceTableManagerGranularity ),
       
    89     iLogIdPresIdMappingArray( KLogIdPresIdMappingArrayGranularity )
       
    90     {    
       
    91     _LOG("CLogsPresenceTableManager::CLogsPresenceTableManager(): begin")
       
    92     _LOG("CLogsPresenceTableManager::CLogsPresenceTableManager(): end")
       
    93     }    
       
    94 
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 //  Gets the index of a certain icon in the listbox's icon array.
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 TInt CLogsPresenceTableManager::GetIndex( 
       
   102     const TUint32 aServiceId, 
       
   103     const TDesC& aPresentityId, 
       
   104     TInt& aIndex )
       
   105     {    
       
   106     _LOG("CLogsPresenceTableManager::GetIndex: begin")
       
   107     TInt error( KErrNotFound );    
       
   108     
       
   109     TDesC* status = GetStatusFromStatusTable( aServiceId, aPresentityId );
       
   110     
       
   111     if ( status )
       
   112         {        
       
   113         TInt index( KErrNotFound );
       
   114         error = GetIndexFromIndexTable( aServiceId, *status, index );
       
   115         
       
   116         if ( KErrNone == error )
       
   117             {            
       
   118             if ( index >= 0 )
       
   119                 {
       
   120                 aIndex = index;
       
   121                 error = KErrNone;
       
   122                 }            
       
   123             else 
       
   124                 {
       
   125                 error = KErrNotFound;
       
   126                 }            
       
   127             }
       
   128         else if ( KErrNotFound == error )
       
   129             {
       
   130             error = KErrNotReady;
       
   131             }
       
   132         }
       
   133 
       
   134     _LOGP("CLogsPresenceTableManager::GetIndex: end (error==%d)",error)    
       
   135     
       
   136     return error;
       
   137     }
       
   138   
       
   139 // ---------------------------------------------------------------------------
       
   140 // Gets the index of a certain icon in the listbox's icon array from the
       
   141 // index table. 
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 TInt CLogsPresenceTableManager::GetIndexFromIndexTable( 
       
   145     const TUint32 aServiceId, 
       
   146     const TDesC& aPresenceStatusString, 
       
   147     TInt& aIndex )
       
   148     {
       
   149     _LOG("CLogsPresenceTableManager::GetIndexFromIndexTable: begin")    
       
   150     TInt error( KErrNotFound );
       
   151     
       
   152     for ( TInt i( 0 ); i < IndexTableEntriesCount(); i++ )
       
   153         {
       
   154         CLogsPresenceIndexTableEntry* entry = iPresenceIndexTable[i];
       
   155         if ( entry 
       
   156             && entry->ServiceId() == aServiceId 
       
   157             && entry->PresenceStatusString() == aPresenceStatusString )
       
   158             {
       
   159             aIndex = entry->PresenceIconIndex();
       
   160             error = KErrNone;
       
   161             }        
       
   162         }    
       
   163 
       
   164     _LOGP("CLogsPresenceTableManager::GetIndexFromIndexTable: end (error=%d)",
       
   165         error)        
       
   166 
       
   167     return error;       
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // Gets the status of a status entry from the status table. 
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 TDesC* CLogsPresenceTableManager::GetStatusFromStatusTable( 
       
   175     const TUint32 aServiceId, 
       
   176     const TDesC& aPresentityId )
       
   177     {
       
   178     _LOG("CLogsPresenceTableManager::GetStatusFromStatusTable: begin")        
       
   179 
       
   180     TDesC* presenceStatus = NULL;
       
   181     
       
   182     _LOGP("CLogsPresenceTableManager::GetStatusFromStatusTable: count=%d",
       
   183         StatusTableEntriesCount())
       
   184     TBool found( EFalse );
       
   185     for ( TInt i( 0 ); !found && i < StatusTableEntriesCount(); i++ )
       
   186         {
       
   187         CLogsPresenceStatusTableEntry* entry = iPresenceStatusTable[i];
       
   188         _LOGP("CLogsPresenceTableManager::GetStatusFromStatusTable: i=%d",i)        
       
   189         if ( entry
       
   190             && entry->ServiceId() == aServiceId 
       
   191             && entry->PresentityId() == aPresentityId
       
   192             && entry->DisplayPresence() 
       
   193             && entry->PresenceStatusString() )
       
   194             {
       
   195             _LOG("CLogsPresenceTableManager::GetStatusFromStatusTable:...")
       
   196             _LOGPP("...INSIDE IF i=%d presenceString=%S",
       
   197                 i , entry->PresenceStatusString() )                   
       
   198             
       
   199             presenceStatus = entry->PresenceStatusString();
       
   200             found = ETrue;            
       
   201             }                    
       
   202         }
       
   203         
       
   204     return presenceStatus;
       
   205     }
       
   206     
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // Creates a new CLogsStatusTableEntry object and adds it to the manager's
       
   210 // status table (which is iPresenceStatusTable). Before adding an entry to
       
   211 // the table it is checked whether the entry already exists in the table 
       
   212 // to avoid duplicates. Entries with the same service id and presentity id
       
   213 // are considered to be duplicates.
       
   214 // Note: Since the presence status might not being known when adding the
       
   215 //       entry it is possible to leave it unspecified.
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 TInt CLogsPresenceTableManager::AddEntryToStatusTable( 
       
   219     const TUint32 aServiceId, 
       
   220     const TDesC& aPresentityId,
       
   221     TBool aShowStatus )
       
   222     {
       
   223     _LOG("CLogsPresenceTableManager::AddEntryToStatusTable: begin")        
       
   224     TInt error( KErrNotFound );
       
   225     
       
   226     // if entry does not exist -> create it.
       
   227     if ( !StatusEntryExists( aServiceId, aPresentityId ) )
       
   228         {
       
   229         CLogsPresenceStatusTableEntry* entry = NULL;
       
   230         TRAP( error, entry = 
       
   231                         CLogsPresenceStatusTableEntry::NewL(
       
   232                                                            aServiceId,
       
   233                                                            aPresentityId,
       
   234                                                            aShowStatus ); );
       
   235         
       
   236         if ( KErrNone == error )
       
   237             {
       
   238             error = iPresenceStatusTable.Append( entry );
       
   239             if ( KErrNone != error )
       
   240                 {
       
   241                 delete entry;
       
   242                 entry = NULL;
       
   243                 error = KErrNoMemory;
       
   244                 }            
       
   245             }        
       
   246         }
       
   247     // if entry already exists -> dont create it again.
       
   248     else 
       
   249         {
       
   250         //entry exists already
       
   251         error = KErrAlreadyExists;
       
   252         }
       
   253 
       
   254     _LOGP("CLogsPresenceTableManager::AddEntryToStatusTable: end (error=%d)",
       
   255         error )                
       
   256     return error;
       
   257     } 
       
   258     
       
   259 
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // Creates a new CLogsIndexTableEntry object and adds it to the manager's
       
   263 // index table (which is iPresenceIndexTable). Before adding an entry to
       
   264 // the table it is checked whether the entry already exists in the table 
       
   265 // to avoid duplicates. Entries with the same service id and presence
       
   266 // status are considered to be duplicates.
       
   267 // Note: Since the index might not being known when adding the
       
   268 //       entry it is possible to leave it unspecified.
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 TInt CLogsPresenceTableManager::AddEntryToIndexTable( 
       
   272     const TUint32 aServiceId, 
       
   273     const TDesC& aPresenceStatusString )
       
   274     {
       
   275     _LOGP("CLogsPresenceTableManager::AddEntryToIndexTable: aServiceId=%d", 
       
   276             aServiceId )
       
   277             
       
   278     TInt error( KErrNotFound );
       
   279 
       
   280     // if entry does not exist -> create it.
       
   281     TBool entryexists( ETrue );
       
   282     entryexists = IndexEntryExists( aServiceId, aPresenceStatusString );
       
   283     if ( !entryexists )
       
   284         {        
       
   285         CLogsPresenceIndexTableEntry* entry = NULL;
       
   286         TRAP( error, 
       
   287               entry = CLogsPresenceIndexTableEntry::NewL( aServiceId, 
       
   288                                                     aPresenceStatusString ) );
       
   289         if ( KErrNone == error )
       
   290             {
       
   291             error = iPresenceIndexTable.Append( entry );
       
   292             if ( KErrNone != error )
       
   293                 {
       
   294                 delete entry;
       
   295                 entry = NULL;
       
   296                 error = KErrNoMemory;
       
   297                 }            
       
   298             }        
       
   299         }
       
   300     // if entry already exists -> dont create it again.
       
   301     else 
       
   302         {
       
   303         //entry exists already
       
   304         error = KErrAlreadyExists;
       
   305         }
       
   306     
       
   307     _LOGP("CLogsPresenceTableManager::AddEntryToIndexTable: end (error==%d)",
       
   308             error)                    
       
   309     return error;
       
   310     }
       
   311 
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // Check whether the presence icon index is available or not.
       
   315 // ---------------------------------------------------------------------------
       
   316 //
       
   317 TBool CLogsPresenceTableManager::PresenceIconIndexAvailable( 
       
   318     const TUint32 aServiceId,
       
   319     const TDesC& aPresentityId )
       
   320     {
       
   321     _LOG("CLogsPresenceTableManager::PresenceIconIndexAvailable: begin")        
       
   322     TBool IsIndexAvailable( EFalse );
       
   323     
       
   324     TInt index( KErrNotFound );
       
   325     TInt error ( GetIndex( aServiceId, aPresentityId, index ) );    
       
   326     
       
   327     switch( error )
       
   328         {
       
   329         case KErrNone:
       
   330             {
       
   331             if ( index >= 0 )
       
   332                 {
       
   333                 IsIndexAvailable = ETrue;
       
   334                 }            
       
   335             break;
       
   336             }
       
   337         case KErrNotReady:
       
   338         case KErrNotFound:
       
   339         default:
       
   340             {
       
   341             IsIndexAvailable = EFalse;
       
   342             }        
       
   343         }
       
   344 
       
   345     if ( IsIndexAvailable )
       
   346         {
       
   347         _LOG("CLogsPresenceTableManager::PresenceIconIndexAvailable: end...")
       
   348         _LOG("... PresenceIndex => available")
       
   349         }
       
   350     
       
   351     else
       
   352         {
       
   353         _LOG("CLogsPresenceTableManager::PresenceIconIndexAvailable: end...")
       
   354         _LOG("... PresenceIndex => NOT available")
       
   355         }
       
   356     
       
   357 
       
   358 
       
   359     return IsIndexAvailable;
       
   360     }
       
   361 
       
   362   
       
   363 // ---------------------------------------------------------------------------
       
   364 // Sets the status of a certain status entry of the status table.
       
   365 // ---------------------------------------------------------------------------
       
   366 //   
       
   367 TInt CLogsPresenceTableManager::SetStatusInStatusTable( 
       
   368     const TUint32 aServiceId,
       
   369     const TDesC& aPresentityId,
       
   370     const TDesC& aPresenceStatusString,
       
   371     TBool aShowStatus )
       
   372     {
       
   373     _LOG("CLogsPresenceTableManager::SetStatusInStatusTable: begin")        
       
   374     TInt error( KErrGeneral );
       
   375     TBool found( EFalse );
       
   376     
       
   377     for ( TInt i( 0 ); !found && i < StatusTableEntriesCount(); i++ )
       
   378         {
       
   379         CLogsPresenceStatusTableEntry* entry = iPresenceStatusTable[i];
       
   380         if ( entry 
       
   381             && entry->ServiceId() == aServiceId 
       
   382             && entry->PresentityId() == aPresentityId )
       
   383             {
       
   384             found = ETrue;
       
   385             entry->SetDisplayPresence( aShowStatus );
       
   386             error = entry->SetPresenceStatusString( aPresenceStatusString );
       
   387             }        
       
   388         }
       
   389     
       
   390     _LOGP("CLogsPresenceTableManager::SetStatusInStatusTable: end (error=%d)",
       
   391             error)                 
       
   392     return error;
       
   393     }
       
   394             
       
   395 
       
   396 // ---------------------------------------------------------------------------
       
   397 // Sets the status of a certain status entry of the status table to the 
       
   398 // initial value. Presense status is not displayed.
       
   399 // ---------------------------------------------------------------------------
       
   400 //   
       
   401 TInt CLogsPresenceTableManager::UpdateStatusTableEntry( 
       
   402     const TUint32 aServiceId,
       
   403     const TDesC& aPresentityId,
       
   404     TBool aShowStatus )
       
   405     {
       
   406     _LOG("CLogsPresenceTableManager::ResetStatusTableEntry: begin")        
       
   407     TInt error( KErrNotFound );
       
   408     TBool found( EFalse );
       
   409     
       
   410     for ( TInt i( 0 ); !found && i < StatusTableEntriesCount(); i++ )
       
   411         {
       
   412         CLogsPresenceStatusTableEntry* entry = iPresenceStatusTable[i];
       
   413         if ( entry 
       
   414             && entry->ServiceId() == aServiceId 
       
   415             && entry->PresentityId() == aPresentityId )
       
   416             {            
       
   417             entry->SetDisplayPresence( aShowStatus );
       
   418             found = ETrue;
       
   419             error = KErrNone;
       
   420             }        
       
   421         }
       
   422     
       
   423     _LOGP("CLogsPresenceTableManager::ResetStatusTableEntry: end (error==%d)",
       
   424             error)                 
       
   425     return error;
       
   426     }
       
   427 
       
   428 
       
   429 // ---------------------------------------------------------------------------
       
   430 // Sets the status of all status entries of the status table to the initial 
       
   431 // value.
       
   432 // ---------------------------------------------------------------------------
       
   433 //   
       
   434 void CLogsPresenceTableManager::ResetStatusTableEntries()
       
   435     {
       
   436     _LOG("CLogsPresenceTableManager::ResetStatusTableEntries: begin")        
       
   437     
       
   438     for ( TInt i( 0 ); i < StatusTableEntriesCount(); i++ )
       
   439         {
       
   440         CLogsPresenceStatusTableEntry* entry = iPresenceStatusTable[i];
       
   441         if ( entry )
       
   442             {            
       
   443             entry->ResetPresenceStatusString();
       
   444             entry->SetDisplayPresence( EFalse );
       
   445             }        
       
   446         }
       
   447     
       
   448     _LOG("CLogsPresenceTableManager::ResetStatusTableEntries: end")                 
       
   449     }
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // Sets the presence icon index values to initial values.
       
   453 // ---------------------------------------------------------------------------
       
   454 //  
       
   455 void CLogsPresenceTableManager::ResetState()
       
   456     {
       
   457     _LOG("CLogsPresenceTableManager::ResetIndexTableEntries: begin")  
       
   458     iPresenceIndexTable.ResetAndDestroy();
       
   459     iPresenceStatusTable.ResetAndDestroy();
       
   460     iLogIdPresIdMappingArray.ResetAndDestroy();
       
   461     _LOG("CLogsPresenceTableManager::ResetIndexTableEntries: end")  
       
   462     }
       
   463  
       
   464  
       
   465 // ---------------------------------------------------------------------------
       
   466 // Sets the index of a certain index entry of the index table.
       
   467 // ---------------------------------------------------------------------------
       
   468 //     
       
   469 TInt CLogsPresenceTableManager::SetIndexInIndexTable( 
       
   470     const TUint32 aServiceId,
       
   471     const TDesC& aPresenceStatusString,
       
   472     const TInt aIndex )
       
   473     {
       
   474     _LOG("CLogsPresenceTableManager::SetIndexInIndexTable: begin")        
       
   475     TInt error( KErrGeneral );
       
   476     TBool found( EFalse );
       
   477     
       
   478     for ( TInt i( 0 ); !found && i < IndexTableEntriesCount() ; i++ )
       
   479         {
       
   480         CLogsPresenceIndexTableEntry* entry = iPresenceIndexTable[i];
       
   481         if ( entry 
       
   482             && entry->ServiceId() == aServiceId 
       
   483             && entry->PresenceStatusString() == aPresenceStatusString )
       
   484             {
       
   485             found = ETrue;            
       
   486             error = entry->SetPresenceIconIndex( aIndex );            
       
   487             }        
       
   488         }
       
   489     
       
   490     _LOGP("CLogsPresenceTableManager::SetIndexInIndexTable: end (error==%d)",
       
   491             error)
       
   492     return error; 
       
   493     }
       
   494 
       
   495 // ---------------------------------------------------------------------------
       
   496 // Checks the existance of a status entry with the specified arguments.
       
   497 // ---------------------------------------------------------------------------
       
   498 //
       
   499 TBool CLogsPresenceTableManager::StatusEntryExists( 
       
   500         const TUint32 aServiceId,
       
   501         const TDesC& aPresentityId )
       
   502     {
       
   503     _LOG("CLogsPresenceTableManager::StatusEntryExists: begin")        
       
   504     TBool exists( EFalse );
       
   505     
       
   506     for ( TInt i( 0 ); !exists && i < StatusTableEntriesCount(); i++ )
       
   507         {
       
   508         CLogsPresenceStatusTableEntry* entry = iPresenceStatusTable[i];
       
   509         if ( entry 
       
   510             && entry->ServiceId() == aServiceId 
       
   511             && entry->PresentityId() == aPresentityId )
       
   512             {
       
   513             _LOG("CLogsPresenceTableManager::StatusEntryExists: entry exists")
       
   514             exists = ETrue;            
       
   515             }
       
   516         }
       
   517     
       
   518     _LOG("CLogsPresenceTableManager::StatusEntryExists: end")
       
   519     return exists;     
       
   520     }
       
   521 
       
   522 
       
   523 // ---------------------------------------------------------------------------
       
   524 // Checks the existance of a index entry with the specified arguments.
       
   525 // ---------------------------------------------------------------------------
       
   526 //
       
   527 TBool CLogsPresenceTableManager::IndexEntryExists( 
       
   528         const TUint32 aServiceId,
       
   529         const TDesC& aPresenceStatus )
       
   530     {
       
   531     _LOG("CLogsPresenceTableManager::IndexEntryExists: begin")        
       
   532     TBool exists( EFalse );
       
   533     
       
   534     for ( TInt i( 0 ); !exists && i < IndexTableEntriesCount() ; i++ )
       
   535         {
       
   536         CLogsPresenceIndexTableEntry* entry = iPresenceIndexTable[i];
       
   537         if ( entry 
       
   538             && entry->ServiceId() == aServiceId 
       
   539             && entry->PresenceStatusString() == aPresenceStatus )
       
   540             {
       
   541             _LOG("CLogsPresenceTableManager::IndexEntryExists: entry exists")
       
   542             exists = ETrue;            
       
   543             }
       
   544         }
       
   545     
       
   546     _LOG("CLogsPresenceTableManager::IndexEntryExists: end")
       
   547     return exists;     
       
   548     }
       
   549 
       
   550 
       
   551 // ---------------------------------------------------------------------------
       
   552 // Returns the number of entries in the status table.
       
   553 // ---------------------------------------------------------------------------
       
   554 //
       
   555 TInt CLogsPresenceTableManager::StatusTableEntriesCount()
       
   556     {
       
   557     _LOGP("CLogsPresenceTableManager::StatusTableEntriesCount(): count=%d", 
       
   558         iPresenceStatusTable.Count())    
       
   559     return iPresenceStatusTable.Count();
       
   560     }
       
   561     
       
   562     
       
   563 // ---------------------------------------------------------------------------
       
   564 // Returns the number of entries in the index table.
       
   565 // ---------------------------------------------------------------------------
       
   566 //
       
   567 TInt CLogsPresenceTableManager::IndexTableEntriesCount()
       
   568     {
       
   569     _LOGP("CLogsPresenceTableManager::IndexTableEntriesCount()=%d", 
       
   570         iPresenceIndexTable.Count())
       
   571     return iPresenceIndexTable.Count();    
       
   572     }
       
   573 
       
   574 
       
   575 // ---------------------------------------------------------------------------
       
   576 // Adds a mapping (Log Id is mapped to a presentity id).
       
   577 // ---------------------------------------------------------------------------
       
   578 //   
       
   579 void CLogsPresenceTableManager::AddMappingL( const TLogId aLogId, 
       
   580                                              const TDesC& aPresentityId )
       
   581     {    
       
   582     _LOG("CLogsPresenceTableManager::AddMappingL(): begin")
       
   583     
       
   584     // if a mapping for aLogId already exists and the two pres ids of both
       
   585     // mappings are different, only then update the existing mapping with the
       
   586     // new pres id   
       
   587     
       
   588     const TDesC* presId = NULL;
       
   589     presId = RetrievePresentityId( aLogId );
       
   590     
       
   591     if ( presId && ( *presId != aPresentityId ) ) //update mapping
       
   592         {
       
   593         _LOG("CLogsPresenceTableManager::AddMappingL():...")
       
   594         _LOG("... update existing mapping")
       
   595         UpdateMappingL( aLogId, aPresentityId );
       
   596         }
       
   597     else if( !presId ) // add mapping
       
   598         {
       
   599         _LOG("CLogsPresenceTableManager::AddMappingL(): create new mapping")
       
   600         AppendMappingL( aLogId, aPresentityId );
       
   601         }
       
   602     
       
   603     _LOGP("CLogsPresenceTableManager::RetrievePresentityId(): #mappings=%d",
       
   604         iLogIdPresIdMappingArray.Count() )
       
   605     
       
   606     _LOG("CLogsPresenceTableManager::AddMappingL(): end")
       
   607     }
       
   608     
       
   609     
       
   610 // ---------------------------------------------------------------------------
       
   611 // Updates the presentity id an existing mapping.
       
   612 // ---------------------------------------------------------------------------
       
   613 //
       
   614 void CLogsPresenceTableManager::UpdateMappingL( const TLogId aLogId, 
       
   615                                                 const TDesC& aPresentityId )
       
   616     {
       
   617     _LOG("CLogsPresenceTableManager::UpdateMappingL(): begin")    
       
   618     
       
   619     // delete the mapping with aLogId    
       
   620     TBool mappingFound( EFalse );
       
   621     CLogsExtLogIdPresIdMapping* mapping = NULL;
       
   622     for ( TInt i( 0 ); 
       
   623           i < iLogIdPresIdMappingArray.Count() && !mappingFound; 
       
   624           i++ )
       
   625         {
       
   626         mapping = iLogIdPresIdMappingArray[i];
       
   627         if ( mapping && ( mapping->LogId() == aLogId ) )
       
   628             {
       
   629             delete mapping;
       
   630             mapping = NULL;
       
   631             iLogIdPresIdMappingArray.Remove( i );
       
   632             mappingFound = ETrue;
       
   633             }
       
   634         }
       
   635     iLogIdPresIdMappingArray.Compress();
       
   636     
       
   637     // create a new mapping
       
   638     AppendMappingL( aLogId, aPresentityId );
       
   639     
       
   640     _LOG("CLogsPresenceTableManager::UpdateMappingL(): end")        
       
   641     }
       
   642 
       
   643 
       
   644 // ---------------------------------------------------------------------------
       
   645 // Creates a new mapping with the specified arguments.
       
   646 // ---------------------------------------------------------------------------
       
   647 //
       
   648 void CLogsPresenceTableManager::AppendMappingL( const TLogId aLogId, 
       
   649                                                 const TDesC& aPresentitytId )
       
   650     {
       
   651     _LOG("CLogsPresenceTableManager::AppendMappingL(): begin")    
       
   652     
       
   653     CLogsExtLogIdPresIdMapping* mapping = 
       
   654         CLogsExtLogIdPresIdMapping::NewLC( aLogId, aPresentitytId );         
       
   655     iLogIdPresIdMappingArray.AppendL( mapping );
       
   656     CleanupStack::Pop( mapping );
       
   657 
       
   658     _LOG("CLogsPresenceTableManager::AppendMappingL(): end")    
       
   659     }
       
   660 
       
   661 
       
   662     
       
   663 // ---------------------------------------------------------------------------
       
   664 // Returns the presentity id of a mapping using the log id to retrieve the
       
   665 // mapping.
       
   666 // ---------------------------------------------------------------------------
       
   667 //
       
   668 const TDesC* CLogsPresenceTableManager::RetrievePresentityId( 
       
   669         const TLogId aLogId )
       
   670     {
       
   671     _LOG("CLogsPresenceTableManager::RetrievePresentityId(): begin")
       
   672         
       
   673     const TDesC* result = NULL;
       
   674     CLogsExtLogIdPresIdMapping* mapping = NULL;
       
   675     for ( TInt i( 0 ); i < iLogIdPresIdMappingArray.Count(); i++ )
       
   676         {
       
   677         mapping = iLogIdPresIdMappingArray[i];
       
   678         if ( mapping && ( mapping->LogId() == aLogId ) )
       
   679             {
       
   680             result = mapping->PresentityId();
       
   681             }
       
   682         }
       
   683     
       
   684     _LOG("CLogsPresenceTableManager::RetrievePresentityId(): end")        
       
   685     return result;    
       
   686     }    
       
   687    
       
   688 
       
   689 // ---------------------------------------------------------------------------
       
   690 // Removes unnecessary mappings by comparing the log ids of the current 
       
   691 // view to the log ids in the array of mappings. Those mappings which 
       
   692 // contain a log id that cannot be found from 'aModel' will be deleted.
       
   693 // ---------------------------------------------------------------------------
       
   694 // 
       
   695 void CLogsPresenceTableManager::RemoveUnneededMappings( MLogsModel& aModel )
       
   696     {
       
   697     _LOG("CLogsPresenceTableManager::RemoveUnneededMappings(): begin")
       
   698     
       
   699     CLogsExtLogIdPresIdMapping* mapping = NULL;
       
   700     _LOG("CLogsPresenceTableManager::RemoveUnneededMappings():...")
       
   701     _LOGP("... #mappingsBeforeCleanup=%d",iLogIdPresIdMappingArray.Count() )  
       
   702       
       
   703     for ( TInt i( 0 ); i < iLogIdPresIdMappingArray.Count(); i++ )
       
   704         {
       
   705         mapping = iLogIdPresIdMappingArray[i];        
       
   706         if ( mapping && !IsLogIdInMappingArray( aModel, mapping->LogId() ) )
       
   707             {
       
   708             RemoveMapping( mapping->LogId() );
       
   709             }            
       
   710         }
       
   711         
       
   712     _LOG("CLogsPresenceTableManager::RemoveUnneededMappings():...")
       
   713     _LOGP("... #mappingsAfterCleanup=%d",iLogIdPresIdMappingArray.Count() )
       
   714     
       
   715     _LOG("CLogsPresenceTableManager::RemoveUnneededMappings(): end")
       
   716     }
       
   717 
       
   718 
       
   719 // ---------------------------------------------------------------------------
       
   720 // Checks if one of the log events in 'aModel' has the same LogId as the one 
       
   721 // that is specified.
       
   722 // ---------------------------------------------------------------------------
       
   723 // 
       
   724 TBool CLogsPresenceTableManager::IsLogIdInMappingArray( MLogsModel& aModel, 
       
   725                                                         TLogId aLogId )
       
   726     {
       
   727     _LOG("CLogsPresenceTableManager::IsLogIdInMappingArray(): begin")    
       
   728     
       
   729     TBool isLogIdInMappingArray( EFalse );
       
   730     TBool found( EFalse );
       
   731     
       
   732     for ( TInt i( 0 ); i < aModel.Count() && !found; i++ )
       
   733         {
       
   734         if ( aModel.At( i ) && aLogId == aModel.At( i )->LogId() )
       
   735             {
       
   736             isLogIdInMappingArray = ETrue;
       
   737             found = ETrue;            
       
   738             }        
       
   739         }
       
   740     
       
   741     _LOG("CLogsPresenceTableManager::IsLogIdInMappingArray(): end")    
       
   742     return isLogIdInMappingArray;    
       
   743     }
       
   744 
       
   745 
       
   746 // ---------------------------------------------------------------------------
       
   747 // Removes a mapping from the array that contains the pointer of all the 
       
   748 // mappings. This includes the deletion of the object whose pointer was 
       
   749 // stored in the mapping array.
       
   750 // ---------------------------------------------------------------------------
       
   751 // 
       
   752 void CLogsPresenceTableManager::RemoveMapping( TLogId aLogId )
       
   753     {
       
   754     _LOG("CLogsPresenceTableManager::RemoveMapping(): begin ")    
       
   755     
       
   756     _LOG("CLogsPresenceTableManager::RemoveMapping(): remove mapping...")
       
   757     _LOGP("... with logId=%d", aLogId )
       
   758     
       
   759     CLogsExtLogIdPresIdMapping* mapping = NULL;
       
   760     TBool deleted( EFalse );
       
   761     for ( TInt i( 0 ); i < iLogIdPresIdMappingArray.Count(); i++ )
       
   762         {
       
   763         mapping = iLogIdPresIdMappingArray[i];
       
   764         if ( mapping && ( mapping->LogId() == aLogId ) && !deleted )
       
   765             {
       
   766             iLogIdPresIdMappingArray.Remove( i );
       
   767             iLogIdPresIdMappingArray.Compress();
       
   768             delete mapping;
       
   769             mapping = NULL;
       
   770             deleted = ETrue;
       
   771             _LOG("CLogsPresenceTableManager::RemoveMapping(): mapping...")
       
   772             _LOGP("... with logId=%d deleted from mapping array", aLogId )
       
   773             }
       
   774         }
       
   775     
       
   776     _LOG("CLogsPresenceTableManager::RemoveMapping(): end")    
       
   777     }
       
   778 
       
   779