1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/loggingservices/eventlogger/LogWrap/src/LOGEVENT.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,319 @@
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 <logwrap.h>
1.20 +#include <logwraplimits.h>
1.21 +#include "logcntdef.h"
1.22 +#include "s32strm.h"
1.23 +#include "LOGPANIC.H"
1.24 +
1.25 +#ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.26 +
1.27 +/**
1.28 +This is the current version number of the event data, after the introduction of the "dual SIM support".
1.29 +New event properties in this version:
1.30 + - TInt iVersion;
1.31 + - TSimId iSimId;
1.32 +
1.33 +The data versioning was introduced together with the "dual SIM support" changes where a new data member was
1.34 +added to the CLogEvent class.
1.35 +The idea is to keep InternalizeL()/ExternalizeL() functionality binary compatibly in case of the unlikely event
1.36 +CLogEvent data gets persisted to a file for example.
1.37 +
1.38 +The old format of the externalized event data is:
1.39 + <id><type>.....<data length>[<optional: data>]
1.40 +
1.41 +The new format of the externalized event data is:
1.42 + <id><type>.....<uint: data version><data length>[<optional: data>]<simId>
1.43 +
1.44 +In case if CLogEvent::InternalizeL() reads from a stream with old event data, then:
1.45 +1) The data vesrion is read first as an integer.
1.46 +2) If the data version is negative then this is an event data with "dual SIM support",
1.47 + because the version number of that is positive integer above the KMaxTInt constant
1.48 + (interpreted as negative one if read as an integer from the stream)
1.49 +3) If the data version is positive then this is an event data without "dual SIM support".
1.50 +
1.51 +@internalComponent
1.52 +*/
1.53 +const TUint KLogEventDataVersion = 0x80000002U;
1.54 +
1.55 +#endif//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.56 +
1.57 +EXPORT_C CLogEvent* CLogEvent::NewL()
1.58 +/** Creates a new log event detail object.
1.59 +
1.60 +@return Pointer to the new log event detail object. */
1.61 + {
1.62 + CLogEvent* self = new(ELeave)CLogEvent;
1.63 + CleanupStack::PushL(self);
1.64 + self->ConstructL();
1.65 + CleanupStack::Pop(); // self
1.66 + return self;
1.67 + }
1.68 +
1.69 +CLogEvent::CLogEvent() :
1.70 + iId(KLogNullId),
1.71 + iEventType(KNullUid),
1.72 + iDurationType(KLogNullDurationType),
1.73 + iDuration(KLogNullDuration),
1.74 + iContact(KLogNullContactId),
1.75 + iLink(KLogNullLink),
1.76 + iFlags(KLogNullFlags)
1.77 + {
1.78 + }
1.79 +
1.80 +void CLogEvent::ConstructL()
1.81 + {
1.82 + iDescription = HBufC::NewL(KLogMaxDescriptionLength);
1.83 + iRemoteParty = HBufC::NewL(KLogMaxRemotePartyLength);
1.84 + iDirection = HBufC::NewL(KLogMaxDirectionLength);
1.85 + iStatus = HBufC::NewL(KLogMaxStatusLength);
1.86 + iSubject = HBufC::NewL(KLogMaxSubjectLength);
1.87 + iNumber = HBufC::NewL(KLogMaxNumberLength);
1.88 + }
1.89 +
1.90 +EXPORT_C CLogEvent::~CLogEvent()
1.91 +/** Frees all resources owned by the log event detail object. */
1.92 + {
1.93 + delete iDescription;
1.94 + delete iRemoteParty;
1.95 + delete iDirection;
1.96 + delete iStatus;
1.97 + delete iSubject;
1.98 + delete iNumber;
1.99 + delete iData;
1.100 + }
1.101 +
1.102 +EXPORT_C void CLogEvent::SetDataL(const TDesC8& aData)
1.103 +/** Sets event specific data.
1.104 +
1.105 +The data can be used for any purpose. The data is copied into a heap descriptor
1.106 +allocated by this function; the amount of data is only limited by the available
1.107 +memory.
1.108 +
1.109 +@param aData The event specific data. */
1.110 + {
1.111 + if (iData)
1.112 + {
1.113 + if (iData->Des().MaxLength() < aData.Length())
1.114 + iData = iData->ReAllocL(aData.Length());
1.115 + }
1.116 + else
1.117 + {
1.118 + if (aData.Length() > 0)
1.119 + iData = HBufC8::NewL(aData.Length());
1.120 + else
1.121 + return;
1.122 + }
1.123 +
1.124 + iData->Des().Copy(aData);
1.125 + }
1.126 +
1.127 +EXPORT_C void CLogEvent::SetDataL(RReadStream& aStream, TInt aLen)
1.128 +/** Sets event specific data from the specified stream.
1.129 +
1.130 +The data can be used for any purpose. The data is copied into a heap descriptor
1.131 +allocated by this function; the amount of data is only limited by the available
1.132 +memory.
1.133 +
1.134 +@param aStream The stream containing the event specific data.
1.135 +@param aLen The length of data to be read from the stream. */
1.136 + {
1.137 + HBufC8* buf = NULL;
1.138 +
1.139 + if (aLen > 0)
1.140 + {
1.141 + buf = HBufC8::NewLC(aLen);
1.142 + buf->Des().SetLength(aLen);
1.143 +
1.144 + TPtr8 ptr(buf->Des());
1.145 + aStream.ReadL(ptr, aLen);
1.146 +
1.147 + CleanupStack::Pop(); // buf
1.148 + }
1.149 +
1.150 + delete iData;
1.151 + iData = buf;
1.152 + }
1.153 +
1.154 +EXPORT_C void CLogEvent::CopyL(const CLogEvent& aEvent)
1.155 +/** Makes a copy of the specified log event.
1.156 +
1.157 +@param aEvent The log event to be copied. */
1.158 + {
1.159 + // Set data first as this is the only function that can leave
1.160 + // If this function fails nothing will be changed
1.161 + SetDataL(aEvent.Data());
1.162 +
1.163 + SetId(aEvent.Id());
1.164 + SetEventType(aEvent.EventType());
1.165 + SetTime(aEvent.Time());
1.166 + SetDurationType(aEvent.DurationType());
1.167 + SetDuration(aEvent.Duration());
1.168 + SetContact(aEvent.Contact());
1.169 + SetLink(aEvent.Link());
1.170 + SetDescription(aEvent.Description());
1.171 + SetRemoteParty(aEvent.RemoteParty());
1.172 + SetDirection(aEvent.Direction());
1.173 + SetStatus(aEvent.Status());
1.174 + SetSubject(aEvent.Subject());
1.175 + SetNumber(aEvent.Number());
1.176 +
1.177 + ClearFlags(KLogFlagsMask);
1.178 + SetFlags(aEvent.Flags());
1.179 +#ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.180 + SetSimId(aEvent.SimId());
1.181 +#endif
1.182 + }
1.183 +
1.184 +EXPORT_C void CLogEvent::InternalizeL(RReadStream& aStream)
1.185 + {
1.186 + iId = (TLogId) aStream.ReadInt32L();
1.187 + iEventType.iUid = aStream.ReadInt32L();
1.188 +
1.189 + TInt64 time;
1.190 + aStream >> time;
1.191 + iTime = time;
1.192 +
1.193 + iDurationType = (TLogDurationType) aStream.ReadInt8L();
1.194 + iDuration = (TLogDuration) aStream.ReadUint32L();
1.195 + iContact = (TLogContactItemId ) aStream.ReadInt32L();
1.196 + iLink = (TLogLink) aStream.ReadUint32L();
1.197 + iFlags = (TLogFlags) aStream.ReadUint8L();
1.198 +
1.199 + InternalizeBufL(aStream, iDescription);
1.200 + InternalizeBufL(aStream, iRemoteParty);
1.201 + InternalizeBufL(aStream, iDirection);
1.202 + InternalizeBufL(aStream, iStatus);
1.203 + InternalizeBufL(aStream, iSubject);
1.204 + InternalizeBufL(aStream, iNumber);
1.205 +
1.206 + TInt dataLen = aStream.ReadInt32L();
1.207 +#ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.208 + TUint dataVersion = 0;
1.209 + if(dataLen < 0)
1.210 + {
1.211 + //This is CLogEvent data version with dual SIM support.
1.212 + //The next property is the data length.
1.213 + dataVersion = (TUint)dataLen;
1.214 + dataLen = aStream.ReadInt32L();
1.215 + }
1.216 +#endif
1.217 + HBufC8* temp = NULL;
1.218 + if(dataLen != 0)
1.219 + {
1.220 + temp = HBufC8::NewL(aStream, dataLen);
1.221 + }
1.222 + delete iData;
1.223 + iData = temp;
1.224 +
1.225 +#ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.226 + if(dataVersion >= KLogEventDataVersion)
1.227 + {
1.228 + aStream >> iSimId;
1.229 + }
1.230 +#endif
1.231 + }
1.232 +
1.233 +void CLogEvent::InternalizeBufL(RReadStream& aStream, HBufC*& aDes)
1.234 + {
1.235 + TPtr ptr(aDes->Des());
1.236 + HBufC* temp = HBufC::NewL(aStream, ptr.MaxLength());
1.237 + ptr.Copy(*temp);
1.238 + delete temp;
1.239 + }
1.240 +
1.241 +EXPORT_C void CLogEvent::ExternalizeL(RWriteStream& aStream) const
1.242 + {
1.243 + aStream.WriteInt32L(iId);
1.244 + aStream.WriteInt32L(iEventType.iUid);
1.245 + aStream << iTime.Int64();
1.246 + aStream.WriteInt8L(iDurationType);
1.247 + aStream.WriteUint32L(iDuration);
1.248 + aStream.WriteInt32L(iContact);
1.249 + aStream.WriteUint32L(iLink);
1.250 + aStream.WriteInt8L(iFlags);
1.251 + aStream << *iDescription;
1.252 + aStream << *iRemoteParty;
1.253 + aStream << *iDirection;
1.254 + aStream << *iStatus;
1.255 + aStream << *iSubject;
1.256 + aStream << *iNumber;
1.257 +
1.258 +#ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.259 + aStream.WriteUint32L(KLogEventDataVersion);
1.260 +#endif
1.261 +
1.262 + TInt dataLength = 0;
1.263 + if(iData)
1.264 + {
1.265 + dataLength = iData->Length();
1.266 + }
1.267 + aStream.WriteInt32L(dataLength);
1.268 + if (iData && dataLength)
1.269 + {
1.270 + aStream << *iData;
1.271 + }
1.272 +#ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.273 + aStream << iSimId;
1.274 +#endif
1.275 + }
1.276 +
1.277 +#ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.278 +
1.279 +/**
1.280 +Sets the short Id of the SIM card being used.
1.281 +
1.282 +@param aSimId SIM card short Id;
1.283 +*/
1.284 +EXPORT_C void CLogEvent::SetSimId(TSimId aSimId)
1.285 + {//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is defined
1.286 + iSimId = aSimId;
1.287 + }
1.288 +
1.289 +/**
1.290 +Returns the short Id of the SIM card that was used.
1.291 +
1.292 +@return SIM card short Id;
1.293 +*/
1.294 +EXPORT_C TSimId CLogEvent::SimId() const
1.295 + {//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is defined
1.296 + return iSimId;
1.297 + }
1.298 +
1.299 +#else//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
1.300 +
1.301 +#pragma BullseyeCoverage off
1.302 +
1.303 +/**
1.304 +Not supported.
1.305 +*/
1.306 +EXPORT_C void CLogEvent::SetSimId(TSimId)
1.307 + {//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is not defined
1.308 + __ASSERT_ALWAYS(0, ::Panic(ELogDualSimNotSupported));
1.309 + }
1.310 +
1.311 +/**
1.312 +Not supported.
1.313 +*/
1.314 +EXPORT_C TSimId CLogEvent::SimId() const
1.315 + {//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is not defined
1.316 + __ASSERT_ALWAYS(0, ::Panic(ELogDualSimNotSupported));
1.317 + return 0;
1.318 + }
1.319 +
1.320 +#pragma BullseyeCoverage on
1.321 +
1.322 +#endif//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM