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