sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include <logcli.h>
sl@0: #include <logwraplimits.h>
sl@0: #include "LogCliServShared.h"
sl@0: #include "logcntdef.h"
sl@0: #include "logclipanic.h"
sl@0: 
sl@0: const TInt KLogFilterListGranuality = 10;
sl@0: 
sl@0: //**********************************
sl@0: // CLogFilter
sl@0: //**********************************
sl@0: 
sl@0: /** Creates a new filter object.
sl@0: 
sl@0: All fields in the new instance are initialised to default values, so that 
sl@0: if none of the fields are changed, the filter has no effect on the selection 
sl@0: of events in view.
sl@0: 
sl@0: @return A pointer to the new event object. */
sl@0: EXPORT_C CLogFilter* CLogFilter::NewL()
sl@0: 	{
sl@0: 	CLogFilter* self = new(ELeave)CLogFilter;
sl@0: 	CleanupStack::PushL(self);
sl@0: 	self->ConstructL();
sl@0: 	CleanupStack::Pop(); // self
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: CLogFilter::CLogFilter()
sl@0: : iDurationType(KLogNullDurationType), iContact(KLogNullContactId), iFlags(KLogNullFlags),
sl@0: iStartTime(TTime(0)), iEndTime(TTime(0))
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: void CLogFilter::ConstructL()
sl@0: 	{
sl@0: 	iRemoteParty = HBufC::NewL(KLogMaxRemotePartyLength);
sl@0: 	iDirection = HBufC::NewL(KLogMaxDirectionLength);
sl@0: 	iStatus = HBufC::NewL(KLogMaxStatusLength);
sl@0: 	iNumber = HBufC::NewL(KLogMaxNumberLength);
sl@0: 	}
sl@0: 
sl@0: /** Frees all resource owned by the object prior to its destruction. */
sl@0: EXPORT_C CLogFilter::~CLogFilter()
sl@0: 	{
sl@0: 	delete iRemoteParty;
sl@0: 	delete iDirection;
sl@0: 	delete iStatus;
sl@0: 	delete iNumber;
sl@0: 	}
sl@0: 
sl@0: /** Makes a copy of a filter.
sl@0: 
sl@0: @param aFilter The filter object to be copied. */
sl@0: EXPORT_C void CLogFilter::Copy(const CLogFilter& aFilter)
sl@0: 	{
sl@0: 	SetEventType(aFilter.EventType());
sl@0: 	SetDurationType(aFilter.DurationType());
sl@0: 	SetContact(aFilter.Contact());
sl@0: 	SetRemoteParty(aFilter.RemoteParty());
sl@0: 	SetDirection(aFilter.Direction());
sl@0: 	SetStatus(aFilter.Status());
sl@0: 	SetNumber(aFilter.Number());
sl@0: 	SetNullFields(aFilter.NullFields());
sl@0: 
sl@0: 	ClearFlags(KLogFlagsMask);
sl@0: 	SetFlags(aFilter.Flags());
sl@0: #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
sl@0: 	SetSimId(aFilter.SimId());
sl@0: #endif
sl@0: 	}
sl@0: 
sl@0: void CLogFilter::InternalizeL(RReadStream& aStream)
sl@0: 	{
sl@0: 	TBuf<KLogMaxDateLength> buf;
sl@0: 	aStream >> iEventType;
sl@0: 	aStream >> iDurationType;
sl@0: 	aStream >> iContact;
sl@0: 	InternalizeBufL(aStream, iRemoteParty);
sl@0: 	InternalizeBufL(aStream, iDirection);
sl@0: 	InternalizeBufL(aStream, iStatus);
sl@0: 	InternalizeBufL(aStream, iNumber);
sl@0: 	aStream >> iNullFields;
sl@0: 	aStream >> iFlags;
sl@0: 	aStream >> buf;
sl@0: 	iStartTime.Parse(buf);
sl@0: 	buf.FillZ();
sl@0: 	aStream >> buf;
sl@0: 	iEndTime.Parse(buf);
sl@0: #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
sl@0: 	aStream >> iSimId;
sl@0: #endif
sl@0: 	}
sl@0: 
sl@0: void CLogFilter::InternalizeBufL(RReadStream& aStream, HBufC*& aDes)
sl@0: 	{
sl@0: 	TPtr ptr(aDes->Des());
sl@0: 	HBufC* temp = HBufC::NewL(aStream, ptr.MaxLength());
sl@0: 	ptr.Zero();
sl@0: 	ptr.Copy(*temp);
sl@0: 	delete temp;
sl@0: 	}
sl@0: 
sl@0: void CLogFilter::ExternalizeL(RWriteStream& aStream) const
sl@0: 	{
sl@0: 	TBuf<KLogMaxDateLength> buf;  
sl@0: 	aStream << iEventType;
sl@0: 	aStream << iDurationType;
sl@0: 	aStream << iContact;
sl@0: 	aStream << *iRemoteParty;
sl@0: 	aStream << *iDirection;
sl@0: 	aStream << *iStatus;
sl@0: 	aStream << *iNumber;
sl@0: 	aStream << iNullFields;
sl@0: 	aStream << iFlags;
sl@0: 	if (iStartTime != TTime(0))
sl@0: 		iStartTime.FormatL(buf, LogUtils::DateFormatForLocale());
sl@0: 	aStream << buf;
sl@0: 	buf.FillZ();
sl@0: 	if (iEndTime != TTime(0))
sl@0: 		iEndTime.FormatL(buf, LogUtils::DateFormatForLocale());
sl@0: 	aStream << buf;
sl@0: #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
sl@0: 	aStream << iSimId;
sl@0: #endif
sl@0: 	}
sl@0: 
sl@0: #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
sl@0: 
sl@0: /**
sl@0: Sets the short Id of the SIM card that will be used by the filter.
sl@0: 
sl@0: @param aSimId SIM card short Id;  
sl@0: */
sl@0: EXPORT_C void CLogFilter::SetSimId(TSimId aSimId)
sl@0: 	{//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is defined
sl@0: 	iSimId = aSimId;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: Returns the short Id of the SIM card that is used by the filter.
sl@0: 
sl@0: @return SIM card short Id;  
sl@0: */
sl@0: EXPORT_C TSimId CLogFilter::SimId() const
sl@0: 	{//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is defined
sl@0: 	return iSimId;
sl@0: 	}
sl@0: 
sl@0: #else//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
sl@0: 
sl@0: #pragma BullseyeCoverage off
sl@0: 
sl@0: /**
sl@0: Not supported. 
sl@0: */
sl@0: EXPORT_C void CLogFilter::SetSimId(TSimId)
sl@0: 	{//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is not defined
sl@0: 	__ASSERT_ALWAYS(0, ::Panic(ELogDualSimNotSupported));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: Not supported. 
sl@0: */
sl@0: EXPORT_C TSimId CLogFilter::SimId() const
sl@0: 	{//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is not defined
sl@0: 	__ASSERT_ALWAYS(0, ::Panic(ELogDualSimNotSupported));
sl@0: 	return 0;
sl@0: 	}
sl@0: 
sl@0: #pragma BullseyeCoverage on
sl@0: 
sl@0: #endif//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
sl@0: 
sl@0: //**********************************
sl@0: // CLogFilterList
sl@0: //**********************************
sl@0: 
sl@0: /** Constructs a flat array of pointers to const CLogFilter objects. */
sl@0: EXPORT_C CLogFilterList::CLogFilterList()
sl@0: : CArrayPtrFlat<const CLogFilter>(KLogFilterListGranuality)
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: /** Creates a copy of this set of event view filters.
sl@0: 
sl@0: @return A pointer to the new copy of the set of event view filters. */
sl@0: EXPORT_C CLogFilterList* CLogFilterList::CopyL() const
sl@0: 	{
sl@0: 	CLogFilterList* newList = CopyLC();
sl@0: 	CleanupStack::Pop();
sl@0: 	return newList;
sl@0: 	}
sl@0: 
sl@0: /** Creates a copy of this set of event view filters and puts a pointer to the 
sl@0: copy onto the cleanup stack.
sl@0: 
sl@0: @return A pointer to the new copy of the set of event view filters. */
sl@0: EXPORT_C CLogFilterList* CLogFilterList::CopyLC() const
sl@0: 	{
sl@0: 	CLogFilterList* newList = new(ELeave)CLogFilterList;
sl@0: 	CleanupStack::PushL(newList);
sl@0: 	if (Count())
sl@0: 		{
sl@0: 		newList->ResizeL(Count(), NULL);
sl@0: 		Mem::Copy(newList->Back(0), Back(0), Count() * sizeof(const CLogFilter*));	
sl@0: 		}
sl@0: 	return newList;
sl@0: 	}
sl@0: 
sl@0: void CLogFilterList::InternalizeL(RReadStream& aStream)
sl@0: 	{
sl@0: 	ResetAndDestroy();
sl@0: 	TInt count;
sl@0: 	count = aStream.ReadInt32L();
sl@0: 	while(count--)
sl@0: 		{
sl@0: 		CLogFilter* filter = CLogFilter::NewL();
sl@0: 		CleanupStack::PushL(filter);
sl@0: 		filter->InternalizeL(aStream);
sl@0: 		AppendL(filter); 
sl@0: 		CleanupStack::Pop(filter);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: void CLogFilterList::ExternalizeL(RWriteStream& aStream) const
sl@0: 	{
sl@0: 	aStream.WriteInt32L(Count());	
sl@0: 	for(TInt index = 0; index < Count(); index++)
sl@0: 		{
sl@0: 		At(index)->ExternalizeL(aStream);
sl@0: 		}
sl@0: 	}