114
|
1 |
/*
|
|
2 |
* Copyright (c) 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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System include files
|
|
19 |
#include <s32strm.h>
|
|
20 |
#include <s32mem.h>
|
|
21 |
|
|
22 |
// User include files
|
|
23 |
#include "ccsrvsession.h"
|
|
24 |
#include "ccsrv.h"
|
|
25 |
#include "ccresource.h"
|
|
26 |
#include "ccsrvapi.h"
|
|
27 |
|
|
28 |
// Local constants
|
|
29 |
|
|
30 |
|
|
31 |
// ======== MEMBER FUNCTIONS ========
|
|
32 |
|
|
33 |
// -----------------------------------------------------------------------
|
|
34 |
// CCcSrvSession::CCcSrvSession()
|
|
35 |
// -----------------------------------------------------------------------
|
|
36 |
//
|
|
37 |
CCcSrvSession::CCcSrvSession():
|
|
38 |
iLastTrId( 0 )
|
|
39 |
{
|
|
40 |
}
|
|
41 |
|
|
42 |
// -----------------------------------------------------------------------
|
|
43 |
// CCcSrvSession::~CCcSrvSession()
|
|
44 |
// -----------------------------------------------------------------------
|
|
45 |
//
|
|
46 |
CCcSrvSession::~CCcSrvSession()
|
|
47 |
{
|
|
48 |
iRequests.ResetAndDestroy();
|
|
49 |
iObservers.Close();
|
|
50 |
Server().DropSession( this );
|
|
51 |
}
|
|
52 |
|
|
53 |
// -----------------------------------------------------------------------
|
|
54 |
// CCcSrvSession::CreateL()
|
|
55 |
// -----------------------------------------------------------------------
|
|
56 |
//
|
|
57 |
void CCcSrvSession::CreateL()
|
|
58 |
{
|
|
59 |
Server().AddSessionL( this );
|
|
60 |
}
|
|
61 |
|
|
62 |
// -----------------------------------------------------------------------
|
|
63 |
// CCcSrvSession::Id()
|
|
64 |
// -----------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
TUint32 CCcSrvSession::Id()
|
|
67 |
{
|
|
68 |
return iId;
|
|
69 |
}
|
|
70 |
|
|
71 |
// -----------------------------------------------------------------------
|
|
72 |
// CCcSrvSession::SetId()
|
|
73 |
// -----------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
void CCcSrvSession::SetId(
|
|
76 |
TUint32 aId )
|
|
77 |
{
|
|
78 |
iId = aId;
|
|
79 |
}
|
|
80 |
|
|
81 |
// -----------------------------------------------------------------------
|
|
82 |
// CCcSrvSession::ServiceL()
|
|
83 |
// -----------------------------------------------------------------------
|
|
84 |
//
|
|
85 |
void CCcSrvSession::ServiceL(
|
|
86 |
const RMessage2& aMessage )
|
|
87 |
{
|
|
88 |
RMessage2 msg = aMessage;
|
|
89 |
TRAPD( err, DoServiceL( msg ) );
|
|
90 |
if ( err )
|
|
91 |
{
|
|
92 |
aMessage.Complete( err );
|
|
93 |
}
|
|
94 |
}
|
|
95 |
|
|
96 |
// -----------------------------------------------------------------------
|
|
97 |
// CCcSrvSession::DoServiceL()
|
|
98 |
// -----------------------------------------------------------------------
|
|
99 |
//
|
|
100 |
void CCcSrvSession::DoServiceL(
|
|
101 |
RMessage2& aMessage )
|
|
102 |
{
|
|
103 |
switch ( aMessage.Function() )
|
|
104 |
{
|
|
105 |
case ECcReqisterProvider:
|
|
106 |
HandleRegisterProviderL( aMessage );
|
|
107 |
break;
|
|
108 |
case ECcRegisterObserver:
|
|
109 |
HandleRegisterObserverL( aMessage );
|
|
110 |
break;
|
|
111 |
case ECcWaitForApiReq:
|
|
112 |
HandleWaitForApiReqL( aMessage );
|
|
113 |
break;
|
|
114 |
case ECcWaitForApiNtf:
|
|
115 |
HandleWaitForApiNtfL( aMessage );
|
|
116 |
break;
|
|
117 |
case ECcCancel:
|
|
118 |
HandleCancelReqL( aMessage );
|
|
119 |
break;
|
|
120 |
case ECcApiReq:
|
|
121 |
HandleApiReqL( aMessage );
|
|
122 |
break;
|
|
123 |
case ECcApiResp:
|
|
124 |
HandleApiRespL( aMessage );
|
|
125 |
break;
|
|
126 |
case ECcGetMsgData:
|
|
127 |
HandleGetMsgDataL( aMessage );
|
|
128 |
break;
|
|
129 |
case ECcApiNtf:
|
|
130 |
HandleApiNtfL( aMessage );
|
|
131 |
break;
|
|
132 |
default:
|
|
133 |
User::Leave( KErrNotSupported );
|
|
134 |
break;
|
|
135 |
}
|
|
136 |
}
|
|
137 |
|
|
138 |
// -----------------------------------------------------------------------
|
|
139 |
// CCcSrvSession::HandleRegisterProviderL()
|
|
140 |
// -----------------------------------------------------------------------
|
|
141 |
//
|
|
142 |
void CCcSrvSession::HandleRegisterProviderL(
|
|
143 |
RMessage2& aMessage )
|
|
144 |
{
|
|
145 |
TUint32 provider;
|
|
146 |
TPckgBuf<TUint32> packagedProvider;
|
|
147 |
aMessage.ReadL(0, packagedProvider);
|
|
148 |
provider = packagedProvider();
|
|
149 |
|
|
150 |
Server().RegisterProviderL(
|
|
151 |
provider,
|
|
152 |
this );
|
|
153 |
|
|
154 |
TPckgBuf<TUint32> packagedSessionId( iId );
|
|
155 |
aMessage.WriteL( 1, packagedSessionId );
|
|
156 |
aMessage.Complete( KErrNone );
|
|
157 |
}
|
|
158 |
|
|
159 |
// -----------------------------------------------------------------------
|
|
160 |
// CCcSrvSession::HandleRegisterObserverL()
|
|
161 |
// -----------------------------------------------------------------------
|
|
162 |
//
|
|
163 |
void CCcSrvSession::HandleRegisterObserverL(
|
|
164 |
RMessage2& aMessage )
|
|
165 |
{
|
|
166 |
TUint32 provider;
|
|
167 |
TPckgBuf<TUint32> packagedProvider;
|
|
168 |
aMessage.ReadL(0, packagedProvider);
|
|
169 |
provider = packagedProvider();
|
|
170 |
|
|
171 |
Server().RegisterObserverL(
|
|
172 |
provider,
|
|
173 |
this );
|
|
174 |
|
|
175 |
TPckgBuf<TUint32> packagedSessionId( iId );
|
|
176 |
aMessage.WriteL( 1, packagedSessionId );
|
|
177 |
aMessage.Complete( KErrNone );
|
|
178 |
}
|
|
179 |
|
|
180 |
// -----------------------------------------------------------------------
|
|
181 |
// CCcSrvSession::RegisterObserverSessionL()
|
|
182 |
// -----------------------------------------------------------------------
|
|
183 |
//
|
|
184 |
void CCcSrvSession::RegisterObserverSessionL(
|
|
185 |
TUint32 aObserver )
|
|
186 |
{
|
|
187 |
// Notify provider of registered observer
|
|
188 |
SendObserverNtfL( aObserver, ECcRegisterObserverNtf );
|
|
189 |
iObservers.AppendL( aObserver );
|
|
190 |
}
|
|
191 |
|
|
192 |
// -----------------------------------------------------------------------
|
|
193 |
// CCcSrvSession::UnregisterObserverSessionL()
|
|
194 |
// -----------------------------------------------------------------------
|
|
195 |
//
|
|
196 |
void CCcSrvSession::UnregisterObserverSessionL(
|
|
197 |
TUint32 aObserver )
|
|
198 |
{
|
|
199 |
for ( TInt i = 0; i < iObservers.Count(); i++ )
|
|
200 |
{
|
|
201 |
if ( iObservers[ i ] == aObserver )
|
|
202 |
{
|
|
203 |
// Notify provider of unregistered observer
|
|
204 |
SendObserverNtfL( aObserver, ECcUnregisterObserverNtf );
|
|
205 |
iObservers.Remove( i );
|
|
206 |
break;
|
|
207 |
}
|
|
208 |
}
|
|
209 |
}
|
|
210 |
|
|
211 |
// -----------------------------------------------------------------------
|
|
212 |
// CCcSrvSession::HandleWaitForApiReqL()
|
|
213 |
// -----------------------------------------------------------------------
|
|
214 |
//
|
|
215 |
void CCcSrvSession::HandleWaitForApiReqL(
|
|
216 |
RMessage2& aMessage )
|
|
217 |
{
|
|
218 |
// Wait for the next API request or Observer notification
|
|
219 |
CCcSrvMsg* tr = CCcSrvMsg::NewL();
|
|
220 |
CleanupStack::PushL( tr );
|
|
221 |
tr->SetMessage( aMessage );
|
|
222 |
iRequests.AppendL( tr );
|
|
223 |
CleanupStack::Pop( tr );
|
|
224 |
|
|
225 |
// Check if there is outstanding requests
|
|
226 |
for ( TInt i = 0; i < iRequests.Count(); i++ )
|
|
227 |
{
|
|
228 |
CCcSrvMsg* req = iRequests[ i ];
|
|
229 |
if ( req->MsgId() == ECcRegisterObserverNtf ||
|
|
230 |
req->MsgId() == ECcUnregisterObserverNtf )
|
|
231 |
{
|
|
232 |
iRequests.Remove( i );
|
|
233 |
CleanupStack::PushL( req );
|
|
234 |
SendObserverNtfL( req->Sender(), req->MsgId() );
|
|
235 |
CleanupStack::PopAndDestroy( req );
|
|
236 |
break;
|
|
237 |
}
|
|
238 |
else if ( req->Function() == ECcApiReq )
|
|
239 |
{
|
|
240 |
iRequests.Remove( i );
|
|
241 |
CleanupStack::PushL( req );
|
|
242 |
ReceiveMsgL( *req );
|
|
243 |
CleanupStack::PopAndDestroy( req );
|
|
244 |
break;
|
|
245 |
}
|
|
246 |
}
|
|
247 |
}
|
|
248 |
|
|
249 |
// -----------------------------------------------------------------------
|
|
250 |
// CCcSrvSession::HandleWaitForApiNtfL()
|
|
251 |
// -----------------------------------------------------------------------
|
|
252 |
//
|
|
253 |
void CCcSrvSession::HandleWaitForApiNtfL(
|
|
254 |
RMessage2& aMessage )
|
|
255 |
{
|
|
256 |
CCcSrvMsg* tr = CCcSrvMsg::NewL();
|
|
257 |
CleanupStack::PushL( tr );
|
|
258 |
tr->SetMessage( aMessage );
|
|
259 |
iRequests.AppendL( tr );
|
|
260 |
CleanupStack::Pop( tr );
|
|
261 |
|
|
262 |
// Check if there is outstanding API notifications
|
|
263 |
for ( TInt i = 0; i < iRequests.Count(); i++ )
|
|
264 |
{
|
|
265 |
CCcSrvMsg* req = iRequests[ i ];
|
|
266 |
if ( req->Function() == ECcApiNtf )
|
|
267 |
{
|
|
268 |
iRequests.Remove( i );
|
|
269 |
CleanupStack::PushL( req );
|
|
270 |
ReceiveMsgL( *req );
|
|
271 |
CleanupStack::PopAndDestroy( req );
|
|
272 |
break;
|
|
273 |
}
|
|
274 |
}
|
|
275 |
}
|
|
276 |
|
|
277 |
// -----------------------------------------------------------------------
|
|
278 |
// CCcSrvSession::HandleCancelReqL()
|
|
279 |
// -----------------------------------------------------------------------
|
|
280 |
//
|
|
281 |
void CCcSrvSession::HandleCancelReqL(
|
|
282 |
RMessage2& aMessage )
|
|
283 |
{
|
|
284 |
TInt function;
|
|
285 |
TPckgBuf<TInt> packagedFunction;
|
|
286 |
aMessage.ReadL( 0, packagedFunction );
|
|
287 |
function = packagedFunction();
|
|
288 |
|
|
289 |
for ( TInt i = 0; i < iRequests.Count(); i++ )
|
|
290 |
{
|
|
291 |
CCcSrvMsg* req = iRequests[ i ];
|
|
292 |
if ( req->Message().Function() == function &&
|
|
293 |
!req->Message().IsNull() )
|
|
294 |
{
|
|
295 |
// Complete canceled request
|
|
296 |
req->Message().Complete( KErrCancel );
|
|
297 |
iRequests.Remove( i );
|
|
298 |
delete req;
|
|
299 |
}
|
|
300 |
}
|
|
301 |
aMessage.Complete( KErrNone );
|
|
302 |
}
|
|
303 |
|
|
304 |
// -----------------------------------------------------------------------
|
|
305 |
// CCcSrvSession::HandleApiReqL()
|
|
306 |
// -----------------------------------------------------------------------
|
|
307 |
//
|
|
308 |
void CCcSrvSession::HandleApiReqL(
|
|
309 |
RMessage2& aMessage )
|
|
310 |
{
|
|
311 |
TUint32 provider;
|
|
312 |
TPckgBuf<TUint32> packagedProvider;
|
|
313 |
aMessage.ReadL( 0, packagedProvider );
|
|
314 |
provider = packagedProvider();
|
|
315 |
TUint32 providerAddress;
|
|
316 |
Server().ResolveProviderAddressL( provider, providerAddress );
|
|
317 |
|
|
318 |
HBufC8* msgBuf = HBufC8::NewL( aMessage.GetDesLengthL( 3 ) );
|
|
319 |
CleanupStack::PushL( msgBuf );
|
|
320 |
TPtr8 msgBufPtr = msgBuf->Des();
|
|
321 |
aMessage.ReadL( 3, msgBufPtr, 0 );
|
|
322 |
|
|
323 |
RDesReadStream stream( msgBufPtr );
|
|
324 |
|
|
325 |
CCcSrvMsg* message = CCcSrvMsg::NewL();
|
|
326 |
CleanupStack::PushL( message );
|
|
327 |
message->InternalizeL( stream );
|
|
328 |
message->SetTrId( Server().GetTrId() );
|
|
329 |
message->SetMessage( aMessage );
|
|
330 |
message->SetSender( iId );
|
|
331 |
message->SetReceiver( providerAddress );
|
|
332 |
|
|
333 |
iRequests.AppendL( message );
|
|
334 |
CleanupStack::Pop( message );
|
|
335 |
|
|
336 |
Server().SendMsgL( *message );
|
|
337 |
|
|
338 |
CleanupStack::PopAndDestroy( msgBuf );
|
|
339 |
|
|
340 |
}
|
|
341 |
|
|
342 |
// -----------------------------------------------------------------------
|
|
343 |
// CCcSrvSession::HandleApiReqL()
|
|
344 |
// -----------------------------------------------------------------------
|
|
345 |
//
|
|
346 |
void CCcSrvSession::HandleApiRespL(
|
|
347 |
RMessage2& aMessage )
|
|
348 |
{
|
|
349 |
// Read sender and receiver of a response
|
|
350 |
TPckgBuf<TUint32> pckg;
|
|
351 |
aMessage.ReadL( 1, pckg );
|
|
352 |
TUint32 sender = pckg();
|
|
353 |
aMessage.ReadL( 2, pckg );
|
|
354 |
TUint32 receiver = pckg();
|
|
355 |
|
|
356 |
// Read message data
|
|
357 |
HBufC8* msgBuf = HBufC8::NewL( aMessage.GetDesLengthL( 3 ) );
|
|
358 |
CleanupStack::PushL( msgBuf );
|
|
359 |
TPtr8 msgBufPtr = msgBuf->Des();
|
|
360 |
aMessage.ReadL( 3, msgBufPtr, 0 );
|
|
361 |
|
|
362 |
// Internalize message
|
|
363 |
RDesReadStream stream( msgBufPtr );
|
|
364 |
CCcSrvMsg* message = CCcSrvMsg::NewL();
|
|
365 |
CleanupStack::PushL( message );
|
|
366 |
message->InternalizeL( stream );
|
|
367 |
message->SetMessage( aMessage );
|
|
368 |
message->SetSender( sender );
|
|
369 |
message->SetReceiver( receiver );
|
|
370 |
|
|
371 |
// Forward message to receiver
|
|
372 |
Server().SendMsgL( *message );
|
|
373 |
|
|
374 |
CleanupStack::PopAndDestroy( message );
|
|
375 |
CleanupStack::PopAndDestroy( msgBuf );
|
|
376 |
|
|
377 |
aMessage.Complete( KErrNone );
|
|
378 |
|
|
379 |
}
|
|
380 |
|
|
381 |
// -----------------------------------------------------------------------
|
|
382 |
// CCcSrvSession::HandleGetMsgDataL()
|
|
383 |
// -----------------------------------------------------------------------
|
|
384 |
//
|
|
385 |
void CCcSrvSession::HandleGetMsgDataL(
|
|
386 |
RMessage2& aMessage )
|
|
387 |
{
|
|
388 |
// Read transaction id which message data is requested
|
|
389 |
TPckgBuf<TUint32> pckg;
|
|
390 |
aMessage.ReadL( 0, pckg );
|
|
391 |
TUint32 trId = pckg();
|
|
392 |
|
|
393 |
CCcSrvMsg* req( NULL );
|
|
394 |
TBool found( EFalse );
|
|
395 |
for( TInt i = 0; i < iRequests.Count() && !found; i++ )
|
|
396 |
{
|
|
397 |
req = iRequests[ i ];
|
|
398 |
if ( req->Function() == ECcGetMsgData &&
|
|
399 |
req->TrId() == trId )
|
|
400 |
{
|
|
401 |
iRequests.Remove( i );
|
|
402 |
found = ETrue;
|
|
403 |
}
|
|
404 |
}
|
|
405 |
|
|
406 |
TInt err( KErrNone );
|
|
407 |
if ( found )
|
|
408 |
{
|
|
409 |
CleanupStack::PushL( req );
|
|
410 |
|
|
411 |
// Write message data
|
|
412 |
aMessage.WriteL( 1, req->Data(), 0);
|
|
413 |
|
|
414 |
CleanupStack::PopAndDestroy( req );
|
|
415 |
}
|
|
416 |
else
|
|
417 |
{
|
|
418 |
err = KErrNotFound;
|
|
419 |
}
|
|
420 |
|
|
421 |
aMessage.Complete( err );
|
|
422 |
|
|
423 |
}
|
|
424 |
|
|
425 |
// -----------------------------------------------------------------------
|
|
426 |
// CCcSrvSession::HandleApiNtfL()
|
|
427 |
// -----------------------------------------------------------------------
|
|
428 |
//
|
|
429 |
void CCcSrvSession::HandleApiNtfL(
|
|
430 |
RMessage2& aMessage )
|
|
431 |
{
|
|
432 |
// Read notification data
|
|
433 |
HBufC8* msgBuf = HBufC8::NewL( aMessage.GetDesLengthL( 3 ) );
|
|
434 |
CleanupStack::PushL( msgBuf );
|
|
435 |
TPtr8 msgBufPtr = msgBuf->Des();
|
|
436 |
aMessage.ReadL( 3, msgBufPtr, 0 );
|
|
437 |
|
|
438 |
// Internalize notification
|
|
439 |
RDesReadStream stream( msgBufPtr );
|
|
440 |
CCcSrvMsg* message = CCcSrvMsg::NewL();
|
|
441 |
CleanupStack::PushL( message );
|
|
442 |
message->InternalizeL( stream );
|
|
443 |
message->SetMessage( aMessage );
|
|
444 |
message->SetSender( iId );
|
|
445 |
|
|
446 |
// Forward notification to observers
|
|
447 |
for ( TInt i = 0; i < iObservers.Count(); i++ )
|
|
448 |
{
|
|
449 |
message->SetReceiver( iObservers[ i ] );
|
|
450 |
Server().SendMsgL( *message );
|
|
451 |
}
|
|
452 |
|
|
453 |
message->Message().Complete( KErrNone );
|
|
454 |
|
|
455 |
CleanupStack::PopAndDestroy( message );
|
|
456 |
CleanupStack::PopAndDestroy( msgBuf );
|
|
457 |
}
|
|
458 |
|
|
459 |
// -----------------------------------------------------------------------
|
|
460 |
// CCcSrvSession::ReceiveMsgL()
|
|
461 |
// -----------------------------------------------------------------------
|
|
462 |
//
|
|
463 |
void CCcSrvSession::ReceiveMsgL(
|
|
464 |
CCcSrvMsg& aMessage )
|
|
465 |
{
|
|
466 |
TBool found( EFalse );
|
|
467 |
CCcSrvMsg* req( NULL );
|
|
468 |
for ( TInt i = 0; i < iRequests.Count() && !found; i++ )
|
|
469 |
{
|
|
470 |
req = iRequests[ i ];
|
|
471 |
if ( aMessage.Function() == ECcApiReq &&
|
|
472 |
req->Function() == ECcWaitForApiReq &&
|
|
473 |
!req->Message().IsNull() )
|
|
474 |
{
|
|
475 |
// Pending WaitForApiReq transaction found
|
|
476 |
iRequests.Remove( i );
|
|
477 |
found = ETrue;
|
|
478 |
}
|
|
479 |
else if ( aMessage.Function() == ECcApiResp &&
|
|
480 |
req->Function() == ECcApiReq &&
|
|
481 |
req->TrId() == aMessage.TrId() &&
|
|
482 |
!req->Message().IsNull() )
|
|
483 |
{
|
|
484 |
// Pending ApiReq transaction found
|
|
485 |
iRequests.Remove( i );
|
|
486 |
found = ETrue;
|
|
487 |
}
|
|
488 |
else if ( aMessage.Function() == ECcApiNtf &&
|
|
489 |
req->Function() == ECcWaitForApiNtf &&
|
|
490 |
!req->Message().IsNull() )
|
|
491 |
{
|
|
492 |
// Pending WaitForApiNtf transaction found
|
|
493 |
iRequests.Remove( i );
|
|
494 |
found = ETrue;
|
|
495 |
}
|
|
496 |
}
|
|
497 |
|
|
498 |
if ( found )
|
|
499 |
{
|
|
500 |
CleanupStack::PushL( req );
|
|
501 |
|
|
502 |
// Write sender of message
|
|
503 |
TPckgBuf<TUint32> packagedSender( aMessage.Sender() );
|
|
504 |
req->Message().WriteL( 1, packagedSender, 0 );
|
|
505 |
|
|
506 |
// Write receiver of message
|
|
507 |
TPckgBuf<TUint32> packagedReceiver( aMessage.Receiver() );
|
|
508 |
req->Message().WriteL( 2, packagedReceiver, 0 );
|
|
509 |
|
|
510 |
// Externalize message header
|
|
511 |
CBufFlat* buf = CBufFlat::NewL( KCcHeaderSize );
|
|
512 |
CleanupStack::PushL( buf );
|
|
513 |
RBufWriteStream stream( *buf );
|
|
514 |
CleanupClosePushL( stream );
|
|
515 |
aMessage.ExternalizeHeaderL( stream );
|
|
516 |
CleanupStack::PopAndDestroy( &stream );
|
|
517 |
|
|
518 |
//Create a heap descriptor from the buffer
|
|
519 |
HBufC8* des = HBufC8::NewL( buf->Size() );
|
|
520 |
CleanupStack::PushL( des );
|
|
521 |
TPtr8 ptr( des->Des() );
|
|
522 |
buf->Read( 0, ptr, buf->Size() );
|
|
523 |
|
|
524 |
// Write request header
|
|
525 |
req->Message().WriteL( 3, ptr, 0);
|
|
526 |
CleanupStack::PopAndDestroy( des );
|
|
527 |
CleanupStack::PopAndDestroy( buf );
|
|
528 |
|
|
529 |
// Complete request
|
|
530 |
req->Message().Complete( KErrNone );
|
|
531 |
|
|
532 |
CleanupStack::PopAndDestroy( req );
|
|
533 |
}
|
|
534 |
|
|
535 |
// Store message to enable message data requesting later or
|
|
536 |
// to wait receiver to be ready to receive request
|
|
537 |
if ( found && aMessage.DataSize() ||
|
|
538 |
!found && ( aMessage.Function() == ECcApiReq ||
|
|
539 |
aMessage.Function() == ECcApiNtf ) )
|
|
540 |
{
|
|
541 |
// Store message to handled later
|
|
542 |
CCcSrvMsg* msg = CCcSrvMsg::NewL();
|
|
543 |
CleanupStack::PushL( msg );
|
|
544 |
if ( found && aMessage.DataSize() )
|
|
545 |
{
|
|
546 |
msg->SetFunction( ECcGetMsgData );
|
|
547 |
}
|
|
548 |
else
|
|
549 |
{
|
|
550 |
msg->SetFunction( aMessage.Function() );
|
|
551 |
}
|
|
552 |
msg->SetSender( aMessage.Sender() );
|
|
553 |
msg->SetReceiver( aMessage.Receiver() );
|
|
554 |
msg->SetMsgId( aMessage.MsgId() );
|
|
555 |
msg->SetTrId( aMessage.TrId() );
|
|
556 |
msg->SetStatus( aMessage.Status() );
|
|
557 |
msg->SetData( aMessage.Data() );
|
|
558 |
iRequests.AppendL( msg );
|
|
559 |
CleanupStack::Pop( msg );
|
|
560 |
}
|
|
561 |
}
|
|
562 |
|
|
563 |
// -----------------------------------------------------------------------
|
|
564 |
// CCcSrvSession::SendObserverNtfL()
|
|
565 |
// -----------------------------------------------------------------------
|
|
566 |
//
|
|
567 |
void CCcSrvSession::SendObserverNtfL(
|
|
568 |
TUint32 aSender,
|
|
569 |
TUint32 aNtf )
|
|
570 |
{
|
|
571 |
// Create notification
|
|
572 |
CCcSrvMsg* ntf = CCcSrvMsg::NewL();
|
|
573 |
CleanupStack::PushL( ntf );
|
|
574 |
ntf->SetMsgId( aNtf );
|
|
575 |
ntf->SetSender( aSender );
|
|
576 |
|
|
577 |
// Notify provider of registered observer
|
|
578 |
TBool found( EFalse );
|
|
579 |
CCcSrvMsg* req( NULL );
|
|
580 |
for ( TInt i = 0; i < iRequests.Count() && !found; i++ )
|
|
581 |
{
|
|
582 |
req = iRequests[ i ];
|
|
583 |
if ( req->Function() == ECcWaitForApiReq &&
|
|
584 |
!req->Message().IsNull() )
|
|
585 |
{
|
|
586 |
// Pending WaitForApiReq transaction found
|
|
587 |
iRequests.Remove( i );
|
|
588 |
found = ETrue;
|
|
589 |
}
|
|
590 |
}
|
|
591 |
if ( found )
|
|
592 |
{
|
|
593 |
// Write sender of message
|
|
594 |
TPckgBuf<TUint32> packagedSender( ntf->Sender() );
|
|
595 |
req->Message().WriteL( 1, packagedSender, 0 );
|
|
596 |
|
|
597 |
// Write receiver of message
|
|
598 |
TPckgBuf<TUint32> packagedReceiver( iId );
|
|
599 |
req->Message().WriteL( 2, packagedReceiver, 0 );
|
|
600 |
|
|
601 |
// Externalize notification
|
|
602 |
HBufC8* ntfBuf = ntf->MarshalL();
|
|
603 |
CleanupStack::PushL( ntfBuf );
|
|
604 |
TPtr8 ntfPtr( NULL, 0);
|
|
605 |
ntfPtr.Set( ntfBuf->Des() );
|
|
606 |
|
|
607 |
// Write request header
|
|
608 |
req->Message().WriteL( 3, ntfPtr, 0);
|
|
609 |
CleanupStack::PopAndDestroy( ntfBuf );
|
|
610 |
CleanupStack::PopAndDestroy( ntf );
|
|
611 |
|
|
612 |
// Complete request
|
|
613 |
req->Message().Complete( KErrNone );
|
|
614 |
delete req;
|
|
615 |
|
|
616 |
}
|
|
617 |
else
|
|
618 |
{
|
|
619 |
// Store notification to be sent later
|
|
620 |
iRequests.AppendL( ntf );
|
|
621 |
CleanupStack::Pop( ntf );
|
|
622 |
}
|
|
623 |
}
|
|
624 |
|
|
625 |
// End of file
|