|
1 /* |
|
2 * Copyright (c) 2008-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 the License "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 |
|
18 |
|
19 #include <f32file.h> |
|
20 #include <usif/sif/sifcommon.h> |
|
21 #include <s32mem.h> |
|
22 |
|
23 using namespace Usif; |
|
24 |
|
25 /** |
|
26 The COpaqueNamedParams and CComponentInfo containers implement the deferred internalization |
|
27 logic. This mechanism is necessary because these containers may be passed through IPC between |
|
28 the SIF client and server. Hence, they must be externalized and internalized on both sides. |
|
29 However, The SIF client doesn't implement an active object and therefore it cannot internalize |
|
30 parameters returned by the SIF server. This de-serialization is done by the deferred internalization |
|
31 logic when the user accesses them first time. |
|
32 Hence, all the get methods, for example Name(), GetIntByName(), StringByNameL(), call the |
|
33 InternalizeFromExternalBufferL() method which calls ConstInternalizeL() in order to unpack |
|
34 the data recived from the SIF server if there is any. ConstInternalizeL() is a const method despite |
|
35 the fact it modifies class'es members. This is done to keep the get methods const as expected by |
|
36 the users. |
|
37 */ |
|
38 |
|
39 // ########################################################################################## |
|
40 |
|
41 namespace |
|
42 { |
|
43 TInt PackCapabilitySet(const TCapabilitySet& aCapSet) |
|
44 { |
|
45 TInt caps=0; |
|
46 for (TInt c=0; c<ECapability_Limit; ++c) |
|
47 { |
|
48 if (aCapSet.HasCapability(TCapability(c))) |
|
49 { |
|
50 caps += (1<<c); |
|
51 } |
|
52 } |
|
53 return caps; |
|
54 } |
|
55 |
|
56 void UnpackCapabilitySet(TInt aPackedCapSet, TCapabilitySet& aCapSet) |
|
57 { |
|
58 for (TInt c=0; c<ECapability_Limit; ++c) |
|
59 { |
|
60 const TInt cap = 1<<c; |
|
61 if (aPackedCapSet&cap) |
|
62 { |
|
63 aCapSet.AddCapability(TCapability(c)); |
|
64 } |
|
65 } |
|
66 } |
|
67 } |
|
68 |
|
69 // ########################################################################################## |
|
70 |
|
71 EXPORT_C TSecurityContext::TSecurityContext(const RMessage2& aMessage): iMsg(aMessage) |
|
72 { |
|
73 } |
|
74 |
|
75 EXPORT_C TBool TSecurityContext::HasCapability(TCapability aCapability) const |
|
76 { |
|
77 return iMsg.HasCapability(aCapability); |
|
78 } |
|
79 |
|
80 EXPORT_C void TSecurityContext::HasCapabilityL(TCapability aCapability) const |
|
81 { |
|
82 iMsg.HasCapabilityL(aCapability); |
|
83 } |
|
84 |
|
85 EXPORT_C TSecureId TSecurityContext::SecureId() const |
|
86 { |
|
87 return iMsg.SecureId(); |
|
88 } |
|
89 |
|
90 // ########################################################################################## |
|
91 |
|
92 CComponentInfo::CNode::CNode() : iAuthenticity(ENotAuthenticated) |
|
93 { |
|
94 iUserGrantableCaps.SetEmpty(); |
|
95 } |
|
96 |
|
97 EXPORT_C CComponentInfo::CNode::~CNode() |
|
98 { |
|
99 delete iSoftwareTypeName; |
|
100 delete iComponentName; |
|
101 delete iGlobalComponentId; |
|
102 delete iVersion; |
|
103 delete iVendor; |
|
104 |
|
105 iChildren.Close(); |
|
106 } |
|
107 |
|
108 EXPORT_C CComponentInfo::CNode* CComponentInfo::CNode::NewLC(const TDesC& aSoftwareTypeName, const TDesC& aComponentName, |
|
109 const TDesC& aVersion, const TDesC& aVendor, TScomoState aScomoState, |
|
110 TInstallStatus aInstallStatus, TComponentId aComponentId, |
|
111 const TDesC& aGlobalComponentId, TAuthenticity aAuthenticity, |
|
112 const TCapabilitySet& aUserGrantableCaps, TInt aMaxInstalledSize, |
|
113 TBool aHasExe, |
|
114 RPointerArray<CNode>* aChildren) |
|
115 { |
|
116 // We leave if aSoftwareTypeName, aComponentName, aVersion, aVendor or aGlobalComponentId exceeds KMaxDescriptorLength |
|
117 if (aSoftwareTypeName.Length() > KMaxDescriptorLength || |
|
118 aComponentName.Length() > KMaxDescriptorLength || |
|
119 aVersion.Length() > KMaxDescriptorLength || |
|
120 aVendor.Length() > KMaxDescriptorLength || |
|
121 aGlobalComponentId.Length() > KMaxDescriptorLength) |
|
122 { |
|
123 User::Leave(KErrOverflow); |
|
124 } |
|
125 |
|
126 |
|
127 // Since the max heap buffer length is 2K, which is more than (num of parameters * KMaxDescriptorLength), we just assert this condition |
|
128 __ASSERT_ALWAYS(aSoftwareTypeName.Length() + aComponentName.Length() + aVersion.Length() + aVendor.Length() + |
|
129 aGlobalComponentId.Length() <= KMaxHeapBufLength, User::Leave(KErrOverflow)); |
|
130 |
|
131 // Create an instance of CNode |
|
132 CNode* self = new (ELeave) CNode(); |
|
133 CleanupStack::PushL(self); |
|
134 |
|
135 // Copy Software Type Name, Component Name, Version, aVendor, aGlobalComponentId |
|
136 self->iSoftwareTypeName = aSoftwareTypeName.AllocL(); |
|
137 self->iComponentName = aComponentName.AllocL(); |
|
138 self->iVersion = aVersion.AllocL(); |
|
139 self->iVendor = aVendor.AllocL(); |
|
140 self->iGlobalComponentId = aGlobalComponentId.AllocL(); |
|
141 |
|
142 // Others |
|
143 self->iScomoState = aScomoState; |
|
144 self->iInstallStatus = aInstallStatus; |
|
145 self->iComponentId = aComponentId; |
|
146 self->iAuthenticity = aAuthenticity; |
|
147 self->iUserGrantableCaps = aUserGrantableCaps; |
|
148 self->iMaxInstalledSize = aMaxInstalledSize; |
|
149 self->iHasExe = aHasExe; |
|
150 |
|
151 // Embedded Components |
|
152 if(aChildren != NULL) |
|
153 { |
|
154 for (TInt i=aChildren->Count()-1; i>=0; --i) |
|
155 { |
|
156 self->iChildren.InsertL((*aChildren)[i], 0); |
|
157 aChildren->Remove(i); |
|
158 } |
|
159 } |
|
160 |
|
161 return self; |
|
162 } |
|
163 |
|
164 EXPORT_C void CComponentInfo::CNode::AddChildL(CComponentInfo::CNode* aChild) |
|
165 { |
|
166 if (aChild == NULL) |
|
167 { |
|
168 User::Leave(KErrArgument); |
|
169 } |
|
170 |
|
171 iChildren.AppendL(aChild); |
|
172 } |
|
173 |
|
174 CComponentInfo::CNode* CComponentInfo::CNode::NewL(RReadStream& aStream) |
|
175 { |
|
176 // Create an instance of CNode |
|
177 CNode* self = new (ELeave) CNode(); |
|
178 CleanupStack::PushL(self); |
|
179 |
|
180 self->iSoftwareTypeName = HBufC::NewL(aStream, KMaxDescriptorLength); |
|
181 self->iComponentName = HBufC::NewL(aStream, KMaxDescriptorLength); |
|
182 self->iVersion = HBufC::NewL(aStream, KMaxDescriptorLength); |
|
183 self->iVendor = HBufC::NewL(aStream, KMaxDescriptorLength); |
|
184 self->iGlobalComponentId = HBufC::NewL(aStream, KMaxDescriptorLength); |
|
185 self->iScomoState = static_cast<TScomoState>(aStream.ReadInt32L()); |
|
186 self->iInstallStatus = static_cast<TInstallStatus>(aStream.ReadInt32L()); |
|
187 self->iComponentId = aStream.ReadInt32L(); |
|
188 self->iAuthenticity = static_cast<TAuthenticity>(aStream.ReadInt32L()); |
|
189 UnpackCapabilitySet(aStream.ReadInt32L(), self->iUserGrantableCaps); |
|
190 self->iMaxInstalledSize = aStream.ReadInt32L(); |
|
191 self->iHasExe = aStream.ReadInt32L(); |
|
192 |
|
193 const TInt numChildren = aStream.ReadInt32L(); |
|
194 for (TInt i=0; i<numChildren; ++i) |
|
195 { |
|
196 CNode* node = CNode::NewL(aStream); |
|
197 CleanupStack::PushL(node); |
|
198 self->iChildren.AppendL(node); |
|
199 CleanupStack::Pop(node); |
|
200 } |
|
201 |
|
202 CleanupStack::Pop(self); |
|
203 return self; |
|
204 } |
|
205 |
|
206 void CComponentInfo::CNode::ExternalizeL(RWriteStream& aStream) const |
|
207 { |
|
208 ASSERT (iSoftwareTypeName!=NULL && iComponentName!=NULL && iVersion!=NULL && iVendor!=NULL && iGlobalComponentId!=NULL); |
|
209 |
|
210 aStream << *iSoftwareTypeName; |
|
211 aStream << *iComponentName; |
|
212 aStream << *iVersion; |
|
213 aStream << *iVendor; |
|
214 aStream << *iGlobalComponentId; |
|
215 |
|
216 aStream.WriteInt32L(iScomoState); |
|
217 aStream.WriteInt32L(iInstallStatus); |
|
218 aStream.WriteInt32L(iComponentId); |
|
219 aStream.WriteInt32L(static_cast<TInt>(iAuthenticity)); |
|
220 aStream.WriteInt32L(PackCapabilitySet(iUserGrantableCaps)); |
|
221 aStream.WriteInt32L(iMaxInstalledSize); |
|
222 aStream.WriteInt32L(iHasExe); |
|
223 |
|
224 const TInt numChildren = iChildren.Count(); |
|
225 aStream.WriteInt32L(numChildren); |
|
226 for (TInt i=0; i<numChildren; ++i) |
|
227 { |
|
228 iChildren[i]->ExternalizeL(aStream); |
|
229 } |
|
230 } |
|
231 |
|
232 EXPORT_C const TDesC& CComponentInfo::CNode::SoftwareTypeName() const |
|
233 { |
|
234 return *iSoftwareTypeName; |
|
235 } |
|
236 |
|
237 EXPORT_C const TDesC& CComponentInfo::CNode::ComponentName() const |
|
238 { |
|
239 return *iComponentName; |
|
240 } |
|
241 |
|
242 EXPORT_C const TDesC& CComponentInfo::CNode::Version() const |
|
243 { |
|
244 return *iVersion; |
|
245 } |
|
246 |
|
247 EXPORT_C const TDesC& CComponentInfo::CNode::Vendor() const |
|
248 { |
|
249 return *iVendor; |
|
250 } |
|
251 |
|
252 EXPORT_C TScomoState CComponentInfo::CNode::ScomoState() const |
|
253 { |
|
254 return iScomoState; |
|
255 } |
|
256 |
|
257 EXPORT_C TInstallStatus CComponentInfo::CNode::InstallStatus() const |
|
258 { |
|
259 return iInstallStatus; |
|
260 } |
|
261 |
|
262 EXPORT_C TComponentId CComponentInfo::CNode::ComponentId() const |
|
263 { |
|
264 return iComponentId; |
|
265 } |
|
266 |
|
267 EXPORT_C const TDesC& CComponentInfo::CNode::GlobalComponentId() const |
|
268 { |
|
269 return *iGlobalComponentId; |
|
270 } |
|
271 |
|
272 EXPORT_C TAuthenticity CComponentInfo::CNode::Authenticity() const |
|
273 { |
|
274 return iAuthenticity; |
|
275 } |
|
276 |
|
277 EXPORT_C const TCapabilitySet& CComponentInfo::CNode::UserGrantableCaps() const |
|
278 { |
|
279 return iUserGrantableCaps; |
|
280 } |
|
281 |
|
282 EXPORT_C TInt CComponentInfo::CNode::MaxInstalledSize() const |
|
283 { |
|
284 return iMaxInstalledSize; |
|
285 } |
|
286 |
|
287 EXPORT_C TBool CComponentInfo::CNode::HasExecutable() const |
|
288 { |
|
289 return iHasExe; |
|
290 } |
|
291 |
|
292 EXPORT_C const RPointerArray<CComponentInfo::CNode>& CComponentInfo::CNode::Children() const |
|
293 { |
|
294 return iChildren; |
|
295 } |
|
296 |
|
297 // ########################################################################################## |
|
298 |
|
299 CComponentInfo::CComponentInfo() : iExternalBufferPtr(NULL, 0, 0) |
|
300 { |
|
301 } |
|
302 |
|
303 EXPORT_C CComponentInfo::~CComponentInfo() |
|
304 { |
|
305 delete iRootNode; |
|
306 |
|
307 CleanupExternalBuffer(); |
|
308 } |
|
309 |
|
310 EXPORT_C CComponentInfo* CComponentInfo::NewL() |
|
311 { |
|
312 return new (ELeave) CComponentInfo; |
|
313 } |
|
314 |
|
315 EXPORT_C CComponentInfo* CComponentInfo::NewLC() |
|
316 { |
|
317 CComponentInfo* self = new (ELeave) CComponentInfo; |
|
318 CleanupStack::PushL(self); |
|
319 return self; |
|
320 } |
|
321 |
|
322 EXPORT_C const CComponentInfo::CNode& CComponentInfo::RootNodeL() const |
|
323 { |
|
324 InternalizeFromExternalBufferL(); |
|
325 |
|
326 if (iRootNode == NULL) |
|
327 { |
|
328 User::Leave(KErrNotFound); |
|
329 } |
|
330 |
|
331 return *iRootNode; |
|
332 } |
|
333 |
|
334 EXPORT_C void CComponentInfo::SetRootNodeL(CNode* aRootNode) |
|
335 { |
|
336 InternalizeFromExternalBufferL(); |
|
337 |
|
338 if (aRootNode == NULL) |
|
339 { |
|
340 User::Leave(KErrArgument); |
|
341 } |
|
342 |
|
343 delete iRootNode; |
|
344 iRootNode = aRootNode; |
|
345 } |
|
346 |
|
347 EXPORT_C void CComponentInfo::SetRootNodeAsChildL(CNode& aParentNode) |
|
348 { |
|
349 InternalizeFromExternalBufferL(); |
|
350 |
|
351 if (iRootNode == NULL) |
|
352 { |
|
353 User::Leave(KErrNotFound); |
|
354 } |
|
355 |
|
356 aParentNode.AddChildL(iRootNode); |
|
357 iRootNode = NULL; |
|
358 } |
|
359 |
|
360 EXPORT_C void CComponentInfo::ExternalizeL(RWriteStream& aStream) const |
|
361 { |
|
362 InternalizeFromExternalBufferL(); |
|
363 |
|
364 aStream.WriteInt8L(iRootNode != NULL); |
|
365 |
|
366 if (iRootNode != NULL) |
|
367 { |
|
368 iRootNode->ExternalizeL(aStream); |
|
369 } |
|
370 } |
|
371 |
|
372 void CComponentInfo::ConstInternalizeL(RReadStream& aStream) const |
|
373 { |
|
374 CNode*& rootNode = const_cast<CNode*&>(iRootNode); |
|
375 delete rootNode; |
|
376 rootNode = NULL; |
|
377 |
|
378 if (aStream.ReadInt8L() != 0) |
|
379 { |
|
380 rootNode = CNode::NewL(aStream); |
|
381 } |
|
382 } |
|
383 |
|
384 void CComponentInfo::CleanupExternalBuffer() const |
|
385 { |
|
386 delete iExternalBuffer; |
|
387 iExternalBuffer = NULL; |
|
388 iDeferredInternalization = EFalse; |
|
389 } |
|
390 |
|
391 void CComponentInfo::InternalizeFromExternalBufferL() const |
|
392 { |
|
393 if (iDeferredInternalization) |
|
394 { |
|
395 iDeferredInternalization = EFalse; |
|
396 |
|
397 RDesReadStream rs(*iExternalBuffer); |
|
398 CleanupClosePushL(rs); |
|
399 ConstInternalizeL(rs); |
|
400 CleanupStack::PopAndDestroy(&rs); |
|
401 |
|
402 CleanupExternalBuffer(); |
|
403 } |
|
404 } |
|
405 |
|
406 EXPORT_C void CComponentInfo::PrepareForIpcL(TIpcArgs& aIpcArgs, TInt aIndex) |
|
407 { |
|
408 delete iExternalBuffer; |
|
409 iExternalBuffer = NULL; |
|
410 |
|
411 iExternalBuffer = HBufC8::NewL(KMaxComponentInfoStreamedSize); |
|
412 iExternalBufferPtr.Set(iExternalBuffer->Des()); |
|
413 |
|
414 aIpcArgs.Set(aIndex, &iExternalBufferPtr); |
|
415 |
|
416 iDeferredInternalization = ETrue; |
|
417 } |
|
418 |
|
419 // ########################################################################################## |
|
420 |
|
421 COpaqueNamedParams::COpaqueNamedParams() |
|
422 : iExternalBuffer(NULL), iExternalBufferPtr(NULL, 0, 0), iDeferredInternalization(EFalse), iExternalizedSize(sizeof(TInt)) |
|
423 { |
|
424 } |
|
425 |
|
426 EXPORT_C COpaqueNamedParams::~COpaqueNamedParams() |
|
427 { |
|
428 Cleanup(); |
|
429 iParams.Close(); |
|
430 CleanupExternalBuffer(); |
|
431 } |
|
432 |
|
433 EXPORT_C COpaqueNamedParams* COpaqueNamedParams::NewL() |
|
434 { |
|
435 return new (ELeave) COpaqueNamedParams; |
|
436 } |
|
437 |
|
438 EXPORT_C COpaqueNamedParams* COpaqueNamedParams::NewLC() |
|
439 { |
|
440 COpaqueNamedParams* self = new (ELeave) COpaqueNamedParams; |
|
441 CleanupStack::PushL(self); |
|
442 return self; |
|
443 } |
|
444 |
|
445 void COpaqueNamedParams::VerifyExternalizedSizeForNewParamL(TInt aNameSize, TInt aValueSize) const |
|
446 { |
|
447 const TInt load = 2*sizeof(TInt) + aNameSize + aValueSize; |
|
448 if (aNameSize > KMaxDescriptorLength || aValueSize > KMaxDescriptorLength || |
|
449 iExternalizedSize + load > KMaxExternalizedSize) |
|
450 { |
|
451 User::Leave(KErrOverflow); |
|
452 } |
|
453 iExternalizedSize += load; |
|
454 } |
|
455 |
|
456 void COpaqueNamedParams::VerifyExternalizedSizeForExistingParamL(TInt aOldValueSize, TInt aNewValueSize) const |
|
457 { |
|
458 const TInt diff = aNewValueSize - aOldValueSize; |
|
459 if (aNewValueSize > KMaxDescriptorLength || |
|
460 iExternalizedSize + diff > KMaxExternalizedSize) |
|
461 { |
|
462 User::Leave(KErrOverflow); |
|
463 } |
|
464 iExternalizedSize += diff; |
|
465 } |
|
466 |
|
467 EXPORT_C void COpaqueNamedParams::AddStringL(const TDesC& aName, const TDesC& aValue) |
|
468 { |
|
469 HBufC* value = HBufC::NewLC(aValue.Length()); |
|
470 TPtr bufValue(value->Des()); |
|
471 bufValue.Copy(aValue); |
|
472 |
|
473 const TInt len = iParams.Count(); |
|
474 for (TInt i=0; i<len; ++i) |
|
475 { |
|
476 if (iParams[i].iName->CompareF(aName) == 0) |
|
477 { |
|
478 VerifyExternalizedSizeForExistingParamL(iParams[i].iValue->Size(), value->Size()); |
|
479 delete iParams[i].iValue; |
|
480 iParams[i].iValue = value; |
|
481 CleanupStack::Pop(value); |
|
482 return; |
|
483 } |
|
484 } |
|
485 |
|
486 VerifyExternalizedSizeForNewParamL(aName.Size(), aValue.Size()); |
|
487 |
|
488 HBufC* name = HBufC::NewLC(aName.Length()); |
|
489 TPtr bufName(name->Des()); |
|
490 bufName.Copy(aName); |
|
491 |
|
492 TItem item = {name, value}; |
|
493 iParams.AppendL(item); |
|
494 |
|
495 CleanupStack::Pop(2, value); |
|
496 } |
|
497 |
|
498 EXPORT_C void COpaqueNamedParams::AddIntL(const TDesC& aName, TInt aValue) |
|
499 { |
|
500 // Assumption: the code below won't be compiled in __KERNEL_MODE__ so HBufC is always defined as HBufC16 |
|
501 TBuf<sizeof(TInt)/2> buf; |
|
502 buf.Copy(reinterpret_cast<TUint16*>(&aValue), sizeof(TInt)/2); |
|
503 AddStringL(aName, buf); |
|
504 } |
|
505 |
|
506 EXPORT_C void COpaqueNamedParams::GetNamesL(RPointerArray<HBufC>& aNames) const |
|
507 { |
|
508 InternalizeFromExternalBufferL(); |
|
509 |
|
510 const TInt len = iParams.Count(); |
|
511 for (TInt i=0; i<len; ++i) |
|
512 { |
|
513 const TDesC& ref = *iParams[i].iName; |
|
514 HBufC* name = HBufC::NewLC(ref.Length()); |
|
515 TPtr bufName(name->Des()); |
|
516 bufName.Copy(ref); |
|
517 aNames.AppendL(name); |
|
518 CleanupStack::Pop(name); |
|
519 } |
|
520 } |
|
521 |
|
522 EXPORT_C void COpaqueNamedParams::ExternalizeL(RWriteStream& aStream) const |
|
523 { |
|
524 InternalizeFromExternalBufferL(); |
|
525 |
|
526 TInt len = iParams.Count(); |
|
527 aStream.WriteInt32L(len); |
|
528 for (TInt i=0; i<len; ++i) |
|
529 { |
|
530 aStream << *iParams[i].iName; |
|
531 aStream << *iParams[i].iValue; |
|
532 } |
|
533 } |
|
534 |
|
535 EXPORT_C void COpaqueNamedParams::InternalizeL(RReadStream& aStream) |
|
536 { |
|
537 Cleanup(); |
|
538 ConstInternalizeL(aStream); |
|
539 } |
|
540 |
|
541 void COpaqueNamedParams::ConstInternalizeL(RReadStream& aStream) const |
|
542 { |
|
543 RArray<TItem>& refParams = const_cast<RArray<TItem>&>(iParams); |
|
544 |
|
545 TInt len = aStream.ReadInt32L(); |
|
546 for (TInt i=0; i<len; ++i) |
|
547 { |
|
548 HBufC* name = HBufC::NewLC(aStream, KMaxDescriptorLength); |
|
549 HBufC* value = HBufC::NewLC(aStream, KMaxDescriptorLength); |
|
550 |
|
551 // We need to update iExternalizedSize here because its value must correspond to the params beind added from aStream |
|
552 VerifyExternalizedSizeForNewParamL(name->Size(), value->Size()); |
|
553 |
|
554 TItem item = {name, value}; |
|
555 refParams.AppendL(item); |
|
556 |
|
557 CleanupStack::Pop(2, name); |
|
558 } |
|
559 } |
|
560 |
|
561 EXPORT_C void COpaqueNamedParams::PrepareArgumentsForIpcL(TIpcArgs& aIpcArgs, TInt aIndex) const |
|
562 { |
|
563 delete iExternalBuffer; |
|
564 iExternalBuffer = NULL; |
|
565 iExternalBuffer = HBufC8::NewL(iExternalizedSize); |
|
566 iExternalBufferPtr.Set(iExternalBuffer->Des()); |
|
567 |
|
568 RDesWriteStream ws(iExternalBufferPtr); |
|
569 CleanupClosePushL(ws); |
|
570 ExternalizeL(ws); |
|
571 ws.CommitL(); |
|
572 CleanupStack::PopAndDestroy(&ws); |
|
573 |
|
574 aIpcArgs.Set(aIndex, &iExternalBufferPtr); |
|
575 } |
|
576 |
|
577 EXPORT_C void COpaqueNamedParams::PrepareResultsForIpcL(TIpcArgs& aIpcArgs, TInt aIndex) |
|
578 { |
|
579 delete iExternalBuffer; |
|
580 iExternalBuffer = NULL; |
|
581 iExternalBuffer = HBufC8::NewL(KMaxExternalizedSize); |
|
582 iExternalBufferPtr.Set(iExternalBuffer->Des()); |
|
583 |
|
584 RDesWriteStream ws(iExternalBufferPtr); |
|
585 CleanupClosePushL(ws); |
|
586 ws.WriteInt32L(0); // Write the initial count of results, so that the object will be valid even if no results are added |
|
587 CleanupStack::PopAndDestroy(&ws); |
|
588 |
|
589 aIpcArgs.Set(aIndex, &iExternalBufferPtr); |
|
590 |
|
591 iDeferredInternalization = ETrue; |
|
592 } |
|
593 |
|
594 void COpaqueNamedParams::InternalizeFromExternalBufferL() const |
|
595 { |
|
596 if (iDeferredInternalization) |
|
597 { |
|
598 iDeferredInternalization = EFalse; |
|
599 |
|
600 ConstCleanup(); |
|
601 |
|
602 RDesReadStream rs(*iExternalBuffer); |
|
603 CleanupClosePushL(rs); |
|
604 ConstInternalizeL(rs); |
|
605 CleanupStack::PopAndDestroy(&rs); |
|
606 |
|
607 CleanupExternalBuffer(); |
|
608 } |
|
609 } |
|
610 |
|
611 EXPORT_C const TDesC& COpaqueNamedParams::StringByNameL(const TDesC& aName) const |
|
612 { |
|
613 InternalizeFromExternalBufferL(); |
|
614 |
|
615 const TInt len = iParams.Count(); |
|
616 for (TInt i=0; i<len; ++i) |
|
617 { |
|
618 if (iParams[i].iName->CompareF(aName) == 0) |
|
619 { |
|
620 return *iParams[i].iValue; |
|
621 } |
|
622 } |
|
623 return KNullDesC; |
|
624 } |
|
625 |
|
626 EXPORT_C TBool COpaqueNamedParams::GetIntByNameL(const TDesC& aName, TInt& aValue) const |
|
627 { |
|
628 InternalizeFromExternalBufferL(); |
|
629 |
|
630 const TDesC& value = StringByNameL(aName); |
|
631 if (value == KNullDesC) |
|
632 { |
|
633 return EFalse; |
|
634 } |
|
635 aValue = *(reinterpret_cast<const TUint*>(value.Ptr())); |
|
636 return ETrue; |
|
637 } |
|
638 |
|
639 EXPORT_C TInt COpaqueNamedParams::IntByNameL(const TDesC& aName) const |
|
640 { |
|
641 InternalizeFromExternalBufferL(); |
|
642 |
|
643 TInt val; |
|
644 if (!GetIntByNameL(aName, val)) |
|
645 { |
|
646 User::Leave(KErrNotFound); |
|
647 } |
|
648 return val; |
|
649 } |
|
650 |
|
651 EXPORT_C TInt COpaqueNamedParams::CountL() const |
|
652 { |
|
653 InternalizeFromExternalBufferL(); |
|
654 return iParams.Count(); |
|
655 } |
|
656 |
|
657 EXPORT_C void COpaqueNamedParams::Cleanup() |
|
658 { |
|
659 ConstCleanup(); |
|
660 } |
|
661 |
|
662 void COpaqueNamedParams::ConstCleanup() const |
|
663 { |
|
664 // Cleanup internal params |
|
665 iExternalizedSize = sizeof(TInt); |
|
666 |
|
667 const TInt len = iParams.Count(); |
|
668 for (TInt i=0; i<len; ++i) |
|
669 { |
|
670 delete iParams[i].iName; |
|
671 delete iParams[i].iValue; |
|
672 } |
|
673 RArray<TItem>& refParams = const_cast<RArray<TItem>&>(iParams); |
|
674 refParams.Reset(); |
|
675 } |
|
676 |
|
677 void COpaqueNamedParams::CleanupExternalBuffer() const |
|
678 { |
|
679 delete iExternalBuffer; |
|
680 iExternalBuffer = NULL; |
|
681 iDeferredInternalization = EFalse; |
|
682 } |