First public contribution.
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 "LogServRecentList.h"
18 #include <logcntdef.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"
27 /////////////////////////////////////////////////////////////////////////////////////////
28 // -----> CLogServRecentList (source)
29 /////////////////////////////////////////////////////////////////////////////////////////
31 CLogServRecentList::~CLogServRecentList()
33 iConditions.ResetAndDestroy();
37 void CLogServRecentList::ConstructL(TResourceReader& aReader)
39 iId = static_cast<TLogRecentList>(aReader.ReadInt8());
40 iDuplicates = static_cast<TUint16>(aReader.ReadUint16());
42 TInt count = aReader.ReadInt16();
43 iConditions.ReserveL(count);
46 CLogServRecentCondition* condition = CLogServRecentCondition::NewL(aReader);
47 TInt err = iConditions.Append(condition);
48 __ASSERT_ALWAYS(err == KErrNone, Panic(ELogArrayReserved));
52 CLogServRecentList* CLogServRecentList::NewL(TResourceReader& aReader)
54 CLogServRecentList* self = new(ELeave) CLogServRecentList;
55 CleanupStack::PushL(self);
56 self->ConstructL(aReader);
63 #pragma BullseyeCoverage off
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()
70 CLogServRecentList* self = new(ELeave) CLogServRecentList;
71 CleanupStack::PushL(self);
72 self->TestConstructL();
77 void CLogServRecentList::TestConstructL()
80 iDuplicates = ELogRemotePartyField | ELogNumberField | ELogDirectionField | ELogDurationTypeField |
81 ELogStatusField | ELogFlagsField | ELogSubjectField
82 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
86 TInt count = 7;//7 test recent list conditions added in the code bellow
87 iConditions.ReserveL(count);
89 CLogServRecentCondition* condition1 = CLogServRecentCondition::TestNewL(ELogDirectionField);
90 (void)iConditions.Append(condition1);
92 CLogServRecentCondition* condition2 = CLogServRecentCondition::TestNewL(ELogDurationTypeField);
93 (void)iConditions.Append(condition2);
95 CLogServRecentCondition* condition3 = CLogServRecentCondition::TestNewL(ELogNumberField);
96 (void)iConditions.Append(condition3);
98 CLogServRecentCondition* condition4 = CLogServRecentCondition::TestNewL(ELogRemotePartyField);
99 (void)iConditions.Append(condition4);
101 CLogServRecentCondition* condition5 = CLogServRecentCondition::TestNewL(ELogStatusField);
102 (void)iConditions.Append(condition5);
104 CLogServRecentCondition* condition6 = CLogServRecentCondition::TestNewL(ELogFlagsField);
105 (void)iConditions.Append(condition6);
106 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
108 CLogServRecentCondition* condition7 = CLogServRecentCondition::TestNewL(ELogSimIdField);
109 (void)iConditions.Append(condition7);
113 #pragma BullseyeCoverage on
117 /////////////////////////////////////////////////////////////////////////////////////////
118 /////////////////////////////////////////////////////////////////////////////////////////
119 /////////////////////////////////////////////////////////////////////////////////////////
122 Checks whether the aEvent field values satisfy the conditions described in
123 in this CLogServRecentList object.
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.
128 TBool CLogServRecentList::IsRecent(const CLogEvent& aEvent) const
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.
138 // For example, the iConditions array contains three elements initialised as:
141 // [2, "Incomming Alternate"]
142 // The aEvent object contains these fields initialized:
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)
154 const CLogServRecentCondition& condition = *iConditions[i];
155 usedFieldBitMask |= condition.Field();
156 if(condition.IsMatch(aEvent))
158 matchedFieldBitMask |= condition.Field();
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;
166 void CLogServRecentList::GetFilter(const CLogEvent& aEvent, CLogFilter& aFilter) const
168 TUint16 nullFieldsBitMask = 0;
169 if (iDuplicates & ELogContactField)
171 aFilter.SetContact(aEvent.Contact());
172 if (aEvent.Contact() == KLogNullContactId)
173 nullFieldsBitMask |= ELogContactField;
176 if (iDuplicates & ELogDirectionField)
178 aFilter.SetDirection(aEvent.Direction());
179 if (aEvent.Direction().Length() == 0)
180 nullFieldsBitMask |= ELogDirectionField;
183 if (iDuplicates & ELogDurationTypeField)
185 aFilter.SetDurationType(aEvent.DurationType());
186 if (aEvent.DurationType() == KLogDurationNone)
187 nullFieldsBitMask |= ELogDurationTypeField;
190 if (iDuplicates & ELogEventTypeField)
192 aFilter.SetEventType(aEvent.EventType());
193 if (aEvent.EventType() == KNullUid)
194 nullFieldsBitMask |= ELogEventTypeField;
197 if (iDuplicates & ELogNumberField)
199 aFilter.SetNumber(aEvent.Number());
200 if (aEvent.Number().Length() == 0)
201 nullFieldsBitMask |= ELogNumberField;
204 if (iDuplicates & ELogRemotePartyField)
206 aFilter.SetRemoteParty(aEvent.RemoteParty());
207 if (aEvent.RemoteParty().Length() == 0)
208 nullFieldsBitMask |= ELogRemotePartyField;
211 if (iDuplicates & ELogStatusField)
213 aFilter.SetStatus(aEvent.Status());
214 if (aEvent.Status().Length() == 0)
215 nullFieldsBitMask |= ELogStatusField;
218 if (iDuplicates & ELogFlagsField)
220 aFilter.SetFlags(aEvent.Flags());
221 if (aEvent.Flags() == KLogNullFlags)
222 nullFieldsBitMask |= ELogFlagsField;
225 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
226 if (iDuplicates & ELogSimIdField)
228 aFilter.SetSimId(aEvent.SimId());
229 if (aEvent.SimId() == KLogNullSimId)
230 nullFieldsBitMask |= ELogSimIdField;
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);
241 TBool CLogServRecentList::IsFilterEmpty(const CLogFilter& aFilter) const
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
251 aFilter.SimId() == KLogNullSimId