os/persistentdata/loggingservices/eventlogger/LogCli/src/LogChangeDefinition.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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
#include "LogChangeDefinition.h"
sl@0
    17
sl@0
    18
// User includes
sl@0
    19
#include "logclipanic.h"
sl@0
    20
sl@0
    21
sl@0
    22
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    23
// -----> CLogChangeDefinition (source)
sl@0
    24
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    25
sl@0
    26
CLogChangeDefinition::CLogChangeDefinition(TInt aGranularity)
sl@0
    27
:	iChanges(aGranularity)
sl@0
    28
	{
sl@0
    29
	}
sl@0
    30
sl@0
    31
EXPORT_C CLogChangeDefinition::~CLogChangeDefinition()
sl@0
    32
	{
sl@0
    33
	iChanges.Close();
sl@0
    34
	}
sl@0
    35
sl@0
    36
void CLogChangeDefinition::ConstructL(const CLogChangeDefinition& aCopy)
sl@0
    37
	{
sl@0
    38
	const TInt count = aCopy.Count();
sl@0
    39
	for(TInt i=0; i<count; i++)
sl@0
    40
		{
sl@0
    41
		const TLogShdChangeDetails& item = aCopy.iChanges[i];
sl@0
    42
		User::LeaveIfError(iChanges.Append(item));
sl@0
    43
		}
sl@0
    44
	}
sl@0
    45
sl@0
    46
EXPORT_C CLogChangeDefinition* CLogChangeDefinition::NewL(TInt aGranularity)
sl@0
    47
	{
sl@0
    48
	CLogChangeDefinition* self = new(ELeave) CLogChangeDefinition(aGranularity);
sl@0
    49
	return self;
sl@0
    50
	}
sl@0
    51
sl@0
    52
EXPORT_C CLogChangeDefinition* CLogChangeDefinition::NewL(const CLogChangeDefinition& aCopy)
sl@0
    53
	{
sl@0
    54
	const TInt count = Max(1, aCopy.Count());
sl@0
    55
	CLogChangeDefinition* self = new(ELeave) CLogChangeDefinition(count);
sl@0
    56
	CleanupStack::PushL(self);
sl@0
    57
	self->ConstructL(aCopy);
sl@0
    58
	CleanupStack::Pop(self);
sl@0
    59
	return self;
sl@0
    60
	}
sl@0
    61
sl@0
    62
EXPORT_C CLogChangeDefinition* CLogChangeDefinition::NewL(RReadStream& aStream)
sl@0
    63
	{
sl@0
    64
	CLogChangeDefinition* self = new(ELeave) CLogChangeDefinition(KLogChangeDefinitionDefaultGranularity);
sl@0
    65
	CleanupStack::PushL(self);
sl@0
    66
	aStream >> *self;
sl@0
    67
	CleanupStack::Pop(self);
sl@0
    68
	return self;
sl@0
    69
	}
sl@0
    70
sl@0
    71
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    72
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    73
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    74
sl@0
    75
EXPORT_C TInt CLogChangeDefinition::Count() const
sl@0
    76
	{
sl@0
    77
	return iChanges.Count();
sl@0
    78
	}
sl@0
    79
sl@0
    80
EXPORT_C TLogDatabaseChangeType CLogChangeDefinition::At(TInt aIndex) const
sl@0
    81
	{
sl@0
    82
	const TLogShdChangeDetails& entry = iChanges[aIndex];
sl@0
    83
	return entry.iType;
sl@0
    84
	}
sl@0
    85
sl@0
    86
EXPORT_C TLogDatabaseChangeType CLogChangeDefinition::At(TInt aIndex, TLogId& aId) const
sl@0
    87
	{
sl@0
    88
	const TLogShdChangeDetails& entry = iChanges[aIndex];
sl@0
    89
	aId = entry.iId;
sl@0
    90
	return entry.iType;
sl@0
    91
	}
sl@0
    92
sl@0
    93
EXPORT_C TLogDatabaseChangeType CLogChangeDefinition::At(TInt aIndex, TLogId& aId, TInt& aViewIndex) const
sl@0
    94
	{
sl@0
    95
	const TLogShdChangeDetails& entry = iChanges[aIndex];
sl@0
    96
	aId = entry.iId;
sl@0
    97
	aViewIndex = entry.iViewIndex;
sl@0
    98
	return entry.iType;
sl@0
    99
	}
sl@0
   100
sl@0
   101
EXPORT_C TInt CLogChangeDefinition::Find(TLogId aId) const
sl@0
   102
	{
sl@0
   103
	// Linear search
sl@0
   104
	const TLogShdChangeDetails entryToFind(aId);
sl@0
   105
	TIdentityRelation<TLogShdChangeDetails> relation(CompareEntryIds);
sl@0
   106
	const TInt position = iChanges.Find(entryToFind, relation);
sl@0
   107
	return position;
sl@0
   108
	}
sl@0
   109
sl@0
   110
EXPORT_C TInt CLogChangeDefinition::Find(TLogId aId, TLogDatabaseChangeType aType) const
sl@0
   111
	{
sl@0
   112
	// First try and find any log id regardless of change type
sl@0
   113
	TInt position = Find(aId);
sl@0
   114
	if	(position >= 0)
sl@0
   115
		{
sl@0
   116
		const TInt count = iChanges.Count();
sl@0
   117
sl@0
   118
		// Keep iterating through the changes until we 
sl@0
   119
		//
sl@0
   120
		// a) Reach the end of the changes OR
sl@0
   121
		// b) Reach a change corresponding to a different log id OR
sl@0
   122
		// c) Find the change we're interested in
sl@0
   123
		TInt i = position;
sl@0
   124
		position = KErrNotFound;
sl@0
   125
		//
sl@0
   126
		for(; i<count; i++)
sl@0
   127
			{
sl@0
   128
			const TLogShdChangeDetails& entry = iChanges[i];
sl@0
   129
			if	(entry.iId == aId)
sl@0
   130
				{
sl@0
   131
				// Now check the change type
sl@0
   132
				if	(entry.iType == aType)
sl@0
   133
					{
sl@0
   134
					// (c)
sl@0
   135
					position = i;
sl@0
   136
					break;
sl@0
   137
					}
sl@0
   138
				}
sl@0
   139
			else
sl@0
   140
				{
sl@0
   141
				// (b)
sl@0
   142
				break;
sl@0
   143
				}
sl@0
   144
			}
sl@0
   145
		// (a) is implicit
sl@0
   146
		}
sl@0
   147
	return position;
sl@0
   148
	}
sl@0
   149
sl@0
   150
EXPORT_C TInt CLogChangeDefinition::FindByViewIndex(TInt aViewIndex) const
sl@0
   151
	{
sl@0
   152
	// Cannot use binary search
sl@0
   153
	const TLogShdChangeDetails entryToFind(KLogNullId, ELogChangeTypeUndefined, aViewIndex);
sl@0
   154
	TIdentityRelation<TLogShdChangeDetails> relation(CompareViewIndicies);
sl@0
   155
	const TInt position = iChanges.Find(entryToFind, relation);
sl@0
   156
	return position;
sl@0
   157
	}
sl@0
   158
sl@0
   159
EXPORT_C void CLogChangeDefinition::AddL(TLogId aId, TLogDatabaseChangeType aType, TInt aViewIndex)
sl@0
   160
	{
sl@0
   161
	switch(aType)
sl@0
   162
		{
sl@0
   163
	case ELogChangeTypeEventChanged:
sl@0
   164
	case ELogChangeTypeEventChangedHidden:
sl@0
   165
	case ELogChangeTypeEventAdded:
sl@0
   166
	case ELogChangeTypeEventDeleted:
sl@0
   167
	case ELogChangeTypeLogCleared:
sl@0
   168
		AddToContainerL(aId, aType, aViewIndex);
sl@0
   169
		break;
sl@0
   170
	//
sl@0
   171
	default:
sl@0
   172
	case ELogChangeTypeUndefined:
sl@0
   173
		__ASSERT_ALWAYS(0, Panic(ELogUndefinedChangeType));
sl@0
   174
		break;
sl@0
   175
		}
sl@0
   176
	}
sl@0
   177
sl@0
   178
EXPORT_C void CLogChangeDefinition::Reset()
sl@0
   179
	{
sl@0
   180
	iChanges.Reset();
sl@0
   181
	iChanges.GranularCompress();
sl@0
   182
	}
sl@0
   183
sl@0
   184
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   185
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   186
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   187
sl@0
   188
EXPORT_C void CLogChangeDefinition::InternalizeL(RReadStream& aStream)
sl@0
   189
	{
sl@0
   190
	TLogShdChangeDetails entry;
sl@0
   191
	//
sl@0
   192
	TCardinality count;
sl@0
   193
	aStream >> count;
sl@0
   194
	//
sl@0
   195
	for(TInt i=0; i<count; i++)
sl@0
   196
		{
sl@0
   197
		entry.iId = static_cast<TLogId>(aStream.ReadInt32L());
sl@0
   198
		entry.iType = static_cast<TLogDatabaseChangeType>(aStream.ReadUint8L());
sl@0
   199
		entry.iViewIndex = static_cast<TInt>(aStream.ReadInt32L());
sl@0
   200
		//
sl@0
   201
		User::LeaveIfError(iChanges.Append(entry));
sl@0
   202
		}
sl@0
   203
	}
sl@0
   204
sl@0
   205
EXPORT_C void CLogChangeDefinition::ExternalizeL(RWriteStream& aStream) const
sl@0
   206
	{
sl@0
   207
	TCardinality count = Count();
sl@0
   208
	aStream << count;
sl@0
   209
	//
sl@0
   210
	for(TInt i=0; i<count; i++)
sl@0
   211
		{
sl@0
   212
		const TLogShdChangeDetails& entry = iChanges[i];
sl@0
   213
		//
sl@0
   214
		aStream.WriteInt32L(entry.iId);
sl@0
   215
		aStream.WriteUint8L(entry.iType);
sl@0
   216
		aStream.WriteInt32L(entry.iViewIndex);
sl@0
   217
		}
sl@0
   218
	}
sl@0
   219
sl@0
   220
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   221
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   222
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   223
sl@0
   224
TBool CLogChangeDefinition::CompareEntryIds(const TLogShdChangeDetails& aLeft, const TLogShdChangeDetails& aRight)
sl@0
   225
	{
sl@0
   226
	return (aLeft.iId == aRight.iId);
sl@0
   227
	}
sl@0
   228
sl@0
   229
TBool CLogChangeDefinition::CompareViewIndicies(const TLogShdChangeDetails& aLeft, const TLogShdChangeDetails& aRight)
sl@0
   230
	{
sl@0
   231
	return (aLeft.iViewIndex == aRight.iViewIndex);
sl@0
   232
	}
sl@0
   233
sl@0
   234
void CLogChangeDefinition::AddToContainerL(TLogId aId, TLogDatabaseChangeType aType, TInt aViewIndex)
sl@0
   235
	{
sl@0
   236
	const TLogShdChangeDetails entry(aId, aType, aViewIndex);
sl@0
   237
	const TInt error = iChanges.Append(entry);
sl@0
   238
	User::LeaveIfError(error);
sl@0
   239
	}
sl@0
   240
sl@0
   241