sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __LOGSERVCACHESTRINGS_H__ sl@0: #define __LOGSERVCACHESTRINGS_H__ sl@0: sl@0: #include <logwrap.h> sl@0: #include <logwraplimits.h> sl@0: sl@0: // Classes referenced sl@0: class MLogServDatabaseTransactionInterface; sl@0: sl@0: /** sl@0: Caches the most often used strings, such as "Incoming", "Outgoing", "Missed", etc. sl@0: Every string in the cache is identified by an ID. The cached strings come from sl@0: event's "status" and "direction" fields. If an event is about to be added to the events database sl@0: table, instead of storing in the table often repeated "status" and "direction" string fields values, sl@0: the CLogServCacheStrings is searched for the ID of the string. If such string is already in the cache sl@0: its ID is returned, if no such string is found in the cache, then the string will be added to the cache sl@0: and the ID of the added string is returned. The returned ID will be stored as part of the event sl@0: properties in the events table. sl@0: sl@0: Wherever the strings cache is changed, if the database is already in transaction, the cache changes will sl@0: be committed/rolled back when the transaction is committed/rolled back. sl@0: sl@0: Note: the often used LogEng strings are kept in a database table with name "String". sl@0: sl@0: @see CLogAddEvent sl@0: @see CLogEvent sl@0: @see MLogServDatabaseTransactionInterface sl@0: @internalComponent sl@0: */ sl@0: class CLogServCacheStrings : public CBase sl@0: { sl@0: public: sl@0: static CLogServCacheStrings* NewL(MLogServDatabaseTransactionInterface& aDatabase); sl@0: ~CLogServCacheStrings(); sl@0: sl@0: const TPtrC FindString(TLogStringId aId) const; sl@0: TLogStringId FindId(const TDesC& aString); sl@0: TLogStringId GetIdL(const TDesC& aString); sl@0: void Commit(); sl@0: void Rollback(); sl@0: sl@0: private: sl@0: struct TLogServCacheStringEntry sl@0: { sl@0: public: sl@0: static void CleanupEntry(TAny* aEntry); sl@0: static inline TLogServCacheStringEntry* NewEntryL(TLogStringId aId, const TDesC& aString, TBool aDirty = EFalse) sl@0: { sl@0: TUint8* entry = (TUint8*)User::AllocL(sizeof(TLogServCacheStringEntry) + aString.Size()); sl@0: return new (entry) TLogServCacheStringEntry(aId, aString, aDirty); sl@0: } sl@0: static inline TLogServCacheStringEntry* NewEntryLC(TLogStringId aId, const TDesC& aString, TBool aDirty = EFalse) sl@0: { sl@0: TLogServCacheStringEntry* entry = TLogServCacheStringEntry::NewEntryL(aId, aString, aDirty); sl@0: CleanupStack::PushL(TCleanupItem(&TLogServCacheStringEntry::CleanupEntry, entry)); sl@0: return entry; sl@0: } sl@0: static inline void DeleteEntry(TLogServCacheStringEntry* aEntry) sl@0: { sl@0: User::Free(aEntry); sl@0: } sl@0: inline const TPtrC String() const sl@0: { sl@0: return TPtrC(iString, iStringLength); sl@0: } sl@0: private: sl@0: inline TLogServCacheStringEntry(TLogStringId aId, const TDesC& aString, TBool aDirty) : sl@0: iId(aId), sl@0: iDirty(aDirty), sl@0: iStringLength(aString.Length()) sl@0: { sl@0: (void)Mem::Copy(iString, aString.Ptr(), aString.Size()); sl@0: } sl@0: TLogServCacheStringEntry(); sl@0: TLogServCacheStringEntry(const TLogServCacheStringEntry&); sl@0: TLogServCacheStringEntry& operator=(const TLogServCacheStringEntry&); sl@0: public: sl@0: TLogStringId iId; sl@0: TBool iDirty;//if set, this entry has been added to the cache during transaction sl@0: private: sl@0: TInt iStringLength; sl@0: TText iString[1]; sl@0: }; sl@0: sl@0: CLogServCacheStrings(MLogServDatabaseTransactionInterface& aDatabase); sl@0: void ConstructL(); sl@0: void ReadStringsFromDatabaseL(); sl@0: TLogStringId DoAddStringL(const TDesC& aString); sl@0: void DestroyCache(); sl@0: void InitializeColNumsL(RDbRowSet& aRowSet); sl@0: static TInt Compare1(const TDesC* aString, TLogServCacheStringEntry* const& aRight); sl@0: static TInt Compare2(TLogServCacheStringEntry* const& aLeft, TLogServCacheStringEntry* const& aRight); sl@0: sl@0: private: sl@0: MLogServDatabaseTransactionInterface& iDatabase; sl@0: RArray<TLogServCacheStringEntry*> iStrings;//List of cached strings sl@0: TBool iDirty;//iDirty flag is set when strings are added to the cache during transaction sl@0: TDbColNo iIdColNo; sl@0: TDbColNo iStringColNo; sl@0: sl@0: }; sl@0: sl@0: #endif