|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <logwrap.h> |
|
17 #include <logwraplimits.h> |
|
18 #include "logcntdef.h" |
|
19 #include "s32strm.h" |
|
20 #include "LOGPANIC.H" |
|
21 |
|
22 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
23 |
|
24 /** |
|
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: |
|
27 - TInt iVersion; |
|
28 - TSimId iSimId; |
|
29 |
|
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. |
|
34 |
|
35 The old format of the externalized event data is: |
|
36 <id><type>.....<data length>[<optional: data>] |
|
37 |
|
38 The new format of the externalized event data is: |
|
39 <id><type>.....<uint: data version><data length>[<optional: data>]<simId> |
|
40 |
|
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". |
|
47 |
|
48 @internalComponent |
|
49 */ |
|
50 const TUint KLogEventDataVersion = 0x80000002U; |
|
51 |
|
52 #endif//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
53 |
|
54 EXPORT_C CLogEvent* CLogEvent::NewL() |
|
55 /** Creates a new log event detail object. |
|
56 |
|
57 @return Pointer to the new log event detail object. */ |
|
58 { |
|
59 CLogEvent* self = new(ELeave)CLogEvent; |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop(); // self |
|
63 return self; |
|
64 } |
|
65 |
|
66 CLogEvent::CLogEvent() : |
|
67 iId(KLogNullId), |
|
68 iEventType(KNullUid), |
|
69 iDurationType(KLogNullDurationType), |
|
70 iDuration(KLogNullDuration), |
|
71 iContact(KLogNullContactId), |
|
72 iLink(KLogNullLink), |
|
73 iFlags(KLogNullFlags) |
|
74 { |
|
75 } |
|
76 |
|
77 void CLogEvent::ConstructL() |
|
78 { |
|
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); |
|
85 } |
|
86 |
|
87 EXPORT_C CLogEvent::~CLogEvent() |
|
88 /** Frees all resources owned by the log event detail object. */ |
|
89 { |
|
90 delete iDescription; |
|
91 delete iRemoteParty; |
|
92 delete iDirection; |
|
93 delete iStatus; |
|
94 delete iSubject; |
|
95 delete iNumber; |
|
96 delete iData; |
|
97 } |
|
98 |
|
99 EXPORT_C void CLogEvent::SetDataL(const TDesC8& aData) |
|
100 /** Sets event specific data. |
|
101 |
|
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 |
|
104 memory. |
|
105 |
|
106 @param aData The event specific data. */ |
|
107 { |
|
108 if (iData) |
|
109 { |
|
110 if (iData->Des().MaxLength() < aData.Length()) |
|
111 iData = iData->ReAllocL(aData.Length()); |
|
112 } |
|
113 else |
|
114 { |
|
115 if (aData.Length() > 0) |
|
116 iData = HBufC8::NewL(aData.Length()); |
|
117 else |
|
118 return; |
|
119 } |
|
120 |
|
121 iData->Des().Copy(aData); |
|
122 } |
|
123 |
|
124 EXPORT_C void CLogEvent::SetDataL(RReadStream& aStream, TInt aLen) |
|
125 /** Sets event specific data from the specified stream. |
|
126 |
|
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 |
|
129 memory. |
|
130 |
|
131 @param aStream The stream containing the event specific data. |
|
132 @param aLen The length of data to be read from the stream. */ |
|
133 { |
|
134 HBufC8* buf = NULL; |
|
135 |
|
136 if (aLen > 0) |
|
137 { |
|
138 buf = HBufC8::NewLC(aLen); |
|
139 buf->Des().SetLength(aLen); |
|
140 |
|
141 TPtr8 ptr(buf->Des()); |
|
142 aStream.ReadL(ptr, aLen); |
|
143 |
|
144 CleanupStack::Pop(); // buf |
|
145 } |
|
146 |
|
147 delete iData; |
|
148 iData = buf; |
|
149 } |
|
150 |
|
151 EXPORT_C void CLogEvent::CopyL(const CLogEvent& aEvent) |
|
152 /** Makes a copy of the specified log event. |
|
153 |
|
154 @param aEvent The log event to be copied. */ |
|
155 { |
|
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()); |
|
159 |
|
160 SetId(aEvent.Id()); |
|
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()); |
|
173 |
|
174 ClearFlags(KLogFlagsMask); |
|
175 SetFlags(aEvent.Flags()); |
|
176 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
177 SetSimId(aEvent.SimId()); |
|
178 #endif |
|
179 } |
|
180 |
|
181 EXPORT_C void CLogEvent::InternalizeL(RReadStream& aStream) |
|
182 { |
|
183 iId = (TLogId) aStream.ReadInt32L(); |
|
184 iEventType.iUid = aStream.ReadInt32L(); |
|
185 |
|
186 TInt64 time; |
|
187 aStream >> time; |
|
188 iTime = time; |
|
189 |
|
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(); |
|
195 |
|
196 InternalizeBufL(aStream, iDescription); |
|
197 InternalizeBufL(aStream, iRemoteParty); |
|
198 InternalizeBufL(aStream, iDirection); |
|
199 InternalizeBufL(aStream, iStatus); |
|
200 InternalizeBufL(aStream, iSubject); |
|
201 InternalizeBufL(aStream, iNumber); |
|
202 |
|
203 TInt dataLen = aStream.ReadInt32L(); |
|
204 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
205 TUint dataVersion = 0; |
|
206 if(dataLen < 0) |
|
207 { |
|
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(); |
|
212 } |
|
213 #endif |
|
214 HBufC8* temp = NULL; |
|
215 if(dataLen != 0) |
|
216 { |
|
217 temp = HBufC8::NewL(aStream, dataLen); |
|
218 } |
|
219 delete iData; |
|
220 iData = temp; |
|
221 |
|
222 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
223 if(dataVersion >= KLogEventDataVersion) |
|
224 { |
|
225 aStream >> iSimId; |
|
226 } |
|
227 #endif |
|
228 } |
|
229 |
|
230 void CLogEvent::InternalizeBufL(RReadStream& aStream, HBufC*& aDes) |
|
231 { |
|
232 TPtr ptr(aDes->Des()); |
|
233 HBufC* temp = HBufC::NewL(aStream, ptr.MaxLength()); |
|
234 ptr.Copy(*temp); |
|
235 delete temp; |
|
236 } |
|
237 |
|
238 EXPORT_C void CLogEvent::ExternalizeL(RWriteStream& aStream) const |
|
239 { |
|
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; |
|
251 aStream << *iStatus; |
|
252 aStream << *iSubject; |
|
253 aStream << *iNumber; |
|
254 |
|
255 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
256 aStream.WriteUint32L(KLogEventDataVersion); |
|
257 #endif |
|
258 |
|
259 TInt dataLength = 0; |
|
260 if(iData) |
|
261 { |
|
262 dataLength = iData->Length(); |
|
263 } |
|
264 aStream.WriteInt32L(dataLength); |
|
265 if (iData && dataLength) |
|
266 { |
|
267 aStream << *iData; |
|
268 } |
|
269 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
270 aStream << iSimId; |
|
271 #endif |
|
272 } |
|
273 |
|
274 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
275 |
|
276 /** |
|
277 Sets the short Id of the SIM card being used. |
|
278 |
|
279 @param aSimId SIM card short Id; |
|
280 */ |
|
281 EXPORT_C void CLogEvent::SetSimId(TSimId aSimId) |
|
282 {//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is defined |
|
283 iSimId = aSimId; |
|
284 } |
|
285 |
|
286 /** |
|
287 Returns the short Id of the SIM card that was used. |
|
288 |
|
289 @return SIM card short Id; |
|
290 */ |
|
291 EXPORT_C TSimId CLogEvent::SimId() const |
|
292 {//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is defined |
|
293 return iSimId; |
|
294 } |
|
295 |
|
296 #else//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
297 |
|
298 #pragma BullseyeCoverage off |
|
299 |
|
300 /** |
|
301 Not supported. |
|
302 */ |
|
303 EXPORT_C void CLogEvent::SetSimId(TSimId) |
|
304 {//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is not defined |
|
305 __ASSERT_ALWAYS(0, ::Panic(ELogDualSimNotSupported)); |
|
306 } |
|
307 |
|
308 /** |
|
309 Not supported. |
|
310 */ |
|
311 EXPORT_C TSimId CLogEvent::SimId() const |
|
312 {//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is not defined |
|
313 __ASSERT_ALWAYS(0, ::Panic(ELogDualSimNotSupported)); |
|
314 return 0; |
|
315 } |
|
316 |
|
317 #pragma BullseyeCoverage on |
|
318 |
|
319 #endif//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |