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