os/persistentdata/loggingservices/eventlogger/LogServ/inc/LogServCacheStrings.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#ifndef __LOGSERVCACHESTRINGS_H__
sl@0
    17
#define __LOGSERVCACHESTRINGS_H__
sl@0
    18
sl@0
    19
#include <logwrap.h>
sl@0
    20
#include <logwraplimits.h>
sl@0
    21
sl@0
    22
// Classes referenced
sl@0
    23
class MLogServDatabaseTransactionInterface;
sl@0
    24
sl@0
    25
/**
sl@0
    26
Caches the most often used strings, such as "Incoming", "Outgoing", "Missed", etc.
sl@0
    27
Every string in the cache is identified by an ID. The cached strings come from 
sl@0
    28
event's "status" and "direction" fields. If an event is about to be added to the events database
sl@0
    29
table, instead of storing in the table often repeated "status" and "direction" string fields values,
sl@0
    30
the CLogServCacheStrings is searched for the ID of the string. If such string is already in the cache
sl@0
    31
its ID is returned, if no such string is found in the cache, then the string will be added to the cache 
sl@0
    32
and the ID of the added string is returned. The returned ID will be stored as part of the event 
sl@0
    33
properties in the events table. 
sl@0
    34
sl@0
    35
Wherever the strings cache is changed, if the database is already in transaction, the cache changes will
sl@0
    36
be committed/rolled back when the transaction is committed/rolled back.
sl@0
    37
sl@0
    38
Note: the often used LogEng strings are kept in a database table with name "String".
sl@0
    39
sl@0
    40
@see CLogAddEvent
sl@0
    41
@see CLogEvent
sl@0
    42
@see MLogServDatabaseTransactionInterface
sl@0
    43
@internalComponent
sl@0
    44
*/
sl@0
    45
class CLogServCacheStrings : public CBase
sl@0
    46
	{
sl@0
    47
public:
sl@0
    48
	static CLogServCacheStrings* NewL(MLogServDatabaseTransactionInterface& aDatabase);
sl@0
    49
	~CLogServCacheStrings();
sl@0
    50
sl@0
    51
	const TPtrC  FindString(TLogStringId aId) const;
sl@0
    52
	TLogStringId FindId(const TDesC& aString);
sl@0
    53
	TLogStringId GetIdL(const TDesC& aString);
sl@0
    54
	void Commit();
sl@0
    55
	void Rollback();
sl@0
    56
sl@0
    57
private:
sl@0
    58
   	struct TLogServCacheStringEntry
sl@0
    59
		{
sl@0
    60
		public:
sl@0
    61
			static void CleanupEntry(TAny* aEntry);
sl@0
    62
			static inline TLogServCacheStringEntry* NewEntryL(TLogStringId aId, const TDesC& aString, TBool aDirty = EFalse)
sl@0
    63
				{
sl@0
    64
				TUint8* entry = (TUint8*)User::AllocL(sizeof(TLogServCacheStringEntry) + aString.Size());
sl@0
    65
				return new (entry) TLogServCacheStringEntry(aId, aString, aDirty);
sl@0
    66
				}
sl@0
    67
			static inline TLogServCacheStringEntry* NewEntryLC(TLogStringId aId, const TDesC& aString, TBool aDirty = EFalse)
sl@0
    68
				{
sl@0
    69
				TLogServCacheStringEntry* entry = TLogServCacheStringEntry::NewEntryL(aId, aString, aDirty);
sl@0
    70
				CleanupStack::PushL(TCleanupItem(&TLogServCacheStringEntry::CleanupEntry, entry));
sl@0
    71
				return entry;
sl@0
    72
				}
sl@0
    73
			static inline void DeleteEntry(TLogServCacheStringEntry* aEntry)
sl@0
    74
				{
sl@0
    75
				User::Free(aEntry);
sl@0
    76
				}
sl@0
    77
			inline const TPtrC String() const
sl@0
    78
				{
sl@0
    79
				return TPtrC(iString, iStringLength);
sl@0
    80
				}
sl@0
    81
		private:
sl@0
    82
			inline TLogServCacheStringEntry(TLogStringId aId, const TDesC& aString, TBool aDirty) :
sl@0
    83
				iId(aId),
sl@0
    84
				iDirty(aDirty),
sl@0
    85
				iStringLength(aString.Length())
sl@0
    86
				{
sl@0
    87
				(void)Mem::Copy(iString, aString.Ptr(), aString.Size());
sl@0
    88
				}
sl@0
    89
			TLogServCacheStringEntry();				
sl@0
    90
			TLogServCacheStringEntry(const TLogServCacheStringEntry&);
sl@0
    91
			TLogServCacheStringEntry& operator=(const TLogServCacheStringEntry&);
sl@0
    92
		public:		
sl@0
    93
			TLogStringId 	iId;
sl@0
    94
			TBool 			iDirty;//if set, this entry has been added to the cache during transaction
sl@0
    95
		private:			
sl@0
    96
			TInt 			iStringLength;
sl@0
    97
			TText 			iString[1];
sl@0
    98
		};
sl@0
    99
sl@0
   100
	CLogServCacheStrings(MLogServDatabaseTransactionInterface& aDatabase);
sl@0
   101
	void ConstructL();
sl@0
   102
	void ReadStringsFromDatabaseL();
sl@0
   103
	TLogStringId DoAddStringL(const TDesC& aString);
sl@0
   104
	void DestroyCache();
sl@0
   105
	void InitializeColNumsL(RDbRowSet& aRowSet);
sl@0
   106
	static TInt Compare1(const TDesC* aString, TLogServCacheStringEntry* const& aRight);
sl@0
   107
	static TInt Compare2(TLogServCacheStringEntry* const& aLeft, TLogServCacheStringEntry* const& aRight);
sl@0
   108
sl@0
   109
private:
sl@0
   110
	MLogServDatabaseTransactionInterface& iDatabase;
sl@0
   111
	RArray<TLogServCacheStringEntry*> iStrings;//List of cached strings
sl@0
   112
	TBool iDirty;//iDirty flag is set when strings are added to the cache during transaction
sl@0
   113
	TDbColNo iIdColNo;
sl@0
   114
	TDbColNo iStringColNo;
sl@0
   115
	
sl@0
   116
	};
sl@0
   117
sl@0
   118
#endif