|
1 // Copyright (c) 2006-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 @publishedPartner |
|
19 */ |
|
20 |
|
21 #include <mtp/mtpdatatypeconstants.h> |
|
22 #include <mtp/cmtptypeopaquedata.h> |
|
23 |
|
24 |
|
25 const TInt KMaxSizeOfWriteBuffer = 0x00010000; // 64KB |
|
26 |
|
27 EXPORT_C CMTPTypeOpaqueData* CMTPTypeOpaqueData::NewL() |
|
28 { |
|
29 CMTPTypeOpaqueData* self = NewLC(); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 EXPORT_C CMTPTypeOpaqueData* CMTPTypeOpaqueData::NewLC() |
|
35 { |
|
36 CMTPTypeOpaqueData* self = new(ELeave) CMTPTypeOpaqueData(); |
|
37 CleanupStack::PushL(self); |
|
38 self->ConstructL(); |
|
39 return self; |
|
40 } |
|
41 |
|
42 EXPORT_C CMTPTypeOpaqueData* CMTPTypeOpaqueData::NewL(const TDesC8 &aDes) |
|
43 { |
|
44 CMTPTypeOpaqueData* self = NewLC(aDes); |
|
45 CleanupStack::Pop(self); |
|
46 return self; |
|
47 } |
|
48 |
|
49 EXPORT_C CMTPTypeOpaqueData* CMTPTypeOpaqueData::NewLC(const TDesC8 &aDes) |
|
50 { |
|
51 CMTPTypeOpaqueData* self = new(ELeave) CMTPTypeOpaqueData(); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(aDes); |
|
54 return self; |
|
55 } |
|
56 |
|
57 void CMTPTypeOpaqueData::ConstructL() |
|
58 { |
|
59 |
|
60 } |
|
61 |
|
62 CMTPTypeOpaqueData::CMTPTypeOpaqueData(): |
|
63 iPtrBuffer(NULL, 0) |
|
64 { |
|
65 |
|
66 } |
|
67 |
|
68 EXPORT_C CMTPTypeOpaqueData::~CMTPTypeOpaqueData() |
|
69 { |
|
70 iBuffer.Close(); |
|
71 } |
|
72 |
|
73 void CMTPTypeOpaqueData::ConstructL(const TDesC8 &aDes) |
|
74 { |
|
75 iPtrBuffer.Set(const_cast<TUint8*>(aDes.Ptr()), aDes.Length(), aDes.Size()); |
|
76 } |
|
77 |
|
78 EXPORT_C TInt CMTPTypeOpaqueData::FirstReadChunk(TPtrC8& aChunk) const |
|
79 { |
|
80 aChunk.Set(iPtrBuffer); |
|
81 |
|
82 return KMTPChunkSequenceCompletion; |
|
83 } |
|
84 |
|
85 EXPORT_C TInt CMTPTypeOpaqueData::NextReadChunk(TPtrC8& aChunk) const |
|
86 { |
|
87 aChunk.Set(NULL, 0); |
|
88 return KErrNotReady; |
|
89 } |
|
90 |
|
91 TInt CMTPTypeOpaqueData::CreateBuffer( const TInt aMaxSize ) |
|
92 { |
|
93 TInt err = iBuffer.Create( aMaxSize ); |
|
94 if( KErrNone != err) |
|
95 return err; |
|
96 |
|
97 iPtrBuffer.Set(const_cast<TUint8*>(iBuffer.Ptr()), 0, aMaxSize); |
|
98 |
|
99 return KErrNone; |
|
100 } |
|
101 |
|
102 EXPORT_C TInt CMTPTypeOpaqueData::FirstWriteChunk(TPtr8& aChunk) |
|
103 { |
|
104 if(iPtrBuffer.MaxSize() == 0) |
|
105 { |
|
106 TInt err = CreateBuffer( KMaxSizeOfWriteBuffer ); |
|
107 if( KErrNone != err) |
|
108 return err; |
|
109 } |
|
110 |
|
111 aChunk.Set( const_cast<TUint8*>(iPtrBuffer.Ptr()), 0, iPtrBuffer.MaxSize()); |
|
112 |
|
113 return KMTPChunkSequenceCompletion; |
|
114 } |
|
115 |
|
116 EXPORT_C TInt CMTPTypeOpaqueData::FirstWriteChunk(TPtr8& aChunk, TUint aDataLength ) |
|
117 { |
|
118 if(KMaxSizeOfWriteBuffer < aDataLength ) |
|
119 return KErrOverflow; |
|
120 |
|
121 TInt size = aDataLength; |
|
122 if( aDataLength <= 0 ) |
|
123 { |
|
124 size = KMaxSizeOfWriteBuffer; |
|
125 } |
|
126 |
|
127 TInt err = CreateBuffer( size ); |
|
128 if( KErrNone != err) |
|
129 return err; |
|
130 |
|
131 |
|
132 return FirstWriteChunk(aChunk); |
|
133 } |
|
134 |
|
135 EXPORT_C TInt CMTPTypeOpaqueData::NextWriteChunk(TPtr8& aChunk) |
|
136 { |
|
137 aChunk.Set(NULL, 0, 0); |
|
138 return KErrNotReady; |
|
139 } |
|
140 |
|
141 EXPORT_C TBool CMTPTypeOpaqueData::CommitRequired() const |
|
142 { |
|
143 return ETrue; |
|
144 } |
|
145 |
|
146 EXPORT_C MMTPType* CMTPTypeOpaqueData::CommitChunkL(TPtr8& aChunk) |
|
147 { |
|
148 iPtrBuffer.Set(aChunk); |
|
149 return NULL; |
|
150 } |
|
151 |
|
152 EXPORT_C TUint64 CMTPTypeOpaqueData::Size() const |
|
153 { |
|
154 return iPtrBuffer.Size(); |
|
155 } |
|
156 |
|
157 EXPORT_C TUint CMTPTypeOpaqueData::Type() const |
|
158 { |
|
159 return EMTPTypeOpaqueData; |
|
160 } |
|
161 |
|
162 EXPORT_C TInt CMTPTypeOpaqueData::Read(TPtrC8 &aDes) const |
|
163 { |
|
164 aDes.Set( iPtrBuffer ); |
|
165 return KErrNone; |
|
166 } |
|
167 |
|
168 EXPORT_C TInt CMTPTypeOpaqueData::Write( const TPtrC8 &aDes) |
|
169 { |
|
170 if(iBuffer.MaxSize() != 0) |
|
171 { |
|
172 iBuffer.Close(); |
|
173 } |
|
174 |
|
175 iPtrBuffer.Set(const_cast<TUint8*>(aDes.Ptr()), aDes.Length(), aDes.Size()); |
|
176 return KErrNone; |
|
177 } |
|
178 |
|
179 |
|
180 |