loggingservices/eventlogger/LogServ/inc/LogServCacheStrings.h
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __LOGSERVCACHESTRINGS_H__
       
    17 #define __LOGSERVCACHESTRINGS_H__
       
    18 
       
    19 #include <logwrap.h>
       
    20 #include <logwraplimits.h>
       
    21 
       
    22 // Classes referenced
       
    23 class MLogServDatabaseTransactionInterface;
       
    24 
       
    25 /**
       
    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. 
       
    34 
       
    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.
       
    37 
       
    38 Note: the often used LogEng strings are kept in a database table with name "String".
       
    39 
       
    40 @see CLogAddEvent
       
    41 @see CLogEvent
       
    42 @see MLogServDatabaseTransactionInterface
       
    43 @internalComponent
       
    44 */
       
    45 class CLogServCacheStrings : public CBase
       
    46 	{
       
    47 public:
       
    48 	static CLogServCacheStrings* NewL(MLogServDatabaseTransactionInterface& aDatabase);
       
    49 	~CLogServCacheStrings();
       
    50 
       
    51 	const TPtrC  FindString(TLogStringId aId) const;
       
    52 	TLogStringId FindId(const TDesC& aString);
       
    53 	TLogStringId GetIdL(const TDesC& aString);
       
    54 	void Commit();
       
    55 	void Rollback();
       
    56 
       
    57 private:
       
    58    	struct TLogServCacheStringEntry
       
    59 		{
       
    60 		public:
       
    61 			static void CleanupEntry(TAny* aEntry);
       
    62 			static inline TLogServCacheStringEntry* NewEntryL(TLogStringId aId, const TDesC& aString, TBool aDirty = EFalse)
       
    63 				{
       
    64 				TUint8* entry = (TUint8*)User::AllocL(sizeof(TLogServCacheStringEntry) + aString.Size());
       
    65 				return new (entry) TLogServCacheStringEntry(aId, aString, aDirty);
       
    66 				}
       
    67 			static inline TLogServCacheStringEntry* NewEntryLC(TLogStringId aId, const TDesC& aString, TBool aDirty = EFalse)
       
    68 				{
       
    69 				TLogServCacheStringEntry* entry = TLogServCacheStringEntry::NewEntryL(aId, aString, aDirty);
       
    70 				CleanupStack::PushL(TCleanupItem(&TLogServCacheStringEntry::CleanupEntry, entry));
       
    71 				return entry;
       
    72 				}
       
    73 			static inline void DeleteEntry(TLogServCacheStringEntry* aEntry)
       
    74 				{
       
    75 				User::Free(aEntry);
       
    76 				}
       
    77 			inline const TPtrC String() const
       
    78 				{
       
    79 				return TPtrC(iString, iStringLength);
       
    80 				}
       
    81 		private:
       
    82 			inline TLogServCacheStringEntry(TLogStringId aId, const TDesC& aString, TBool aDirty) :
       
    83 				iId(aId),
       
    84 				iDirty(aDirty),
       
    85 				iStringLength(aString.Length())
       
    86 				{
       
    87 				(void)Mem::Copy(iString, aString.Ptr(), aString.Size());
       
    88 				}
       
    89 			TLogServCacheStringEntry();				
       
    90 			TLogServCacheStringEntry(const TLogServCacheStringEntry&);
       
    91 			TLogServCacheStringEntry& operator=(const TLogServCacheStringEntry&);
       
    92 		public:		
       
    93 			TLogStringId 	iId;
       
    94 			TBool 			iDirty;//if set, this entry has been added to the cache during transaction
       
    95 		private:			
       
    96 			TInt 			iStringLength;
       
    97 			TText 			iString[1];
       
    98 		};
       
    99 
       
   100 	CLogServCacheStrings(MLogServDatabaseTransactionInterface& aDatabase);
       
   101 	void ConstructL();
       
   102 	void ReadStringsFromDatabaseL();
       
   103 	TLogStringId DoAddStringL(const TDesC& aString);
       
   104 	void DestroyCache();
       
   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);
       
   108 
       
   109 private:
       
   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
       
   113 	TDbColNo iIdColNo;
       
   114 	TDbColNo iStringColNo;
       
   115 	
       
   116 	};
       
   117 
       
   118 #endif