1 /* |
|
2 * Copyright (c) 2007 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: Parameters for the IPC message handling between the |
|
15 * Location Centre API and Location Centre Server. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // SYSTEM INCLUDES |
|
21 #include <e32std.h> |
|
22 |
|
23 // USER INCLUDES |
|
24 #include "lcipcparams.h" |
|
25 |
|
26 // CONSTANT DEFINITIONS |
|
27 const TInt KSizeofTUint32 = sizeof( TUint32 ); |
|
28 |
|
29 // ----- Member funtions for RLcIpcAppIdArray -------------------------------- |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // void RLcIpcAppIdArray::ExternalizeL |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 EXPORT_C void RLcIpcAppIdArray::ExternalizeL( RWriteStream& aWriteStream ) |
|
36 { |
|
37 // The format for packing the buffer would be as follows |
|
38 // Count | Length1 | ID1 | Length2 | ID2 | ... |
|
39 // where |
|
40 // Count - The number of strings which would be packed |
|
41 // Length1 - The Length of the first Identifier string |
|
42 // ID1 - First Identifier |
|
43 // Length2 - The Length of the second Identifier string |
|
44 // ID2 - Second Identifier. |
|
45 // ... |
|
46 |
|
47 const TInt count = Count(); |
|
48 // First pack the number of elements in the array. Even if there is no |
|
49 // elements pack a 0 |
|
50 |
|
51 aWriteStream.WriteUint32L( Count()); |
|
52 |
|
53 for ( TInt i = 0; i < count; i++ ) |
|
54 { |
|
55 // Obtain the element at position i |
|
56 HBufC* element = ( *this )[i]; |
|
57 |
|
58 // As per the grammar first pack the length and then pack the string |
|
59 TInt length = element->Des().Length(); |
|
60 aWriteStream.WriteUint32L( length ); |
|
61 |
|
62 // Now pack the identifier |
|
63 aWriteStream.WriteL( element->Des(), length ); |
|
64 } |
|
65 |
|
66 aWriteStream.CommitL(); |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // void RLcIpcAppIdArray::InternalizeL |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 EXPORT_C void RLcIpcAppIdArray::InternalizeL( RReadStream& aReadStream ) |
|
74 { |
|
75 // Clean up all the elements in the array so that the previous internalized |
|
76 // structure would be removed. |
|
77 ResetAndDestroy(); |
|
78 |
|
79 // The first element in the array is the Count variable which indicates |
|
80 // the number of elements in this array. |
|
81 const TUint32 count = aReadStream.ReadUint32L(); |
|
82 |
|
83 // Even a string containing no elements is acceptable. |
|
84 for ( TInt i = 0; i < count; i++ ) |
|
85 { |
|
86 // First read the length of the Identifer |
|
87 TUint32 length = aReadStream.ReadUint32L(); |
|
88 if ( length >= KMaxTInt/2 ) |
|
89 { |
|
90 User::Leave( KErrArgument ); |
|
91 } |
|
92 |
|
93 // Now create a buffer to read the actual identifier name. The length |
|
94 // of the buffer would be defined by the length value. Use this buffer |
|
95 // read the identifier. |
|
96 HBufC* buffer = HBufC::NewLC( length ); |
|
97 TPtr bufferPtr( buffer->Des()); |
|
98 |
|
99 aReadStream.ReadL( bufferPtr, length ); |
|
100 |
|
101 // Transfer the ownership of the buffer to this array. |
|
102 User::LeaveIfError( Append( buffer )); |
|
103 CleanupStack::Pop( buffer ); |
|
104 } |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // void RLcIpcAppIdArray::BufferLength |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 EXPORT_C TInt RLcIpcAppIdArray::BufferLength() |
|
112 { |
|
113 TInt length = 0; |
|
114 |
|
115 // Pack the Length for including the length of Count buffer |
|
116 length += KSizeofTUint32; |
|
117 |
|
118 // Even a string containing no elements is acceptable. |
|
119 for ( TInt i = 0; i < Count(); i++ ) |
|
120 { |
|
121 // First 4 bytes for the Length of the string |
|
122 length += KSizeofTUint32; |
|
123 |
|
124 // Now pack the length for the buffer |
|
125 length += ( *this )[i]->Des().Size(); |
|
126 } |
|
127 return length; |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // void RLcIpcAppIdArray::ResetAndDestroyIdArray |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 EXPORT_C void RLcIpcAppIdArray::ResetAndDestroyIdArray( TAny* aIdArray ) |
|
135 { |
|
136 RLcIpcAppIdArray* array = reinterpret_cast< RLcIpcAppIdArray* >( aIdArray ); |
|
137 if ( array ) |
|
138 { |
|
139 array->ResetAndDestroy(); |
|
140 } |
|
141 |
|
142 } |
|
143 |
|
144 |
|
145 // ----- Member funtions for RLcIpcAppIdArray -------------------------------- |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // void RLcIpcAppInfoArray::ExternalizeL |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 EXPORT_C void RLcIpcAppInfoArray::ExternalizeL( RWriteStream& aWriteStream ) |
|
152 { |
|
153 // The format for packing the buffer would be as follows |
|
154 // Count | IDLength | ID | NameLength | Name | Launch mode | Sys Characteristics | |
|
155 // Application Characteristics |
|
156 // where |
|
157 // Count - The number of structures which would be packed |
|
158 // IDLength - The Length of the Identifier string |
|
159 // ID - Application Identifier |
|
160 // NameLength - The Length of the name string |
|
161 // Name - Application Name. |
|
162 // IconFile Length - Length of the Icon file name. |
|
163 // Icon File - Full path of the icon file with file name |
|
164 // IconFile Type - The Icon file type |
|
165 // Frame No - The Frame no of the icon if the icon file is a MIF |
|
166 // file |
|
167 // Launch Mode - Launching mode of the application |
|
168 // Sys Char - System characteristics |
|
169 // App Char - Application characteristics |
|
170 // These elements are repeated for all Application information structures. |
|
171 |
|
172 const TInt count = Count(); |
|
173 // First pack the number of elements in the array. Even if there is no |
|
174 // elements pack a 0 |
|
175 |
|
176 aWriteStream.WriteUint32L( Count()); |
|
177 |
|
178 for ( TInt i = 0; i < count; i++ ) |
|
179 { |
|
180 // Obtain the element at position i |
|
181 CLcAppInfo* element = ( *this )[i]; |
|
182 |
|
183 // Externalize the parent class first and then externalize the child |
|
184 element->ExternalizeL( aWriteStream ); |
|
185 } |
|
186 |
|
187 aWriteStream.CommitL(); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // void RLcIpcAppIdArray::InternalizeL |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 EXPORT_C void RLcIpcAppInfoArray::InternalizeL( RReadStream& aReadStream ) |
|
195 { |
|
196 // Clean up all the elements in the array so that the previous internalized |
|
197 // structure would be removed. |
|
198 ResetAndDestroy(); |
|
199 |
|
200 // The first element in the array is the Count variable which indicates |
|
201 // the number of elements in this array. |
|
202 const TUint32 count = aReadStream.ReadUint32L(); |
|
203 |
|
204 // Even a string containing no elements is acceptable. |
|
205 for ( TInt i = 0; i < count; i++ ) |
|
206 { |
|
207 |
|
208 // Create a new CLcAppInfo element |
|
209 CLcAppInfo* element = CLcAppInfo::NewLC(); |
|
210 |
|
211 // Internalize the Parent class first and then proceed to the child |
|
212 element->InternalizeL( aReadStream ); |
|
213 |
|
214 // Transfer the ownership of the buffer to this array. |
|
215 User::LeaveIfError( Append( element )); |
|
216 CleanupStack::Pop( element ); |
|
217 |
|
218 } |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // TInt RLcIpcAppInfoArray::BufferLength |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 EXPORT_C TInt RLcIpcAppInfoArray::BufferLength() |
|
226 { |
|
227 TInt length = 0; |
|
228 |
|
229 // Pack the length for the Count field. |
|
230 length += KSizeofTUint32; |
|
231 |
|
232 // Pack the length required for the individual app structures |
|
233 |
|
234 TInt count = Count(); |
|
235 for ( TInt i = 0; i < count; i++ ) |
|
236 { |
|
237 // Obtain the element at position i |
|
238 CLcAppInfo* element = ( *this )[i]; |
|
239 |
|
240 // Pack the length required for this element |
|
241 length += element->BufferLength(); |
|
242 } |
|
243 |
|
244 return length; |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // void RLcIpcAppIdArray::ResetAndDestroyIdArray |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 EXPORT_C void RLcIpcAppInfoArray::ResetAndDestroyAppArray( TAny* aIdArray ) |
|
252 { |
|
253 RLcIpcAppInfoArray* array = reinterpret_cast< RLcIpcAppInfoArray* >( aIdArray ); |
|
254 if ( array ) |
|
255 { |
|
256 array->ResetAndDestroy(); |
|
257 } |
|
258 } |
|
259 |
|
260 // ----- Member funtions for CLcBasicAppInfo --------------------------------- |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // void CLcBasicAppInfo::ExternalizeL |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 EXPORT_C void CLcBasicAppInfo::ExternalizeL( RWriteStream& aWriteStream ) |
|
267 { |
|
268 // The format for packing the buffer would be as follows |
|
269 // Application Type | DataLength | Data | CmdLength | Cmd |
|
270 // where |
|
271 // Application Type - The type of the Application which is stored in the |
|
272 // structure. |
|
273 // DataLength - The Length of the Application data string |
|
274 // Data - Application Data |
|
275 // CmdLength - The Length of the command line arguments |
|
276 // Cmd - Command line arguments |
|
277 |
|
278 // First pack the Application type |
|
279 |
|
280 aWriteStream.WriteUint32L( iAppType ); |
|
281 |
|
282 // Pack the Launching mode of the application |
|
283 aWriteStream.WriteUint32L( iLaunchMode ); |
|
284 |
|
285 // Pack the length of the Application Data. If there is no application |
|
286 // data then pack zero. |
|
287 TUint length = 0; |
|
288 if ( iAppData ) |
|
289 { |
|
290 length = iAppData->Length(); |
|
291 } |
|
292 aWriteStream.WriteUint32L( length ); |
|
293 |
|
294 // If there is a valid data field pack it onto the buffer. |
|
295 if ( length ) |
|
296 { |
|
297 aWriteStream.WriteL( iAppData->Des(), length ); |
|
298 } |
|
299 |
|
300 // Pack the command line arguments. If there is no command line |
|
301 // parameters then pack a length of 0 |
|
302 length = 0; |
|
303 if ( iCmdLineParams ) |
|
304 { |
|
305 length = iCmdLineParams->Length(); |
|
306 } |
|
307 aWriteStream.WriteUint32L( length ); |
|
308 |
|
309 // If there is a valid command line parameters field pack it onto the buffer. |
|
310 if ( length ) |
|
311 { |
|
312 aWriteStream.WriteL( iCmdLineParams->Des(), length ); |
|
313 } |
|
314 |
|
315 aWriteStream.CommitL(); |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // void CLcBasicAppInfo::InternalizeL |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 EXPORT_C void CLcBasicAppInfo::InternalizeL( RReadStream& aReadStream ) |
|
323 { |
|
324 // Clear the application data |
|
325 delete iAppData; |
|
326 iAppData = NULL; |
|
327 |
|
328 // Clear the command line params |
|
329 delete iCmdLineParams; |
|
330 iCmdLineParams = NULL; |
|
331 |
|
332 // The first element in the array if the Application type variable. |
|
333 iAppType = aReadStream.ReadUint32L(); |
|
334 |
|
335 // The second element is the Application Launch mode |
|
336 iLaunchMode = aReadStream.ReadUint32L(); |
|
337 |
|
338 // Now get the length of the data field. |
|
339 TUint32 length = aReadStream.ReadUint32L(); |
|
340 if ( length >= KMaxTInt/2 ) |
|
341 { |
|
342 User::Leave( KErrArgument ); |
|
343 } |
|
344 // Set the application data only if the length is a +ve value. |
|
345 if ( length ) |
|
346 { |
|
347 iAppData = HBufC::NewL( length ); |
|
348 TPtr appData( iAppData->Des()); |
|
349 aReadStream.ReadL( appData, length ); |
|
350 } |
|
351 |
|
352 // Now read the length of the command line parameters |
|
353 length = aReadStream.ReadUint32L(); |
|
354 if ( length >= KMaxTInt/2 ) |
|
355 { |
|
356 User::Leave( KErrArgument ); |
|
357 } |
|
358 // Set the command line params only if the length is a +ve value. |
|
359 if ( length ) |
|
360 { |
|
361 iCmdLineParams = HBufC::NewL( length ); |
|
362 TPtr cmdParam( iCmdLineParams->Des()); |
|
363 aReadStream.ReadL( cmdParam, length ); |
|
364 } |
|
365 } |
|
366 |
|
367 // --------------------------------------------------------------------------- |
|
368 // TInt CLcBasicAppInfo::BufferLength |
|
369 // --------------------------------------------------------------------------- |
|
370 // |
|
371 EXPORT_C TInt CLcBasicAppInfo::BufferLength() |
|
372 { |
|
373 TInt length = 0; |
|
374 |
|
375 // Include length for Application type |
|
376 length += KSizeofTUint32; |
|
377 |
|
378 // Add the length for Launch mode |
|
379 length += KSizeofTUint32; |
|
380 |
|
381 // Add the length of the Application Data and the length for Application |
|
382 // data if it exists |
|
383 length += KSizeofTUint32; |
|
384 |
|
385 if ( iAppData ) |
|
386 { |
|
387 length += iAppData->Des().MaxSize(); |
|
388 } |
|
389 |
|
390 // Add the length of the Command line args and the length for Cmd line |
|
391 // args if it exists |
|
392 length += KSizeofTUint32; |
|
393 |
|
394 if ( iCmdLineParams ) |
|
395 { |
|
396 length += iCmdLineParams->Des().MaxSize(); |
|
397 } |
|
398 return length; |
|
399 } |
|
400 |
|
401 |
|
402 // ----- Member funtions for CLcBasicAppInfo --------------------------------- |
|
403 |
|
404 // --------------------------------------------------------------------------- |
|
405 // void CLcBasicAppInfo::ExternalizeL |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 void CLcAppInfo::ExternalizeL( RWriteStream& aWriteStream ) |
|
409 { |
|
410 CLcBasicAppInfo::ExternalizeL( aWriteStream ); |
|
411 |
|
412 // As per the grammar first pack the length and then pack the string |
|
413 TInt length = Id().Length(); |
|
414 aWriteStream.WriteUint32L( length ); |
|
415 |
|
416 // Pack the Identifier. No need to check for the Length since |
|
417 // this is a mandatory field and the Application would not have been |
|
418 // accepted if it were not +ve |
|
419 aWriteStream.WriteL( Id(), length ); |
|
420 |
|
421 // Pack the name. If there is no name then pack a length of 0 for the |
|
422 // name field. |
|
423 length = Name().Length(); |
|
424 aWriteStream.WriteUint32L( length ); |
|
425 |
|
426 // Pack the name field only if the length is +ve |
|
427 if ( length ) |
|
428 { |
|
429 aWriteStream.WriteL( Name(), length ); |
|
430 } |
|
431 |
|
432 // Pack the Icon file and Icon file type for the file |
|
433 length = IconFile().Length(); |
|
434 aWriteStream.WriteUint32L( length ); |
|
435 |
|
436 if ( length ) |
|
437 { |
|
438 aWriteStream.WriteL( IconFile(), length ); |
|
439 aWriteStream.WriteUint32L( iIconFileType); |
|
440 |
|
441 // If the Icon file type is a MIF, pack the Frame no |
|
442 if ( EMifFile == iIconFileType ) |
|
443 { |
|
444 aWriteStream.WriteUint32L( iFrameNo ); |
|
445 } |
|
446 } |
|
447 |
|
448 // Pack the System characteristics |
|
449 aWriteStream.WriteUint32L( iSystemCharacteristics ); |
|
450 |
|
451 // Pack the application characteristics |
|
452 aWriteStream.WriteUint32L( iAppCharacteristics ); |
|
453 |
|
454 aWriteStream.CommitL(); |
|
455 } |
|
456 |
|
457 // --------------------------------------------------------------------------- |
|
458 // void CLcBasicAppInfo::InternalizeL |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 void CLcAppInfo::InternalizeL( RReadStream& aReadStream ) |
|
462 { |
|
463 CLcBasicAppInfo::InternalizeL( aReadStream ); |
|
464 |
|
465 // First read the length of the Identifer |
|
466 TUint32 length = aReadStream.ReadUint32L(); |
|
467 if ( length >= KMaxTInt/2 ) |
|
468 { |
|
469 User::Leave( KErrArgument ); |
|
470 } |
|
471 |
|
472 // No need to check for the length for this is a mandatory field. |
|
473 // Now create a buffer to read the actual identifier. The length |
|
474 // of the buffer would be defined by the length value. Use this buffer |
|
475 // read the identifier. |
|
476 iId = HBufC::NewL( length ); |
|
477 TPtr bufferPtr( iId->Des()); |
|
478 aReadStream.ReadL( bufferPtr, length ); |
|
479 |
|
480 // Read the length of the name buffer |
|
481 length = aReadStream.ReadUint32L(); |
|
482 if ( length >= KMaxTInt/2 ) |
|
483 { |
|
484 User::Leave( KErrArgument ); |
|
485 } |
|
486 |
|
487 if ( length ) |
|
488 { |
|
489 iApplicationName = HBufC::NewL( length ); |
|
490 bufferPtr.Set( iApplicationName->Des()); |
|
491 |
|
492 // Read the name field |
|
493 aReadStream.ReadL( bufferPtr, length ); |
|
494 } |
|
495 |
|
496 // Read the Icon file if its exists |
|
497 length = aReadStream.ReadUint32L(); |
|
498 if ( length >= KMaxTInt/2 ) |
|
499 { |
|
500 User::Leave( KErrArgument ); |
|
501 } |
|
502 |
|
503 if ( length ) |
|
504 { |
|
505 iIconFile = HBufC::NewL( length ); |
|
506 bufferPtr.Set( iIconFile->Des()); |
|
507 |
|
508 // Read the Icon file field |
|
509 aReadStream.ReadL( bufferPtr, length ); |
|
510 |
|
511 // Set the Icon file type |
|
512 iIconFileType = |
|
513 static_cast< CLcAppInfo::TLcIconFileType >( aReadStream.ReadUint32L()); |
|
514 |
|
515 // If the Icon file type is a MIF file then set the Frame no |
|
516 if ( EMifFile == iIconFileType ) |
|
517 { |
|
518 iFrameNo = aReadStream.ReadUint32L(); |
|
519 } |
|
520 } |
|
521 |
|
522 // Set the System characteristics |
|
523 iSystemCharacteristics = aReadStream.ReadUint32L(); |
|
524 |
|
525 // Set the Application characteristics |
|
526 iAppCharacteristics = aReadStream.ReadUint32L(); |
|
527 } |
|
528 |
|
529 // --------------------------------------------------------------------------- |
|
530 // TInt CLcAppInfo::BufferLength |
|
531 // --------------------------------------------------------------------------- |
|
532 // |
|
533 EXPORT_C TInt CLcAppInfo::BufferLength() |
|
534 { |
|
535 TInt length = 0; |
|
536 |
|
537 // First pack the length for the Basic App Info structure |
|
538 length += CLcBasicAppInfo::BufferLength(); |
|
539 |
|
540 // Include length for Application Identifier |
|
541 length += KSizeofTUint32; |
|
542 length += iId->Des().MaxSize(); |
|
543 |
|
544 // Pack the name field and the Length of the name field if it exists |
|
545 // Add the length of the Command line args and the length for Cmd line |
|
546 // args if it exists |
|
547 length += KSizeofTUint32; |
|
548 |
|
549 if ( iApplicationName ) |
|
550 { |
|
551 length += iApplicationName->Des().MaxSize(); |
|
552 } |
|
553 |
|
554 // Pack the Icon file field and the name of icon file if it exists |
|
555 // Read the Icon file if its exists |
|
556 length += KSizeofTUint32; |
|
557 if ( iIconFile ) |
|
558 { |
|
559 // Pack the Icon file name length |
|
560 length += iIconFile->Des().MaxSize(); |
|
561 |
|
562 // Pack the Icon file type |
|
563 length += KSizeofTUint32; |
|
564 |
|
565 // If the Icon file type is a MIF file then add length for the |
|
566 // frame number |
|
567 if ( EMifFile == iIconFileType ) |
|
568 { |
|
569 length += KSizeofTUint32; |
|
570 } |
|
571 } |
|
572 |
|
573 // Add the length for System characteristics |
|
574 length += KSizeofTUint32; |
|
575 |
|
576 // Add the length for Application characteristics |
|
577 length += KSizeofTUint32; |
|
578 |
|
579 return length; |
|
580 } |
|
581 // End of File |
|