|
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: Class for packaging a descriptor array for IPC. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "CNcnPackDescrArray.h" |
|
21 #include <s32mem.h> |
|
22 |
|
23 namespace { |
|
24 |
|
25 // Local utility functions: |
|
26 |
|
27 TInt PackedLength( const MDesCArray& aArray ) |
|
28 { |
|
29 const TInt count = aArray.MdcaCount(); |
|
30 TInt result = count * sizeof( TInt32 ); |
|
31 for ( TInt i = 0; i < count; ++i ) |
|
32 { |
|
33 result += aArray.MdcaPoint( i ).Size(); |
|
34 } |
|
35 return result; |
|
36 } |
|
37 |
|
38 void PackArrayL( TDes8& aBuffer, const MDesCArray& aArray ) |
|
39 { |
|
40 RDesWriteStream stream( aBuffer ); |
|
41 CleanupClosePushL( stream ); |
|
42 const TInt count = aArray.MdcaCount(); |
|
43 for ( TInt i = 0; i < count; ++i ) |
|
44 { |
|
45 TPtrC des( aArray.MdcaPoint( i ) ); |
|
46 stream.WriteInt32L( des.Length() ); |
|
47 stream.WriteL( des ); |
|
48 } |
|
49 CleanupStack::PopAndDestroy(); // stream |
|
50 } |
|
51 |
|
52 } // namespace |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // MEMBER FUNCTIONS |
|
56 // ---------------------------------------------------------------------------- |
|
57 // |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // CNcnPackDescrArray::NewLC |
|
61 // |
|
62 // Symbian two-phased constructor. |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 CNcnPackDescrArray* CNcnPackDescrArray::NewL() |
|
66 { |
|
67 CNcnPackDescrArray* self = new( ELeave ) CNcnPackDescrArray; |
|
68 return self; |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------------------------------- |
|
72 // CNcnPackDescrArray::NewLC |
|
73 // |
|
74 // Symbian two-phased constructor. |
|
75 // ---------------------------------------------------------------------------- |
|
76 // |
|
77 CNcnPackDescrArray* CNcnPackDescrArray::NewLC() |
|
78 { |
|
79 CNcnPackDescrArray* self = new( ELeave ) CNcnPackDescrArray; |
|
80 CleanupStack::PushL( self ); |
|
81 return self; |
|
82 } |
|
83 |
|
84 // ---------------------------------------------------------------------------- |
|
85 // CNcnPackDescrArray::PackL |
|
86 // |
|
87 // Packages descriptor array to a buffer. |
|
88 // ---------------------------------------------------------------------------- |
|
89 // |
|
90 TDesC8* CNcnPackDescrArray::PackL( const MDesCArray& aSourceArray ) |
|
91 { |
|
92 const TInt packedLength = PackedLength( aSourceArray ); |
|
93 HBufC8* buffer = HBufC8::NewLC( packedLength ); |
|
94 TPtr8 bufferPtr = buffer->Des(); |
|
95 PackArrayL( bufferPtr, aSourceArray ); |
|
96 CleanupStack::Pop( buffer ); |
|
97 return buffer; |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // CNcnPackDescrArray::~CNcnPackDescrArray |
|
102 // |
|
103 // Destructor. |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 CNcnPackDescrArray::~CNcnPackDescrArray() |
|
107 { |
|
108 } |
|
109 |
|
110 // ---------------------------------------------------------------------------- |
|
111 // CNcnPackDescrArray::CNcnPackDescrArray |
|
112 // |
|
113 // Constructor. |
|
114 // ---------------------------------------------------------------------------- |
|
115 // |
|
116 CNcnPackDescrArray::CNcnPackDescrArray() |
|
117 { |
|
118 } |
|
119 |
|
120 // End of file |