1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/loggingservices/eventlogger/LogServ/inc/LogServCacheStrings.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,118 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#ifndef __LOGSERVCACHESTRINGS_H__
1.20 +#define __LOGSERVCACHESTRINGS_H__
1.21 +
1.22 +#include <logwrap.h>
1.23 +#include <logwraplimits.h>
1.24 +
1.25 +// Classes referenced
1.26 +class MLogServDatabaseTransactionInterface;
1.27 +
1.28 +/**
1.29 +Caches the most often used strings, such as "Incoming", "Outgoing", "Missed", etc.
1.30 +Every string in the cache is identified by an ID. The cached strings come from
1.31 +event's "status" and "direction" fields. If an event is about to be added to the events database
1.32 +table, instead of storing in the table often repeated "status" and "direction" string fields values,
1.33 +the CLogServCacheStrings is searched for the ID of the string. If such string is already in the cache
1.34 +its ID is returned, if no such string is found in the cache, then the string will be added to the cache
1.35 +and the ID of the added string is returned. The returned ID will be stored as part of the event
1.36 +properties in the events table.
1.37 +
1.38 +Wherever the strings cache is changed, if the database is already in transaction, the cache changes will
1.39 +be committed/rolled back when the transaction is committed/rolled back.
1.40 +
1.41 +Note: the often used LogEng strings are kept in a database table with name "String".
1.42 +
1.43 +@see CLogAddEvent
1.44 +@see CLogEvent
1.45 +@see MLogServDatabaseTransactionInterface
1.46 +@internalComponent
1.47 +*/
1.48 +class CLogServCacheStrings : public CBase
1.49 + {
1.50 +public:
1.51 + static CLogServCacheStrings* NewL(MLogServDatabaseTransactionInterface& aDatabase);
1.52 + ~CLogServCacheStrings();
1.53 +
1.54 + const TPtrC FindString(TLogStringId aId) const;
1.55 + TLogStringId FindId(const TDesC& aString);
1.56 + TLogStringId GetIdL(const TDesC& aString);
1.57 + void Commit();
1.58 + void Rollback();
1.59 +
1.60 +private:
1.61 + struct TLogServCacheStringEntry
1.62 + {
1.63 + public:
1.64 + static void CleanupEntry(TAny* aEntry);
1.65 + static inline TLogServCacheStringEntry* NewEntryL(TLogStringId aId, const TDesC& aString, TBool aDirty = EFalse)
1.66 + {
1.67 + TUint8* entry = (TUint8*)User::AllocL(sizeof(TLogServCacheStringEntry) + aString.Size());
1.68 + return new (entry) TLogServCacheStringEntry(aId, aString, aDirty);
1.69 + }
1.70 + static inline TLogServCacheStringEntry* NewEntryLC(TLogStringId aId, const TDesC& aString, TBool aDirty = EFalse)
1.71 + {
1.72 + TLogServCacheStringEntry* entry = TLogServCacheStringEntry::NewEntryL(aId, aString, aDirty);
1.73 + CleanupStack::PushL(TCleanupItem(&TLogServCacheStringEntry::CleanupEntry, entry));
1.74 + return entry;
1.75 + }
1.76 + static inline void DeleteEntry(TLogServCacheStringEntry* aEntry)
1.77 + {
1.78 + User::Free(aEntry);
1.79 + }
1.80 + inline const TPtrC String() const
1.81 + {
1.82 + return TPtrC(iString, iStringLength);
1.83 + }
1.84 + private:
1.85 + inline TLogServCacheStringEntry(TLogStringId aId, const TDesC& aString, TBool aDirty) :
1.86 + iId(aId),
1.87 + iDirty(aDirty),
1.88 + iStringLength(aString.Length())
1.89 + {
1.90 + (void)Mem::Copy(iString, aString.Ptr(), aString.Size());
1.91 + }
1.92 + TLogServCacheStringEntry();
1.93 + TLogServCacheStringEntry(const TLogServCacheStringEntry&);
1.94 + TLogServCacheStringEntry& operator=(const TLogServCacheStringEntry&);
1.95 + public:
1.96 + TLogStringId iId;
1.97 + TBool iDirty;//if set, this entry has been added to the cache during transaction
1.98 + private:
1.99 + TInt iStringLength;
1.100 + TText iString[1];
1.101 + };
1.102 +
1.103 + CLogServCacheStrings(MLogServDatabaseTransactionInterface& aDatabase);
1.104 + void ConstructL();
1.105 + void ReadStringsFromDatabaseL();
1.106 + TLogStringId DoAddStringL(const TDesC& aString);
1.107 + void DestroyCache();
1.108 + void InitializeColNumsL(RDbRowSet& aRowSet);
1.109 + static TInt Compare1(const TDesC* aString, TLogServCacheStringEntry* const& aRight);
1.110 + static TInt Compare2(TLogServCacheStringEntry* const& aLeft, TLogServCacheStringEntry* const& aRight);
1.111 +
1.112 +private:
1.113 + MLogServDatabaseTransactionInterface& iDatabase;
1.114 + RArray<TLogServCacheStringEntry*> iStrings;//List of cached strings
1.115 + TBool iDirty;//iDirty flag is set when strings are added to the cache during transaction
1.116 + TDbColNo iIdColNo;
1.117 + TDbColNo iStringColNo;
1.118 +
1.119 + };
1.120 +
1.121 +#endif