|
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: Codec to code attribute requests. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "PEngAttributeRequestCodec.h" |
|
20 #include "MPEngPresenceAdvancedAttrModel2.h" |
|
21 #include "MPEngPresenceAttrManager.h" |
|
22 |
|
23 |
|
24 #include <E32Base.h> |
|
25 #include <MPEngPresenceAttrModel2.h> |
|
26 #include <S32strm.h> |
|
27 #include <S32mem.h> |
|
28 |
|
29 |
|
30 //CONSTS |
|
31 const TInt KStreamExpandSize = 500; |
|
32 |
|
33 |
|
34 // ============================ LOCAL FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // AlignBufferTo2L() |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 void AlignBufferTo2L( CBufFlat& aBuffer, RWriteStream& aWStream ) |
|
41 { |
|
42 //align stream size to 2 |
|
43 if ( ( aBuffer.Size() % 2 ) == 1 ) |
|
44 { |
|
45 //pad with zero |
|
46 aWStream.WriteInt8L( 0 ); |
|
47 } |
|
48 } |
|
49 |
|
50 |
|
51 |
|
52 // ============================ MEMBER FUNCTIONS =============================== |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // PEngAttributeRequestCodec::PackModelArrayL() |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 HBufC16* PEngAttributeRequestCodec::PackModelArrayL( |
|
59 const RPointerArray<MPEngPresenceAttrModel2>& aModels ) |
|
60 { |
|
61 //Init stream |
|
62 CBufFlat* dynBuffer = CBufFlat::NewL( KStreamExpandSize ); |
|
63 CleanupStack::PushL( dynBuffer ); |
|
64 |
|
65 RBufWriteStream wstream; |
|
66 wstream.Open( *dynBuffer ); |
|
67 CleanupClosePushL( wstream ); |
|
68 |
|
69 |
|
70 //Serialize the data |
|
71 const TInt modelCount = aModels.Count(); |
|
72 wstream.WriteInt32L( modelCount ); |
|
73 for ( TInt ii = 0; ii < modelCount; ii++ ) |
|
74 { |
|
75 const MPEngPresenceAdvancedAttrModel2* model = aModels[ ii ]->Advanced(); |
|
76 wstream.WriteUint32L( model->Type() ); |
|
77 WritePresenceIdL( wstream, model->PresenceID() ); |
|
78 |
|
79 model->ExternalizeL( wstream ); |
|
80 } |
|
81 |
|
82 |
|
83 AlignBufferTo2L( *dynBuffer, wstream ); |
|
84 |
|
85 //Cleanup |
|
86 wstream.CommitL(); |
|
87 CleanupStack::PopAndDestroy(); //wstream |
|
88 |
|
89 |
|
90 //make 16 bit presentation of data |
|
91 TPtrC8 bufDataPtr8( dynBuffer->Ptr( 0 ) ); |
|
92 TPtrC16 bufDataPtr16( ( TUint16* ) bufDataPtr8.Ptr(), ( bufDataPtr8.Size() / 2 ) ); |
|
93 |
|
94 HBufC16* heapBuffer = bufDataPtr16.AllocL(); |
|
95 CleanupStack::PopAndDestroy( dynBuffer ); |
|
96 |
|
97 return heapBuffer; |
|
98 } |
|
99 |
|
100 |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // PEngAttributeRequestCodec::UnpackModelArrayL() |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void PEngAttributeRequestCodec::UnpackModelArrayL( |
|
107 const TDesC16& aModelPkg, |
|
108 TInt aInstanceOptions, |
|
109 RPointerArray<MPEngPresenceAttrModel2>& aModels, |
|
110 MPEngPresenceAttrManager& aAttributeManager ) |
|
111 |
|
112 { |
|
113 //make 8 bit presentation of data |
|
114 TPtrC8 modelPkg8( ( TUint8* ) aModelPkg.Ptr(), ( aModelPkg.Size() * 2 ) ); |
|
115 |
|
116 |
|
117 //Init stream |
|
118 RDesReadStream rstream; |
|
119 rstream.Open( modelPkg8 ); |
|
120 CleanupClosePushL( rstream ); |
|
121 |
|
122 //Deserialize |
|
123 const TInt modelCount = rstream.ReadInt32L(); |
|
124 for ( TInt ii = 0; ii < modelCount; ii++ ) |
|
125 { |
|
126 //Read model details |
|
127 TUint32 type = rstream.ReadUint32L(); |
|
128 HBufC* presenceId = ReadPresenceIdLC( rstream ); |
|
129 |
|
130 //Create model |
|
131 MPEngPresenceAttrModel2* model = NULL; |
|
132 aAttributeManager.InstantiateAttributeLC( model, |
|
133 *presenceId, |
|
134 type, |
|
135 aInstanceOptions ); |
|
136 |
|
137 model->Advanced()->InternalizeL( rstream ); |
|
138 aModels.AppendL( model ); |
|
139 CleanupStack::Pop(); //model |
|
140 CleanupStack::PopAndDestroy( presenceId ); |
|
141 } |
|
142 |
|
143 |
|
144 CleanupStack::PopAndDestroy(); //rstream |
|
145 } |
|
146 |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // PEngAttributeRequestCodec::PackFetchRequestL() |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 HBufC16* PEngAttributeRequestCodec::PackFetchRequestL( |
|
153 const MDesCArray& aPresenceIDs, |
|
154 const TArray<TUint32>& aTypes ) |
|
155 { |
|
156 CBufFlat* dynBuffer = CBufFlat::NewL( KStreamExpandSize ); |
|
157 CleanupStack::PushL( dynBuffer ); |
|
158 |
|
159 RBufWriteStream wstream; |
|
160 wstream.Open( *dynBuffer ); |
|
161 CleanupClosePushL( wstream ); |
|
162 |
|
163 |
|
164 //Presence IDs |
|
165 const TInt presenceIdCount = aPresenceIDs.MdcaCount(); |
|
166 wstream.WriteInt32L( presenceIdCount ); |
|
167 for ( TInt ii = 0; ii < presenceIdCount; ii++ ) |
|
168 { |
|
169 WritePresenceIdL( wstream, aPresenceIDs.MdcaPoint( ii ) ); |
|
170 } |
|
171 |
|
172 //Attribute types |
|
173 const TInt typeCount = aTypes.Count(); |
|
174 wstream.WriteInt32L( typeCount ); |
|
175 for ( TInt jj = 0; jj < typeCount; jj++ ) |
|
176 { |
|
177 wstream.WriteUint32L( aTypes[ jj ] ); |
|
178 } |
|
179 |
|
180 AlignBufferTo2L( *dynBuffer, wstream ); |
|
181 |
|
182 wstream.CommitL(); |
|
183 CleanupStack::PopAndDestroy(); //wstream |
|
184 |
|
185 |
|
186 //make 16 bit presentation of data |
|
187 TPtrC8 bufDataPtr8( dynBuffer->Ptr( 0 ) ); |
|
188 TPtrC16 bufDataPtr16( ( TUint16* ) bufDataPtr8.Ptr(), ( bufDataPtr8.Size() / 2 ) ); |
|
189 |
|
190 HBufC16* heapBuffer = bufDataPtr16.AllocL(); |
|
191 CleanupStack::PopAndDestroy( dynBuffer ); |
|
192 |
|
193 |
|
194 return heapBuffer; |
|
195 } |
|
196 |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // PEngAttributeRequestCodec::UnpackFetchRequestL() |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 void PEngAttributeRequestCodec::UnpackFetchRequestL( const TDesC16& aFetchRequestPkg, |
|
203 CDesCArray& aPresenceIDs, |
|
204 RArray<TUint32>& aTypes ) |
|
205 { |
|
206 //make 8 bit presentation of data |
|
207 TPtrC8 fetchRequestPkg8( ( TUint8* ) aFetchRequestPkg.Ptr(), ( aFetchRequestPkg.Size() * 2 ) ); |
|
208 |
|
209 //Init stream |
|
210 RDesReadStream rstream; |
|
211 rstream.Open( fetchRequestPkg8 ); |
|
212 CleanupClosePushL( rstream ); |
|
213 |
|
214 //Deserialize Presence IDs |
|
215 const TInt presenceIdCount = rstream.ReadInt32L(); |
|
216 for ( TInt ii = 0; ii < presenceIdCount; ii++ ) |
|
217 { |
|
218 HBufC* presenceId = ReadPresenceIdLC( rstream ); |
|
219 aPresenceIDs.AppendL( *presenceId ); |
|
220 CleanupStack::PopAndDestroy( presenceId ); |
|
221 } |
|
222 |
|
223 |
|
224 //Deserialize Attribute types |
|
225 const TInt typeCount = rstream.ReadInt32L(); |
|
226 for ( TInt jj = 0; jj < typeCount; jj++ ) |
|
227 { |
|
228 TUint32 type = rstream.ReadUint32L(); |
|
229 aTypes.AppendL( type ); |
|
230 } |
|
231 |
|
232 CleanupStack::PopAndDestroy(); //rstream |
|
233 } |
|
234 |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // PEngAttributeRequestCodec::CopyModelDataL() |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void PEngAttributeRequestCodec::CopyModelDataL( const MPEngPresenceAttrModel2& aSource, |
|
241 MPEngPresenceAttrModel2& aDest ) |
|
242 { |
|
243 const MPEngPresenceAdvancedAttrModel2* sourceAdv = aSource.Advanced(); |
|
244 TInt size = sourceAdv->ExternalizeSize(); |
|
245 |
|
246 //Init stream |
|
247 CBufFlat* dynBuffer = CBufFlat::NewL( size ); |
|
248 CleanupStack::PushL( dynBuffer ); |
|
249 |
|
250 RBufWriteStream wstream; |
|
251 wstream.Open( *dynBuffer ); |
|
252 CleanupClosePushL( wstream ); |
|
253 |
|
254 //Serialize the data |
|
255 sourceAdv->ExternalizeL( wstream ); |
|
256 wstream.CommitL(); |
|
257 CleanupStack::PopAndDestroy(); //wstream |
|
258 |
|
259 |
|
260 //And deserialize data to dest. model |
|
261 RBufReadStream rstream; |
|
262 rstream.Open( *dynBuffer ); |
|
263 CleanupClosePushL( rstream ); |
|
264 |
|
265 aDest.Advanced()->InternalizeL( rstream ); |
|
266 |
|
267 CleanupStack::PopAndDestroy(); //rstream |
|
268 CleanupStack::PopAndDestroy( dynBuffer ); |
|
269 } |
|
270 |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // PEngAttributeRequestCodec::WritePresenceIdL() |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 void PEngAttributeRequestCodec::WritePresenceIdL( RWriteStream& aWStream, |
|
277 const TDesC& aPresenceId ) |
|
278 { |
|
279 aWStream.WriteInt32L( aPresenceId.Length() ); |
|
280 aWStream.WriteL( aPresenceId ); |
|
281 } |
|
282 |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // PEngAttributeRequestCodec::ReadPresenceIdLC() |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 HBufC* PEngAttributeRequestCodec::ReadPresenceIdLC( RReadStream& aRStream ) |
|
289 { |
|
290 const TInt presenceIdLength = aRStream.ReadInt32L(); |
|
291 HBufC* presenceId = HBufC::NewLC( presenceIdLength ); |
|
292 TPtr ptr( presenceId->Des() ); |
|
293 aRStream.ReadL( ptr, presenceIdLength ); |
|
294 |
|
295 return presenceId; |
|
296 } |
|
297 |
|
298 |
|
299 // End of File |
|
300 |
|
301 |