|
1 /* |
|
2 * Copyright (c) 2008-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: CCFContextService class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 #include <cfcontextdataobject.h> |
|
21 #include <s32mem.h> |
|
22 #include <f32file.h> |
|
23 #include <centralrepository.h> |
|
24 |
|
25 // USER INCLUDES |
|
26 #include "cfcontextservice.h" |
|
27 #include "cftrace.h" |
|
28 #include "cfcommon.h" |
|
29 #include "CFContextObjectImpl.h" |
|
30 #include "cfcontextsubscriptionlistener.h" |
|
31 #include "CFClientSession.h" |
|
32 #include "cfservermessagelistener.h" |
|
33 #include "ContextFrameworkPrivateCRKeys.h" |
|
34 #include "CFContextQueryImpl.h" |
|
35 #include "CFContextSubscriptionImpl.h" |
|
36 |
|
37 // CONSTANTS |
|
38 static const TInt KDefaultBufferSize = 1024; |
|
39 |
|
40 // ======== MEMBER FUNCTIONS ======== |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // C++ constructor. |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CCFContextService::CCFContextService( RCFClientSession& aSession, |
|
47 MCFListener& aListener ): |
|
48 CCFServiceBase( CCFServiceBase::ECFContextService, aSession, aListener ), |
|
49 iContextDataMaxSize( KContextDataObjectDefaultSize ) |
|
50 { |
|
51 FUNC_LOG; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // Symbian 2nd phase constructor. |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 void CCFContextService::ConstructL( ) |
|
59 { |
|
60 FUNC_LOG; |
|
61 |
|
62 // Create context subscription listener |
|
63 iContextSubscriptionListener = CCFContextSubscriptionListener::NewL( |
|
64 iListener, |
|
65 iSession ); |
|
66 |
|
67 // Create server message listener |
|
68 iServerMessageListener = CCFServerMessageListener::NewL( |
|
69 iListener, |
|
70 iSession ); |
|
71 |
|
72 // Get context data object maximum size |
|
73 CRepository* cenrep = NULL; |
|
74 TRAPD( err, cenrep = CRepository::NewL( KCRUidCFCommonConf ) ); |
|
75 if( cenrep && err == KErrNone ) |
|
76 { |
|
77 INFO( "Context data object size read from cenrep." ); |
|
78 err = cenrep->Get( KContextDataObjectMaxSize, iContextDataMaxSize ); |
|
79 if( err != KErrNone ) |
|
80 { |
|
81 iContextDataMaxSize = KContextDataObjectDefaultSize; |
|
82 } |
|
83 delete cenrep; |
|
84 } |
|
85 INFO_1( "Context data object max size set to: [0x%x].", |
|
86 iContextDataMaxSize ); |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // Symbian two phased constructor. |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 CCFContextService* CCFContextService::NewL( RCFClientSession& aSession, |
|
94 MCFListener& aListener ) |
|
95 { |
|
96 FUNC_LOG; |
|
97 |
|
98 CCFContextService* self = CCFContextService::NewLC( aSession, aListener ); |
|
99 CleanupStack::Pop ( self ); |
|
100 return self; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // Symbian two phased constructor. |
|
105 // Leaves pointer in the cleanup stack. |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 CCFContextService* CCFContextService::NewLC( RCFClientSession& aSession, |
|
109 MCFListener& aListener ) |
|
110 { |
|
111 FUNC_LOG; |
|
112 |
|
113 CCFContextService* self = new( ELeave ) CCFContextService( |
|
114 aSession, |
|
115 aListener ); |
|
116 CleanupStack::PushL ( self ); |
|
117 self->ConstructL ( ); |
|
118 return self; |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // C++ destructor. |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 CCFContextService::~CCFContextService( ) |
|
126 { |
|
127 FUNC_LOG; |
|
128 |
|
129 delete iContextSubscriptionListener; |
|
130 delete iServerMessageListener; |
|
131 } |
|
132 |
|
133 //---------------------------------------------------------------------------- |
|
134 // CCFContextService::DefineContext |
|
135 //---------------------------------------------------------------------------- |
|
136 // |
|
137 TInt CCFContextService::DefineContext( const TDesC& aContextSource, |
|
138 const TDesC& aContextType, |
|
139 const TSecurityPolicy& aReadSecurityPolicy, |
|
140 const TSecurityPolicy& aWriteSecurityPolicy ) |
|
141 { |
|
142 FUNC_LOG; |
|
143 |
|
144 TInt err = KErrNone; |
|
145 if( aContextSource.Length() && aContextType.Length() ) |
|
146 { |
|
147 TSecurityPolicyBuf readSecPolicyBuf( aReadSecurityPolicy ); |
|
148 TSecurityPolicyBuf writeSecPolicyBuf( aWriteSecurityPolicy ); |
|
149 TIpcArgs args( &aContextSource, &aContextType, &readSecPolicyBuf, |
|
150 &writeSecPolicyBuf ); |
|
151 err = iSession.SendSync( EDefineContext, args ); |
|
152 } |
|
153 else |
|
154 { |
|
155 // Incorrect context definition |
|
156 err = KErrArgument; |
|
157 } |
|
158 |
|
159 if( err == KErrNone ) |
|
160 { |
|
161 if( !iServerMessageListener->IsActive() ) |
|
162 { |
|
163 // Activate listening |
|
164 iServerMessageListener->ReceiveMessages(); |
|
165 } |
|
166 } |
|
167 |
|
168 return err; |
|
169 } |
|
170 |
|
171 //---------------------------------------------------------------------------- |
|
172 // CCFContextService::PublishContextL |
|
173 //---------------------------------------------------------------------------- |
|
174 // |
|
175 void CCFContextService::PublishContextL( CCFContextObject& aContext ) |
|
176 { |
|
177 FUNC_LOG; |
|
178 |
|
179 TInt err = KErrNone; |
|
180 if( IsContextLegalForAdd( aContext ) ) |
|
181 { |
|
182 HBufC8* buffer = WriteStreamContextObjectLC( aContext ); |
|
183 TIpcArgs args( buffer ); |
|
184 err = iSession.SendSync( EPublishContext, args ); |
|
185 CleanupStack::PopAndDestroy( buffer ); |
|
186 } |
|
187 else |
|
188 { |
|
189 err = KErrArgument; |
|
190 } |
|
191 |
|
192 User::LeaveIfError( err ); |
|
193 } |
|
194 |
|
195 //---------------------------------------------------------------------------- |
|
196 // CCFContextService::PublishContextL |
|
197 //---------------------------------------------------------------------------- |
|
198 // |
|
199 void CCFContextService::PublishContextL( CCFContextObject& aContext, |
|
200 CCFContextDataObject& aData ) |
|
201 { |
|
202 FUNC_LOG; |
|
203 |
|
204 TInt err = KErrNone; |
|
205 |
|
206 if( IsContextLegalForAdd( aContext ) ) |
|
207 { |
|
208 err = IsContextDataLegalForAdd( aData ); |
|
209 if( err == KErrNone ) |
|
210 { |
|
211 // Define IPC arguments |
|
212 HBufC8* contextBuffer = WriteStreamContextObjectLC( aContext ); |
|
213 HBufC8* contextDataBuffer = WriteStreamContextDataObjectLC( aData ); |
|
214 TPckg<TUid> uidPckg( aData.Uid() ); |
|
215 TIpcArgs args( contextBuffer, contextDataBuffer, &uidPckg ); |
|
216 |
|
217 // Send message |
|
218 err = iSession.SendSync( EPublishContextWithData, args ); |
|
219 |
|
220 // Clean up |
|
221 CleanupStack::PopAndDestroy( contextDataBuffer ); |
|
222 CleanupStack::PopAndDestroy( contextBuffer ); |
|
223 } |
|
224 } |
|
225 else |
|
226 { |
|
227 err = KErrArgument; |
|
228 } |
|
229 |
|
230 User::LeaveIfError( err ); |
|
231 } |
|
232 |
|
233 //---------------------------------------------------------------------------- |
|
234 // CCFContextService::SubscribeContextL |
|
235 //---------------------------------------------------------------------------- |
|
236 // |
|
237 void CCFContextService::SubscribeContextL( |
|
238 CCFContextSubscription& aSubscription) |
|
239 { |
|
240 FUNC_LOG; |
|
241 |
|
242 TInt err = KErrNone; |
|
243 |
|
244 // Stream subscription and send |
|
245 HBufC8* buffer = WriteStreamContextSubscriptionLC( aSubscription ); |
|
246 TIpcArgs args( buffer ); |
|
247 err = iSession.SendSync( EAddSubscription, args ); |
|
248 CleanupStack::PopAndDestroy( buffer ); |
|
249 |
|
250 User::LeaveIfError( err ); |
|
251 |
|
252 if( err == KErrNone ) |
|
253 { |
|
254 if( !iContextSubscriptionListener->IsActive() ) |
|
255 { |
|
256 // Activate listening |
|
257 iContextSubscriptionListener->ReceiveContextIndications(); |
|
258 } |
|
259 } |
|
260 } |
|
261 |
|
262 //---------------------------------------------------------------------------- |
|
263 // CCFContextService::UnsubscribeContextL |
|
264 //---------------------------------------------------------------------------- |
|
265 // |
|
266 void CCFContextService::UnsubscribeContextL( |
|
267 CCFContextSubscription& aSubscription) |
|
268 { |
|
269 FUNC_LOG; |
|
270 |
|
271 TInt err = KErrNone; |
|
272 |
|
273 // Stream subscription and send |
|
274 HBufC8* buffer = WriteStreamContextSubscriptionLC( aSubscription ); |
|
275 TIpcArgs args( buffer ); |
|
276 err = iSession.SendSync( ERemoveSubscription, args ); |
|
277 CleanupStack::PopAndDestroy( buffer ); |
|
278 |
|
279 User::LeaveIfError( err ); |
|
280 } |
|
281 |
|
282 //---------------------------------------------------------------------------- |
|
283 // CCFContextService::RequestContextL |
|
284 //---------------------------------------------------------------------------- |
|
285 // |
|
286 void CCFContextService::RequestContextL( CCFContextQuery& aContextQuery, |
|
287 RContextObjectArray& aRequestResults ) |
|
288 { |
|
289 FUNC_LOG; |
|
290 |
|
291 TInt err = KErrNone; |
|
292 |
|
293 // Stream context query set into buffer |
|
294 HBufC8* buffer = buffer = WriteStreamContextQueryLC( aContextQuery ); |
|
295 HBufC8* resultBuffer = HBufC8::NewLC( iRequestBufferSize ); |
|
296 TPtr8 resultBufferPtr = resultBuffer->Des(); |
|
297 TPckg<TInt> bufferSizePtr( iRequestBufferSize ); |
|
298 |
|
299 // Send request to server |
|
300 TIpcArgs args( &resultBufferPtr, buffer, &bufferSizePtr ); |
|
301 err = iSession.SendSync( ERequestContext, args ); |
|
302 if( err == KErrNone ) |
|
303 { |
|
304 // Results succesfully received |
|
305 ReadStreamContextObjectL( *resultBuffer, aRequestResults ); |
|
306 } |
|
307 else if( err == KErrTooBig ) |
|
308 { |
|
309 // Insufficient buffer size, increase buffer and try again |
|
310 CleanupStack::PopAndDestroy( resultBuffer ); |
|
311 resultBuffer = HBufC8::NewLC( iRequestBufferSize ); |
|
312 resultBufferPtr.Set( resultBuffer->Des() ); |
|
313 TIpcArgs args( &resultBufferPtr ); |
|
314 err = iSession.SendSync( ERequestContext, args ); |
|
315 if( err == KErrNone ) |
|
316 { |
|
317 ReadStreamContextObjectL( *resultBuffer, aRequestResults ); |
|
318 } |
|
319 else |
|
320 { |
|
321 err = KErrNoMemory; |
|
322 } |
|
323 } |
|
324 CleanupStack::PopAndDestroy( resultBuffer ); |
|
325 CleanupStack::PopAndDestroy( buffer ); |
|
326 |
|
327 // If requst buffer size grows too big, zero it |
|
328 if( iRequestBufferSize > KDefaultBufferSize ) |
|
329 { |
|
330 iRequestBufferSize = 0; |
|
331 } |
|
332 |
|
333 User::LeaveIfError( err ); |
|
334 } |
|
335 |
|
336 //---------------------------------------------------------------------------- |
|
337 // CCFContextService::RequestContextSetL |
|
338 //---------------------------------------------------------------------------- |
|
339 // |
|
340 void CCFContextService::RequestContextSetL( |
|
341 RContextQueryArray& aContextQuerySet, |
|
342 RContextObjectArray& aRequestResults) |
|
343 { |
|
344 FUNC_LOG; |
|
345 |
|
346 TInt err = KErrNone; |
|
347 |
|
348 // Stream context query set into buffer |
|
349 HBufC8* buffer = WriteStreamContextQueryLC( aContextQuerySet ); |
|
350 HBufC8* resultBuffer = HBufC8::NewLC( iRequestBufferSize ); |
|
351 TPtr8 resultBufferPtr = resultBuffer->Des(); |
|
352 resultBufferPtr.Set( resultBuffer->Des() ); |
|
353 |
|
354 // Send request to server |
|
355 TPckg<TInt> bufferSizePtr( iRequestBufferSize ); |
|
356 TIpcArgs args( &resultBufferPtr, buffer, &bufferSizePtr ); |
|
357 err = iSession.SendSync( ERequestContextSet, args ); |
|
358 if( err == KErrNone ) |
|
359 { |
|
360 // Results succesfully received |
|
361 ReadStreamContextObjectL( *resultBuffer, aRequestResults ); |
|
362 } |
|
363 else if( err == KErrTooBig ) |
|
364 { |
|
365 // Insufficient buffer size, increase buffer and try again |
|
366 CleanupStack::PopAndDestroy( resultBuffer ); |
|
367 resultBuffer = HBufC8::NewLC( iRequestBufferSize ); |
|
368 resultBufferPtr.Set( resultBuffer->Des() ); |
|
369 TIpcArgs args( &resultBufferPtr ); |
|
370 err = iSession.SendSync( ERequestContextSet, args ); |
|
371 if( err == KErrNone ) |
|
372 { |
|
373 ReadStreamContextObjectL( *resultBuffer, aRequestResults ); |
|
374 } |
|
375 else |
|
376 { |
|
377 err = KErrNoMemory; |
|
378 } |
|
379 } |
|
380 CleanupStack::PopAndDestroy( resultBuffer ); |
|
381 CleanupStack::PopAndDestroy( buffer ); |
|
382 |
|
383 // If requst buffer size grows too big, zero it |
|
384 if( iRequestBufferSize > KDefaultBufferSize ) |
|
385 { |
|
386 iRequestBufferSize = 0; |
|
387 } |
|
388 |
|
389 User::LeaveIfError( err ); |
|
390 } |
|
391 |
|
392 //---------------------------------------------------------------------------- |
|
393 // CCFContextService::InstallContextSourceSetting |
|
394 //---------------------------------------------------------------------------- |
|
395 // |
|
396 TInt CCFContextService::InstallContextSourceSetting( |
|
397 const TDesC& aSettingFilename, |
|
398 const TUid& aContextSourceUid ) |
|
399 { |
|
400 FUNC_LOG; |
|
401 |
|
402 RFs fs; |
|
403 TInt err = fs.Connect(); |
|
404 if ( err != KErrNone ) |
|
405 { |
|
406 return err; |
|
407 } |
|
408 |
|
409 // Make possible to share the file server session with the CF server. |
|
410 err = fs.ShareProtected(); |
|
411 if( err != KErrNone ) |
|
412 { |
|
413 fs.Close(); |
|
414 return err; |
|
415 } |
|
416 |
|
417 // Open the file. |
|
418 RFile settingFile; |
|
419 err = settingFile.Open( fs, aSettingFilename, EFileRead ); |
|
420 if( err != KErrNone ) |
|
421 { |
|
422 fs.Close(); |
|
423 return err; |
|
424 } |
|
425 |
|
426 // Deliver the file handle to the server. |
|
427 TIpcArgs args; |
|
428 err = settingFile.TransferToServer( args, 0, 1 ); |
|
429 if( err != KErrNone ) |
|
430 { |
|
431 settingFile.Close(); |
|
432 fs.Close(); |
|
433 return err; |
|
434 } |
|
435 |
|
436 TPckgC< TUid > uidPckgC( aContextSourceUid ); |
|
437 args.Set( 2, &uidPckgC ); |
|
438 |
|
439 err = iSession.SendSync( EInstallSourceSetting, args ); |
|
440 |
|
441 settingFile.Close(); |
|
442 fs.Close(); |
|
443 |
|
444 return err; |
|
445 } |
|
446 |
|
447 //---------------------------------------------------------------------------- |
|
448 // CCFContextService::UninstallContextSourceSetting |
|
449 //---------------------------------------------------------------------------- |
|
450 // |
|
451 TInt CCFContextService::UninstallContextSourceSetting( |
|
452 const TDesC& aSettingFilename, |
|
453 const TUid& aContextSourceUid ) |
|
454 { |
|
455 FUNC_LOG; |
|
456 |
|
457 // Deliver setting filename and context source UID to the server. |
|
458 TPckgC< TUid > uidPckgC( aContextSourceUid ); |
|
459 TIpcArgs args( &aSettingFilename, &uidPckgC ); |
|
460 |
|
461 TInt err = iSession.SendSync( EUninstallSourceSetting, args ); |
|
462 |
|
463 return err; |
|
464 } |
|
465 |
|
466 //---------------------------------------------------------------------------- |
|
467 // CCFContextService::UninstallContextSourceSettings |
|
468 //---------------------------------------------------------------------------- |
|
469 // |
|
470 TInt CCFContextService::UninstallContextSourceSettings( |
|
471 const TUid& aContextSourceUid ) |
|
472 { |
|
473 FUNC_LOG; |
|
474 |
|
475 // Deliver context source UID to the server. |
|
476 TPckgC< TUid > uidPckgC( aContextSourceUid ); |
|
477 TIpcArgs args( &uidPckgC ); |
|
478 |
|
479 TInt err = iSession.SendSync( EUninstallSourceSettings, args ); |
|
480 |
|
481 return err; |
|
482 } |
|
483 |
|
484 //---------------------------------------------------------------------------- |
|
485 // CCFContextService::IsContextLegalForAdd |
|
486 //---------------------------------------------------------------------------- |
|
487 // |
|
488 TBool CCFContextService::IsContextLegalForAdd( |
|
489 const CCFContextObject& aContext) |
|
490 { |
|
491 FUNC_LOG; |
|
492 |
|
493 TBool retVal = EFalse; |
|
494 |
|
495 if( aContext.Type().Length() > 0 && |
|
496 aContext.Source().Length() > 0 && |
|
497 aContext.Value().Length() > 0 ) |
|
498 { |
|
499 retVal = ETrue; |
|
500 } |
|
501 |
|
502 return retVal; |
|
503 } |
|
504 |
|
505 //---------------------------------------------------------------------------- |
|
506 // CCFContextService::IsContextDataLegalForAdd |
|
507 //---------------------------------------------------------------------------- |
|
508 // |
|
509 TInt CCFContextService::IsContextDataLegalForAdd( |
|
510 const CCFContextDataObject& aContextData ) |
|
511 { |
|
512 FUNC_LOG; |
|
513 |
|
514 TInt retVal = KErrNone; |
|
515 if( aContextData.Size() > iContextDataMaxSize ) |
|
516 { |
|
517 retVal = KErrTooBig; |
|
518 } |
|
519 else if( aContextData.Uid() == KNullUid ) |
|
520 { |
|
521 retVal = KErrNotSupported; |
|
522 } |
|
523 |
|
524 return retVal; |
|
525 } |
|
526 |
|
527 //---------------------------------------------------------------------------- |
|
528 // CCFContextService::ReadStreamContextObjectL |
|
529 //---------------------------------------------------------------------------- |
|
530 // |
|
531 void CCFContextService::ReadStreamContextObjectL( const TDesC8& aData, |
|
532 RContextObjectArray& aArray ) |
|
533 { |
|
534 FUNC_LOG; |
|
535 |
|
536 // Check that we have received data from server |
|
537 if( aData.Length() ) |
|
538 { |
|
539 CCFContextObjectImpl* context = NULL; |
|
540 RDesReadStream stream( aData ); |
|
541 stream.PushL(); |
|
542 TInt count = stream.ReadInt16L(); |
|
543 for( TInt i = 0; i < count; i++ ) |
|
544 { |
|
545 context = CCFContextObjectImpl::NewLC(); |
|
546 context->InternalizeL( stream ); |
|
547 aArray.AppendL( context ); |
|
548 CleanupStack::Pop( context ); |
|
549 } |
|
550 |
|
551 // Clean up |
|
552 CleanupStack::PopAndDestroy( &stream ); |
|
553 } |
|
554 } |
|
555 |
|
556 //---------------------------------------------------------------------------- |
|
557 // CCFContextService::WriteStreamContextSubscriptionLC |
|
558 //---------------------------------------------------------------------------- |
|
559 // |
|
560 HBufC8* CCFContextService::WriteStreamContextSubscriptionLC( |
|
561 CCFContextSubscription& aSubscription ) |
|
562 { |
|
563 FUNC_LOG; |
|
564 |
|
565 CCFContextSubscriptionImpl& subscription = |
|
566 static_cast<CCFContextSubscriptionImpl&>( aSubscription ); |
|
567 |
|
568 HBufC8* buffer = HBufC8::NewLC( subscription.Size() ); |
|
569 TPtr8 bufferPtr = buffer->Des(); |
|
570 |
|
571 RDesWriteStream stream( bufferPtr ); |
|
572 stream.PushL(); |
|
573 subscription.ExternalizeL( stream ); |
|
574 |
|
575 // Cleanup |
|
576 CleanupStack::PopAndDestroy( &stream ); |
|
577 |
|
578 return buffer; |
|
579 } |
|
580 |
|
581 //---------------------------------------------------------------------------- |
|
582 // CCFContextService::WriteStreamContextObjectLC |
|
583 //---------------------------------------------------------------------------- |
|
584 // |
|
585 HBufC8* CCFContextService::WriteStreamContextObjectLC( |
|
586 CCFContextObject& aContext ) |
|
587 { |
|
588 FUNC_LOG; |
|
589 |
|
590 CCFContextObjectImpl& context = |
|
591 static_cast<CCFContextObjectImpl&>( aContext ); |
|
592 |
|
593 HBufC8* buffer = HBufC8::NewLC( context.Size() ); |
|
594 TPtr8 bufferPtr = buffer->Des(); |
|
595 |
|
596 RDesWriteStream stream( bufferPtr ); |
|
597 stream.PushL(); |
|
598 context.ExternalizeL( stream ); |
|
599 |
|
600 // Cleanup |
|
601 CleanupStack::PopAndDestroy( &stream ); |
|
602 |
|
603 return buffer; |
|
604 } |
|
605 |
|
606 //---------------------------------------------------------------------------- |
|
607 // CCFContextService::WriteStreamContextQueryLC |
|
608 //---------------------------------------------------------------------------- |
|
609 // |
|
610 HBufC8* CCFContextService::WriteStreamContextQueryLC( |
|
611 RContextQueryArray& aQueryArray ) |
|
612 { |
|
613 FUNC_LOG; |
|
614 |
|
615 // Calculate buffer size |
|
616 // Count of array and queries |
|
617 CCFContextQueryImpl* query = NULL; |
|
618 TInt size = 0; |
|
619 size += sizeof( TInt ); |
|
620 TInt count = aQueryArray.Count(); |
|
621 for( TInt i = 0; i < count; i++ ) |
|
622 { |
|
623 query = static_cast<CCFContextQueryImpl*>( aQueryArray[i] ); |
|
624 size += query->Size(); |
|
625 } |
|
626 |
|
627 HBufC8* buffer = HBufC8::NewLC( size ); |
|
628 TPtr8 bufferPtr = buffer->Des(); |
|
629 |
|
630 RDesWriteStream stream( bufferPtr ); |
|
631 stream.PushL(); |
|
632 stream.WriteInt16L( count ); |
|
633 for( TInt i = 0; i < count; i++ ) |
|
634 { |
|
635 query = static_cast<CCFContextQueryImpl*>( aQueryArray[i] ); |
|
636 query->ExternalizeL( stream ); |
|
637 } |
|
638 |
|
639 // Commit stream |
|
640 stream.CommitL(); |
|
641 |
|
642 // Cleanup |
|
643 CleanupStack::PopAndDestroy( &stream ); |
|
644 |
|
645 return buffer; |
|
646 } |
|
647 |
|
648 //---------------------------------------------------------------------------- |
|
649 // CCFContextService::WriteStreamContextQueryLC |
|
650 //---------------------------------------------------------------------------- |
|
651 // |
|
652 HBufC8* CCFContextService::WriteStreamContextQueryLC( CCFContextQuery& aQuery ) |
|
653 { |
|
654 FUNC_LOG; |
|
655 |
|
656 CCFContextQueryImpl& query = |
|
657 static_cast<CCFContextQueryImpl&>( aQuery ); |
|
658 |
|
659 HBufC8* buffer = HBufC8::NewLC( query.Size() ); |
|
660 TPtr8 bufferPtr = buffer->Des(); |
|
661 |
|
662 RDesWriteStream stream( bufferPtr ); |
|
663 stream.PushL(); |
|
664 query.ExternalizeL( stream ); |
|
665 |
|
666 // Cleanup |
|
667 CleanupStack::PopAndDestroy( &stream ); |
|
668 |
|
669 return buffer; |
|
670 } |
|
671 |
|
672 //---------------------------------------------------------------------------- |
|
673 // CCFContextService::WriteStreamContextDataObjectLC |
|
674 //---------------------------------------------------------------------------- |
|
675 // |
|
676 HBufC8* CCFContextService::WriteStreamContextDataObjectLC( |
|
677 CCFContextDataObject& aContextData ) |
|
678 { |
|
679 FUNC_LOG; |
|
680 |
|
681 HBufC8* streamBuf = HBufC8::NewLC( aContextData.Size() ); |
|
682 TPtr8 streamBufPtr( streamBuf->Des() ); |
|
683 RDesWriteStream writeStream( streamBufPtr ); |
|
684 CleanupClosePushL( writeStream ); |
|
685 aContextData.ExternalizeL( writeStream ); |
|
686 |
|
687 // Clean up |
|
688 CleanupStack::PopAndDestroy( &writeStream ); |
|
689 |
|
690 return streamBuf; |
|
691 } |
|
692 |
|
693 // End of file |