|
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 "LogServRecentList.h" |
|
17 #include <barsread.h> |
|
18 #include <logcntdef.h> |
|
19 #include <logcli.h> |
|
20 #include <logengdurations.h> |
|
21 #include <logfilterandeventconstants.hrh> |
|
22 #include <logwraplimits.h> |
|
23 #include "logservpanic.h" |
|
24 #include "LogServRecentCondition.h" |
|
25 #include "LogServSqlStrings.h" |
|
26 |
|
27 ///////////////////////////////////////////////////////////////////////////////////////// |
|
28 // -----> CLogServRecentList (source) |
|
29 ///////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
31 CLogServRecentList::~CLogServRecentList() |
|
32 { |
|
33 iConditions.ResetAndDestroy(); |
|
34 iConditions.Close(); |
|
35 } |
|
36 |
|
37 void CLogServRecentList::ConstructL(TResourceReader& aReader) |
|
38 { |
|
39 iId = static_cast<TLogRecentList>(aReader.ReadInt8()); |
|
40 iDuplicates = static_cast<TUint16>(aReader.ReadUint16()); |
|
41 |
|
42 TInt count = aReader.ReadInt16(); |
|
43 iConditions.ReserveL(count); |
|
44 while(count--) |
|
45 { |
|
46 CLogServRecentCondition* condition = CLogServRecentCondition::NewL(aReader); |
|
47 TInt err = iConditions.Append(condition); |
|
48 __ASSERT_ALWAYS(err == KErrNone, Panic(ELogArrayReserved)); |
|
49 } |
|
50 } |
|
51 |
|
52 CLogServRecentList* CLogServRecentList::NewL(TResourceReader& aReader) |
|
53 { |
|
54 CLogServRecentList* self = new(ELeave) CLogServRecentList; |
|
55 CleanupStack::PushL(self); |
|
56 self->ConstructL(aReader); |
|
57 CleanupStack::Pop(); |
|
58 return self; |
|
59 } |
|
60 |
|
61 #ifdef SYSLIBS_TEST |
|
62 |
|
63 #pragma BullseyeCoverage off |
|
64 |
|
65 //Used by the unit tests when SYSLIBS_TEST macro is defined. |
|
66 //Creates a complex recent list with a lot of fields. |
|
67 //This helps covering most of recent list related production code branches. |
|
68 CLogServRecentList* CLogServRecentList::TestNewL() |
|
69 { |
|
70 CLogServRecentList* self = new(ELeave) CLogServRecentList; |
|
71 CleanupStack::PushL(self); |
|
72 self->TestConstructL(); |
|
73 CleanupStack::Pop(); |
|
74 return self; |
|
75 } |
|
76 |
|
77 void CLogServRecentList::TestConstructL() |
|
78 { |
|
79 iId = KLogRctTListId; |
|
80 iDuplicates = ELogRemotePartyField | ELogNumberField | ELogDirectionField | ELogDurationTypeField | |
|
81 ELogStatusField | ELogFlagsField | ELogSubjectField |
|
82 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
83 | ELogSimIdField |
|
84 #endif |
|
85 ; |
|
86 TInt count = 7;//7 test recent list conditions added in the code bellow |
|
87 iConditions.ReserveL(count); |
|
88 //1 |
|
89 CLogServRecentCondition* condition1 = CLogServRecentCondition::TestNewL(ELogDirectionField); |
|
90 (void)iConditions.Append(condition1); |
|
91 //2 |
|
92 CLogServRecentCondition* condition2 = CLogServRecentCondition::TestNewL(ELogDurationTypeField); |
|
93 (void)iConditions.Append(condition2); |
|
94 //3 |
|
95 CLogServRecentCondition* condition3 = CLogServRecentCondition::TestNewL(ELogNumberField); |
|
96 (void)iConditions.Append(condition3); |
|
97 //4 |
|
98 CLogServRecentCondition* condition4 = CLogServRecentCondition::TestNewL(ELogRemotePartyField); |
|
99 (void)iConditions.Append(condition4); |
|
100 //5 |
|
101 CLogServRecentCondition* condition5 = CLogServRecentCondition::TestNewL(ELogStatusField); |
|
102 (void)iConditions.Append(condition5); |
|
103 //6 |
|
104 CLogServRecentCondition* condition6 = CLogServRecentCondition::TestNewL(ELogFlagsField); |
|
105 (void)iConditions.Append(condition6); |
|
106 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
107 //7 |
|
108 CLogServRecentCondition* condition7 = CLogServRecentCondition::TestNewL(ELogSimIdField); |
|
109 (void)iConditions.Append(condition7); |
|
110 #endif |
|
111 } |
|
112 |
|
113 #pragma BullseyeCoverage on |
|
114 |
|
115 #endif//SYSLIBS_TEST |
|
116 |
|
117 ///////////////////////////////////////////////////////////////////////////////////////// |
|
118 ///////////////////////////////////////////////////////////////////////////////////////// |
|
119 ///////////////////////////////////////////////////////////////////////////////////////// |
|
120 |
|
121 /** |
|
122 Checks whether the aEvent field values satisfy the conditions described in |
|
123 in this CLogServRecentList object. |
|
124 |
|
125 @param aEvent Reference to a CLogEvent object which field values will be tested. |
|
126 @return True If the aEvent field values satisfy the conditions, false otherwise. |
|
127 */ |
|
128 TBool CLogServRecentList::IsRecent(const CLogEvent& aEvent) const |
|
129 { |
|
130 //The implemented algorithm is: |
|
131 // usedFieldBitMask - bit mask, where the "1" bits correspond to the fields used in the "recent condition" objects - |
|
132 // the iConditions array. Each "recent condition" object has "field" and "value" data members, |
|
133 // where the "field" data member value is a power of 2. |
|
134 // Some of the iConditions elemens may have the same field value. |
|
135 // matchedFieldBitMask - bit mask, where the "1" bits correspond to a "recent condition" object which field value is |
|
136 // equal to the corresponding field value of the aEvent object. |
|
137 // |
|
138 // For example, the iConditions array contains three elements initialised as: |
|
139 // [2, "Incomming"] |
|
140 // [8, 1000550D] |
|
141 // [2, "Incomming Alternate"] |
|
142 // The aEvent object contains these fields initialized: |
|
143 // [2, "Incomming"] |
|
144 // [8, 1000550D] |
|
145 // Then usedFieldBitMask value will be: 0000000A - (2 | 8). |
|
146 // matchedFieldBitMask value will be: 0000000A - (2 | 8). |
|
147 // So, the operation performed on particular matchedFieldBitMask bit is bitwise OR - |
|
148 // in case if two "recent condition" objects use the same field (but have different field values), then the result |
|
149 // of the matching operation with the corresponding aEvent field value will be OR-ed in that matchedFieldBitMask bit. |
|
150 TUint16 usedFieldBitMask = 0; |
|
151 TUint16 matchedFieldBitMask = 0; |
|
152 for(TInt i=iConditions.Count()-1;i>=0;--i) |
|
153 { |
|
154 const CLogServRecentCondition& condition = *iConditions[i]; |
|
155 usedFieldBitMask |= condition.Field(); |
|
156 if(condition.IsMatch(aEvent)) |
|
157 { |
|
158 matchedFieldBitMask |= condition.Field(); |
|
159 } |
|
160 } |
|
161 //If both usedFieldBitMask and matchedFieldBitMask are 0, that means - the iConditions array is empty. |
|
162 //The function returns true in this case. |
|
163 return usedFieldBitMask == matchedFieldBitMask; |
|
164 } |
|
165 |
|
166 void CLogServRecentList::GetFilter(const CLogEvent& aEvent, CLogFilter& aFilter) const |
|
167 { |
|
168 TUint16 nullFieldsBitMask = 0; |
|
169 if (iDuplicates & ELogContactField) |
|
170 { |
|
171 aFilter.SetContact(aEvent.Contact()); |
|
172 if (aEvent.Contact() == KLogNullContactId) |
|
173 nullFieldsBitMask |= ELogContactField; |
|
174 } |
|
175 |
|
176 if (iDuplicates & ELogDirectionField) |
|
177 { |
|
178 aFilter.SetDirection(aEvent.Direction()); |
|
179 if (aEvent.Direction().Length() == 0) |
|
180 nullFieldsBitMask |= ELogDirectionField; |
|
181 } |
|
182 |
|
183 if (iDuplicates & ELogDurationTypeField) |
|
184 { |
|
185 aFilter.SetDurationType(aEvent.DurationType()); |
|
186 if (aEvent.DurationType() == KLogDurationNone) |
|
187 nullFieldsBitMask |= ELogDurationTypeField; |
|
188 } |
|
189 |
|
190 if (iDuplicates & ELogEventTypeField) |
|
191 { |
|
192 aFilter.SetEventType(aEvent.EventType()); |
|
193 if (aEvent.EventType() == KNullUid) |
|
194 nullFieldsBitMask |= ELogEventTypeField; |
|
195 } |
|
196 |
|
197 if (iDuplicates & ELogNumberField) |
|
198 { |
|
199 aFilter.SetNumber(aEvent.Number()); |
|
200 if (aEvent.Number().Length() == 0) |
|
201 nullFieldsBitMask |= ELogNumberField; |
|
202 } |
|
203 |
|
204 if (iDuplicates & ELogRemotePartyField) |
|
205 { |
|
206 aFilter.SetRemoteParty(aEvent.RemoteParty()); |
|
207 if (aEvent.RemoteParty().Length() == 0) |
|
208 nullFieldsBitMask |= ELogRemotePartyField; |
|
209 } |
|
210 |
|
211 if (iDuplicates & ELogStatusField) |
|
212 { |
|
213 aFilter.SetStatus(aEvent.Status()); |
|
214 if (aEvent.Status().Length() == 0) |
|
215 nullFieldsBitMask |= ELogStatusField; |
|
216 } |
|
217 |
|
218 if (iDuplicates & ELogFlagsField) |
|
219 { |
|
220 aFilter.SetFlags(aEvent.Flags()); |
|
221 if (aEvent.Flags() == KLogNullFlags) |
|
222 nullFieldsBitMask |= ELogFlagsField; |
|
223 } |
|
224 |
|
225 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
226 if (iDuplicates & ELogSimIdField) |
|
227 { |
|
228 aFilter.SetSimId(aEvent.SimId()); |
|
229 if (aEvent.SimId() == KLogNullSimId) |
|
230 nullFieldsBitMask |= ELogSimIdField; |
|
231 } |
|
232 #endif |
|
233 |
|
234 aFilter.SetNullFields(nullFieldsBitMask); |
|
235 // This is a special case, if all the fields are null |
|
236 // In this case we want to be a duplicate of other events where all the fields are null |
|
237 if (IsFilterEmpty(aFilter)) |
|
238 aFilter.SetNullFields(iDuplicates); |
|
239 } |
|
240 |
|
241 TBool CLogServRecentList::IsFilterEmpty(const CLogFilter& aFilter) const |
|
242 { |
|
243 return aFilter.EventType() == KNullUid && |
|
244 aFilter.RemoteParty().Length() == 0 && |
|
245 aFilter.Direction().Length() == 0 && |
|
246 aFilter.Status().Length() == 0 && |
|
247 aFilter.Contact() == KLogNullContactId && |
|
248 aFilter.Number().Length() == 0 |
|
249 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
250 && |
|
251 aFilter.SimId() == KLogNullSimId |
|
252 #endif |
|
253 ; |
|
254 } |
|
255 |