1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "afentry.h" |
|
18 #include <s32mem.h> |
|
19 |
|
20 // ----------------------------------------------------------------------------- |
|
21 /** |
|
22 * Two-phase constructor. Create and initialize instance |
|
23 * @return entry instance |
|
24 */ |
|
25 CAfEntry* CAfEntry::NewL() |
|
26 { |
|
27 CAfEntry *self = CAfEntry::NewLC(); |
|
28 CleanupStack::Pop(self); |
|
29 return self; |
|
30 } |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 /** |
|
34 * Two-phase constructor. Create, initialize and push instance into cleanup stack |
|
35 * @return entry instance |
|
36 */ |
|
37 CAfEntry* CAfEntry::NewLC() |
|
38 { |
|
39 CAfEntry *self = new (ELeave)CAfEntry(); |
|
40 CleanupStack::PushL(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 /** |
|
46 * Two-phase constructor. Create and initialize instance |
|
47 * @param flags - entry flags |
|
48 * @param applicationId - application unique identifier |
|
49 * @param activityId - activity unique identifier |
|
50 * @param imgSrc - thumbanail source |
|
51 * @param privateData - privated application data |
|
52 * @param publicData - public activity data |
|
53 * @return entry instance |
|
54 */ |
|
55 CAfEntry* CAfEntry::NewL(TInt flags, |
|
56 TInt applicationId, |
|
57 const TDesC &activityId, |
|
58 const TDesC &imgSrc, |
|
59 const TDesC8 &privateData, |
|
60 const TDesC8 &publicData) |
|
61 { |
|
62 CAfEntry* self = CAfEntry::NewLC(flags, |
|
63 applicationId, |
|
64 activityId, |
|
65 imgSrc, |
|
66 privateData, |
|
67 publicData); |
|
68 CleanupStack::Pop(self); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 /** |
|
74 * Two-phase constructor. Create, initialize and push instance into cleanup stack |
|
75 * @param flags - entry flags |
|
76 * @param applicationId - application unique identifier |
|
77 * @param activityId - activity unique identifier |
|
78 * @param imgSrc - thumbanail source |
|
79 * @param privateData - privated application data |
|
80 * @param publicData - public activity data |
|
81 * @return entry instance |
|
82 */ |
|
83 CAfEntry* CAfEntry::NewLC(TInt flags, |
|
84 TInt applicationId, |
|
85 const TDesC &activityId, |
|
86 const TDesC &imgSrc, |
|
87 const TDesC8 &privateData, |
|
88 const TDesC8 &publicData) |
|
89 { |
|
90 CAfEntry *self = CAfEntry::NewLC(); |
|
91 self->ConstructL(flags, |
|
92 applicationId, |
|
93 activityId, |
|
94 imgSrc, |
|
95 privateData, |
|
96 publicData); |
|
97 return self; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 /** |
|
102 * First phase constructor |
|
103 */ |
|
104 CAfEntry::CAfEntry() |
|
105 { |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 /** |
|
110 * Second phase constructor. Initialize instance |
|
111 * @param flags - entry flags |
|
112 * @param applicationId - application unique identifier |
|
113 * @param activityId - activity unique identifier |
|
114 * @param imgSrc - thumbanail source |
|
115 * @param privateData - privated application data |
|
116 * @param publicData - public activity data |
|
117 */ |
|
118 void CAfEntry::ConstructL(TInt flags, |
|
119 TInt applicationId, |
|
120 const TDesC &activityId, |
|
121 const TDesC &imgSrc, |
|
122 const TDesC8 &privateData, |
|
123 const TDesC8 &publicData) |
|
124 { |
|
125 mFlags = flags; |
|
126 mAppId = applicationId; |
|
127 CopyL(mActivityId, activityId); |
|
128 CopyL(mImgSrc, imgSrc); |
|
129 CopyL(mPrivateData, privateData); |
|
130 CopyL(mPublicData, publicData); |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 /** |
|
135 * Destructor. Release allocated resources |
|
136 */ |
|
137 CAfEntry::~CAfEntry() |
|
138 { |
|
139 mActivityId.Close(); |
|
140 mPrivateData.Close(); |
|
141 mPublicData.Close(); |
|
142 mImgSrc.Close(); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 /** |
|
147 * Provide size of serialized entry |
|
148 * @return size of serialized entry instance |
|
149 */ |
|
150 TInt CAfEntry::Size() const |
|
151 { |
|
152 return (sizeof(TInt) * 3) + //flags + appId + actId size info |
|
153 mActivityId.Size() + //actId content size |
|
154 DataSize(); //data size |
|
155 |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 /** |
|
160 * Provide size of serialized entry |
|
161 * @return size of serialized entry instance |
|
162 */ |
|
163 TInt CAfEntry::DataSize() const |
|
164 { |
|
165 return (sizeof(TInt) * 3) + //privData size info + pubData size info + imgSrc size info |
|
166 mImgSrc.Size() + //imgSize content size |
|
167 mPrivateData.Size() + //privData content size |
|
168 mPublicData.Size(); //pubData content size |
|
169 } |
|
170 // ----------------------------------------------------------------------------- |
|
171 /** |
|
172 * Serialize entry content into output stream. |
|
173 * @param stream - output stream |
|
174 */ |
|
175 void CAfEntry::ExternalizeL(RWriteStream &stream) const |
|
176 { |
|
177 stream.WriteInt32L(mFlags); |
|
178 stream.WriteInt32L(mAppId); |
|
179 ExternalizeL(stream, mActivityId); |
|
180 ExternalizeDataOnlyL(stream); |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 /** |
|
185 * Deserialize entry content from input stream |
|
186 * @param stream - input stream |
|
187 */ |
|
188 void CAfEntry::InternalizeL(RReadStream &stream) |
|
189 { |
|
190 mFlags = stream.ReadInt32L(); |
|
191 mAppId = stream.ReadInt32L(); |
|
192 InternalizeL(mActivityId, stream); |
|
193 InternalizeDataOnlyL(stream); |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 /** |
|
198 * Serialize entry content into output stream. |
|
199 * @param stream - output stream |
|
200 */ |
|
201 void CAfEntry::ExternalizeDataOnlyL(RWriteStream &stream) const |
|
202 { |
|
203 ExternalizeL(stream, mImgSrc); |
|
204 ExternalizeL(stream, mPrivateData); |
|
205 ExternalizeL(stream, mPublicData); |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 /** |
|
210 * Deserialize entry content from input stream |
|
211 * @param stream - input stream |
|
212 */ |
|
213 void CAfEntry::InternalizeDataOnlyL(RReadStream &stream) |
|
214 { |
|
215 |
|
216 InternalizeL(mImgSrc, stream); |
|
217 InternalizeL(mPrivateData, stream); |
|
218 InternalizeL(mPublicData, stream); |
|
219 |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 /** |
|
224 * Provide access to activity flags |
|
225 * @return activity flags |
|
226 */ |
|
227 TInt CAfEntry::Flags() const |
|
228 { |
|
229 return mFlags; |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 /** |
|
234 * Provide access to activity identifier. |
|
235 * @return activity identifier |
|
236 */ |
|
237 TInt CAfEntry::ApplicationId() const |
|
238 { |
|
239 return mAppId; |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 /** |
|
244 * Provide access to activity identifier. |
|
245 * @return activity identifier |
|
246 */ |
|
247 const TDesC& CAfEntry::ActivityId() const |
|
248 { |
|
249 return mActivityId; |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 /** |
|
254 * Provide access to activity data. |
|
255 * @param rights - type of requested data |
|
256 * @return activity data |
|
257 */ |
|
258 const TDesC8& CAfEntry::Data(CAfEntry::AccessRights rights) const |
|
259 { |
|
260 return Private == rights ? mPrivateData : mPublicData; |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 /** |
|
265 * Provide access to activity data. |
|
266 * @param rights - type of requested data |
|
267 * @return activity data |
|
268 */ |
|
269 void CAfEntry::SetDataL(const TDesC8& src, CAfEntry::AccessRights rights) |
|
270 { |
|
271 CopyL(Private == rights ? mPrivateData : mPublicData, src); |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 /** |
|
276 * Provide access to activity thumbail path |
|
277 * @return path to activity thumbnail |
|
278 */ |
|
279 const TDesC& CAfEntry::ImageSrc() const |
|
280 { |
|
281 return mImgSrc; |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 /** |
|
286 * Set new value of image source |
|
287 */ |
|
288 void CAfEntry::SetImageSrcL(const TDesC& src) |
|
289 { |
|
290 CopyL(mImgSrc, src); |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 /** |
|
295 * Reallocate blob buffer to requested size |
|
296 * @param dst - destination buffer |
|
297 * @param length - requested length |
|
298 */ |
|
299 void CAfEntry::ReallocL(RBuf8 &dst,TInt length) |
|
300 { |
|
301 if (0 < length) { |
|
302 if (dst.MaxLength() < length) { |
|
303 dst.ReAllocL(length); |
|
304 } |
|
305 } else { |
|
306 dst.Close(); |
|
307 } |
|
308 } |
|
309 |
|
310 // ----------------------------------------------------------------------------- |
|
311 /** |
|
312 * Reallocate text buffer to requested size |
|
313 * @param dst - destination buffer |
|
314 * @param length - requested length |
|
315 */ |
|
316 void CAfEntry::ReallocL(RBuf &dst,TInt length) |
|
317 { |
|
318 if (0 < length) { |
|
319 if (dst.MaxLength() < length) { |
|
320 dst.ReAllocL(length); |
|
321 } |
|
322 } else { |
|
323 dst.Close(); |
|
324 } |
|
325 } |
|
326 // ----------------------------------------------------------------------------- |
|
327 /** |
|
328 * Copy blob content from input stream |
|
329 * @param dst - destination buffer |
|
330 * @param src - source buffer |
|
331 */ |
|
332 void CAfEntry::CopyL(RBuf8 &dst,const TDesC8 &src) |
|
333 { |
|
334 ReallocL(dst, src.Length()); |
|
335 if(0 < src.Length()) { |
|
336 dst.Copy(src); |
|
337 } |
|
338 } |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 /** |
|
342 * Copy text content from input buffer |
|
343 * @param dst - destination buffer |
|
344 * @param src - source buffer |
|
345 */ |
|
346 void CAfEntry::CopyL(RBuf &dst,const TDesC &src) |
|
347 { |
|
348 ReallocL(dst, src.Length()); |
|
349 if(0 < src.Length()) { |
|
350 dst.Copy(src); |
|
351 } |
|
352 } |
|
353 |
|
354 // ----------------------------------------------------------------------------- |
|
355 /** |
|
356 * Deserialize blob content from input stream |
|
357 * @param dst - destination buffer |
|
358 * @param src - input stream |
|
359 */ |
|
360 void CAfEntry::InternalizeL(RBuf8 &dst, RReadStream &src) |
|
361 { |
|
362 const TInt length(src.ReadInt32L()); |
|
363 ReallocL(dst, length); |
|
364 if (0 < length) { |
|
365 src.ReadL(dst, length); |
|
366 } |
|
367 } |
|
368 |
|
369 // ----------------------------------------------------------------------------- |
|
370 /** |
|
371 * Deserialize text content from input stream |
|
372 * @param dst - destination buffer |
|
373 * @param src - input stream |
|
374 */ |
|
375 void CAfEntry::InternalizeL(RBuf &dst, RReadStream &src) |
|
376 { |
|
377 const TInt length(src.ReadInt32L()); |
|
378 ReallocL(dst, length); |
|
379 if (0 < length) { |
|
380 src.ReadL(dst, length); |
|
381 } |
|
382 } |
|
383 |
|
384 // ----------------------------------------------------------------------------- |
|
385 /** |
|
386 * Serialize blob content into output stream |
|
387 * @param dst - destination stream |
|
388 * @param src - input buffer |
|
389 */ |
|
390 void CAfEntry::ExternalizeL(RWriteStream &dst,const TDesC8 & src) |
|
391 { |
|
392 dst.WriteInt32L(src.Length()); |
|
393 if (src.Length()) { |
|
394 dst.WriteL(src, src.Length()); |
|
395 } |
|
396 } |
|
397 |
|
398 // ----------------------------------------------------------------------------- |
|
399 /** |
|
400 * Serialize text content into output stream |
|
401 * @param dst - destination stream |
|
402 * @param src - input buffer |
|
403 */ |
|
404 void CAfEntry::ExternalizeL(RWriteStream &dst,const TDesC& src) |
|
405 { |
|
406 dst.WriteInt32L(src.Length()); |
|
407 if (src.Length()) { |
|
408 dst.WriteL(src, src.Length()); |
|
409 } |
|
410 } |
|
411 |
|
412 // ----------------------------------------------------------------------------- |
|
413 RPointerArray<CAfEntry>& operator <<(RPointerArray<CAfEntry>& dst, const TDesC8 &src) |
|
414 { |
|
415 dst.ResetAndDestroy(); |
|
416 RDesReadStream srcStream(src); |
|
417 CleanupClosePushL(srcStream); |
|
418 int numOfItems(srcStream.ReadInt32L()); |
|
419 for (int i(0); i < numOfItems; ++i) { |
|
420 CAfEntry *entry = CAfEntry::NewLC(); |
|
421 srcStream >> (*entry); |
|
422 dst.AppendL(entry); |
|
423 CleanupStack::Pop(entry); |
|
424 } |
|
425 CleanupStack::PopAndDestroy(&srcStream); |
|
426 return dst; |
|
427 } |
|
428 |
|
429 // ----------------------------------------------------------------------------- |
|
430 RBuf8& operator <<(RBuf8 &dst, const RPointerArray<CAfEntry>& src) |
|
431 { |
|
432 int iter(0), |
|
433 requiredSize(sizeof(int)); |
|
434 for(iter =0; iter< src.Count(); ++iter) { |
|
435 requiredSize += src[iter]->Size(); |
|
436 } |
|
437 CAfEntry::ReallocL(dst, requiredSize); |
|
438 RDesWriteStream dstStream(dst); |
|
439 CleanupClosePushL(dstStream); |
|
440 dstStream.WriteInt32L(src.Count()); |
|
441 for (iter =0; iter < src.Count(); ++iter) { |
|
442 dstStream << *(src[iter]); |
|
443 } |
|
444 CleanupStack::PopAndDestroy(&dstStream); |
|
445 return dst; |
|
446 } |
|