1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/loggingservices/eventlogger/LogServ/src/LogServRecentList.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,255 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "LogServRecentList.h"
1.20 +#include <barsread.h>
1.21 +#include <logcntdef.h>
1.22 +#include <logcli.h>
1.23 +#include <logengdurations.h>
1.24 +#include <logfilterandeventconstants.hrh>
1.25 +#include <logwraplimits.h>
1.26 +#include "logservpanic.h"
1.27 +#include "LogServRecentCondition.h"
1.28 +#include "LogServSqlStrings.h"
1.29 +
1.30 +/////////////////////////////////////////////////////////////////////////////////////////
1.31 +// -----> CLogServRecentList (source)
1.32 +/////////////////////////////////////////////////////////////////////////////////////////
1.33 +
1.34 +CLogServRecentList::~CLogServRecentList()
1.35 + {
1.36 + iConditions.ResetAndDestroy();
1.37 + iConditions.Close();
1.38 + }
1.39 +
1.40 +void CLogServRecentList::ConstructL(TResourceReader& aReader)
1.41 + {
1.42 + iId = static_cast<TLogRecentList>(aReader.ReadInt8());
1.43 + iDuplicates = static_cast<TUint16>(aReader.ReadUint16());
1.44 +
1.45 + TInt count = aReader.ReadInt16();
1.46 + iConditions.ReserveL(count);
1.47 + while(count--)
1.48 + {
1.49 + CLogServRecentCondition* condition = CLogServRecentCondition::NewL(aReader);
1.50 + TInt err = iConditions.Append(condition);
1.51 + __ASSERT_ALWAYS(err == KErrNone, Panic(ELogArrayReserved));
1.52 + }
1.53 + }
1.54 +
1.55 +CLogServRecentList* CLogServRecentList::NewL(TResourceReader& aReader)
1.56 + {
1.57 + CLogServRecentList* self = new(ELeave) CLogServRecentList;
1.58 + CleanupStack::PushL(self);
1.59 + self->ConstructL(aReader);
1.60 + CleanupStack::Pop();
1.61 + return self;
1.62 + }
1.63 +
1.64 +#ifdef SYSLIBS_TEST
1.65 +
1.66 +#pragma BullseyeCoverage off
1.67 +
1.68 +//Used by the unit tests when SYSLIBS_TEST macro is defined.
1.69 +//Creates a complex recent list with a lot of fields.
1.70 +//This helps covering most of recent list related production code branches.
1.71 +CLogServRecentList* CLogServRecentList::TestNewL()
1.72 + {
1.73 + CLogServRecentList* self = new(ELeave) CLogServRecentList;
1.74 + CleanupStack::PushL(self);
1.75 + self->TestConstructL();
1.76 + CleanupStack::Pop();
1.77 + return self;
1.78 + }
1.79 +
1.80 +void CLogServRecentList::TestConstructL()
1.81 + {
1.82 + iId = KLogRctTListId;
1.83 + iDuplicates = ELogRemotePartyField | ELogNumberField | ELogDirectionField | ELogDurationTypeField |
1.84 + ELogStatusField | ELogFlagsField | ELogSubjectField
1.85 +#ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.86 + | ELogSimIdField
1.87 +#endif
1.88 + ;
1.89 + TInt count = 7;//7 test recent list conditions added in the code bellow
1.90 + iConditions.ReserveL(count);
1.91 + //1
1.92 + CLogServRecentCondition* condition1 = CLogServRecentCondition::TestNewL(ELogDirectionField);
1.93 + (void)iConditions.Append(condition1);
1.94 + //2
1.95 + CLogServRecentCondition* condition2 = CLogServRecentCondition::TestNewL(ELogDurationTypeField);
1.96 + (void)iConditions.Append(condition2);
1.97 + //3
1.98 + CLogServRecentCondition* condition3 = CLogServRecentCondition::TestNewL(ELogNumberField);
1.99 + (void)iConditions.Append(condition3);
1.100 + //4
1.101 + CLogServRecentCondition* condition4 = CLogServRecentCondition::TestNewL(ELogRemotePartyField);
1.102 + (void)iConditions.Append(condition4);
1.103 + //5
1.104 + CLogServRecentCondition* condition5 = CLogServRecentCondition::TestNewL(ELogStatusField);
1.105 + (void)iConditions.Append(condition5);
1.106 + //6
1.107 + CLogServRecentCondition* condition6 = CLogServRecentCondition::TestNewL(ELogFlagsField);
1.108 + (void)iConditions.Append(condition6);
1.109 +#ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.110 + //7
1.111 + CLogServRecentCondition* condition7 = CLogServRecentCondition::TestNewL(ELogSimIdField);
1.112 + (void)iConditions.Append(condition7);
1.113 +#endif
1.114 + }
1.115 +
1.116 +#pragma BullseyeCoverage on
1.117 +
1.118 +#endif//SYSLIBS_TEST
1.119 +
1.120 +/////////////////////////////////////////////////////////////////////////////////////////
1.121 +/////////////////////////////////////////////////////////////////////////////////////////
1.122 +/////////////////////////////////////////////////////////////////////////////////////////
1.123 +
1.124 +/**
1.125 +Checks whether the aEvent field values satisfy the conditions described in
1.126 +in this CLogServRecentList object.
1.127 +
1.128 +@param aEvent Reference to a CLogEvent object which field values will be tested.
1.129 +@return True If the aEvent field values satisfy the conditions, false otherwise.
1.130 +*/
1.131 +TBool CLogServRecentList::IsRecent(const CLogEvent& aEvent) const
1.132 + {
1.133 + //The implemented algorithm is:
1.134 + // usedFieldBitMask - bit mask, where the "1" bits correspond to the fields used in the "recent condition" objects -
1.135 + // the iConditions array. Each "recent condition" object has "field" and "value" data members,
1.136 + // where the "field" data member value is a power of 2.
1.137 + // Some of the iConditions elemens may have the same field value.
1.138 + // matchedFieldBitMask - bit mask, where the "1" bits correspond to a "recent condition" object which field value is
1.139 + // equal to the corresponding field value of the aEvent object.
1.140 + //
1.141 + // For example, the iConditions array contains three elements initialised as:
1.142 + // [2, "Incomming"]
1.143 + // [8, 1000550D]
1.144 + // [2, "Incomming Alternate"]
1.145 + // The aEvent object contains these fields initialized:
1.146 + // [2, "Incomming"]
1.147 + // [8, 1000550D]
1.148 + // Then usedFieldBitMask value will be: 0000000A - (2 | 8).
1.149 + // matchedFieldBitMask value will be: 0000000A - (2 | 8).
1.150 + // So, the operation performed on particular matchedFieldBitMask bit is bitwise OR -
1.151 + // in case if two "recent condition" objects use the same field (but have different field values), then the result
1.152 + // of the matching operation with the corresponding aEvent field value will be OR-ed in that matchedFieldBitMask bit.
1.153 + TUint16 usedFieldBitMask = 0;
1.154 + TUint16 matchedFieldBitMask = 0;
1.155 + for(TInt i=iConditions.Count()-1;i>=0;--i)
1.156 + {
1.157 + const CLogServRecentCondition& condition = *iConditions[i];
1.158 + usedFieldBitMask |= condition.Field();
1.159 + if(condition.IsMatch(aEvent))
1.160 + {
1.161 + matchedFieldBitMask |= condition.Field();
1.162 + }
1.163 + }
1.164 + //If both usedFieldBitMask and matchedFieldBitMask are 0, that means - the iConditions array is empty.
1.165 + //The function returns true in this case.
1.166 + return usedFieldBitMask == matchedFieldBitMask;
1.167 + }
1.168 +
1.169 +void CLogServRecentList::GetFilter(const CLogEvent& aEvent, CLogFilter& aFilter) const
1.170 + {
1.171 + TUint16 nullFieldsBitMask = 0;
1.172 + if (iDuplicates & ELogContactField)
1.173 + {
1.174 + aFilter.SetContact(aEvent.Contact());
1.175 + if (aEvent.Contact() == KLogNullContactId)
1.176 + nullFieldsBitMask |= ELogContactField;
1.177 + }
1.178 +
1.179 + if (iDuplicates & ELogDirectionField)
1.180 + {
1.181 + aFilter.SetDirection(aEvent.Direction());
1.182 + if (aEvent.Direction().Length() == 0)
1.183 + nullFieldsBitMask |= ELogDirectionField;
1.184 + }
1.185 +
1.186 + if (iDuplicates & ELogDurationTypeField)
1.187 + {
1.188 + aFilter.SetDurationType(aEvent.DurationType());
1.189 + if (aEvent.DurationType() == KLogDurationNone)
1.190 + nullFieldsBitMask |= ELogDurationTypeField;
1.191 + }
1.192 +
1.193 + if (iDuplicates & ELogEventTypeField)
1.194 + {
1.195 + aFilter.SetEventType(aEvent.EventType());
1.196 + if (aEvent.EventType() == KNullUid)
1.197 + nullFieldsBitMask |= ELogEventTypeField;
1.198 + }
1.199 +
1.200 + if (iDuplicates & ELogNumberField)
1.201 + {
1.202 + aFilter.SetNumber(aEvent.Number());
1.203 + if (aEvent.Number().Length() == 0)
1.204 + nullFieldsBitMask |= ELogNumberField;
1.205 + }
1.206 +
1.207 + if (iDuplicates & ELogRemotePartyField)
1.208 + {
1.209 + aFilter.SetRemoteParty(aEvent.RemoteParty());
1.210 + if (aEvent.RemoteParty().Length() == 0)
1.211 + nullFieldsBitMask |= ELogRemotePartyField;
1.212 + }
1.213 +
1.214 + if (iDuplicates & ELogStatusField)
1.215 + {
1.216 + aFilter.SetStatus(aEvent.Status());
1.217 + if (aEvent.Status().Length() == 0)
1.218 + nullFieldsBitMask |= ELogStatusField;
1.219 + }
1.220 +
1.221 + if (iDuplicates & ELogFlagsField)
1.222 + {
1.223 + aFilter.SetFlags(aEvent.Flags());
1.224 + if (aEvent.Flags() == KLogNullFlags)
1.225 + nullFieldsBitMask |= ELogFlagsField;
1.226 + }
1.227 +
1.228 +#ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.229 + if (iDuplicates & ELogSimIdField)
1.230 + {
1.231 + aFilter.SetSimId(aEvent.SimId());
1.232 + if (aEvent.SimId() == KLogNullSimId)
1.233 + nullFieldsBitMask |= ELogSimIdField;
1.234 + }
1.235 +#endif
1.236 +
1.237 + aFilter.SetNullFields(nullFieldsBitMask);
1.238 + // This is a special case, if all the fields are null
1.239 + // In this case we want to be a duplicate of other events where all the fields are null
1.240 + if (IsFilterEmpty(aFilter))
1.241 + aFilter.SetNullFields(iDuplicates);
1.242 + }
1.243 +
1.244 +TBool CLogServRecentList::IsFilterEmpty(const CLogFilter& aFilter) const
1.245 + {
1.246 + return aFilter.EventType() == KNullUid &&
1.247 + aFilter.RemoteParty().Length() == 0 &&
1.248 + aFilter.Direction().Length() == 0 &&
1.249 + aFilter.Status().Length() == 0 &&
1.250 + aFilter.Contact() == KLogNullContactId &&
1.251 + aFilter.Number().Length() == 0
1.252 +#ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.253 + &&
1.254 + aFilter.SimId() == KLogNullSimId
1.255 +#endif
1.256 + ;
1.257 + }
1.258 +