|
1 // Copyright (c) 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 /** |
|
17 @file |
|
18 @internalTechnology |
|
19 */ |
|
20 |
|
21 #include <e32base.h> |
|
22 |
|
23 #include "cmediasyncdatawriter.h" |
|
24 |
|
25 CMediaSyncDataWriter* CMediaSyncDataWriter::NewLC(const RChunk& aChunk) |
|
26 { |
|
27 CMediaSyncDataWriter* self = new(ELeave) CMediaSyncDataWriter(); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(aChunk); |
|
30 return self; |
|
31 } |
|
32 |
|
33 CMediaSyncDataWriter::~CMediaSyncDataWriter() |
|
34 { |
|
35 |
|
36 } |
|
37 |
|
38 CMediaSyncDataWriter::CMediaSyncDataWriter() |
|
39 { |
|
40 |
|
41 } |
|
42 |
|
43 void CMediaSyncDataWriter::ConstructL(const RChunk& aChunk) |
|
44 { |
|
45 TUint8* base = aChunk.Base(); |
|
46 User::LeaveIfNull(base); |
|
47 |
|
48 iHeaderInfo = reinterpret_cast<TDataHeaderInfo*>(base); |
|
49 iHeaderInfo->iCount = 0; |
|
50 iWriteBase = base + sizeof(TDataHeaderInfo); |
|
51 iMaxSize = aChunk.MaxSize() - sizeof(TDataHeaderInfo); |
|
52 iOffset = 0; |
|
53 } |
|
54 |
|
55 TInt CMediaSyncDataWriter::FreeSpaceBytes() |
|
56 { |
|
57 return (iMaxSize - iOffset); |
|
58 } |
|
59 |
|
60 inline void CMediaSyncDataWriter::CheckBufferCapacityL(TInt aReqSize) |
|
61 { |
|
62 if (aReqSize > (iMaxSize - iOffset)) |
|
63 { |
|
64 User::Leave(KErrOverflow); |
|
65 } |
|
66 } |
|
67 |
|
68 void CMediaSyncDataWriter::AppendEntryL(TUint32 aObjectId, TUint8 aType, const TDesC& aUri) |
|
69 { |
|
70 //copy object id |
|
71 CheckBufferCapacityL(sizeof(TUint32)); |
|
72 Mem::Copy((iWriteBase + iOffset), &aObjectId, sizeof(TUint32)); |
|
73 iOffset += sizeof(TUint32); |
|
74 |
|
75 //copy notification type |
|
76 CheckBufferCapacityL(sizeof(TUint8)); |
|
77 Mem::Copy((iWriteBase + iOffset), &aType, sizeof(TUint8)); |
|
78 iOffset += sizeof(TUint8); |
|
79 |
|
80 //copy uri length |
|
81 CheckBufferCapacityL(sizeof(TUint8)); |
|
82 TUint8 uriLen = aUri.Length(); |
|
83 Mem::Copy((iWriteBase + iOffset), &uriLen, sizeof(TUint8)); |
|
84 iOffset += sizeof(TUint8); |
|
85 if (uriLen > 0) |
|
86 { |
|
87 //copy uri content |
|
88 CheckBufferCapacityL(aUri.Size()); |
|
89 TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(aUri.Ptr())), aUri.Size(), aUri.Size()); |
|
90 Mem::Copy((iWriteBase + iOffset), ptr.Ptr(), ptr.Size()); |
|
91 iOffset += ptr.Size(); |
|
92 } |
|
93 |
|
94 ++iHeaderInfo->iCount; |
|
95 } |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |