|
1 /* |
|
2 * Copyright (c) 2006-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: Message handler context class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <s32mem.h> |
|
21 #include <e32cmn.h> |
|
22 #include <cfcontextsourcecommand.h> |
|
23 |
|
24 #include "CFMessageHandlerContext.h" |
|
25 #include "CFContextObjectImpl.h" |
|
26 #include "cfextendedcontextinterface.h" |
|
27 #include "CFScriptInterface.h" |
|
28 #include "CFContextSubscriptionImpl.h" |
|
29 #include "cfcontextindication.h" |
|
30 #include "CFContextIndicationImpl.h" |
|
31 #include "CFServSession.h" |
|
32 #include "CFContextQueryImpl.h" |
|
33 #include "cfcommon.h" |
|
34 #include "cftrace.h" |
|
35 #include "CFContextDataProxy.h" |
|
36 #include "cfserviceutils.h" |
|
37 |
|
38 // CONSTANTS |
|
39 |
|
40 #ifdef _DEBUG |
|
41 LOCAL_C void Panic( const RMessage2& aMessage, TInt aCode ) |
|
42 { |
|
43 CCFServSession::PanicClient( aMessage, aCode ); |
|
44 } |
|
45 #endif |
|
46 |
|
47 // Local function to clean up RContextQueryArray |
|
48 LOCAL_C void CleanupContextQueryArray( TAny* aArray ) |
|
49 { |
|
50 RContextQueryArray* array = static_cast<RContextQueryArray*>( aArray ); |
|
51 array->ResetAndDestroy(); |
|
52 } |
|
53 |
|
54 // Puts RContextQueryArray in clean up stack |
|
55 LOCAL_C void CleanupResetAndDestroyPushL( RContextQueryArray& aArray ) |
|
56 { |
|
57 TCleanupItem item( CleanupContextQueryArray, &aArray ); |
|
58 CleanupStack::PushL( item ); |
|
59 } |
|
60 |
|
61 // METHODS |
|
62 |
|
63 CCFMessageHandlerContext* CCFMessageHandlerContext::NewL( |
|
64 MCFExtendedContextInterface& aCFContext, |
|
65 MCFActionInterface& aCFAction, |
|
66 MCFScriptInterface& aScriptInterface ) |
|
67 { |
|
68 FUNC_LOG; |
|
69 |
|
70 CCFMessageHandlerContext* self = CCFMessageHandlerContext::NewLC( |
|
71 aCFContext, |
|
72 aCFAction, |
|
73 aScriptInterface ); |
|
74 CleanupStack::Pop( self ); |
|
75 |
|
76 return self; |
|
77 } |
|
78 |
|
79 CCFMessageHandlerContext* CCFMessageHandlerContext::NewLC( |
|
80 MCFExtendedContextInterface& aCFContext, |
|
81 MCFActionInterface& aCFAction, |
|
82 MCFScriptInterface& aScriptInterface ) |
|
83 { |
|
84 FUNC_LOG; |
|
85 |
|
86 CCFMessageHandlerContext* self = new( ELeave ) CCFMessageHandlerContext( |
|
87 aCFContext, |
|
88 aCFAction, |
|
89 aScriptInterface ); |
|
90 CleanupStack::PushL( self ); |
|
91 self->ConstructL(); |
|
92 |
|
93 return self; |
|
94 } |
|
95 |
|
96 CCFMessageHandlerContext::~CCFMessageHandlerContext() |
|
97 { |
|
98 FUNC_LOG; |
|
99 |
|
100 // Cancel outsanding request from client |
|
101 CancelReceiveContextIndicationMessage(); |
|
102 |
|
103 // Remove all subscriptions from this session |
|
104 iCFContext.UnsubscribeContexts( *this ); |
|
105 iCFContext.DeregisterPublisher( *this ); |
|
106 |
|
107 // Clean buffers |
|
108 iIndicationQueue.ResetAndDestroy(); |
|
109 TInt count = iSubscriptionErrors.Count(); |
|
110 for( TInt i = 0; i < count; i++ ) |
|
111 { |
|
112 delete iSubscriptionErrors[i].iContext; |
|
113 } |
|
114 |
|
115 // Close arrays which context are not owned |
|
116 iContextRequestBuffer.Close(); |
|
117 } |
|
118 |
|
119 CCFMessageHandlerContext::CCFMessageHandlerContext( |
|
120 MCFExtendedContextInterface& aCFContext, |
|
121 MCFActionInterface& aCFAction, |
|
122 MCFScriptInterface& aScriptInterface ) |
|
123 : CCFMessageHandlerBase( aCFContext, aCFAction, aScriptInterface ) |
|
124 { |
|
125 FUNC_LOG; |
|
126 } |
|
127 |
|
128 void CCFMessageHandlerContext::ConstructL() |
|
129 { |
|
130 FUNC_LOG; |
|
131 } |
|
132 |
|
133 // METHODS |
|
134 |
|
135 //----------------------------------------------------------------------------- |
|
136 // CCFMessageHandlerContext::HandleMessageL |
|
137 //----------------------------------------------------------------------------- |
|
138 // |
|
139 TBool CCFMessageHandlerContext::HandleMessageL( const RMessage2& aMessage ) |
|
140 { |
|
141 FUNC_LOG; |
|
142 |
|
143 INFO_1( "[MessageHandlerContext] Handling IPC message: %d", aMessage.Function() ); |
|
144 |
|
145 TBool handled = ETrue; |
|
146 switch( aMessage.Function() ) |
|
147 { |
|
148 |
|
149 // Slot[0] = TDesC - CCFContextObject |
|
150 case EPublishContext: |
|
151 { |
|
152 INFO( "Handling IPC message [EPublishContext]" ); |
|
153 |
|
154 // Stream context from client buffer |
|
155 CCFContextObjectImpl* context = CCFContextObjectImpl::NewLC(); |
|
156 TInt length = aMessage.GetDesLengthL( 0 ); |
|
157 HBufC8* buffer = HBufC8::NewLC( length ); |
|
158 TPtr8 bufferPtr = buffer->Des(); |
|
159 aMessage.ReadL( 0, bufferPtr ); |
|
160 RDesReadStream readStream( bufferPtr ); |
|
161 readStream.PushL(); |
|
162 context->InternalizeL( readStream ); |
|
163 |
|
164 // Clean up |
|
165 CleanupStack::PopAndDestroy( &readStream ); |
|
166 CleanupStack::PopAndDestroy( buffer ); |
|
167 |
|
168 // Send request to CF Engine |
|
169 RThread clientThread; |
|
170 aMessage.ClientL( clientThread ); |
|
171 CleanupClosePushL( clientThread ); |
|
172 TInt err = PublishContext( *context, clientThread ); |
|
173 |
|
174 // Clean up |
|
175 CleanupStack::PopAndDestroy( &clientThread ); |
|
176 CleanupStack::PopAndDestroy( context ); |
|
177 |
|
178 // Complete |
|
179 aMessage.Complete( err ); |
|
180 |
|
181 INFO( "Handled IPC message [EPublishContext]" ); |
|
182 |
|
183 break; |
|
184 } |
|
185 |
|
186 // Slot[0] = TDesC - CCFContextSubscription |
|
187 case EAddSubscription: |
|
188 { |
|
189 INFO( "Handling IPC message [EAddSubscription]" ); |
|
190 |
|
191 // Stream subscription from client buffer |
|
192 CCFContextSubscriptionImpl* subscription = |
|
193 CCFContextSubscriptionImpl::NewLC(); |
|
194 TInt length = aMessage.GetDesLengthL( 0 ); |
|
195 HBufC8* buffer = HBufC8::NewLC( length ); |
|
196 TPtr8 bufferPtr = buffer->Des(); |
|
197 aMessage.ReadL( 0, bufferPtr ); |
|
198 RDesReadStream readStream( bufferPtr ); |
|
199 readStream.PushL(); |
|
200 subscription->InternalizeL( readStream ); |
|
201 |
|
202 // Clean up |
|
203 CleanupStack::PopAndDestroy( &readStream ); |
|
204 CleanupStack::PopAndDestroy( buffer ); |
|
205 |
|
206 // Send request to CF Engine |
|
207 RThread clientThread; |
|
208 aMessage.ClientL( clientThread ); |
|
209 CleanupClosePushL( clientThread ); |
|
210 TInt err = AddSubscription( subscription, clientThread ); |
|
211 |
|
212 // Clean up |
|
213 CleanupStack::PopAndDestroy( &clientThread ); |
|
214 CleanupStack::Pop( subscription ); |
|
215 |
|
216 // Handle results |
|
217 if( err != KErrNone ) |
|
218 { |
|
219 // Notify error |
|
220 DoHandleContextSubscriptionErrorL( err, |
|
221 subscription->ContextSource(), |
|
222 subscription->ContextType() ); |
|
223 } |
|
224 |
|
225 // Complete |
|
226 aMessage.Complete( KErrNone ); |
|
227 |
|
228 INFO( "Handled IPC message [EAddSubscription]" ); |
|
229 |
|
230 break; |
|
231 } |
|
232 |
|
233 // Slot[0] = TDesC - CCFContextSubscription |
|
234 case ERemoveSubscription: |
|
235 { |
|
236 INFO( "Handling IPC message [ERemoveSubscription]" ); |
|
237 |
|
238 // Stream subscription from client buffer |
|
239 CCFContextSubscriptionImpl* subscription = |
|
240 CCFContextSubscriptionImpl::NewLC(); |
|
241 TInt length = aMessage.GetDesLengthL( 0 ); |
|
242 HBufC8* buffer = HBufC8::NewLC( length ); |
|
243 TPtr8 bufferPtr = buffer->Des(); |
|
244 aMessage.ReadL( 0, bufferPtr ); |
|
245 RDesReadStream readStream( bufferPtr ); |
|
246 readStream.PushL(); |
|
247 subscription->InternalizeL( readStream ); |
|
248 |
|
249 // Clean up |
|
250 CleanupStack::PopAndDestroy( &readStream ); |
|
251 CleanupStack::PopAndDestroy( buffer ); |
|
252 |
|
253 // Send request to CF Engine |
|
254 RemoveSubscription( *subscription ); |
|
255 |
|
256 // Clean up |
|
257 CleanupStack::PopAndDestroy( subscription ); |
|
258 |
|
259 // Complete |
|
260 aMessage.Complete( KErrNone ); |
|
261 |
|
262 INFO( "Handled IPC message [ERemoveSubscription]" ); |
|
263 |
|
264 break; |
|
265 } |
|
266 |
|
267 // Slot[0] = TDes - Buffer |
|
268 // Slot[1] = TPckg<TInt> - Buffer size |
|
269 case EReceiveContextIndicationMessage: |
|
270 { |
|
271 INFO( "Handling IPC message [EReceiveContextIndicationMessage]" ); |
|
272 |
|
273 ReceiveContextIndicationMessageL( aMessage ); |
|
274 |
|
275 INFO( "Handled IPC message [EReceiveContextIndicationMessage]" ); |
|
276 |
|
277 break; |
|
278 } |
|
279 |
|
280 // Slot[0] = TDes - Buffer |
|
281 // Slot[1] = TPckg<TInt> - Buffer size |
|
282 case EReceiveMessage: |
|
283 { |
|
284 INFO( "Handling IPC message [EReceiveMessage]" ); |
|
285 |
|
286 ReceiveMessageL( aMessage ); |
|
287 |
|
288 INFO( "Handled IPC message [EReceiveMessage]" ); |
|
289 |
|
290 break; |
|
291 } |
|
292 |
|
293 // Slot[0] = TDes - Buffer |
|
294 case EGetContextIndication: |
|
295 { |
|
296 INFO( "Handling IPC message [EGetContextIndication]" ); |
|
297 |
|
298 // Client has increased buffer size |
|
299 // Get next indication from queue |
|
300 // Message will be completed in the method |
|
301 CompleteNextIndicationFromQueueL( aMessage ); |
|
302 |
|
303 INFO( "Handled IPC message [EGetContextIndication]" ); |
|
304 |
|
305 break; |
|
306 } |
|
307 |
|
308 // Slot[0] = TDes - Buffer |
|
309 case EGetMessage: |
|
310 { |
|
311 INFO( "Handling IPC message [EGetMessage]" ); |
|
312 |
|
313 // Client has increased buffer size |
|
314 // Get next indication from queue |
|
315 // Message will be completed in the method |
|
316 CompleteNextMessageFromQueueL( aMessage ); |
|
317 |
|
318 INFO( "Handled IPC message [EGetMessage]" ); |
|
319 |
|
320 break; |
|
321 } |
|
322 |
|
323 |
|
324 // No parameters |
|
325 case ECancelReceiveContextIndicationMessage: |
|
326 { |
|
327 INFO( "Handling IPC message [ECancelReceiveContextIndicationMessage]" ); |
|
328 |
|
329 CancelReceiveContextIndicationMessage(); |
|
330 aMessage.Complete( KErrNone ); |
|
331 |
|
332 INFO( "Handled IPC message [ECancelReceiveContextIndicationMessage]" ); |
|
333 |
|
334 break; |
|
335 } |
|
336 |
|
337 // No parameters |
|
338 case ECancelReceiveMessage: |
|
339 { |
|
340 INFO( "Handling IPC message [ECancelReceiveContextIndicationMessage]" ); |
|
341 |
|
342 CancelReceiveMessage(); |
|
343 aMessage.Complete( KErrNone ); |
|
344 |
|
345 INFO( "Handled IPC message [ECancelReceiveContextIndicationMessage]" ); |
|
346 |
|
347 break; |
|
348 } |
|
349 |
|
350 |
|
351 // Slot[0] = TDes - Result buffer |
|
352 // Slot[1] = TDesC - CCFContextQuery |
|
353 // Slot[2] = TPckg<TInt> - Buffer size |
|
354 case ERequestContext: |
|
355 { |
|
356 INFO( "Handling IPC message [ERequestContext]" ); |
|
357 |
|
358 TInt err = KErrNone; |
|
359 |
|
360 // Check if the client has already requested contexts but |
|
361 // has failed due too small buffer size |
|
362 if( iContextRequestBuffer.Count() ) |
|
363 { |
|
364 // Write request result into client side buffer |
|
365 CompleteRequestContextL( aMessage ); |
|
366 |
|
367 // Reset buffer |
|
368 iContextRequestBuffer.Reset(); |
|
369 } |
|
370 else |
|
371 { |
|
372 // New request |
|
373 // Stream query |
|
374 CCFContextQueryImpl* query = |
|
375 CCFContextQueryImpl::NewLC( KNullDesC, KNullDesC ); |
|
376 TInt bufferSize = aMessage.GetDesLengthL( 1 ); |
|
377 HBufC8* buffer = HBufC8::NewLC( bufferSize ); |
|
378 TPtr8 bufferPtr = buffer->Des(); |
|
379 aMessage.ReadL( 1, bufferPtr ); |
|
380 RDesReadStream readStream( bufferPtr ); |
|
381 readStream.PushL(); |
|
382 query->InternalizeL( readStream ); |
|
383 |
|
384 // Clean up |
|
385 CleanupStack::PopAndDestroy( &readStream ); |
|
386 CleanupStack::PopAndDestroy( buffer ); |
|
387 |
|
388 // Send request to CF Engine |
|
389 RThread clientThread; |
|
390 aMessage.ClientL( clientThread ); |
|
391 CleanupClosePushL( clientThread ); |
|
392 err = RequestContext( *query, clientThread ); |
|
393 |
|
394 // Clean up |
|
395 CleanupStack::PopAndDestroy( &clientThread ); |
|
396 CleanupStack::PopAndDestroy( query ); |
|
397 |
|
398 // Handle request context results |
|
399 if( err == KErrNone && iContextRequestBuffer.Count() ) |
|
400 { |
|
401 // Write request result into client side buffer if |
|
402 // request succesfull |
|
403 CompleteRequestContextL( aMessage ); |
|
404 } |
|
405 else |
|
406 { |
|
407 // Complete with error code |
|
408 aMessage.Complete( err ); |
|
409 } |
|
410 } |
|
411 |
|
412 INFO( "Handled IPC message [ERequestContext]" ); |
|
413 |
|
414 break; |
|
415 } |
|
416 |
|
417 // Slot[0] = TDes - Result buffer |
|
418 // Slot[1] = TDesC - CCFContextQuery |
|
419 // Slot[2] = TPckg<TInt> - Buffer size |
|
420 case ERequestContextSet: |
|
421 { |
|
422 INFO( "Handling IPC message [ERequestContextSet]" ); |
|
423 |
|
424 TInt err = KErrNone; |
|
425 |
|
426 // Check if the client has already requested contexts but |
|
427 // has failed due too small buffer size |
|
428 if( iContextRequestBuffer.Count() ) |
|
429 { |
|
430 // Write request result into client side buffer |
|
431 CompleteRequestContextL( aMessage ); |
|
432 |
|
433 // Reset buffer |
|
434 iContextRequestBuffer.Reset(); |
|
435 } |
|
436 else |
|
437 { |
|
438 // New request |
|
439 // Stream query |
|
440 RContextQueryArray queryArray; |
|
441 CleanupResetAndDestroyPushL( queryArray ); |
|
442 TInt bufferSize = aMessage.GetDesLengthL( 1 ); |
|
443 HBufC8* buffer = HBufC8::NewLC( bufferSize ); |
|
444 TPtr8 bufferPtr = buffer->Des(); |
|
445 aMessage.ReadL( 1, bufferPtr ); |
|
446 RDesReadStream readStream( bufferPtr ); |
|
447 readStream.PushL(); |
|
448 TInt count = readStream.ReadInt16L(); |
|
449 for( TInt i = 0; i < count; i++ ) |
|
450 { |
|
451 CCFContextQueryImpl* query = |
|
452 CCFContextQueryImpl::NewLC( KNullDesC, KNullDesC ); |
|
453 query->InternalizeL( readStream ); |
|
454 queryArray.AppendL( query ); |
|
455 CleanupStack::Pop( query ); |
|
456 } |
|
457 |
|
458 // Clean up |
|
459 CleanupStack::PopAndDestroy( &readStream ); |
|
460 CleanupStack::PopAndDestroy( buffer ); |
|
461 |
|
462 // Send request to CF Engine |
|
463 RThread clientThread; |
|
464 aMessage.ClientL( clientThread ); |
|
465 CleanupClosePushL( clientThread ); |
|
466 count = queryArray.Count(); |
|
467 for( TInt i = 0; i < count; i++ ) |
|
468 { |
|
469 RequestContext( *queryArray[i], clientThread ); |
|
470 } |
|
471 |
|
472 // Clean up |
|
473 CleanupStack::PopAndDestroy( &clientThread ); |
|
474 CleanupStack::PopAndDestroy( &queryArray ); |
|
475 |
|
476 // Handle request context results |
|
477 if( err == KErrNone && iContextRequestBuffer.Count() ) |
|
478 { |
|
479 // Write request result into client side buffer if |
|
480 // request succesfull |
|
481 CompleteRequestContextL( aMessage ); |
|
482 } |
|
483 else |
|
484 { |
|
485 // Complete with error code |
|
486 aMessage.Complete( err ); |
|
487 } |
|
488 } |
|
489 |
|
490 INFO( "Handled IPC message [ERequestContextSet]" ); |
|
491 |
|
492 break; |
|
493 } |
|
494 |
|
495 // Slot[0] = TDesC& |
|
496 // Slot[1] = TDesC& |
|
497 // Slot[2] = TSecurityPolicyBuf - read policy |
|
498 // Slot[3] = TSecurityPolicyBuf - write policy |
|
499 case EDefineContext: |
|
500 { |
|
501 INFO( "Handling IPC message [EDefineContext]" ); |
|
502 |
|
503 TInt err = KErrNone; |
|
504 |
|
505 // Read context source |
|
506 HBufC* contextSource = HBufC::NewLC( aMessage.GetDesLengthL( 0 ) ); |
|
507 TPtr contextSourcePtr = contextSource->Des(); |
|
508 aMessage.ReadL( 0, contextSourcePtr ); |
|
509 |
|
510 // Read context type |
|
511 HBufC* contextType = HBufC::NewLC( aMessage.GetDesLengthL( 1 ) ); |
|
512 TPtr contextTypePtr = contextType->Des(); |
|
513 aMessage.ReadL( 1, contextTypePtr ); |
|
514 |
|
515 // Read security policy |
|
516 TSecurityPolicyBuf readSecPolicyBuf; |
|
517 aMessage.ReadL( 2, readSecPolicyBuf ); |
|
518 TSecurityPolicy readSecPolicy; |
|
519 User::LeaveIfError( readSecPolicy.Set( readSecPolicyBuf ) ); // verifies the security policy |
|
520 |
|
521 TSecurityPolicyBuf writeSecPolicyBuf; |
|
522 aMessage.ReadL( 3, writeSecPolicyBuf ); |
|
523 TSecurityPolicy writeSecPolicy; |
|
524 User::LeaveIfError( writeSecPolicy.Set( writeSecPolicyBuf ) ); // verifies the security policy |
|
525 |
|
526 |
|
527 RThread clientThread; |
|
528 aMessage.ClientL( clientThread ); |
|
529 CleanupClosePushL( clientThread ); |
|
530 |
|
531 // Define context in CF |
|
532 err = iCFContext.DefineContext( contextSourcePtr, |
|
533 contextTypePtr, |
|
534 readSecPolicy, |
|
535 writeSecPolicy, |
|
536 this, |
|
537 clientThread.SecureId() ); |
|
538 |
|
539 // Clean up |
|
540 CleanupStack::PopAndDestroy( &clientThread ); |
|
541 |
|
542 // Cleanup |
|
543 CleanupStack::PopAndDestroy( contextType ); |
|
544 CleanupStack::PopAndDestroy( contextSource ); |
|
545 |
|
546 aMessage.Complete( err ); |
|
547 |
|
548 INFO( "Handled IPC message [EDefineContext]" ); |
|
549 |
|
550 break; |
|
551 } |
|
552 |
|
553 // Slot[0] = TDes - Buffer |
|
554 case EGetContextSubscriptionError: |
|
555 { |
|
556 INFO( "Handling IPC message [EGetContextSubscriptionError]" ); |
|
557 |
|
558 // Check that we actually have errors in the list |
|
559 TInt err = KErrNone; |
|
560 if( iSubscriptionErrors.Count() ) |
|
561 { |
|
562 // We have a context subscription error, send it to client |
|
563 CCFContextObjectImpl* context = iSubscriptionErrors[0].iContext; |
|
564 iSubscriptionErrors.Remove( 0 ); |
|
565 CleanupStack::PushL( context ); |
|
566 HBufC8* buffer = HBufC8::NewLC( aMessage.GetDesMaxLengthL( 0 ) ); |
|
567 TPtr8 bufferPtr = buffer->Des(); |
|
568 RDesWriteStream writeStream( bufferPtr ); |
|
569 writeStream.PushL(); |
|
570 context->ExternalizeL( writeStream ); |
|
571 |
|
572 // Write content into client side buffer |
|
573 aMessage.WriteL( 0, bufferPtr ); |
|
574 |
|
575 // Clean up |
|
576 CleanupStack::PopAndDestroy( &writeStream ); |
|
577 CleanupStack::PopAndDestroy( buffer ); |
|
578 CleanupStack::PopAndDestroy( context ); |
|
579 } |
|
580 else |
|
581 { |
|
582 // No errors found |
|
583 err = KErrNotFound; |
|
584 } |
|
585 |
|
586 // Complete |
|
587 aMessage.Complete( err ); |
|
588 |
|
589 INFO( "Handled IPC message [EGetContextSubscriptionError]" ); |
|
590 |
|
591 break; |
|
592 } |
|
593 |
|
594 // Slot[0]= TDesC - Context |
|
595 // Slot[1]= TDesC - Context data |
|
596 // Slot[2]= TPckg<TUid> - Context data UID |
|
597 case EPublishContextWithData: |
|
598 { |
|
599 INFO( "Handling IPC message [EPublishContextWithData]" ); |
|
600 |
|
601 // Get context |
|
602 CCFContextObjectImpl* context = CCFContextObjectImpl::NewLC(); |
|
603 TInt len = aMessage.GetDesLengthL( 0 ); |
|
604 HBufC8* contextBuf = HBufC8::NewLC( len ); |
|
605 TPtr8 contextBufPtr( contextBuf->Des() ); |
|
606 aMessage.ReadL( 0, contextBufPtr ); |
|
607 RDesReadStream readStream( contextBufPtr ); |
|
608 readStream.PushL(); |
|
609 context->InternalizeL( readStream ); |
|
610 CleanupStack::PopAndDestroy( &readStream ); |
|
611 CleanupStack::PopAndDestroy( contextBuf ); |
|
612 |
|
613 // Get context data |
|
614 CCFContextDataProxy* contextData = CCFContextDataProxy::NewLC(); |
|
615 len = aMessage.GetDesLengthL( 1 ); |
|
616 HBufC8* contextDataBuf = HBufC8::NewLC( len ); |
|
617 TPtr8 contextDataBufPtr( contextDataBuf->Des() ); |
|
618 aMessage.ReadL( 1, contextDataBufPtr ); |
|
619 TPckgBuf<TUid> uidPckgBuf; |
|
620 aMessage.ReadL( 2, uidPckgBuf ); |
|
621 |
|
622 contextData->SetContextData( contextDataBuf ); |
|
623 contextData->SetContextDataUid( uidPckgBuf() ); |
|
624 CleanupStack::Pop( contextDataBuf ); |
|
625 |
|
626 // Publish context |
|
627 RThread clientThread; |
|
628 aMessage.ClientL( clientThread ); |
|
629 CleanupClosePushL( clientThread ); |
|
630 TInt err = iCFContext.PublishContext( *context, |
|
631 *contextData, |
|
632 clientThread ); |
|
633 CleanupStack::PopAndDestroy( &clientThread ); |
|
634 |
|
635 // Clean up |
|
636 CleanupStack::PopAndDestroy( contextData ); |
|
637 CleanupStack::PopAndDestroy( context ); |
|
638 |
|
639 // Complete |
|
640 aMessage.Complete( err ); |
|
641 |
|
642 INFO( "Handled IPC message [EPublishContextWithData]" ); |
|
643 |
|
644 break; |
|
645 } |
|
646 |
|
647 // Slot[0] = RFs handle |
|
648 // Slot[1] = RFile handle |
|
649 // Slot[2] = TPckgC< TUid > - Context Source UID |
|
650 case EInstallSourceSetting: |
|
651 { |
|
652 RFile settingFile; |
|
653 TInt err = settingFile.AdoptFromClient( aMessage, 0, 1 ); |
|
654 CleanupClosePushL( settingFile ); // CLEANUP<< settingFile |
|
655 if ( err == KErrNone ) |
|
656 { |
|
657 TPckgBuf< TUid > uidPckgBuf; |
|
658 aMessage.ReadL( 2, uidPckgBuf ); |
|
659 |
|
660 RThread client; |
|
661 aMessage.ClientL( client ); |
|
662 |
|
663 // Install setting |
|
664 err = iCFContext.InstallContextSourceSetting( settingFile, |
|
665 uidPckgBuf(), |
|
666 client ); |
|
667 |
|
668 client.Close(); |
|
669 } |
|
670 CleanupStack::PopAndDestroy( &settingFile );// CLEANUP>> settingFile |
|
671 aMessage.Complete( err ); |
|
672 |
|
673 break; |
|
674 } |
|
675 |
|
676 // Slot[0] = TDesC& - Setting filename |
|
677 // Slot[1] = TPckgC< TUid > - Context Source UID |
|
678 case EUninstallSourceSetting: |
|
679 { |
|
680 // Read setting filename // CLEANUP<< filename |
|
681 HBufC* filename = HBufC::NewLC( aMessage.GetDesLengthL( 0 ) ); |
|
682 TPtr filenamePtr = filename->Des(); |
|
683 aMessage.ReadL( 0, filenamePtr ); |
|
684 |
|
685 TPckgBuf< TUid > uidPckgBuf; |
|
686 aMessage.ReadL( 1, uidPckgBuf ); |
|
687 |
|
688 RThread client; |
|
689 aMessage.ClientL( client ); |
|
690 |
|
691 // Uninstall setting |
|
692 TInt err = iCFContext.UninstallContextSourceSetting( *filename, |
|
693 uidPckgBuf(), |
|
694 client ); |
|
695 |
|
696 client.Close(); |
|
697 CleanupStack::PopAndDestroy( filename ); // CLEANUP>> filename |
|
698 aMessage.Complete( err ); |
|
699 |
|
700 break; |
|
701 } |
|
702 |
|
703 // Slot[0] = TPckgC< TUid > - Context Source UID |
|
704 case EUninstallSourceSettings: |
|
705 { |
|
706 // Read context source UID |
|
707 TPckgBuf< TUid > uidPckgBuf; |
|
708 aMessage.ReadL( 0, uidPckgBuf ); |
|
709 |
|
710 RThread client; |
|
711 aMessage.ClientL( client ); |
|
712 |
|
713 // Uninstall setting |
|
714 TInt err = iCFContext.UninstallContextSourceSettings( uidPckgBuf(), |
|
715 client ); |
|
716 |
|
717 client.Close(); |
|
718 aMessage.Complete( err ); |
|
719 |
|
720 break; |
|
721 } |
|
722 |
|
723 default: |
|
724 { |
|
725 // Message not handled |
|
726 handled = EFalse; |
|
727 } |
|
728 } |
|
729 |
|
730 INFO_1( "Handled IPC message: %d", handled ); |
|
731 |
|
732 return handled; |
|
733 } |
|
734 |
|
735 //----------------------------------------------------------------------------- |
|
736 // CCFMessageHandlerContext::ContextIndicationL |
|
737 //----------------------------------------------------------------------------- |
|
738 // |
|
739 void CCFMessageHandlerContext::ContextIndicationL( |
|
740 CCFContextIndication* aIndication ) |
|
741 { |
|
742 FUNC_LOG; |
|
743 |
|
744 INFO_2( "Received context indication: %S: %S", |
|
745 &aIndication->Context().Source(), |
|
746 &aIndication->Context().Type() ); |
|
747 |
|
748 CCFContextIndicationImpl* indication = |
|
749 static_cast<CCFContextIndicationImpl*>( aIndication ); |
|
750 iIndicationQueue.AppendL( indication ); |
|
751 CheckContextIndicationQueueL(); |
|
752 } |
|
753 |
|
754 //----------------------------------------------------------------------------- |
|
755 // CCFMessageHandlerContext::Client |
|
756 //----------------------------------------------------------------------------- |
|
757 // |
|
758 TInt CCFMessageHandlerContext::Client( RThread& aThread ) const |
|
759 { |
|
760 FUNC_LOG; |
|
761 |
|
762 TInt err = KErrNone; |
|
763 if( !iReceiveMessage.IsNull() ) |
|
764 { |
|
765 // We have a message pending |
|
766 err = iReceiveMessage.Client( aThread ); |
|
767 } |
|
768 else |
|
769 { |
|
770 err = KErrNotFound; |
|
771 } |
|
772 |
|
773 return err; |
|
774 } |
|
775 |
|
776 //----------------------------------------------------------------------------- |
|
777 // CCFMessageHandlerContext::HandleContextSubscriptionError |
|
778 //----------------------------------------------------------------------------- |
|
779 // |
|
780 void CCFMessageHandlerContext::HandleContextSubscriptionError( TInt aError, |
|
781 const TDesC& aSource, |
|
782 const TDesC& aType ) |
|
783 { |
|
784 FUNC_LOG; |
|
785 |
|
786 // Client will not get notified about error if this fails |
|
787 // Failure only due to OOM |
|
788 TRAP_IGNORE( DoHandleContextSubscriptionErrorL( aError, aSource, aType ) ); |
|
789 } |
|
790 |
|
791 |
|
792 //----------------------------------------------------------------------------- |
|
793 // CCFMessageHandlerContext::Subscribers |
|
794 //----------------------------------------------------------------------------- |
|
795 // |
|
796 // from MCFContextSource |
|
797 void CCFMessageHandlerContext::Subscribers( const TDesC& aContextSource, |
|
798 const TDesC& aContextType ) |
|
799 { |
|
800 FUNC_LOG; |
|
801 |
|
802 INFO_2( "Received subscribers indication: %S: %S", |
|
803 &aContextSource, |
|
804 &aContextType ); |
|
805 |
|
806 TRAPD( err, SubscribersL( aContextSource, aContextType ) ); |
|
807 if( err != KErrNone ) |
|
808 { |
|
809 ERROR_2( err, "Failed to notify subscribers to client: [%S, %S]", |
|
810 &aContextSource, &aContextType ); |
|
811 } |
|
812 } |
|
813 |
|
814 //----------------------------------------------------------------------------- |
|
815 // CCFMessageHandlerContext::PublishContext |
|
816 //----------------------------------------------------------------------------- |
|
817 // |
|
818 // from MCFContextSource |
|
819 void CCFMessageHandlerContext::NoSubscribers( const TDesC& aContextSource, |
|
820 const TDesC& aContextType ) |
|
821 { |
|
822 FUNC_LOG; |
|
823 |
|
824 INFO_2( "Received no subscribers indication: %S: %S", |
|
825 &aContextSource, |
|
826 &aContextType ); |
|
827 |
|
828 TRAPD( err, NoSubscribersL( aContextSource, aContextType ) ); |
|
829 if( err != KErrNone ) |
|
830 { |
|
831 ERROR_2( err, "Failed to notify no subscribers to client: [%S, %S]", |
|
832 &aContextSource, &aContextType ); |
|
833 } |
|
834 } |
|
835 |
|
836 //----------------------------------------------------------------------------- |
|
837 // CCFMessageHandlerContext::HandleCommand |
|
838 //----------------------------------------------------------------------------- |
|
839 // |
|
840 void CCFMessageHandlerContext::HandleCommand( |
|
841 const CCFContextSourceCommand& aCommand ) |
|
842 { |
|
843 FUNC_LOG; |
|
844 |
|
845 TPtrC commandName( aCommand.Name() ); |
|
846 INFO_1( "Received handle command action: %S", &commandName ); |
|
847 |
|
848 TRAPD( err, HandleCommandL( aCommand ) ); |
|
849 if( err != KErrNone ) |
|
850 { |
|
851 ERROR_2( err, "Failed to notify handle command action [%S] to client: [%x]", |
|
852 &commandName, |
|
853 aCommand.SourceUid() ); |
|
854 } |
|
855 } |
|
856 |
|
857 //----------------------------------------------------------------------------- |
|
858 // CCFMessageHandlerContext::PublishContext |
|
859 //----------------------------------------------------------------------------- |
|
860 // |
|
861 TInt CCFMessageHandlerContext::PublishContext( CCFContextObject& aContext, |
|
862 RThread& aClientThread ) |
|
863 { |
|
864 FUNC_LOG; |
|
865 |
|
866 return iCFContext.PublishContext( aContext, aClientThread ); |
|
867 } |
|
868 |
|
869 //----------------------------------------------------------------------------- |
|
870 // CCFMessageHandlerContext::AddSubscription |
|
871 //----------------------------------------------------------------------------- |
|
872 // |
|
873 TInt CCFMessageHandlerContext::AddSubscription( CCFContextSubscription* aSubscription, |
|
874 RThread& aClientThread ) |
|
875 { |
|
876 FUNC_LOG; |
|
877 |
|
878 return iCFContext.SubscribeContext( aSubscription, this, aClientThread ); |
|
879 } |
|
880 |
|
881 //----------------------------------------------------------------------------- |
|
882 // CCFMessageHandlerContext::RemoveSubscriptionL |
|
883 //----------------------------------------------------------------------------- |
|
884 // |
|
885 void CCFMessageHandlerContext::RemoveSubscription( |
|
886 CCFContextSubscription& aSubscription ) |
|
887 { |
|
888 FUNC_LOG; |
|
889 |
|
890 iCFContext.UnsubscribeContext( aSubscription, *this ); |
|
891 } |
|
892 |
|
893 //----------------------------------------------------------------------------- |
|
894 // CCFMessageHandlerContext::CancelReceiveContextIndicationMessage |
|
895 //----------------------------------------------------------------------------- |
|
896 // |
|
897 void CCFMessageHandlerContext::CancelReceiveContextIndicationMessage() |
|
898 { |
|
899 FUNC_LOG; |
|
900 |
|
901 if( !iReceiveMessage.IsNull() ) |
|
902 { |
|
903 iReceiveMessage.Complete( KErrCancel ); |
|
904 } |
|
905 } |
|
906 |
|
907 //----------------------------------------------------------------------------- |
|
908 // CCFMessageHandlerContext::CancelReceiveMessage |
|
909 //----------------------------------------------------------------------------- |
|
910 // |
|
911 void CCFMessageHandlerContext::CancelReceiveMessage() |
|
912 { |
|
913 FUNC_LOG; |
|
914 |
|
915 if( !iReceiveContextSourceMsg.IsNull() ) |
|
916 { |
|
917 iReceiveContextSourceMsg.Complete( KErrCancel ); |
|
918 } |
|
919 } |
|
920 |
|
921 |
|
922 //----------------------------------------------------------------------------- |
|
923 // CCFMessageHandlerContext::RequestContext |
|
924 //----------------------------------------------------------------------------- |
|
925 // |
|
926 TInt CCFMessageHandlerContext::RequestContext( CCFContextQuery& aContextQuery, |
|
927 RThread& aClientThread ) |
|
928 { |
|
929 FUNC_LOG; |
|
930 |
|
931 // request the context |
|
932 return iCFContext.RequestContext( iContextRequestBuffer, |
|
933 aContextQuery, |
|
934 aClientThread ); |
|
935 } |
|
936 |
|
937 //----------------------------------------------------------------------------- |
|
938 // CCFMessageHandlerContext::ReceiveContextIndicationMessageL |
|
939 //----------------------------------------------------------------------------- |
|
940 // |
|
941 void CCFMessageHandlerContext::ReceiveContextIndicationMessageL( |
|
942 const RMessage2& aMessage) |
|
943 { |
|
944 FUNC_LOG; |
|
945 |
|
946 __ASSERT_DEBUG( iReceiveMessage.IsNull(), |
|
947 CCFServSession::PanicClient( aMessage, EReceiveReceiveAlreadyActive ) ); |
|
948 |
|
949 // Store message |
|
950 iReceiveMessage = aMessage; |
|
951 |
|
952 // First check if we have subscription errors in the queue |
|
953 if( iSubscriptionErrors.Count() ) |
|
954 { |
|
955 IndicateSubscriptionErrorL(); |
|
956 } |
|
957 |
|
958 // Check indications |
|
959 else if( iIndicationQueue.Count() ) |
|
960 { |
|
961 CheckContextIndicationQueueL(); |
|
962 } |
|
963 } |
|
964 |
|
965 |
|
966 //----------------------------------------------------------------------------- |
|
967 // CCFMessageHandlerContext::ReceiveMessageL |
|
968 //----------------------------------------------------------------------------- |
|
969 // |
|
970 void CCFMessageHandlerContext::ReceiveMessageL( const RMessage2& aMessage ) |
|
971 { |
|
972 FUNC_LOG; |
|
973 |
|
974 __ASSERT_DEBUG( iReceiveContextSourceMsg.IsNull(), |
|
975 CCFServSession::PanicClient( aMessage, EReceiveReceiveAlreadyActive ) ); |
|
976 |
|
977 // Store message |
|
978 iReceiveContextSourceMsg = aMessage; |
|
979 |
|
980 // Check if we have messages in the queue |
|
981 if( iMessageQueue.Count() ) |
|
982 { |
|
983 CheckMessageQueueL(); |
|
984 } |
|
985 } |
|
986 |
|
987 |
|
988 |
|
989 //----------------------------------------------------------------------------- |
|
990 // CCFMessageHandlerContext::IndicateSubscriptionErrorL |
|
991 //----------------------------------------------------------------------------- |
|
992 // |
|
993 void CCFMessageHandlerContext::IndicateSubscriptionErrorL() |
|
994 { |
|
995 FUNC_LOG; |
|
996 |
|
997 // Get next error, client will request the context related to the error |
|
998 TSubscriptionError error = iSubscriptionErrors[0]; |
|
999 TPckgBuf<TInt> sizeBuf( error.iContext->Size() ); |
|
1000 iReceiveMessage.WriteL( 1, sizeBuf ); |
|
1001 iReceiveMessage.Complete( error.iError ); |
|
1002 } |
|
1003 |
|
1004 //----------------------------------------------------------------------------- |
|
1005 // CCFMessageHandlerContext::CompleteNextIndicationFromQueueL |
|
1006 //----------------------------------------------------------------------------- |
|
1007 // |
|
1008 void CCFMessageHandlerContext::CompleteNextIndicationFromQueueL( |
|
1009 const RMessage2& aMessage ) |
|
1010 { |
|
1011 FUNC_LOG; |
|
1012 |
|
1013 // Leave if the aMessage is null |
|
1014 if( aMessage.IsNull() ) |
|
1015 { |
|
1016 User::Leave( KErrArgument ); |
|
1017 } |
|
1018 |
|
1019 // Check that we have indications in queue |
|
1020 else if( iIndicationQueue.Count() ) |
|
1021 { |
|
1022 CCFContextIndicationImpl* indication = iIndicationQueue[0]; |
|
1023 HBufC8* buffer = HBufC8::NewLC( indication->Size() ); |
|
1024 TPtr8 bufferPtr = buffer->Des(); |
|
1025 RDesWriteStream writeStream( bufferPtr ); |
|
1026 writeStream.PushL(); |
|
1027 indication->ExternalizeL( writeStream ); |
|
1028 CleanupStack::PopAndDestroy( &writeStream ); |
|
1029 |
|
1030 // Write buffer into client side and complete |
|
1031 aMessage.WriteL( 0, bufferPtr ); |
|
1032 aMessage.Complete( KErrNone ); |
|
1033 |
|
1034 // Remove indication from queue |
|
1035 delete indication; |
|
1036 iIndicationQueue.Remove( 0 ); |
|
1037 |
|
1038 // Clean up |
|
1039 CleanupStack::PopAndDestroy( buffer ); |
|
1040 } |
|
1041 } |
|
1042 |
|
1043 //----------------------------------------------------------------------------- |
|
1044 // CCFMessageHandlerContext::CheckContextIndicationQueueL |
|
1045 //----------------------------------------------------------------------------- |
|
1046 // |
|
1047 void CCFMessageHandlerContext::CheckContextIndicationQueueL() |
|
1048 { |
|
1049 FUNC_LOG; |
|
1050 |
|
1051 // We must have something in the queue and receive message pending |
|
1052 if( iIndicationQueue.Count() && !iReceiveMessage.IsNull() ) |
|
1053 { |
|
1054 // First check that client side buffer is big enough |
|
1055 CCFContextIndicationImpl* indication = iIndicationQueue[0]; |
|
1056 TInt clientBufferSize = iReceiveMessage.GetDesMaxLengthL( 0 ); |
|
1057 TInt indicationSize = indication->Size(); |
|
1058 if( indicationSize <= clientBufferSize ) |
|
1059 { |
|
1060 // Client has sufficient buffer |
|
1061 CompleteNextIndicationFromQueueL( iReceiveMessage ); |
|
1062 } |
|
1063 else |
|
1064 { |
|
1065 // Client has insufficient buffer size |
|
1066 // Write new buffer size in client memory and complete |
|
1067 TPckgBuf<TInt> sizeBuf( indicationSize ); |
|
1068 iReceiveMessage.WriteL( 1, sizeBuf ); |
|
1069 iReceiveMessage.Complete( KErrTooBig ); |
|
1070 } |
|
1071 } |
|
1072 } |
|
1073 |
|
1074 //----------------------------------------------------------------------------- |
|
1075 // CCFMessageHandlerContext::CompleteNextMessageFromQueueL |
|
1076 //----------------------------------------------------------------------------- |
|
1077 // |
|
1078 void CCFMessageHandlerContext::CompleteNextMessageFromQueueL( |
|
1079 const RMessage2& aMessage ) |
|
1080 { |
|
1081 FUNC_LOG; |
|
1082 |
|
1083 __ASSERT_DEBUG( iMessageQueue.Count(), Panic( aMessage, KErrNotFound ) ); |
|
1084 __ASSERT_DEBUG( !aMessage.IsNull(), Panic( aMessage, KErrArgument ) ); |
|
1085 |
|
1086 if( iMessageQueue.Count() ) |
|
1087 { |
|
1088 // Write buffer into client side and complete |
|
1089 HBufC8* messageBuffer = iMessageQueue[0]; |
|
1090 aMessage.WriteL( 0, *messageBuffer ); |
|
1091 aMessage.Complete( KErrNone ); |
|
1092 |
|
1093 // Remove indication from queue |
|
1094 delete messageBuffer; |
|
1095 iMessageQueue.Remove( 0 ); |
|
1096 } |
|
1097 } |
|
1098 |
|
1099 |
|
1100 //----------------------------------------------------------------------------- |
|
1101 // CCFMessageHandlerContext::CheckMessageQueueL |
|
1102 //----------------------------------------------------------------------------- |
|
1103 // |
|
1104 void CCFMessageHandlerContext::CheckMessageQueueL() |
|
1105 { |
|
1106 FUNC_LOG; |
|
1107 |
|
1108 // We must have something in the queue and receive message pending |
|
1109 if( iMessageQueue.Count() && !iReceiveContextSourceMsg.IsNull() ) |
|
1110 { |
|
1111 // First check that client side buffer is big enough |
|
1112 TInt clientBufferSize = iReceiveContextSourceMsg.GetDesMaxLengthL( 0 ); |
|
1113 TInt indicationSize = iMessageQueue[0]->Size(); |
|
1114 if( indicationSize <= clientBufferSize ) |
|
1115 { |
|
1116 // Client has sufficient buffer |
|
1117 // Write buffer into client side and complete |
|
1118 HBufC8* messageBuffer = iMessageQueue[0]; |
|
1119 iReceiveContextSourceMsg.WriteL( 0, *messageBuffer ); |
|
1120 iReceiveContextSourceMsg.Complete( KErrNone ); |
|
1121 |
|
1122 // Remove indication from queue |
|
1123 delete messageBuffer; |
|
1124 iMessageQueue.Remove( 0 ); |
|
1125 |
|
1126 } |
|
1127 else |
|
1128 { |
|
1129 // Client has insufficient buffer size |
|
1130 // Write new buffer size in client memory and complete |
|
1131 TPckgBuf<TInt> sizeBuf( indicationSize ); |
|
1132 iReceiveContextSourceMsg.WriteL( 1, sizeBuf ); |
|
1133 iReceiveContextSourceMsg.Complete( KErrTooBig ); |
|
1134 } |
|
1135 } |
|
1136 } |
|
1137 |
|
1138 |
|
1139 |
|
1140 //----------------------------------------------------------------------------- |
|
1141 // CCFMessageHandlerContext::CompleteRequestContextL |
|
1142 //----------------------------------------------------------------------------- |
|
1143 // |
|
1144 void CCFMessageHandlerContext::CompleteRequestContextL( |
|
1145 const RMessage2& aMessage ) |
|
1146 { |
|
1147 FUNC_LOG; |
|
1148 |
|
1149 // Check if client has a sufficient buffer |
|
1150 TInt resultArraySize = 0; |
|
1151 resultArraySize += sizeof( TInt ); |
|
1152 TInt count = iContextRequestBuffer.Count(); |
|
1153 CCFContextObjectImpl* context = NULL; |
|
1154 for( TInt i = 0; i < count; i++ ) |
|
1155 { |
|
1156 context = static_cast<CCFContextObjectImpl*>( |
|
1157 iContextRequestBuffer[i] ); |
|
1158 resultArraySize += context->Size(); |
|
1159 } |
|
1160 TInt clientBufferSize = aMessage.GetDesMaxLengthL( 0 ); |
|
1161 if( resultArraySize <= clientBufferSize ) |
|
1162 { |
|
1163 // Client has a sufficient buffer |
|
1164 HBufC8* buffer = HBufC8::NewLC( resultArraySize ); |
|
1165 TPtr8 bufferPtr = buffer->Des(); |
|
1166 RDesWriteStream writeStream( bufferPtr ); |
|
1167 writeStream.PushL(); |
|
1168 writeStream.WriteInt16L( count ); |
|
1169 for( TInt i = 0; i < count; i++ ) |
|
1170 { |
|
1171 context = static_cast<CCFContextObjectImpl*>( |
|
1172 iContextRequestBuffer[i] ); |
|
1173 context->ExternalizeL( writeStream ); |
|
1174 } |
|
1175 writeStream.CommitL(); |
|
1176 aMessage.WriteL( 0, bufferPtr ); |
|
1177 |
|
1178 // Clean up |
|
1179 CleanupStack::PopAndDestroy( &writeStream ); |
|
1180 CleanupStack::PopAndDestroy( buffer ); |
|
1181 |
|
1182 // Reset context request buffer |
|
1183 iContextRequestBuffer.Reset(); |
|
1184 |
|
1185 // Complete message |
|
1186 aMessage.Complete( KErrNone ); |
|
1187 } |
|
1188 else |
|
1189 { |
|
1190 // Client has an insufficient buffer |
|
1191 TPckgBuf<TInt> resultArraySizeBuf( resultArraySize ); |
|
1192 aMessage.WriteL( 2, resultArraySizeBuf ); |
|
1193 |
|
1194 // Complete message |
|
1195 aMessage.Complete( KErrTooBig ); |
|
1196 } |
|
1197 } |
|
1198 |
|
1199 //----------------------------------------------------------------------------- |
|
1200 // CCFMessageHandlerContext::DoHandleContextSubscriptionErrorL |
|
1201 //----------------------------------------------------------------------------- |
|
1202 // |
|
1203 void CCFMessageHandlerContext::DoHandleContextSubscriptionErrorL( TInt aError, |
|
1204 const TDesC& aSource, |
|
1205 const TDesC& aType ) |
|
1206 { |
|
1207 FUNC_LOG; |
|
1208 |
|
1209 // Context related to error |
|
1210 CCFContextObjectImpl* context = CCFContextObjectImpl::NewLC(); |
|
1211 context->SetSourceL( aSource ); |
|
1212 context->SetTypeL( aType ); |
|
1213 |
|
1214 // Append error to queue |
|
1215 TSubscriptionError error; |
|
1216 error.iError = aError; |
|
1217 error.iContext = context; |
|
1218 |
|
1219 // Ignore append errors |
|
1220 iSubscriptionErrors.AppendL( error ); |
|
1221 CleanupStack::Pop( context ); |
|
1222 if( !iReceiveMessage.IsNull() ) |
|
1223 { |
|
1224 // Can only fail due OOM |
|
1225 IndicateSubscriptionErrorL(); |
|
1226 } |
|
1227 } |
|
1228 |
|
1229 //------------------------------------------------------------------------------ |
|
1230 // CCFMessageHandlerContext::SubscribersL |
|
1231 //------------------------------------------------------------------------------ |
|
1232 // |
|
1233 void CCFMessageHandlerContext::SubscribersL( const TDesC& aContextSource, |
|
1234 const TDesC& aContextType ) |
|
1235 { |
|
1236 FUNC_LOG; |
|
1237 |
|
1238 // calculate message length |
|
1239 TInt size = 0; |
|
1240 size += sizeof( TInt ); // message type |
|
1241 size += sizeof( TInt ) + aContextSource.Size(); |
|
1242 size += sizeof( TInt ) + aContextType.Size(); |
|
1243 |
|
1244 // create a required buffer and stream |
|
1245 HBufC8* buffer = HBufC8::NewLC( size ); // CLEANUP << buffer |
|
1246 TPtr8 bufferPtr = buffer->Des(); |
|
1247 RDesWriteStream writeStream( bufferPtr ); |
|
1248 writeStream.PushL(); // CLEANUP << writeStream |
|
1249 |
|
1250 // write message to the buffer |
|
1251 writeStream.WriteInt32L( ESubscribers ); |
|
1252 writeStream.WriteInt32L( aContextSource.Length() ); |
|
1253 writeStream.WriteL( aContextSource, aContextSource.Length() ); |
|
1254 writeStream.WriteInt32L( aContextType.Length() ); |
|
1255 writeStream.WriteL( aContextType, aContextType.Length() ); |
|
1256 writeStream.CommitL(); |
|
1257 |
|
1258 CleanupStack::PopAndDestroy( &writeStream ); // CLEANUP >> writeStream |
|
1259 |
|
1260 // append pointer to the message array |
|
1261 iMessageQueue.AppendL( buffer ); |
|
1262 CleanupStack::Pop( buffer ); // CLEANUP >> buffer |
|
1263 |
|
1264 CheckMessageQueueL(); |
|
1265 } |
|
1266 |
|
1267 //------------------------------------------------------------------------------ |
|
1268 // CCFMessageHandlerContext::NoSubscribersL |
|
1269 //------------------------------------------------------------------------------ |
|
1270 // |
|
1271 void CCFMessageHandlerContext::NoSubscribersL( const TDesC& aContextSource, |
|
1272 const TDesC& aContextType ) |
|
1273 { |
|
1274 FUNC_LOG; |
|
1275 |
|
1276 // calculate message length |
|
1277 TInt size = 0; |
|
1278 size += sizeof( TInt ); // message type |
|
1279 size += sizeof( TInt ) + aContextSource.Size(); |
|
1280 size += sizeof( TInt ) + aContextType.Size(); |
|
1281 |
|
1282 // create a required buffer and stream |
|
1283 HBufC8* buffer = HBufC8::NewLC( size ); // CLEANUP << buffer |
|
1284 TPtr8 bufferPtr = buffer->Des(); |
|
1285 RDesWriteStream writeStream( bufferPtr ); |
|
1286 writeStream.PushL(); // CLEANUP << writeStream |
|
1287 |
|
1288 // write message to the buffer |
|
1289 writeStream.WriteInt32L( ENoSubscribers ); |
|
1290 writeStream.WriteInt32L( aContextSource.Length() ); |
|
1291 writeStream.WriteL( aContextSource, aContextSource.Length() ); |
|
1292 writeStream.WriteInt32L( aContextType.Length() ); |
|
1293 writeStream.WriteL( aContextType, aContextType.Length() ); |
|
1294 writeStream.CommitL(); |
|
1295 |
|
1296 CleanupStack::PopAndDestroy( &writeStream ); // CLEANUP >> writeStream |
|
1297 |
|
1298 // append pointer to the message array |
|
1299 iMessageQueue.AppendL( buffer ); |
|
1300 CleanupStack::Pop( buffer ); // CLEANUP >> buffer |
|
1301 |
|
1302 CheckMessageQueueL(); |
|
1303 } |
|
1304 |
|
1305 void CCFMessageHandlerContext::HandleCommandL( |
|
1306 const CCFContextSourceCommand& aCommand ) |
|
1307 { |
|
1308 FUNC_LOG; |
|
1309 |
|
1310 TInt size = sizeof( TInt ); // message type |
|
1311 size += aCommand.Size(); // the command |
|
1312 |
|
1313 // Stream command into descriptor |
|
1314 HBufC8* buffer = HBufC8::NewLC( size ); // CLEANUP<< buffer |
|
1315 TPtr8 bufferPtr = buffer->Des(); |
|
1316 RDesWriteStream stream( bufferPtr ); |
|
1317 stream.PushL(); // CLEANUP<< stream |
|
1318 |
|
1319 // Write message to the buffer |
|
1320 stream.WriteInt32L( EHandleCommand ); |
|
1321 aCommand.ExternalizeL( stream ); |
|
1322 stream.CommitL(); |
|
1323 |
|
1324 CleanupStack::PopAndDestroy( &stream ); // CLEANUP>> stream |
|
1325 |
|
1326 // Append buffer to the message array |
|
1327 iMessageQueue.AppendL( buffer ); |
|
1328 CleanupStack::Pop( buffer ); // CLEANUP>> buffer |
|
1329 |
|
1330 CheckMessageQueueL(); |
|
1331 } |
|
1332 |
|
1333 // End of File |