|
1 /* |
|
2 * Copyright (c) 2008 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <s32mem.h> |
|
20 |
|
21 #include "casrvdef.h" |
|
22 |
|
23 class RWriteStream; |
|
24 class RReadStream; |
|
25 class CCaInnerEntry; |
|
26 class RIdsArray; |
|
27 |
|
28 NONSHARABLE_CLASS( MenuUtils ) |
|
29 { |
|
30 public: |
|
31 /** |
|
32 * Gets TUint from a aStr - HEX or Decimal |
|
33 * |
|
34 * @return error code |
|
35 */ |
|
36 IMPORT_C static TInt GetTUint( const TDesC& aStr, TUint& aInt ); |
|
37 |
|
38 /** |
|
39 * Template method for marshaling data. |
|
40 * @param aObject object supporting ExternalizeL method |
|
41 * @param aExpandSize granularity of the buffer |
|
42 * @return descriptor containing serialized object |
|
43 */ |
|
44 template<typename SerializableObject> |
|
45 static HBufC8* MarshalDataL( const SerializableObject& aObject, |
|
46 TInt aExpandSize ) |
|
47 { |
|
48 TIpcArgs args; |
|
49 CBufFlat* buf = CBufFlat::NewL( aExpandSize ); |
|
50 CleanupStack::PushL( buf ); |
|
51 RBufWriteStream stream( *buf ); |
|
52 CleanupClosePushL( stream ); |
|
53 aObject.ExternalizeL( stream ); |
|
54 stream.CommitL(); |
|
55 CleanupStack::PopAndDestroy( &stream ); |
|
56 HBufC8* des = HBufC8::NewL( buf->Size() ); |
|
57 TPtr8 ptr( des->Des() ); |
|
58 buf->Read( 0, ptr, buf->Size() ); |
|
59 CleanupStack::PopAndDestroy( buf ); |
|
60 return des; |
|
61 } |
|
62 |
|
63 /** |
|
64 * Internalizes object from descriptor which is stored in aMessage |
|
65 * @param aMessage message containing descriptor with serialized object |
|
66 * @param aObject an object supporting InternalizeL method |
|
67 */ |
|
68 template<typename SerializableObject> |
|
69 static void InternalizeObjectL( const RMessage2& aMessage, |
|
70 SerializableObject& aObject ) |
|
71 { |
|
72 TInt deslen = aMessage.GetDesLength( KInputPosition1 ); |
|
73 HBufC8* buffer = HBufC8::NewLC( deslen ); |
|
74 TPtr8 tempDes = buffer->Des(); |
|
75 aMessage.Read( KInputPosition1, tempDes ); |
|
76 RDesReadStream datastrm( *buffer ); |
|
77 CleanupClosePushL( datastrm ); |
|
78 aObject.InternalizeL( datastrm ); |
|
79 CleanupStack::PopAndDestroy( &datastrm ); |
|
80 CleanupStack::PopAndDestroy( buffer ); |
|
81 } |
|
82 }; |