Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "LogChangeDefinition.h"
19 #include "logclipanic.h"
22 /////////////////////////////////////////////////////////////////////////////////////////
23 // -----> CLogChangeDefinition (source)
24 /////////////////////////////////////////////////////////////////////////////////////////
26 CLogChangeDefinition::CLogChangeDefinition(TInt aGranularity)
27 : iChanges(aGranularity)
31 EXPORT_C CLogChangeDefinition::~CLogChangeDefinition()
36 void CLogChangeDefinition::ConstructL(const CLogChangeDefinition& aCopy)
38 const TInt count = aCopy.Count();
39 for(TInt i=0; i<count; i++)
41 const TLogShdChangeDetails& item = aCopy.iChanges[i];
42 User::LeaveIfError(iChanges.Append(item));
46 EXPORT_C CLogChangeDefinition* CLogChangeDefinition::NewL(TInt aGranularity)
48 CLogChangeDefinition* self = new(ELeave) CLogChangeDefinition(aGranularity);
52 EXPORT_C CLogChangeDefinition* CLogChangeDefinition::NewL(const CLogChangeDefinition& aCopy)
54 const TInt count = Max(1, aCopy.Count());
55 CLogChangeDefinition* self = new(ELeave) CLogChangeDefinition(count);
56 CleanupStack::PushL(self);
57 self->ConstructL(aCopy);
58 CleanupStack::Pop(self);
62 EXPORT_C CLogChangeDefinition* CLogChangeDefinition::NewL(RReadStream& aStream)
64 CLogChangeDefinition* self = new(ELeave) CLogChangeDefinition(KLogChangeDefinitionDefaultGranularity);
65 CleanupStack::PushL(self);
67 CleanupStack::Pop(self);
71 /////////////////////////////////////////////////////////////////////////////////////////
72 /////////////////////////////////////////////////////////////////////////////////////////
73 /////////////////////////////////////////////////////////////////////////////////////////
75 EXPORT_C TInt CLogChangeDefinition::Count() const
77 return iChanges.Count();
80 EXPORT_C TLogDatabaseChangeType CLogChangeDefinition::At(TInt aIndex) const
82 const TLogShdChangeDetails& entry = iChanges[aIndex];
86 EXPORT_C TLogDatabaseChangeType CLogChangeDefinition::At(TInt aIndex, TLogId& aId) const
88 const TLogShdChangeDetails& entry = iChanges[aIndex];
93 EXPORT_C TLogDatabaseChangeType CLogChangeDefinition::At(TInt aIndex, TLogId& aId, TInt& aViewIndex) const
95 const TLogShdChangeDetails& entry = iChanges[aIndex];
97 aViewIndex = entry.iViewIndex;
101 EXPORT_C TInt CLogChangeDefinition::Find(TLogId aId) const
104 const TLogShdChangeDetails entryToFind(aId);
105 TIdentityRelation<TLogShdChangeDetails> relation(CompareEntryIds);
106 const TInt position = iChanges.Find(entryToFind, relation);
110 EXPORT_C TInt CLogChangeDefinition::Find(TLogId aId, TLogDatabaseChangeType aType) const
112 // First try and find any log id regardless of change type
113 TInt position = Find(aId);
116 const TInt count = iChanges.Count();
118 // Keep iterating through the changes until we
120 // a) Reach the end of the changes OR
121 // b) Reach a change corresponding to a different log id OR
122 // c) Find the change we're interested in
124 position = KErrNotFound;
128 const TLogShdChangeDetails& entry = iChanges[i];
129 if (entry.iId == aId)
131 // Now check the change type
132 if (entry.iType == aType)
150 EXPORT_C TInt CLogChangeDefinition::FindByViewIndex(TInt aViewIndex) const
152 // Cannot use binary search
153 const TLogShdChangeDetails entryToFind(KLogNullId, ELogChangeTypeUndefined, aViewIndex);
154 TIdentityRelation<TLogShdChangeDetails> relation(CompareViewIndicies);
155 const TInt position = iChanges.Find(entryToFind, relation);
159 EXPORT_C void CLogChangeDefinition::AddL(TLogId aId, TLogDatabaseChangeType aType, TInt aViewIndex)
163 case ELogChangeTypeEventChanged:
164 case ELogChangeTypeEventChangedHidden:
165 case ELogChangeTypeEventAdded:
166 case ELogChangeTypeEventDeleted:
167 case ELogChangeTypeLogCleared:
168 AddToContainerL(aId, aType, aViewIndex);
172 case ELogChangeTypeUndefined:
173 __ASSERT_ALWAYS(0, Panic(ELogUndefinedChangeType));
178 EXPORT_C void CLogChangeDefinition::Reset()
181 iChanges.GranularCompress();
184 /////////////////////////////////////////////////////////////////////////////////////////
185 /////////////////////////////////////////////////////////////////////////////////////////
186 /////////////////////////////////////////////////////////////////////////////////////////
188 EXPORT_C void CLogChangeDefinition::InternalizeL(RReadStream& aStream)
190 TLogShdChangeDetails entry;
195 for(TInt i=0; i<count; i++)
197 entry.iId = static_cast<TLogId>(aStream.ReadInt32L());
198 entry.iType = static_cast<TLogDatabaseChangeType>(aStream.ReadUint8L());
199 entry.iViewIndex = static_cast<TInt>(aStream.ReadInt32L());
201 User::LeaveIfError(iChanges.Append(entry));
205 EXPORT_C void CLogChangeDefinition::ExternalizeL(RWriteStream& aStream) const
207 TCardinality count = Count();
210 for(TInt i=0; i<count; i++)
212 const TLogShdChangeDetails& entry = iChanges[i];
214 aStream.WriteInt32L(entry.iId);
215 aStream.WriteUint8L(entry.iType);
216 aStream.WriteInt32L(entry.iViewIndex);
220 /////////////////////////////////////////////////////////////////////////////////////////
221 /////////////////////////////////////////////////////////////////////////////////////////
222 /////////////////////////////////////////////////////////////////////////////////////////
224 TBool CLogChangeDefinition::CompareEntryIds(const TLogShdChangeDetails& aLeft, const TLogShdChangeDetails& aRight)
226 return (aLeft.iId == aRight.iId);
229 TBool CLogChangeDefinition::CompareViewIndicies(const TLogShdChangeDetails& aLeft, const TLogShdChangeDetails& aRight)
231 return (aLeft.iViewIndex == aRight.iViewIndex);
234 void CLogChangeDefinition::AddToContainerL(TLogId aId, TLogDatabaseChangeType aType, TInt aViewIndex)
236 const TLogShdChangeDetails entry(aId, aType, aViewIndex);
237 const TInt error = iChanges.Append(entry);
238 User::LeaveIfError(error);