|
1 // Copyright (c) 2008-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 @released since 9.5 |
|
19 */ |
|
20 |
|
21 #include <comms-infras/es_parameterbundle.h> |
|
22 #include "es_flog.h" |
|
23 #include <es_sock.h> |
|
24 |
|
25 |
|
26 #ifdef _DEBUG |
|
27 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
28 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
29 _LIT(KSpecAssert_ESockCSckCSPrmtB, "ESockCSckCSPrmtB"); |
|
30 #endif |
|
31 |
|
32 |
|
33 |
|
34 using namespace Meta; |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 // PARAMETER SET CONTAINER |
|
41 // ----------------------- |
|
42 /** |
|
43 Creates a new parameter set container. This class is used as a container for a number of parameter |
|
44 sets (generic and extension) that are associated with each other. It is a specific instantiatable class and therefore creates |
|
45 an instance of CParameterSetContainer without using ECOM. |
|
46 |
|
47 @param aBundle Bundle that this container is to be added to |
|
48 @param aContainerId identifier for the specific container instance |
|
49 @return a pointer to a parameter set container if successful, otherwise leaves with system error code. |
|
50 */ |
|
51 EXPORT_C CParameterSetContainer* CParameterSetContainer::NewL(CParameterBundleBase& aBundle, TUint32 aContainerId /* =0 */) |
|
52 { |
|
53 CParameterSetContainer* container = new (ELeave) CParameterSetContainer(aContainerId); |
|
54 CleanupStack::PushL(container); |
|
55 LOG( ESockLog::Printf(_L8("CParameterSetContainer [this=%08x]:\tCreated() tid %d"), container, (TUint)RThread().Id())); |
|
56 container->ConstructL(aBundle); |
|
57 CleanupStack::Pop(container); |
|
58 return container; |
|
59 } |
|
60 |
|
61 |
|
62 /** |
|
63 Creates a new parameter set container. This class is used as a container for a number of parameter |
|
64 sets (generic and extension) that are associated with each other. It is a specific instantiatable class and therefore creates |
|
65 an instance of CParameterSetContainer without using ECOM. |
|
66 |
|
67 @param aContainerId identifier for the specific container instance |
|
68 @return a pointer to a parameter set container if successful, otherwise leaves with system error code. |
|
69 */ |
|
70 EXPORT_C CParameterSetContainer* CParameterSetContainer::NewL(TUint32 aContainerId /* =0 */) |
|
71 { |
|
72 CParameterSetContainer* container = new (ELeave) CParameterSetContainer(aContainerId); |
|
73 CleanupStack::PushL(container); |
|
74 LOG( ESockLog::Printf(_L8("CParameterSetContainer [this=%08x]:\tCreated() tid %d"), container, (TUint)RThread().Id())); |
|
75 CleanupStack::Pop(container); |
|
76 return container; |
|
77 } |
|
78 |
|
79 |
|
80 /** |
|
81 Creates a new parameter set container from a buffer containing the serialised object. |
|
82 |
|
83 @param aBundle Bundle that this container is to be added to |
|
84 @param aBuffer Buffer containing the serialised object information |
|
85 @return a pointer to a parameter set container if successful, otherwise leaves with system error code. |
|
86 */ |
|
87 EXPORT_C CParameterSetContainer* CParameterSetContainer::LoadL(CParameterBundleBase& aBundle, TPtrC8& aBuffer) |
|
88 { |
|
89 CParameterSetContainer* container = new (ELeave) CParameterSetContainer(0); |
|
90 CleanupStack::PushL(container); |
|
91 LOG( ESockLog::Printf(_L8("CParameterSetContainer [this=%08x]:\tCreated() tid %d"), container, (TUint)RThread().Id())); |
|
92 container->ConstructL(aBundle); |
|
93 User::LeaveIfError(container->Load(aBuffer)); |
|
94 CleanupStack::Pop(container); |
|
95 return container; |
|
96 } |
|
97 |
|
98 |
|
99 /** |
|
100 Creates a new parameter set container from a buffer containing the serialised object. |
|
101 |
|
102 @param aBuffer Buffer containing the serialised object information |
|
103 @return a pointer to a parameter set container if successful, otherwise leaves with system error code. |
|
104 */ |
|
105 EXPORT_C CParameterSetContainer* CParameterSetContainer::LoadL(TPtrC8& aBuffer) |
|
106 { |
|
107 CParameterSetContainer* container = new (ELeave) CParameterSetContainer(0); |
|
108 CleanupStack::PushL(container); |
|
109 LOG( ESockLog::Printf(_L8("CParameterSetContainer [this=%08x]:\tCreated() tid %d"), container, (TUint)RThread().Id())); |
|
110 User::LeaveIfError(container->Load(aBuffer)); |
|
111 CleanupStack::Pop(container); |
|
112 return container; |
|
113 } |
|
114 |
|
115 |
|
116 EXPORT_C /*virtual*/ CParameterSetContainer::~CParameterSetContainer() |
|
117 { |
|
118 LOG( ESockLog::Printf(_L8("CParameterSetContainer [this=%08x]:\tDestroyed() tid %d"), this, (TUint)RThread().Id())); |
|
119 iParameterSets.ResetAndDestroy(); |
|
120 } |
|
121 |
|
122 |
|
123 EXPORT_C void CParameterSetContainer::AddParameterSetL(XParameterSetBase* aParameterSet) |
|
124 { |
|
125 __ASSERT_DEBUG(FindParameterSet(aParameterSet->GetTypeId()) == NULL, User::Panic(KSpecAssert_ESockCSckCSPrmtB, 1)); // should only be 1 set of each type in the container |
|
126 ASSERT(FindParameterSet(aParameterSet->GetTypeId()) == NULL); // should only be 1 set of each type in the container |
|
127 iParameterSets.AppendL(aParameterSet); |
|
128 } |
|
129 |
|
130 EXPORT_C TInt CParameterSetContainer::AddParameterSet(XParameterSetBase* aParameterSet) |
|
131 { |
|
132 ASSERT(FindParameterSet(aParameterSet->GetTypeId()) == NULL); // should only be 1 set of each type in the container |
|
133 return iParameterSets.Append(aParameterSet); |
|
134 } |
|
135 |
|
136 |
|
137 /** |
|
138 Searches a parameter set container for a parameter set. |
|
139 @param aSetId The STypeId of the set |
|
140 @return Pointer to the set if found, otherwise a NULL pointer. |
|
141 */ |
|
142 EXPORT_C XParameterSetBase* CParameterSetContainer::FindParameterSet(const STypeId& aSetId) |
|
143 { |
|
144 TUint length = iParameterSets.Count(); |
|
145 for (TUint i = 0; i < length; ++i) |
|
146 { |
|
147 if (iParameterSets[i]->GetTypeId() == aSetId) |
|
148 { |
|
149 return static_cast<XParameterSetBase*>(iParameterSets[i]); |
|
150 } |
|
151 } |
|
152 return NULL; // not found |
|
153 } |
|
154 |
|
155 |
|
156 EXPORT_C TBool CParameterSetContainer::FindParameterSet(const XParameterSetBase& aRhs) |
|
157 { |
|
158 TUint length = iParameterSets.Count(); |
|
159 for (TUint i = 0; i < length; ++i) |
|
160 { |
|
161 if (iParameterSets[i] == &aRhs) |
|
162 { |
|
163 return ETrue; |
|
164 } |
|
165 } |
|
166 return EFalse; // not found |
|
167 } |
|
168 |
|
169 |
|
170 /** |
|
171 Searches a parameter set container for a parameter set. |
|
172 @param aSetId The STypeId of the set |
|
173 @return Pointer to the set if found, otherwise a NULL pointer. |
|
174 */ |
|
175 EXPORT_C XParameterSetBase* CParameterSetContainer::GetParameterSet(TInt aIndex) |
|
176 { |
|
177 TInt length = iParameterSets.Count(); |
|
178 |
|
179 return (aIndex >= length || aIndex < 0) ? 0 : static_cast<XParameterSetBase*>(iParameterSets[aIndex]); |
|
180 } |
|
181 |
|
182 |
|
183 /** |
|
184 Calculates the length of buffer required to serialise this parameter set container. |
|
185 @return Length of buffer required. |
|
186 */ |
|
187 EXPORT_C /*virtual*/ TInt CParameterSetContainer::Length() const |
|
188 { |
|
189 return sizeof(TInt32) + iParameterSets.Length(); |
|
190 } |
|
191 |
|
192 |
|
193 /** |
|
194 Instructs this container to create a serialised version of itself |
|
195 and append it to the buffer that has been passed. |
|
196 |
|
197 @param aDes Buffer to append the serialised object to |
|
198 @return KErrNone if successful, otherwise system wide error (e.g. KErrOverflow if the descriptor is too small) |
|
199 If unsuccessful, there is no guarantee as to the buffer or data stored in it. |
|
200 */ |
|
201 EXPORT_C /*virtual*/ TInt CParameterSetContainer::Store(TDes8& aBuffer) const |
|
202 { |
|
203 // Needs to be at least this size to store len and containerId ptrs |
|
204 // aDes can only grow upto MaxLength. |
|
205 if (aBuffer.MaxLength() < sizeof(TUint32)) |
|
206 { |
|
207 return KErrOverflow; |
|
208 } |
|
209 |
|
210 aBuffer.Append((TUint8*)&iContainerId, sizeof(TUint32)); |
|
211 return iParameterSets.Store(aBuffer); |
|
212 } |
|
213 |
|
214 |
|
215 /** |
|
216 Set up the container with empty sets |
|
217 |
|
218 @param aBundle Bundle (parent container) that this new parameter set container is to be added to |
|
219 @exception leaves with KErrNoMemory in out of memory conditions |
|
220 */ |
|
221 EXPORT_C void CParameterSetContainer::ConstructL(CParameterBundleBase& aBundle) |
|
222 { |
|
223 aBundle.AddParamSetContainerL(*this); // need specific R type.. nngh |
|
224 } |
|
225 |
|
226 |
|
227 /** |
|
228 Instructs this container to set its members based on the serialised data |
|
229 in the buffer passed. |
|
230 |
|
231 @param aBuffer Buffer containing the serialised container object |
|
232 @return KErrNone if successful, otherwise system wide error |
|
233 */ |
|
234 EXPORT_C /*virtual*/ TInt CParameterSetContainer::Load(TPtrC8& aBuffer) |
|
235 { |
|
236 // Guard to ensure length of data, pointed to by the descriptor, is not too small, |
|
237 // I.e. we are pointing to something! |
|
238 if (aBuffer.Length() < sizeof(TUint32)) |
|
239 { |
|
240 return KErrArgument; |
|
241 } |
|
242 |
|
243 // Obtain the ContainerId value of the data pointed to by the descriptor |
|
244 Mem::Copy(&iContainerId, aBuffer.Ptr(),sizeof(TInt32)); |
|
245 aBuffer.Set(aBuffer.Ptr() + sizeof(TInt32), aBuffer.Length() - sizeof(TInt32)); |
|
246 |
|
247 // Load the parameter sets |
|
248 // ----------------------- |
|
249 // This type Id is the type id of the RMetaDataContainerBase, it needs |
|
250 // to stripped by its containing object due to an asymetric Load/Store. |
|
251 // This defect has so far been ignored/dismissed due to the potential |
|
252 // large amount of work to fix and possible wide spread BC issues. |
|
253 TInt ret = iParameterSets.GetTypeId().Check(aBuffer); |
|
254 if (ret == KErrNone) |
|
255 { |
|
256 ret = iParameterSets.Load(aBuffer); |
|
257 } |
|
258 |
|
259 if (ret != KErrNone) |
|
260 { |
|
261 return ret; |
|
262 } |
|
263 |
|
264 return KErrNone; |
|
265 } |
|
266 |
|
267 |
|
268 EXPORT_C void CParameterSetContainer::ReplaceParameterSetL(TInt aIndex, XParameterSetBase* aNewSet) |
|
269 { |
|
270 User::LeaveIfError(ReplaceParameterSet(aIndex, aNewSet)); |
|
271 } |
|
272 |
|
273 EXPORT_C TInt CParameterSetContainer::ReplaceParameterSet(TInt aIndex, XParameterSetBase* aNewSet) |
|
274 { |
|
275 if (aIndex > iParameterSets.Count()) |
|
276 { |
|
277 return KErrNotFound; |
|
278 } |
|
279 |
|
280 XParameterSetBase* oldSet = static_cast<XParameterSetBase*>(iParameterSets[aIndex]); |
|
281 if (oldSet == aNewSet) |
|
282 { |
|
283 // same thing.. so do nothing |
|
284 return KErrNone; |
|
285 } |
|
286 |
|
287 delete oldSet; |
|
288 iParameterSets[aIndex] = aNewSet; |
|
289 return KErrNone; |
|
290 } |
|
291 |
|
292 |
|
293 EXPORT_C void CParameterSetContainer::DeleteParameterSetL(TInt aIndex) |
|
294 { |
|
295 User::LeaveIfError(DeleteParameterSet(aIndex)); |
|
296 } |
|
297 |
|
298 EXPORT_C TInt CParameterSetContainer::DeleteParameterSet(TInt aIndex) |
|
299 { |
|
300 if(aIndex > iParameterSets.Count()) |
|
301 { |
|
302 return KErrNotFound; |
|
303 } |
|
304 |
|
305 delete iParameterSets[aIndex]; |
|
306 iParameterSets.Remove(aIndex); |
|
307 return KErrNone; |
|
308 } |
|
309 |
|
310 |
|
311 EXPORT_C XParameterSetBase* CParameterSetContainer::RemoveParameterSet(TInt aIndex) |
|
312 { |
|
313 if(aIndex > iParameterSets.Count()) |
|
314 { |
|
315 return NULL; |
|
316 } |
|
317 |
|
318 XParameterSetBase* ps = static_cast<XParameterSetBase*>(iParameterSets[aIndex]); |
|
319 iParameterSets.Remove(aIndex); |
|
320 return ps; |
|
321 } |
|
322 |
|
323 |
|
324 EXPORT_C void CParameterSetContainer::GrowToFitL(TInt aMinSize) |
|
325 { |
|
326 User::LeaveIfError(GrowToFit(aMinSize)); |
|
327 } |
|
328 |
|
329 EXPORT_C TInt CParameterSetContainer::GrowToFit(TInt aMinSize) |
|
330 { |
|
331 if(iParameterSets.Count() < aMinSize) |
|
332 { |
|
333 TInt err = iParameterSets.Reserve(aMinSize); |
|
334 if (err != KErrNone) |
|
335 { |
|
336 return err; |
|
337 } |
|
338 |
|
339 while(iParameterSets.Count() < aMinSize) |
|
340 { |
|
341 // Append can't fail - we reserved the space |
|
342 iParameterSets.Append(NULL); |
|
343 } |
|
344 } |
|
345 return KErrNone; |
|
346 } |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 // PARAMETER BUNDLE |
|
352 |
|
353 EXPORT_C /*virtual*/ CParameterBundleBase::~CParameterBundleBase() |
|
354 { |
|
355 iSetContainers.ResetAndDestroy(); |
|
356 } |
|
357 |
|
358 |
|
359 /** |
|
360 Calculates the length of buffer required to serialise this parameter set bundle. |
|
361 @return Length of buffer required. |
|
362 */ |
|
363 EXPORT_C TUint CParameterBundleBase::Length() const |
|
364 { |
|
365 TInt length = 0; |
|
366 TUint count = iSetContainers.Count(); |
|
367 for (TUint i = 0; i < count; ++i) |
|
368 { |
|
369 length += iSetContainers[i]->Length(); |
|
370 } |
|
371 return length; |
|
372 } |
|
373 |
|
374 |
|
375 /** |
|
376 Instructs this sub-connection parameter bundle to create a serilised version of itself |
|
377 and append it to the buffer that has been passed. |
|
378 |
|
379 @param aDes Buffer to append the serialised object to |
|
380 @return KErrNone if successful, otherwise system wide error (e.g. EKrrOverflow if the descriptor is too small) |
|
381 If unsuccessful, there is no guarantee as to the buffer or data stored in it. |
|
382 */ |
|
383 EXPORT_C TInt CParameterBundleBase::Store(TDes8& aDes) const |
|
384 { |
|
385 TUint length = iSetContainers.Count(); |
|
386 |
|
387 for (TUint i = 0; i < length; ++i) |
|
388 { |
|
389 TInt ret = iSetContainers[i]->Store(aDes); |
|
390 if (ret != KErrNone) |
|
391 { |
|
392 aDes.Zero(); |
|
393 return ret; |
|
394 } |
|
395 } |
|
396 return KErrNone; |
|
397 } |
|
398 |
|
399 |
|
400 /** |
|
401 Add a parameter set container to the bundle. |
|
402 @param aContainer Container to be added (bundle takes ownership) |
|
403 @exception Leaves with KErrNoMemory in out of memory conditions |
|
404 */ |
|
405 EXPORT_C void CParameterBundleBase::AddParamSetContainerL(CParameterSetContainer& aContainer) |
|
406 { |
|
407 iSetContainers.AppendL(&aContainer); |
|
408 } |
|
409 |
|
410 /** |
|
411 Add a parameter set container to the bundle. |
|
412 @param aContainer Container to be added (bundle takes ownership) |
|
413 @return Returns with KErrNoMemory in out of memory conditions |
|
414 */ |
|
415 EXPORT_C TInt CParameterBundleBase::AddParamSetContainer(CParameterSetContainer& aContainer) |
|
416 { |
|
417 return iSetContainers.Append(&aContainer); |
|
418 } |
|
419 |
|
420 /** |
|
421 Remove a parameter set container from the bundle, returning ownership to the calling method |
|
422 @param aIndex index of the container to remove |
|
423 @return The removed parameter set container |
|
424 */ |
|
425 EXPORT_C CParameterSetContainer* CParameterBundleBase::RemoveParamSetContainer(TInt aIndex) |
|
426 { |
|
427 CParameterSetContainer* psc = iSetContainers[aIndex]; |
|
428 iSetContainers.Remove(aIndex); |
|
429 return psc; |
|
430 } |
|
431 |
|
432 |
|
433 /** |
|
434 Pick out the parameter set container at the given index in the bundle. |
|
435 @param aIndex index of the container to get |
|
436 @return Matching container or NULL pointer if index out of range |
|
437 */ |
|
438 EXPORT_C CParameterSetContainer* CParameterBundleBase::GetParamSetContainer(TInt aIndex) |
|
439 { |
|
440 TInt length = iSetContainers.Count(); |
|
441 if(aIndex < 0 || aIndex >= length) |
|
442 { |
|
443 return NULL; |
|
444 } |
|
445 return iSetContainers[aIndex]; |
|
446 } |
|
447 |
|
448 |
|
449 /** |
|
450 Search the parameter bundle for a parameter set container |
|
451 @param aContainerId Id of the container to match against |
|
452 @return Matching container or NULL pointer if not found |
|
453 */ |
|
454 EXPORT_C CParameterSetContainer* CParameterBundleBase::FindParamSetContainer(TUint32 aContainerId) |
|
455 { |
|
456 TUint length = iSetContainers.Count(); |
|
457 for (TUint i = 0; i < length; ++i) |
|
458 { |
|
459 if (iSetContainers[i]->Id() == aContainerId) |
|
460 { |
|
461 return iSetContainers[i]; |
|
462 } |
|
463 } |
|
464 return NULL; |
|
465 } |
|
466 |
|
467 |
|
468 /** |
|
469 Deep search the parameter bundle for a parameter set of given type |
|
470 @param aType Id of the set type to match against |
|
471 @return Matching set or NULL pointer if not found |
|
472 */ |
|
473 EXPORT_C XParameterSetBase* CParameterBundleBase::FindParameterSet(const Meta::STypeId& aType) |
|
474 { |
|
475 TUint length = iSetContainers.Count(); |
|
476 for (TUint i = 0; i < length; ++i) |
|
477 { |
|
478 XParameterSetBase* ps = iSetContainers[i]->FindParameterSet(aType); |
|
479 if(ps) |
|
480 { |
|
481 return ps; |
|
482 } |
|
483 } |
|
484 return NULL; |
|
485 } |
|
486 |
|
487 |
|
488 /** |
|
489 Replaces a given parameter set container with another. The old parameter set container is deleted, |
|
490 and the parameter bundle takes ownership of the new one |
|
491 @param aOld A parameter set container that exists in the parameter bundle |
|
492 @param aNew The parameter set container that will take the place of the old one |
|
493 @exception Leaves with KErrNotFound if the parameter set container was not found in the bundle |
|
494 */ |
|
495 EXPORT_C void CParameterBundleBase::ReplaceParamSetContainerL(CParameterSetContainer* aOld, CParameterSetContainer* aNew) |
|
496 { |
|
497 User::LeaveIfError(ReplaceParamSetContainer(aOld, aNew)); |
|
498 } |
|
499 |
|
500 /** |
|
501 Replaces a given parameter set container with another. The old parameter set container is deleted, |
|
502 and the parameter bundle takes ownership of the new one |
|
503 @param aOld A parameter set container that exists in the parameter bundle |
|
504 @param aNew The parameter set container that will take the place of the old one |
|
505 @return KErrNotFound if the parameter set container was not found in the bundle, otherwise KErrNone. |
|
506 */ |
|
507 EXPORT_C TInt CParameterBundleBase::ReplaceParamSetContainer(CParameterSetContainer* aOld, CParameterSetContainer* aNew) |
|
508 { |
|
509 if (!aOld) |
|
510 { |
|
511 // NULL containers will not exist in the array |
|
512 return KErrNotFound; |
|
513 } |
|
514 |
|
515 TUint length = iSetContainers.Count(); |
|
516 for (TUint i = 0; i < length; ++i) |
|
517 { |
|
518 if (iSetContainers[i] == aOld) |
|
519 { |
|
520 delete aOld; |
|
521 iSetContainers[i] = aNew; |
|
522 return KErrNone; |
|
523 } |
|
524 } |
|
525 |
|
526 return KErrNotFound; |
|
527 } |
|
528 |
|
529 |