contentcontrolsrv/ccsrv/src/ccsrvsession.cpp
branchRCL_3
changeset 18 bd874ee5e5e2
parent 0 79c6a41cd166
child 78 1b207dd38b72
equal deleted inserted replaced
9:d0529222e3f0 18:bd874ee5e5e2
   213 // -----------------------------------------------------------------------
   213 // -----------------------------------------------------------------------
   214 //
   214 //
   215 void CCcSrvSession::HandleWaitForApiReqL(
   215 void CCcSrvSession::HandleWaitForApiReqL(
   216     RMessage2& aMessage )
   216     RMessage2& aMessage )
   217     {
   217     {
       
   218     // Wait for the next API request or Observer notification
   218     CCcSrvMsg* tr = CCcSrvMsg::NewL();
   219     CCcSrvMsg* tr = CCcSrvMsg::NewL();
   219     CleanupStack::PushL( tr );
   220     CleanupStack::PushL( tr );
   220     tr->SetMessage( aMessage );
   221     tr->SetMessage( aMessage );
   221     iRequests.AppendL( tr );
   222     iRequests.AppendL( tr );
   222     CleanupStack::Pop( 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         }    
   223     }
   247     }
   224 
   248 
   225 // -----------------------------------------------------------------------
   249 // -----------------------------------------------------------------------
   226 // CCcSrvSession::HandleWaitForApiNtfL()
   250 // CCcSrvSession::HandleWaitForApiNtfL()
   227 // -----------------------------------------------------------------------
   251 // -----------------------------------------------------------------------
   232     CCcSrvMsg* tr = CCcSrvMsg::NewL();
   256     CCcSrvMsg* tr = CCcSrvMsg::NewL();
   233     CleanupStack::PushL( tr );
   257     CleanupStack::PushL( tr );
   234     tr->SetMessage( aMessage );
   258     tr->SetMessage( aMessage );
   235     iRequests.AppendL( tr );
   259     iRequests.AppendL( tr );
   236     CleanupStack::Pop( 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         }
   237     }
   275     }
   238 
   276 
   239 // -----------------------------------------------------------------------
   277 // -----------------------------------------------------------------------
   240 // CCcSrvSession::HandleCancelReqL()
   278 // CCcSrvSession::HandleCancelReqL()
   241 // -----------------------------------------------------------------------
   279 // -----------------------------------------------------------------------
   287     CCcSrvMsg* message = CCcSrvMsg::NewL();
   325     CCcSrvMsg* message = CCcSrvMsg::NewL();
   288     CleanupStack::PushL( message );
   326     CleanupStack::PushL( message );
   289     message->InternalizeL( stream );
   327     message->InternalizeL( stream );
   290     message->SetTrId( Server().GetTrId() );
   328     message->SetTrId( Server().GetTrId() );
   291     message->SetMessage( aMessage );
   329     message->SetMessage( aMessage );
   292     
   330     message->SetSender( iId );
   293     Server().SendMsgL( iId, providerAddress, *message );
   331     message->SetReceiver( providerAddress );
   294 
   332     
   295     iRequests.AppendL( message );
   333     iRequests.AppendL( message );
   296     
       
   297     CleanupStack::Pop( message );    
   334     CleanupStack::Pop( message );    
       
   335 
       
   336     Server().SendMsgL( *message );
       
   337     
   298     CleanupStack::PopAndDestroy( msgBuf );
   338     CleanupStack::PopAndDestroy( msgBuf );
   299         
   339         
   300     }
   340     }
   301 
   341 
   302 // -----------------------------------------------------------------------
   342 // -----------------------------------------------------------------------
   323     RDesReadStream stream( msgBufPtr );
   363     RDesReadStream stream( msgBufPtr );
   324     CCcSrvMsg* message = CCcSrvMsg::NewL();
   364     CCcSrvMsg* message = CCcSrvMsg::NewL();
   325     CleanupStack::PushL( message );
   365     CleanupStack::PushL( message );
   326     message->InternalizeL( stream );
   366     message->InternalizeL( stream );
   327     message->SetMessage( aMessage );
   367     message->SetMessage( aMessage );
       
   368     message->SetSender( sender );
       
   369     message->SetReceiver( receiver );
   328     
   370     
   329     // Forward message to receiver
   371     // Forward message to receiver
   330     Server().SendMsgL( sender, receiver, *message );
   372     Server().SendMsgL( *message );
   331 
   373 
   332     CleanupStack::PopAndDestroy( message );    
   374     CleanupStack::PopAndDestroy( message );    
   333     CleanupStack::PopAndDestroy( msgBuf );
   375     CleanupStack::PopAndDestroy( msgBuf );
   334 
   376 
   335     aMessage.Complete( KErrNone );
   377     aMessage.Complete( KErrNone );
   394     RDesReadStream stream( msgBufPtr );
   436     RDesReadStream stream( msgBufPtr );
   395     CCcSrvMsg* message = CCcSrvMsg::NewL();
   437     CCcSrvMsg* message = CCcSrvMsg::NewL();
   396     CleanupStack::PushL( message );
   438     CleanupStack::PushL( message );
   397     message->InternalizeL( stream );
   439     message->InternalizeL( stream );
   398     message->SetMessage( aMessage );
   440     message->SetMessage( aMessage );
       
   441     message->SetSender( iId );
   399 
   442 
   400     // Forward notification to observers
   443     // Forward notification to observers
   401     for ( TInt i = 0; i < iObservers.Count(); i++ )
   444     for ( TInt i = 0; i < iObservers.Count(); i++ )
   402         {
   445         {
   403         Server().SendMsgL( iId, iObservers[ i ], *message );
   446         message->SetReceiver( iObservers[ i ] );
       
   447         Server().SendMsgL( *message );
   404         }
   448         }
   405     
   449     
   406     message->Message().Complete( KErrNone );
   450     message->Message().Complete( KErrNone );
   407     
   451     
   408     CleanupStack::PopAndDestroy( message );
   452     CleanupStack::PopAndDestroy( message );
   412 // -----------------------------------------------------------------------
   456 // -----------------------------------------------------------------------
   413 // CCcSrvSession::ReceiveMsgL()
   457 // CCcSrvSession::ReceiveMsgL()
   414 // -----------------------------------------------------------------------
   458 // -----------------------------------------------------------------------
   415 //
   459 //
   416 void CCcSrvSession::ReceiveMsgL(
   460 void CCcSrvSession::ReceiveMsgL(
   417     TUint32 aSender,
       
   418     TUint32 aReceiver,
       
   419     CCcSrvMsg& aMessage )
   461     CCcSrvMsg& aMessage )
   420     {
   462     {
   421     TBool found( EFalse );
   463     TBool found( EFalse );
   422     CCcSrvMsg* req( NULL );
   464     CCcSrvMsg* req( NULL );
   423     TInt index( 0 );
       
   424     for ( TInt i = 0; i < iRequests.Count() && !found; i++ )
   465     for ( TInt i = 0; i < iRequests.Count() && !found; i++ )
   425         {
   466         {
   426         req = iRequests[ i ];
   467         req = iRequests[ i ];
   427         if ( aMessage.Message().Function() == ECcApiReq &&
   468         if ( aMessage.Function() == ECcApiReq &&
   428              req->Message().Function() == ECcWaitForApiReq &&  
   469              req->Function() == ECcWaitForApiReq &&  
   429              !req->Message().IsNull() )
   470              !req->Message().IsNull() )
   430             {
   471             {
   431             // Pending WaitForApiReq transaction found
   472             // Pending WaitForApiReq transaction found
   432             index = i;
   473             iRequests.Remove( i );
   433             found = ETrue;
   474             found = ETrue;
   434             }
   475             }
   435         else if ( aMessage.Message().Function() == ECcApiResp &&
   476         else if ( aMessage.Function() == ECcApiResp &&
   436                   req->TrId() == aMessage.TrId() )
   477                   req->TrId() == aMessage.TrId() )
   437             {
   478             {
   438             // Pending ApiReq transaction found
   479             // Pending ApiReq transaction found
   439             index = i;
   480             iRequests.Remove( i );
   440             found = ETrue;
   481             found = ETrue;
   441             }
   482             }
   442         else if ( aMessage.Message().Function()  == ECcApiNtf &&
   483         else if ( aMessage.Function()  == ECcApiNtf &&
   443                   req->Message().Function() == ECcWaitForApiNtf &&
   484                   req->Function() == ECcWaitForApiNtf &&
   444                   !req->Message().IsNull() )
   485                   !req->Message().IsNull() )
   445             {
   486             {
   446             // Pending WaitForApiNtf transaction found
   487             // Pending WaitForApiNtf transaction found
   447             index = i;
   488             iRequests.Remove( i );
   448             found = ETrue;
   489             found = ETrue;
   449             }
   490             }
   450         }
   491         }
   451     
   492     
   452     if ( found )
   493     if ( found )
   453         {
   494         {
       
   495         CleanupStack::PushL( req );
       
   496         
   454         // Write sender of message
   497         // Write sender of message
   455         TPckgBuf<TUint32> packagedSender( aSender );
   498         TPckgBuf<TUint32> packagedSender( aMessage.Sender() );
   456         req->Message().WriteL( 1, packagedSender, 0 );
   499         req->Message().WriteL( 1, packagedSender, 0 );
   457         
   500         
   458         // Write receiver of message
   501         // Write receiver of message
   459         TPckgBuf<TUint32> packagedReceiver( aReceiver );
   502         TPckgBuf<TUint32> packagedReceiver( aMessage.Receiver() );
   460         req->Message().WriteL( 2, packagedReceiver, 0 );
   503         req->Message().WriteL( 2, packagedReceiver, 0 );
   461         
   504         
   462         // Externalize message header
   505         // Externalize message header
   463         CBufFlat* buf = CBufFlat::NewL( KCcHeaderSize );
   506         CBufFlat* buf = CBufFlat::NewL( KCcHeaderSize );
   464         CleanupStack::PushL( buf );
   507         CleanupStack::PushL( buf );
   475         
   518         
   476         // Write request header
   519         // Write request header
   477         req->Message().WriteL( 3, ptr, 0);
   520         req->Message().WriteL( 3, ptr, 0);
   478         CleanupStack::PopAndDestroy( des );
   521         CleanupStack::PopAndDestroy( des );
   479         CleanupStack::PopAndDestroy( buf );
   522         CleanupStack::PopAndDestroy( buf );
   480         
   523 
   481         // Complete request
   524         // Complete request
   482         req->Message().Complete( KErrNone );
   525         req->Message().Complete( KErrNone );
       
   526 
   483         if (  aMessage.DataSize() )
   527         if (  aMessage.DataSize() )
   484             {
   528             {
   485             // Store request data to be read later
   529             // Store request data to be read later
   486             // with GetMsgData()
   530             // with GetMsgData()
   487             req->SetTrId( aMessage.TrId() );
   531             req->SetTrId( aMessage.TrId() );
   488             req->SetData( aMessage.Data() );
   532             req->SetData( aMessage.Data() );
       
   533             iRequests.AppendL( req );
       
   534             CleanupStack::Pop( req );
   489             }
   535             }
   490         else
   536         else
   491             {
   537             {
   492             // Received request does not contain any data
   538             CleanupStack::PopAndDestroy( req );
   493             // -> remove it from request array
       
   494             iRequests.Remove( index );
       
   495             delete req;
       
   496             }
   539             }
   497         }
   540         }
   498     else
   541     else
   499         {
   542         {
   500         User::Leave( KErrNotFound );
   543         if ( aMessage.Function() == ECcApiReq ||
       
   544              aMessage.Function() == ECcApiNtf )
       
   545             {
       
   546             // Store message to handled later
       
   547             CCcSrvMsg* msg = CCcSrvMsg::NewL();
       
   548             CleanupStack::PushL( msg );
       
   549             msg->SetFunction( aMessage.Function() );
       
   550             msg->SetSender( aMessage.Sender() );
       
   551             msg->SetReceiver( aMessage.Receiver() );
       
   552             msg->SetMsgId( aMessage.MsgId() );
       
   553             msg->SetTrId( aMessage.TrId() );
       
   554             msg->SetStatus( aMessage.Status() );
       
   555             msg->SetData( aMessage.Data() );
       
   556             iRequests.AppendL( msg );
       
   557             CleanupStack::Pop( msg );
       
   558             }
       
   559         // ECcApiResp are ignored
   501         }    
   560         }    
   502     }
   561     }
   503 
   562 
   504 // -----------------------------------------------------------------------
   563 // -----------------------------------------------------------------------
   505 // CCcSrvSession::SendObserverNtfL()
   564 // CCcSrvSession::SendObserverNtfL()
   507 //
   566 //
   508 void CCcSrvSession::SendObserverNtfL(
   567 void CCcSrvSession::SendObserverNtfL(
   509     TUint32 aSender,
   568     TUint32 aSender,
   510     TUint32 aNtf )
   569     TUint32 aNtf )
   511     {
   570     {
       
   571     // Create notification
       
   572     CCcSrvMsg* ntf = CCcSrvMsg::NewL();
       
   573     CleanupStack::PushL( ntf );
       
   574     ntf->SetMsgId( aNtf );
       
   575     ntf->SetSender( aSender );
       
   576     
   512     // Notify provider of registered observer
   577     // Notify provider of registered observer
   513     TBool found( EFalse );
   578     TBool found( EFalse );
   514     CCcSrvMsg* req( NULL );
   579     CCcSrvMsg* req( NULL );
   515     TInt index( 0 );
       
   516     for ( TInt i = 0; i < iRequests.Count() && !found; i++ )
   580     for ( TInt i = 0; i < iRequests.Count() && !found; i++ )
   517         {
   581         {
   518         req = iRequests[ i ];
   582         req = iRequests[ i ];
   519         if ( req->Message().Function() == ECcWaitForApiReq &&
   583         if ( req->Function() == ECcWaitForApiReq &&
   520              !req->Message().IsNull() )
   584              !req->Message().IsNull() )
   521             {
   585             {
   522             // Pending WaitForApiReq transaction found
   586             // Pending WaitForApiReq transaction found
   523             index = i;
   587             iRequests.Remove( i );
   524             found = ETrue;
   588             found = ETrue;
   525             }
   589             }
   526         }
   590         }
   527     if ( found )
   591     if ( found )
   528         {
   592         {
   529         // Write sender of message
   593         // Write sender of message
   530         TPckgBuf<TUint32> packagedSender( aSender );
   594         TPckgBuf<TUint32> packagedSender( ntf->Sender() );
   531         req->Message().WriteL( 1, packagedSender, 0 );
   595         req->Message().WriteL( 1, packagedSender, 0 );
   532         
   596         
   533         // Write receiver of message
   597         // Write receiver of message
   534         TPckgBuf<TUint32> packagedReceiver( iId );
   598         TPckgBuf<TUint32> packagedReceiver( iId );
   535         req->Message().WriteL( 2, packagedReceiver, 0 );
   599         req->Message().WriteL( 2, packagedReceiver, 0 );
   536         
   600         
   537         // Externalize notification
   601         // Externalize notification
   538         CCcSrvMsg* ntf = CCcSrvMsg::NewL();
       
   539         CleanupStack::PushL( ntf );
       
   540         ntf->SetMsgId( aNtf );
       
   541         HBufC8* ntfBuf = ntf->MarshalL();
   602         HBufC8* ntfBuf = ntf->MarshalL();
   542         CleanupStack::PushL( ntfBuf );
   603         CleanupStack::PushL( ntfBuf );
   543         TPtr8 ntfPtr( NULL, 0);
   604         TPtr8 ntfPtr( NULL, 0);
   544         ntfPtr.Set( ntfBuf->Des() );
   605         ntfPtr.Set( ntfBuf->Des() );
   545         
   606         
   548         CleanupStack::PopAndDestroy( ntfBuf );
   609         CleanupStack::PopAndDestroy( ntfBuf );
   549         CleanupStack::PopAndDestroy( ntf );
   610         CleanupStack::PopAndDestroy( ntf );
   550         
   611         
   551         // Complete request
   612         // Complete request
   552         req->Message().Complete( KErrNone );
   613         req->Message().Complete( KErrNone );
   553         iRequests.Remove( index );
       
   554         delete req;
   614         delete req;
   555 
   615         
   556         }
   616         }
   557     else
   617     else
   558         {
   618         {
   559         User::Leave( KErrNotFound );
   619         // Store notification to be sent later
       
   620         iRequests.AppendL( ntf );
       
   621         CleanupStack::Pop( ntf );
   560         }
   622         }
   561     }
   623     }
   562 
   624 
   563 // End of file
   625 // End of file