Update contrib.
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __LOGSERVCACHESTRINGS_H__
17 #define __LOGSERVCACHESTRINGS_H__
20 #include <logwraplimits.h>
23 class MLogServDatabaseTransactionInterface;
26 Caches the most often used strings, such as "Incoming", "Outgoing", "Missed", etc.
27 Every string in the cache is identified by an ID. The cached strings come from
28 event's "status" and "direction" fields. If an event is about to be added to the events database
29 table, instead of storing in the table often repeated "status" and "direction" string fields values,
30 the CLogServCacheStrings is searched for the ID of the string. If such string is already in the cache
31 its ID is returned, if no such string is found in the cache, then the string will be added to the cache
32 and the ID of the added string is returned. The returned ID will be stored as part of the event
33 properties in the events table.
35 Wherever the strings cache is changed, if the database is already in transaction, the cache changes will
36 be committed/rolled back when the transaction is committed/rolled back.
38 Note: the often used LogEng strings are kept in a database table with name "String".
42 @see MLogServDatabaseTransactionInterface
45 class CLogServCacheStrings : public CBase
48 static CLogServCacheStrings* NewL(MLogServDatabaseTransactionInterface& aDatabase);
49 ~CLogServCacheStrings();
51 const TPtrC FindString(TLogStringId aId) const;
52 TLogStringId FindId(const TDesC& aString);
53 TLogStringId GetIdL(const TDesC& aString);
58 struct TLogServCacheStringEntry
61 static void CleanupEntry(TAny* aEntry);
62 static inline TLogServCacheStringEntry* NewEntryL(TLogStringId aId, const TDesC& aString, TBool aDirty = EFalse)
64 TUint8* entry = (TUint8*)User::AllocL(sizeof(TLogServCacheStringEntry) + aString.Size());
65 return new (entry) TLogServCacheStringEntry(aId, aString, aDirty);
67 static inline TLogServCacheStringEntry* NewEntryLC(TLogStringId aId, const TDesC& aString, TBool aDirty = EFalse)
69 TLogServCacheStringEntry* entry = TLogServCacheStringEntry::NewEntryL(aId, aString, aDirty);
70 CleanupStack::PushL(TCleanupItem(&TLogServCacheStringEntry::CleanupEntry, entry));
73 static inline void DeleteEntry(TLogServCacheStringEntry* aEntry)
77 inline const TPtrC String() const
79 return TPtrC(iString, iStringLength);
82 inline TLogServCacheStringEntry(TLogStringId aId, const TDesC& aString, TBool aDirty) :
85 iStringLength(aString.Length())
87 (void)Mem::Copy(iString, aString.Ptr(), aString.Size());
89 TLogServCacheStringEntry();
90 TLogServCacheStringEntry(const TLogServCacheStringEntry&);
91 TLogServCacheStringEntry& operator=(const TLogServCacheStringEntry&);
94 TBool iDirty;//if set, this entry has been added to the cache during transaction
100 CLogServCacheStrings(MLogServDatabaseTransactionInterface& aDatabase);
102 void ReadStringsFromDatabaseL();
103 TLogStringId DoAddStringL(const TDesC& aString);
105 void InitializeColNumsL(RDbRowSet& aRowSet);
106 static TInt Compare1(const TDesC* aString, TLogServCacheStringEntry* const& aRight);
107 static TInt Compare2(TLogServCacheStringEntry* const& aLeft, TLogServCacheStringEntry* const& aRight);
110 MLogServDatabaseTransactionInterface& iDatabase;
111 RArray<TLogServCacheStringEntry*> iStrings;//List of cached strings
112 TBool iDirty;//iDirty flag is set when strings are added to the cache during transaction
114 TDbColNo iStringColNo;