Update contrib.
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include <logwraplimits.h>
18 #include "logcntdef.h"
22 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
25 This is the current version number of the event data, after the introduction of the "dual SIM support".
26 New event properties in this version:
30 The data versioning was introduced together with the "dual SIM support" changes where a new data member was
31 added to the CLogEvent class.
32 The idea is to keep InternalizeL()/ExternalizeL() functionality binary compatibly in case of the unlikely event
33 CLogEvent data gets persisted to a file for example.
35 The old format of the externalized event data is:
36 <id><type>.....<data length>[<optional: data>]
38 The new format of the externalized event data is:
39 <id><type>.....<uint: data version><data length>[<optional: data>]<simId>
41 In case if CLogEvent::InternalizeL() reads from a stream with old event data, then:
42 1) The data vesrion is read first as an integer.
43 2) If the data version is negative then this is an event data with "dual SIM support",
44 because the version number of that is positive integer above the KMaxTInt constant
45 (interpreted as negative one if read as an integer from the stream)
46 3) If the data version is positive then this is an event data without "dual SIM support".
50 const TUint KLogEventDataVersion = 0x80000002U;
52 #endif//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
54 EXPORT_C CLogEvent* CLogEvent::NewL()
55 /** Creates a new log event detail object.
57 @return Pointer to the new log event detail object. */
59 CLogEvent* self = new(ELeave)CLogEvent;
60 CleanupStack::PushL(self);
62 CleanupStack::Pop(); // self
66 CLogEvent::CLogEvent() :
69 iDurationType(KLogNullDurationType),
70 iDuration(KLogNullDuration),
71 iContact(KLogNullContactId),
77 void CLogEvent::ConstructL()
79 iDescription = HBufC::NewL(KLogMaxDescriptionLength);
80 iRemoteParty = HBufC::NewL(KLogMaxRemotePartyLength);
81 iDirection = HBufC::NewL(KLogMaxDirectionLength);
82 iStatus = HBufC::NewL(KLogMaxStatusLength);
83 iSubject = HBufC::NewL(KLogMaxSubjectLength);
84 iNumber = HBufC::NewL(KLogMaxNumberLength);
87 EXPORT_C CLogEvent::~CLogEvent()
88 /** Frees all resources owned by the log event detail object. */
99 EXPORT_C void CLogEvent::SetDataL(const TDesC8& aData)
100 /** Sets event specific data.
102 The data can be used for any purpose. The data is copied into a heap descriptor
103 allocated by this function; the amount of data is only limited by the available
106 @param aData The event specific data. */
110 if (iData->Des().MaxLength() < aData.Length())
111 iData = iData->ReAllocL(aData.Length());
115 if (aData.Length() > 0)
116 iData = HBufC8::NewL(aData.Length());
121 iData->Des().Copy(aData);
124 EXPORT_C void CLogEvent::SetDataL(RReadStream& aStream, TInt aLen)
125 /** Sets event specific data from the specified stream.
127 The data can be used for any purpose. The data is copied into a heap descriptor
128 allocated by this function; the amount of data is only limited by the available
131 @param aStream The stream containing the event specific data.
132 @param aLen The length of data to be read from the stream. */
138 buf = HBufC8::NewLC(aLen);
139 buf->Des().SetLength(aLen);
141 TPtr8 ptr(buf->Des());
142 aStream.ReadL(ptr, aLen);
144 CleanupStack::Pop(); // buf
151 EXPORT_C void CLogEvent::CopyL(const CLogEvent& aEvent)
152 /** Makes a copy of the specified log event.
154 @param aEvent The log event to be copied. */
156 // Set data first as this is the only function that can leave
157 // If this function fails nothing will be changed
158 SetDataL(aEvent.Data());
161 SetEventType(aEvent.EventType());
162 SetTime(aEvent.Time());
163 SetDurationType(aEvent.DurationType());
164 SetDuration(aEvent.Duration());
165 SetContact(aEvent.Contact());
166 SetLink(aEvent.Link());
167 SetDescription(aEvent.Description());
168 SetRemoteParty(aEvent.RemoteParty());
169 SetDirection(aEvent.Direction());
170 SetStatus(aEvent.Status());
171 SetSubject(aEvent.Subject());
172 SetNumber(aEvent.Number());
174 ClearFlags(KLogFlagsMask);
175 SetFlags(aEvent.Flags());
176 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
177 SetSimId(aEvent.SimId());
181 EXPORT_C void CLogEvent::InternalizeL(RReadStream& aStream)
183 iId = (TLogId) aStream.ReadInt32L();
184 iEventType.iUid = aStream.ReadInt32L();
190 iDurationType = (TLogDurationType) aStream.ReadInt8L();
191 iDuration = (TLogDuration) aStream.ReadUint32L();
192 iContact = (TLogContactItemId ) aStream.ReadInt32L();
193 iLink = (TLogLink) aStream.ReadUint32L();
194 iFlags = (TLogFlags) aStream.ReadUint8L();
196 InternalizeBufL(aStream, iDescription);
197 InternalizeBufL(aStream, iRemoteParty);
198 InternalizeBufL(aStream, iDirection);
199 InternalizeBufL(aStream, iStatus);
200 InternalizeBufL(aStream, iSubject);
201 InternalizeBufL(aStream, iNumber);
203 TInt dataLen = aStream.ReadInt32L();
204 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
205 TUint dataVersion = 0;
208 //This is CLogEvent data version with dual SIM support.
209 //The next property is the data length.
210 dataVersion = (TUint)dataLen;
211 dataLen = aStream.ReadInt32L();
217 temp = HBufC8::NewL(aStream, dataLen);
222 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
223 if(dataVersion >= KLogEventDataVersion)
230 void CLogEvent::InternalizeBufL(RReadStream& aStream, HBufC*& aDes)
232 TPtr ptr(aDes->Des());
233 HBufC* temp = HBufC::NewL(aStream, ptr.MaxLength());
238 EXPORT_C void CLogEvent::ExternalizeL(RWriteStream& aStream) const
240 aStream.WriteInt32L(iId);
241 aStream.WriteInt32L(iEventType.iUid);
242 aStream << iTime.Int64();
243 aStream.WriteInt8L(iDurationType);
244 aStream.WriteUint32L(iDuration);
245 aStream.WriteInt32L(iContact);
246 aStream.WriteUint32L(iLink);
247 aStream.WriteInt8L(iFlags);
248 aStream << *iDescription;
249 aStream << *iRemoteParty;
250 aStream << *iDirection;
252 aStream << *iSubject;
255 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
256 aStream.WriteUint32L(KLogEventDataVersion);
262 dataLength = iData->Length();
264 aStream.WriteInt32L(dataLength);
265 if (iData && dataLength)
269 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
274 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
277 Sets the short Id of the SIM card being used.
279 @param aSimId SIM card short Id;
281 EXPORT_C void CLogEvent::SetSimId(TSimId aSimId)
282 {//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is defined
287 Returns the short Id of the SIM card that was used.
289 @return SIM card short Id;
291 EXPORT_C TSimId CLogEvent::SimId() const
292 {//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is defined
296 #else//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
298 #pragma BullseyeCoverage off
303 EXPORT_C void CLogEvent::SetSimId(TSimId)
304 {//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is not defined
305 __ASSERT_ALWAYS(0, ::Panic(ELogDualSimNotSupported));
311 EXPORT_C TSimId CLogEvent::SimId() const
312 {//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is not defined
313 __ASSERT_ALWAYS(0, ::Panic(ELogDualSimNotSupported));
317 #pragma BullseyeCoverage on
319 #endif//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM