|
1 /* |
|
2 * Copyright (c) 2005 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: DM Utilities |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32mem.h> |
|
20 #include <smldmadapter.h> |
|
21 #include "nsmldmcmdarghandler.h" |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 // =========================================================================== |
|
27 // NSmlDmCmdArgHandler |
|
28 // =========================================================================== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // NSmlDmCmdArgHandler::PacketDataL() |
|
32 // Packet elements to stream |
|
33 // --------------------------------------------------------------------------- |
|
34 EXPORT_C void NSmlDmCmdArgHandler::PacketDataL(RWriteStream& aWriteStream, |
|
35 const TDesC8& aLuid, |
|
36 const TDesC8& aData, |
|
37 const TDesC8& aURI, |
|
38 const TDesC8& aType) |
|
39 { |
|
40 aWriteStream.WriteUint16L(aLuid.Length()); |
|
41 aWriteStream.WriteL(aLuid); |
|
42 aWriteStream.WriteUint16L(aData.Length()); |
|
43 aWriteStream.WriteL(aData); |
|
44 aWriteStream.WriteUint16L(aURI.Length()); |
|
45 aWriteStream.WriteL(aURI); |
|
46 aWriteStream.WriteUint16L(aType.Length()); |
|
47 aWriteStream.WriteL(aType); |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // NSmlDmCmdArgHandler::ParseDataL() |
|
52 // Parse data from stream |
|
53 // --------------------------------------------------------------------------- |
|
54 EXPORT_C void NSmlDmCmdArgHandler::ParseDataL(RReadStream& aReadStream, |
|
55 HBufC8*& aLuid, |
|
56 HBufC8*& aData, |
|
57 HBufC8*& aURI, |
|
58 HBufC8*& aType) |
|
59 { |
|
60 TUint16 length16; |
|
61 length16 = aReadStream.ReadUint16L(); |
|
62 aLuid = HBufC8::NewLC(length16); |
|
63 TPtr8 luidPtr= aLuid->Des(); |
|
64 aReadStream.ReadL(luidPtr,length16); |
|
65 |
|
66 length16 = aReadStream.ReadUint16L(); |
|
67 aData = HBufC8::NewLC(length16); |
|
68 TPtr8 dataPtr= aData->Des(); |
|
69 aReadStream.ReadL(dataPtr,length16); |
|
70 |
|
71 length16 = aReadStream.ReadUint16L(); |
|
72 aURI = HBufC8::NewLC(length16); |
|
73 TPtr8 uriPtr= aURI->Des(); |
|
74 aReadStream.ReadL(uriPtr,length16); |
|
75 |
|
76 length16 = aReadStream.ReadUint16L(); |
|
77 aType = HBufC8::NewLC(length16); |
|
78 TPtr8 typePtr= aType->Des(); |
|
79 aReadStream.ReadL(typePtr,length16); |
|
80 |
|
81 CleanupStack::Pop(4); //aLuid,aData,aURI,aType |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // NSmlDmCmdArgHandler::PacketFetchArgumentsL() |
|
86 // Packet fetch arguments to stream |
|
87 // --------------------------------------------------------------------------- |
|
88 EXPORT_C void NSmlDmCmdArgHandler::PacketFetchArgumentsL( |
|
89 RWriteStream& aWriteStream, |
|
90 const TDesC8& aLuid, |
|
91 const TDesC8& aURI, |
|
92 const TDesC8& aType, |
|
93 const CArrayFixFlat<TSmlDmMappingInfo>& aPreviousURISegementList) |
|
94 { |
|
95 aWriteStream.WriteUint16L(aLuid.Length()); |
|
96 aWriteStream.WriteL(aLuid); |
|
97 aWriteStream.WriteUint16L(aURI.Length()); |
|
98 aWriteStream.WriteL(aURI); |
|
99 aWriteStream.WriteUint16L(aType.Length()); |
|
100 aWriteStream.WriteL(aType); |
|
101 TUint8 count=aPreviousURISegementList.Count(); |
|
102 aWriteStream.WriteUint8L(count); |
|
103 for(TUint8 i=0;i<count;i++) |
|
104 { |
|
105 aWriteStream.WriteUint8L( |
|
106 aPreviousURISegementList.At(i).iURISeg.Length()); |
|
107 |
|
108 aWriteStream.WriteL(aPreviousURISegementList.At(i).iURISeg); |
|
109 |
|
110 aWriteStream.WriteUint8L( |
|
111 aPreviousURISegementList.At(i).iURISegLUID.Length()); |
|
112 |
|
113 aWriteStream.WriteL(aPreviousURISegementList.At(i).iURISegLUID); |
|
114 } |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // NSmlDmCmdArgHandler::ParseFetchArgumentsL() |
|
119 // Parse fetch arguments from stream |
|
120 // --------------------------------------------------------------------------- |
|
121 EXPORT_C void NSmlDmCmdArgHandler::ParseFetchArgumentsL( |
|
122 RReadStream& aReadStream, |
|
123 HBufC8*& aLuid, |
|
124 HBufC8*& aURI, |
|
125 HBufC8*& aType, |
|
126 CArrayFixFlat<TSmlDmMappingInfo>& aPreviousURISegementList, |
|
127 RPointerArray<HBufC8>& aLuids) |
|
128 { |
|
129 TUint16 length16; |
|
130 length16 = aReadStream.ReadUint16L(); |
|
131 aLuid = HBufC8::NewLC(length16); |
|
132 TPtr8 luidPtr = aLuid->Des(); |
|
133 aReadStream.ReadL(luidPtr,length16); |
|
134 |
|
135 length16 = aReadStream.ReadUint16L(); |
|
136 aURI = HBufC8::NewLC(length16); |
|
137 TPtr8 uriPtr = aURI->Des(); |
|
138 aReadStream.ReadL(uriPtr,length16); |
|
139 |
|
140 length16 = aReadStream.ReadUint16L(); |
|
141 aType = HBufC8::NewLC(length16); |
|
142 TPtr8 typePtr = aType->Des(); |
|
143 aReadStream.ReadL(typePtr,length16); |
|
144 |
|
145 TUint8 count = aReadStream.ReadUint8L(); |
|
146 TUint8 length8; |
|
147 |
|
148 for(TInt i=0;i<count;i++) |
|
149 { |
|
150 length8 = aReadStream.ReadUint8L(); |
|
151 HBufC8 *uriSeg =HBufC8::NewLC(length8); |
|
152 TPtr8 uriSegPtr = uriSeg->Des(); |
|
153 aReadStream.ReadL(uriSegPtr,length8); |
|
154 |
|
155 length8 = aReadStream.ReadUint8L(); |
|
156 HBufC8 *luid =HBufC8::NewLC(length8); |
|
157 TPtr8 luidPtr = luid->Des(); |
|
158 aReadStream.ReadL(luidPtr,length8); |
|
159 aLuids.AppendL(luid); |
|
160 CleanupStack::Pop(); //luid |
|
161 |
|
162 TSmlDmMappingInfo mapInfo; |
|
163 mapInfo.iURISeg = TBufC8<KSmlMaxURISegLen>(uriSegPtr); |
|
164 mapInfo.iURISegLUID.Set(*luid); |
|
165 aPreviousURISegementList.AppendL(mapInfo); |
|
166 CleanupStack::PopAndDestroy(); //uriSeg |
|
167 } |
|
168 CleanupStack::Pop(3); //aLuid,aURI,aType |
|
169 } |
|
170 |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // NSmlDmCmdArgHandler::PacketMappingsL() |
|
174 // Packet mappings to stream |
|
175 // --------------------------------------------------------------------------- |
|
176 EXPORT_C void NSmlDmCmdArgHandler::PacketMappingsL( |
|
177 RWriteStream& aWriteStream, |
|
178 const CArrayPtrSeg<HBufC8>& aURIs, |
|
179 const CArrayPtrSeg<HBufC8>& aLuids ) |
|
180 { |
|
181 |
|
182 if(aURIs.Count()!=aLuids.Count()) |
|
183 { |
|
184 aWriteStream.WriteUint16L(0); |
|
185 return; |
|
186 } |
|
187 |
|
188 aWriteStream.WriteUint16L(aURIs.Count()); |
|
189 for(TInt i=0;i<aURIs.Count();i++) |
|
190 { |
|
191 aWriteStream.WriteUint16L(aURIs.At(i)->Length()); |
|
192 aWriteStream.WriteL(*aURIs.At(i)); |
|
193 aWriteStream.WriteUint16L(aLuids.At(i)->Length()); |
|
194 aWriteStream.WriteL(*aLuids.At(i)); |
|
195 } |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // NSmlDmCmdArgHandler::ParseMappingsL() |
|
200 // Parse mappings from stream |
|
201 // --------------------------------------------------------------------------- |
|
202 EXPORT_C void NSmlDmCmdArgHandler::ParseMappingsL( |
|
203 RReadStream& aReadStream, |
|
204 CArrayPtrSeg<HBufC8>& aURIs, |
|
205 CArrayPtrSeg<HBufC8>& aLuids ) |
|
206 { |
|
207 TUint16 mapCount = aReadStream.ReadUint16L(); |
|
208 |
|
209 for(TUint16 i=0;i<mapCount;i++) |
|
210 { |
|
211 TUint16 length; |
|
212 length = aReadStream.ReadUint16L(); |
|
213 HBufC8* uri = HBufC8::NewLC(length); |
|
214 TPtr8 uriPtr = uri->Des(); |
|
215 aReadStream.ReadL(uriPtr,length); |
|
216 CleanupStack::Pop(); //uri |
|
217 aURIs.AppendL(uri); |
|
218 |
|
219 length = aReadStream.ReadUint16L(); |
|
220 HBufC8* luid = HBufC8::NewLC(length); |
|
221 TPtr8 luidPtr = luid->Des(); |
|
222 aReadStream.ReadL(luidPtr,length); |
|
223 CleanupStack::Pop(); //luid |
|
224 aLuids.AppendL(luid); |
|
225 } |
|
226 } |
|
227 |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // NSmlDmCmdArgHandler::PacketStatusesL() |
|
231 // Packet statuses to stream |
|
232 // --------------------------------------------------------------------------- |
|
233 EXPORT_C void NSmlDmCmdArgHandler::PacketStatusesL(RWriteStream& aWriteStream, |
|
234 const RArray<TNSmlDmStatusElement>& aStatusArray) |
|
235 { |
|
236 TUint16 count = aStatusArray.Count(); |
|
237 aWriteStream.WriteUint16L(count); |
|
238 for(TInt i=0;i<count;i++) |
|
239 { |
|
240 aWriteStream.WriteUint16L(aStatusArray[i].iStatusRef); |
|
241 aWriteStream.WriteUint8L(aStatusArray[i].iStatus); |
|
242 } |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // NSmlDmCmdArgHandler::ParseStatusesL() |
|
247 // Parse statuses from stream |
|
248 // --------------------------------------------------------------------------- |
|
249 EXPORT_C void NSmlDmCmdArgHandler::ParseStatusesL(RReadStream& aReadStream, |
|
250 RArray<TNSmlDmStatusElement>& aStatusArray ) |
|
251 { |
|
252 TUint16 count = aReadStream.ReadUint16L(); |
|
253 |
|
254 for(TUint16 i=0;i<count;i++) |
|
255 { |
|
256 TNSmlDmStatusElement element; |
|
257 element.iStatusRef = aReadStream.ReadUint16L(); |
|
258 element.iStatus = (MSmlDmAdapter::TError) aReadStream.ReadUint8L(); |
|
259 aStatusArray.AppendL(element); |
|
260 } |
|
261 } |
|
262 |
|
263 |
|
264 |
|
265 // --------------------------------------------------------------------------- |
|
266 // NSmlDmCmdArgHandler::PacketResultsL() |
|
267 // Packet results to stream |
|
268 // --------------------------------------------------------------------------- |
|
269 EXPORT_C void NSmlDmCmdArgHandler::PacketResultsL(RWriteStream& aWriteStream, |
|
270 const RPointerArray<CNSmlDmResultElement>& aResults) |
|
271 { |
|
272 TUint16 count = aResults.Count(); |
|
273 aWriteStream.WriteUint16L(count); |
|
274 |
|
275 for(TInt i=0;i<count;i++) |
|
276 { |
|
277 aWriteStream.WriteUint16L(aResults[i]->iResultRef); |
|
278 aWriteStream.WriteUint32L(aResults[i]->iResult->Size()); |
|
279 aWriteStream.WriteL(aResults[i]->iResult->Ptr(0),aResults[i]->iResult->Size()); |
|
280 aWriteStream.WriteUint16L(aResults[i]->iMimeType->Length()); |
|
281 aWriteStream.WriteL(*aResults[i]->iMimeType); |
|
282 } |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // NSmlDmCmdArgHandler::ParseResultsL() |
|
287 // Parse results from stream |
|
288 // --------------------------------------------------------------------------- |
|
289 EXPORT_C void NSmlDmCmdArgHandler::ParseResultsL(RReadStream& aReadStream, |
|
290 RPointerArray<CNSmlDmResultElement>& aResults) |
|
291 { |
|
292 TUint16 count = aReadStream.ReadUint16L(); |
|
293 |
|
294 for(TUint16 i=0;i<count;i++) |
|
295 { |
|
296 CNSmlDmResultElement* element = new (ELeave) CNSmlDmResultElement(); |
|
297 CleanupStack::PushL(element); |
|
298 element->iResultRef = aReadStream.ReadUint16L(); |
|
299 TUint32 len32 = aReadStream.ReadUint32L(); |
|
300 if(len32) |
|
301 { |
|
302 element->iResult = CBufFlat::NewL(len32); |
|
303 } |
|
304 else |
|
305 { |
|
306 element->iResult = CBufFlat::NewL(8); |
|
307 } |
|
308 element->iResult->ResizeL(len32); |
|
309 TPtr8 resultPtr = element->iResult->Ptr(0); |
|
310 aReadStream.ReadL(resultPtr,len32); |
|
311 |
|
312 TUint16 len16 = aReadStream.ReadUint16L(); |
|
313 element->iMimeType = HBufC8::NewL(len16); |
|
314 TPtr8 mimePtr = element->iMimeType->Des(); |
|
315 aReadStream.ReadL(mimePtr,len16); |
|
316 aResults.AppendL(element); |
|
317 CleanupStack::Pop(); //element |
|
318 } |
|
319 } |
|
320 |
|
321 |
|
322 // --------------------------------------------------------------------------- |
|
323 // NSmlDmCmdArgHandler::PacketCopyArgumentsL() |
|
324 // Packet copy arguments to stream |
|
325 // --------------------------------------------------------------------------- |
|
326 EXPORT_C void NSmlDmCmdArgHandler::PacketCopyArgumentsL( |
|
327 RWriteStream& aWriteStream, |
|
328 const TDesC8& aTargetLuid, |
|
329 const TDesC8& aTargetURI, |
|
330 const TDesC8& aSourceLuid, |
|
331 const TDesC8& aSourceURI, |
|
332 const TDesC8& aType) |
|
333 { |
|
334 aWriteStream.WriteUint16L(aTargetLuid.Length()); |
|
335 aWriteStream.WriteL(aTargetLuid); |
|
336 aWriteStream.WriteUint16L(aTargetURI.Length()); |
|
337 aWriteStream.WriteL(aTargetURI); |
|
338 aWriteStream.WriteUint16L(aSourceLuid.Length()); |
|
339 aWriteStream.WriteL(aSourceLuid); |
|
340 aWriteStream.WriteUint16L(aSourceURI.Length()); |
|
341 aWriteStream.WriteL(aSourceURI); |
|
342 aWriteStream.WriteUint16L(aType.Length()); |
|
343 aWriteStream.WriteL(aType); |
|
344 } |
|
345 |
|
346 // --------------------------------------------------------------------------- |
|
347 // NSmlDmCmdArgHandler::ParseCopyArgumentsL() |
|
348 // Parse copy arguments from stream |
|
349 // --------------------------------------------------------------------------- |
|
350 EXPORT_C void NSmlDmCmdArgHandler::ParseCopyArgumentsL( |
|
351 RReadStream& aReadStream, |
|
352 HBufC8*& aTargetLuid, |
|
353 HBufC8*& aTargetURI, |
|
354 HBufC8*& aSourceLuid, |
|
355 HBufC8*& aSourceURI, |
|
356 HBufC8*& aType) |
|
357 { |
|
358 TUint16 length16; |
|
359 |
|
360 length16 = aReadStream.ReadUint16L(); |
|
361 aTargetLuid = HBufC8::NewLC(length16); |
|
362 TPtr8 targetLuidPtr= aTargetLuid->Des(); |
|
363 aReadStream.ReadL(targetLuidPtr,length16); |
|
364 |
|
365 length16 = aReadStream.ReadUint16L(); |
|
366 aTargetURI = HBufC8::NewLC(length16); |
|
367 TPtr8 targetUriPtr= aTargetURI->Des(); |
|
368 aReadStream.ReadL(targetUriPtr,length16); |
|
369 |
|
370 length16 = aReadStream.ReadUint16L(); |
|
371 aSourceLuid = HBufC8::NewLC(length16); |
|
372 TPtr8 sourceLuidPtr= aSourceLuid->Des(); |
|
373 aReadStream.ReadL(sourceLuidPtr,length16); |
|
374 |
|
375 length16 = aReadStream.ReadUint16L(); |
|
376 aSourceURI = HBufC8::NewLC(length16); |
|
377 TPtr8 sourceUriPtr= aSourceURI->Des(); |
|
378 aReadStream.ReadL(sourceUriPtr,length16); |
|
379 |
|
380 length16 = aReadStream.ReadUint16L(); |
|
381 aType = HBufC8::NewLC(length16); |
|
382 TPtr8 typePtr= aType->Des(); |
|
383 aReadStream.ReadL(typePtr,length16); |
|
384 |
|
385 //POP aTargetLuid,aTargetURI,aSourceLuid,aSourceURI,aType |
|
386 CleanupStack::Pop(5); |
|
387 } |
|
388 |
|
389 |
|
390 // =========================================================================== |
|
391 // NSmlDmCmdArgHandler |
|
392 // =========================================================================== |
|
393 |
|
394 // --------------------------------------------------------------------------- |
|
395 // CNSmlDmResultElement::~CNSmlDmResultElement() |
|
396 // --------------------------------------------------------------------------- |
|
397 EXPORT_C CNSmlDmResultElement::~CNSmlDmResultElement() |
|
398 { |
|
399 delete iResult; |
|
400 delete iMimeType; |
|
401 } |
|
402 |