sl@0: // Copyright (c) 2002-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 sl@0: #include sl@0: #include "logcntdef.h" sl@0: #include "s32strm.h" sl@0: #include "LOGPANIC.H" sl@0: sl@0: #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM sl@0: sl@0: /** sl@0: This is the current version number of the event data, after the introduction of the "dual SIM support". sl@0: New event properties in this version: sl@0: - TInt iVersion; sl@0: - TSimId iSimId; sl@0: sl@0: The data versioning was introduced together with the "dual SIM support" changes where a new data member was sl@0: added to the CLogEvent class. sl@0: The idea is to keep InternalizeL()/ExternalizeL() functionality binary compatibly in case of the unlikely event sl@0: CLogEvent data gets persisted to a file for example. sl@0: sl@0: The old format of the externalized event data is: sl@0: .....[] sl@0: sl@0: The new format of the externalized event data is: sl@0: .....[] sl@0: sl@0: In case if CLogEvent::InternalizeL() reads from a stream with old event data, then: sl@0: 1) The data vesrion is read first as an integer. sl@0: 2) If the data version is negative then this is an event data with "dual SIM support", sl@0: because the version number of that is positive integer above the KMaxTInt constant sl@0: (interpreted as negative one if read as an integer from the stream) sl@0: 3) If the data version is positive then this is an event data without "dual SIM support". sl@0: sl@0: @internalComponent sl@0: */ sl@0: const TUint KLogEventDataVersion = 0x80000002U; sl@0: sl@0: #endif//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM sl@0: sl@0: EXPORT_C CLogEvent* CLogEvent::NewL() sl@0: /** Creates a new log event detail object. sl@0: sl@0: @return Pointer to the new log event detail object. */ sl@0: { sl@0: CLogEvent* self = new(ELeave)CLogEvent; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); // self sl@0: return self; sl@0: } sl@0: sl@0: CLogEvent::CLogEvent() : sl@0: iId(KLogNullId), sl@0: iEventType(KNullUid), sl@0: iDurationType(KLogNullDurationType), sl@0: iDuration(KLogNullDuration), sl@0: iContact(KLogNullContactId), sl@0: iLink(KLogNullLink), sl@0: iFlags(KLogNullFlags) sl@0: { sl@0: } sl@0: sl@0: void CLogEvent::ConstructL() sl@0: { sl@0: iDescription = HBufC::NewL(KLogMaxDescriptionLength); sl@0: iRemoteParty = HBufC::NewL(KLogMaxRemotePartyLength); sl@0: iDirection = HBufC::NewL(KLogMaxDirectionLength); sl@0: iStatus = HBufC::NewL(KLogMaxStatusLength); sl@0: iSubject = HBufC::NewL(KLogMaxSubjectLength); sl@0: iNumber = HBufC::NewL(KLogMaxNumberLength); sl@0: } sl@0: sl@0: EXPORT_C CLogEvent::~CLogEvent() sl@0: /** Frees all resources owned by the log event detail object. */ sl@0: { sl@0: delete iDescription; sl@0: delete iRemoteParty; sl@0: delete iDirection; sl@0: delete iStatus; sl@0: delete iSubject; sl@0: delete iNumber; sl@0: delete iData; sl@0: } sl@0: sl@0: EXPORT_C void CLogEvent::SetDataL(const TDesC8& aData) sl@0: /** Sets event specific data. sl@0: sl@0: The data can be used for any purpose. The data is copied into a heap descriptor sl@0: allocated by this function; the amount of data is only limited by the available sl@0: memory. sl@0: sl@0: @param aData The event specific data. */ sl@0: { sl@0: if (iData) sl@0: { sl@0: if (iData->Des().MaxLength() < aData.Length()) sl@0: iData = iData->ReAllocL(aData.Length()); sl@0: } sl@0: else sl@0: { sl@0: if (aData.Length() > 0) sl@0: iData = HBufC8::NewL(aData.Length()); sl@0: else sl@0: return; sl@0: } sl@0: sl@0: iData->Des().Copy(aData); sl@0: } sl@0: sl@0: EXPORT_C void CLogEvent::SetDataL(RReadStream& aStream, TInt aLen) sl@0: /** Sets event specific data from the specified stream. sl@0: sl@0: The data can be used for any purpose. The data is copied into a heap descriptor sl@0: allocated by this function; the amount of data is only limited by the available sl@0: memory. sl@0: sl@0: @param aStream The stream containing the event specific data. sl@0: @param aLen The length of data to be read from the stream. */ sl@0: { sl@0: HBufC8* buf = NULL; sl@0: sl@0: if (aLen > 0) sl@0: { sl@0: buf = HBufC8::NewLC(aLen); sl@0: buf->Des().SetLength(aLen); sl@0: sl@0: TPtr8 ptr(buf->Des()); sl@0: aStream.ReadL(ptr, aLen); sl@0: sl@0: CleanupStack::Pop(); // buf sl@0: } sl@0: sl@0: delete iData; sl@0: iData = buf; sl@0: } sl@0: sl@0: EXPORT_C void CLogEvent::CopyL(const CLogEvent& aEvent) sl@0: /** Makes a copy of the specified log event. sl@0: sl@0: @param aEvent The log event to be copied. */ sl@0: { sl@0: // Set data first as this is the only function that can leave sl@0: // If this function fails nothing will be changed sl@0: SetDataL(aEvent.Data()); sl@0: sl@0: SetId(aEvent.Id()); sl@0: SetEventType(aEvent.EventType()); sl@0: SetTime(aEvent.Time()); sl@0: SetDurationType(aEvent.DurationType()); sl@0: SetDuration(aEvent.Duration()); sl@0: SetContact(aEvent.Contact()); sl@0: SetLink(aEvent.Link()); sl@0: SetDescription(aEvent.Description()); sl@0: SetRemoteParty(aEvent.RemoteParty()); sl@0: SetDirection(aEvent.Direction()); sl@0: SetStatus(aEvent.Status()); sl@0: SetSubject(aEvent.Subject()); sl@0: SetNumber(aEvent.Number()); sl@0: sl@0: ClearFlags(KLogFlagsMask); sl@0: SetFlags(aEvent.Flags()); sl@0: #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM sl@0: SetSimId(aEvent.SimId()); sl@0: #endif sl@0: } sl@0: sl@0: EXPORT_C void CLogEvent::InternalizeL(RReadStream& aStream) sl@0: { sl@0: iId = (TLogId) aStream.ReadInt32L(); sl@0: iEventType.iUid = aStream.ReadInt32L(); sl@0: sl@0: TInt64 time; sl@0: aStream >> time; sl@0: iTime = time; sl@0: sl@0: iDurationType = (TLogDurationType) aStream.ReadInt8L(); sl@0: iDuration = (TLogDuration) aStream.ReadUint32L(); sl@0: iContact = (TLogContactItemId ) aStream.ReadInt32L(); sl@0: iLink = (TLogLink) aStream.ReadUint32L(); sl@0: iFlags = (TLogFlags) aStream.ReadUint8L(); sl@0: sl@0: InternalizeBufL(aStream, iDescription); sl@0: InternalizeBufL(aStream, iRemoteParty); sl@0: InternalizeBufL(aStream, iDirection); sl@0: InternalizeBufL(aStream, iStatus); sl@0: InternalizeBufL(aStream, iSubject); sl@0: InternalizeBufL(aStream, iNumber); sl@0: sl@0: TInt dataLen = aStream.ReadInt32L(); sl@0: #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM sl@0: TUint dataVersion = 0; sl@0: if(dataLen < 0) sl@0: { sl@0: //This is CLogEvent data version with dual SIM support. sl@0: //The next property is the data length. sl@0: dataVersion = (TUint)dataLen; sl@0: dataLen = aStream.ReadInt32L(); sl@0: } sl@0: #endif sl@0: HBufC8* temp = NULL; sl@0: if(dataLen != 0) sl@0: { sl@0: temp = HBufC8::NewL(aStream, dataLen); sl@0: } sl@0: delete iData; sl@0: iData = temp; sl@0: sl@0: #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM sl@0: if(dataVersion >= KLogEventDataVersion) sl@0: { sl@0: aStream >> iSimId; sl@0: } sl@0: #endif sl@0: } sl@0: sl@0: void CLogEvent::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.Copy(*temp); sl@0: delete temp; sl@0: } sl@0: sl@0: EXPORT_C void CLogEvent::ExternalizeL(RWriteStream& aStream) const sl@0: { sl@0: aStream.WriteInt32L(iId); sl@0: aStream.WriteInt32L(iEventType.iUid); sl@0: aStream << iTime.Int64(); sl@0: aStream.WriteInt8L(iDurationType); sl@0: aStream.WriteUint32L(iDuration); sl@0: aStream.WriteInt32L(iContact); sl@0: aStream.WriteUint32L(iLink); sl@0: aStream.WriteInt8L(iFlags); sl@0: aStream << *iDescription; sl@0: aStream << *iRemoteParty; sl@0: aStream << *iDirection; sl@0: aStream << *iStatus; sl@0: aStream << *iSubject; sl@0: aStream << *iNumber; sl@0: sl@0: #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM sl@0: aStream.WriteUint32L(KLogEventDataVersion); sl@0: #endif sl@0: sl@0: TInt dataLength = 0; sl@0: if(iData) sl@0: { sl@0: dataLength = iData->Length(); sl@0: } sl@0: aStream.WriteInt32L(dataLength); sl@0: if (iData && dataLength) sl@0: { sl@0: aStream << *iData; sl@0: } 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 being used. sl@0: sl@0: @param aSimId SIM card short Id; sl@0: */ sl@0: EXPORT_C void CLogEvent::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 was used. sl@0: sl@0: @return SIM card short Id; sl@0: */ sl@0: EXPORT_C TSimId CLogEvent::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 CLogEvent::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 CLogEvent::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