logsui/logsserviceextension/src/clogseventinfomanager.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 manage TLogsEventInfo objects
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "clogseventinfomanager.h"
       
    22 #include "tlogseventinfo.h"
       
    23 #include "logsextconsts.h"
       
    24 #include "simpledebug.h"
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // NewL
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CLogsEventInfoManager* CLogsEventInfoManager::NewL()
       
    31     {
       
    32     CLogsEventInfoManager* self = CLogsEventInfoManager::NewLC();
       
    33     CleanupStack::Pop( self );
       
    34     return self;
       
    35     }
       
    36 
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // NewLC
       
    40 // ---------------------------------------------------------------------------
       
    41 //    
       
    42 CLogsEventInfoManager* CLogsEventInfoManager::NewLC()
       
    43     {
       
    44     CLogsEventInfoManager* self = new( ELeave ) CLogsEventInfoManager;
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     return self;
       
    48     }
       
    49 
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // Descructor
       
    53 // ---------------------------------------------------------------------------
       
    54 //        
       
    55 CLogsEventInfoManager::~CLogsEventInfoManager()
       
    56     {
       
    57     _LOG("CLogsEventInfoManager::~CLogsEventInfoManager(): begin")
       
    58     iEventInfoArray.ResetAndDestroy();    
       
    59     _LOG("CLogsEventInfoManager::~CLogsEventInfoManager(): end")
       
    60     }
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // Constructor
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CLogsEventInfoManager::CLogsEventInfoManager()
       
    68     : iEventInfoArray( KEventInfoManagerArrayGranularity )
       
    69     {    
       
    70     }    
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // ConstructL
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void CLogsEventInfoManager::ConstructL()
       
    78     {
       
    79     _LOG("CLogsEventInfoManager::ConstructL(): begin")    
       
    80     _LOG("CLogsEventInfoManager::ConstructL(): end")
       
    81     }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // Adds TLogsEventInfo entry to this manager.Manager takes ownership of the
       
    86 // entry. Before adding the entry it is checked whether the entry already 
       
    87 // exists to avoid duplicates. Entries with the same service id are considered
       
    88 // to be duplicates.
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CLogsEventInfoManager::AddEventEntryL( TUint32 aServiceId )
       
    92     {
       
    93     _LOG("CLogsEventInfoManager::AddEventEntryL(): begin")
       
    94         
       
    95     if ( !EntryExists ( aServiceId ) )
       
    96         {
       
    97         // Pc-lint warning: #429: Custodial pointer 'eventInfo'has not been 
       
    98         // freed or returned.
       
    99         // Explanation: pointer ownership transferred to the array or deleted
       
   100         // if transfer not successful
       
   101         TLogsEventInfo* eventInfo = 
       
   102                             new( ELeave ) TLogsEventInfo( aServiceId );
       
   103 
       
   104         TInt error = iEventInfoArray.Append( eventInfo );
       
   105         if ( KErrNone != error )
       
   106             {
       
   107             delete eventInfo;
       
   108             eventInfo = NULL;
       
   109             User::LeaveNoMemory();
       
   110             }
       
   111         }
       
   112     else
       
   113         {
       
   114         //entry exists already
       
   115         User::Leave( KErrAlreadyExists );
       
   116         }
       
   117         
       
   118     _LOG("CLogsEventInfoManager::AddEventEntryL(): end ")
       
   119     }
       
   120 
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // Checks whether an entry exists for the specified service id
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 TBool CLogsEventInfoManager::EntryExists( TUint32 aServiceId )
       
   127     {
       
   128     _LOGP("CLogsEventInfoManager::EntryExists(): begin=%d", aServiceId)
       
   129 
       
   130     TBool success( EFalse );
       
   131     for ( TInt i = 0 ; ( i < Count() ) && ( success == EFalse ) ; i++ )
       
   132         {
       
   133         TLogsEventInfo* info = iEventInfoArray[i];
       
   134         if ( info && info->ServiceId() )
       
   135             {
       
   136             if ( info->ServiceId() == aServiceId ) 
       
   137                 {
       
   138                 success = ETrue;
       
   139                 }
       
   140             }
       
   141         }
       
   142 
       
   143     _LOG("CLogsEventInfoManager::EntryExists(): end")
       
   144     return success;
       
   145     }
       
   146 
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // Get an TLogsEventInfo entry with the specified service id. Returns Null if
       
   150 // such an entry does not exist. Ownership not transferred.
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 TLogsEventInfo* CLogsEventInfoManager::GetEventInfoEntry( 
       
   154                                                 TUint32 aServiceId ) const
       
   155     {
       
   156     _LOG("CLogsEventInfoManager::GetEventInfoEntry(): begin")
       
   157 
       
   158     TLogsEventInfo* entry = NULL;
       
   159     TBool success( EFalse );
       
   160     for ( TInt i = 0 ; ( i < Count() ) && ( success == EFalse ) ; i++ )    
       
   161         {
       
   162         TLogsEventInfo* info = iEventInfoArray[i];
       
   163         if ( info && info->ServiceId() )
       
   164             {
       
   165             if ( info->ServiceId() == aServiceId )
       
   166                 {
       
   167                 entry = info;
       
   168                 success = ETrue;
       
   169                 }
       
   170             }
       
   171         }
       
   172         
       
   173     _LOG("CLogsEventInfoManager::GetEventInfoEntry(): end")
       
   174     return entry;
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // Get an TLogsEventInfo entry with the specified service id. Returns Null if
       
   179 // such an entry does not exist. Ownership not transferred.
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 TLogsEventInfo* CLogsEventInfoManager::GetEventInfoEntryByIndex( 
       
   183                                                         TInt aIndex ) const
       
   184     {
       
   185     _LOGP("CLogsEventInfoManager::GetEventInfoEntryByIndex():begin=%d",aIndex)
       
   186 
       
   187     TLogsEventInfo* entry = NULL;
       
   188 
       
   189     if ( aIndex >= 0 && aIndex < Count() )
       
   190         {
       
   191         entry = iEventInfoArray[aIndex];
       
   192         }
       
   193 
       
   194 
       
   195     _LOG("CLogsEventInfoManager::GetEventInfoEntryByIndex(): end")
       
   196     return entry;
       
   197     }
       
   198 
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // Sets the brand icon index of the event info entry with a certain
       
   202 // service id to 'aBrandingIconIndex'.
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 TInt CLogsEventInfoManager::SetBrandIndex(
       
   206     TUint32 aServiceId, 
       
   207     TInt aBrandingIconIndex )
       
   208     {
       
   209     _LOGPP("CLogsEventInfoManager::SetBrandIndex(): %d, %d", 
       
   210         aServiceId, aBrandingIconIndex)            
       
   211     TInt err( KErrNotFound );
       
   212     TLogsEventInfo* entry = GetEventInfoEntry( aServiceId );
       
   213     if ( entry )
       
   214         {
       
   215         entry->SetBrandingIconIndex( aBrandingIconIndex );
       
   216         err = KErrNone;
       
   217         }
       
   218         
       
   219     _LOGP("CLogsEventInfoManager::SetBrandIndex(): end return==%d",err)
       
   220     return err;
       
   221     }
       
   222 
       
   223 
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // The brand icon index for a log event with the specified service id 
       
   227 // is retrieved and assigned to 'aIndex'.
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 TBool CLogsEventInfoManager::GetBrandIconIndex( TUint32 aServiceId, 
       
   231                                                 TInt& aIndex) const
       
   232     {
       
   233     _LOG("CLogsEventInfoManager::GetBrandIconIndex(): begin")
       
   234 
       
   235     TBool success( EFalse );
       
   236 
       
   237     // find the entry that contains 'aServiceId' and return its brandindex
       
   238     // or do nothing    
       
   239     for ( TInt i = 0 ; ( i < Count() ) && ( success == EFalse ) ; i++ )
       
   240         {
       
   241         TLogsEventInfo* info = iEventInfoArray[i];
       
   242         if ( info && info->ServiceId() )
       
   243             {
       
   244             if ( info->ServiceId() == aServiceId )
       
   245                 {
       
   246                 aIndex = info->BrandingIconIndex();
       
   247                 success = ETrue;
       
   248                 }
       
   249             }
       
   250         }
       
   251 
       
   252     _LOG("CLogsEventInfoManager::GetBrandIconIndex(): end")
       
   253     return success;
       
   254     }
       
   255 
       
   256 
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // Returns the number of TLogsEventInfo objects that the manager maintains
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 TInt CLogsEventInfoManager::Count() const
       
   263     {    
       
   264     _LOGP("CLogsPresenceStatusTableEntry::Count(): =%d",
       
   265         iEventInfoArray.Count())
       
   266     return iEventInfoArray.Count();
       
   267     }
       
   268 
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // Check whether the brand icon index for the specified service
       
   272 // id is already available or not.
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 TBool CLogsEventInfoManager::BrandIconIndexAvailable( 
       
   276                                                     TUint32 aServiceId ) const
       
   277     {
       
   278     _LOG("CLogsEventInfoManager::BrandIconIndexAvailable(): begin")
       
   279 
       
   280     TBool result( EFalse );
       
   281     TInt brandIndex( KErrNotFound );
       
   282     if ( GetBrandIconIndex( aServiceId, brandIndex )
       
   283         && brandIndex > KInitialIndexValue )
       
   284         {
       
   285         result = ETrue;
       
   286         }
       
   287 
       
   288 #ifdef _DEBUG
       
   289     if ( result )
       
   290         {
       
   291         _LOG("CLogsEventInfoManager::BrandIconIndexAvailable(): end ...")
       
   292         _LOG("...BrandIndex => available")
       
   293         }
       
   294     else
       
   295         {
       
   296         _LOG("CLogsEventInfoManager::BrandIconIndexAvailable(): end ...")
       
   297         _LOG("...BrandIndex => NOT available")
       
   298         }
       
   299 #endif
       
   300 
       
   301     return result;
       
   302     }
       
   303