convergedconnectionhandler/cchserver/src/cchsubsession.cpp
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CCCHSubsession implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <cchclientserver.h>
       
    21 
       
    22 #include "cchlogger.h"
       
    23 #include "cchsubsession.h"
       
    24 #include "cchserverbase.h"
       
    25 #include "cchrequeststorage.h"
       
    26 #include "cchpluginhandler.h"
       
    27 #include "cchservicehandler.h"
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 // None
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES
       
    33 // None
       
    34 
       
    35 // CONSTANTS
       
    36 // None
       
    37 
       
    38 // MACROS
       
    39 // None
       
    40 
       
    41 // LOCAL CONSTANTS AND MACROS
       
    42 // None
       
    43 
       
    44 // MODULE DATA STRUCTURES
       
    45 // None
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 // None
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 // None
       
    52 
       
    53 // ============================= LOCAL FUNCTIONS =============================
       
    54 
       
    55 // ============================ MEMBER FUNCTIONS =============================
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CCCHSubsession::CCCHSubsession
       
    59 // C++ default constructor can NOT contain any code, that might leave.
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CCCHSubsession::CCCHSubsession( CCCHServerBase& aServer ) :
       
    63     iServer( aServer ),
       
    64     iMessage( NULL ),
       
    65     iQueueEvents( EFalse )
       
    66     {
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CCCHSubsession::NewL
       
    71 // Two-phased constructor.
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CCCHSubsession* CCCHSubsession::NewL( CCCHServerBase& aServer )
       
    75     {
       
    76     CCCHSubsession* self = CCCHSubsession::NewLC( aServer );
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CCCHSubsession::NewLC
       
    83 // Two-phased constructor.
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CCCHSubsession* CCCHSubsession::NewLC( CCCHServerBase& aServer )
       
    87     {
       
    88     CCCHSubsession* self = new (ELeave)CCCHSubsession( aServer );
       
    89     CleanupStack::PushL( self );
       
    90     self->ConstructL();
       
    91     return self;
       
    92     }
       
    93 
       
    94 // Destructor
       
    95 CCCHSubsession::~CCCHSubsession()
       
    96     {
       
    97     iServer.RequestStorage().RemoveRequestsBySession( this );
       
    98     iServer.RequestStorage().RemoveSession( this );
       
    99     iEventQueue.Close();
       
   100  
       
   101     delete iRegisterMessage;
       
   102     delete iMessage;            
       
   103     }
       
   104 
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // CCCHSubsession::ConstructL
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CCCHSubsession::ConstructL(  )
       
   111     {
       
   112     CCHLOGSTRING( "CCCHSubsession::ConstructL: IN" );
       
   113     
       
   114     iServer.RequestStorage().AddSession( this );
       
   115     
       
   116     CCHLOGSTRING( "CCCHSubsession::ConstructL: OUT" );
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CCCHSubsession::ServiceEventOccured
       
   121 // (other items were commented in a header).
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void CCCHSubsession::ServiceEventOccured(
       
   125     TServiceStatus aNewStatus )
       
   126     {
       
   127     CCHLOGSTRING( "CCCHSubsession::ServiceEventOccured: IN" );
       
   128     //if are we queuing
       
   129     if( iQueueEvents )
       
   130         {
       
   131         //check if we can accept this event
       
   132         if ( 0 == iSubscribedService.iServiceId ||        // all services
       
   133         		iSubscribedService.iServiceId == aNewStatus.ServiceId() )  // specified service
       
   134             {
       
   135             if ( iSubscribedService.iType == ECCHUnknown ||   
       
   136             		iSubscribedService.iType == aNewStatus.Type() )        // subservice specified
       
   137                 {
       
   138                 iEventQueue.Append( aNewStatus );
       
   139                 CompleteMessage( );
       
   140                 }
       
   141             }
       
   142         }
       
   143     
       
   144     CCHLOGSTRING( "CCCHSubsession::ServiceEventOccured: OUT" );
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CCCHSubsession::CompleteMessage
       
   149 // (other items were commented in a header).
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 void CCCHSubsession::CompleteMessage( )
       
   153     {
       
   154     CCHLOGSTRING( "CCCHSubsession::CompleteMessage: IN" );
       
   155     //if there is pending SubscribeToEvents and we have something in queue
       
   156     if( iMessage && 0 < iEventQueue.Count() )
       
   157         {
       
   158         TInt error( KErrNone );
       
   159         TPckgBuf<TServiceStatus> serviceStatus;
       
   160         
       
   161         // while we append to queue, we consume from the start (fifo)
       
   162         serviceStatus() = iEventQueue[ 0 ];   
       
   163         CCHLOGSTRING2( "CCCHSubsession::CompleteMessage: type  : %d", serviceStatus().Type() );
       
   164         CCHLOGSTRING2( "CCCHSubsession::CompleteMessage: state : %d", serviceStatus().iState );
       
   165         // Write status to IPC message
       
   166         TRAP( error, iMessage->WriteL( 2, serviceStatus ) );    
       
   167         
       
   168         //complete & delete message 
       
   169         iMessage->Complete( error );
       
   170         delete iMessage;
       
   171         iMessage = NULL;
       
   172         
       
   173         // Remove consumed event from queue
       
   174         iEventQueue.Remove( 0 );
       
   175         }
       
   176     CCHLOGSTRING( "CCCHSubsession::CompleteMessage: OUT" );
       
   177     } 
       
   178        
       
   179 // ---------------------------------------------------------------------------
       
   180 // CCCHSubsession::ServiceL
       
   181 // Handles request received from client.
       
   182 // (other items were commented in a header).
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 void CCCHSubsession::ServiceL( const RMessage2& aMessage )
       
   186     {
       
   187     CCHLOGSTRING( "CCCHSubsession::ServiceL: IN" );
       
   188     TInt command = aMessage.Function();
       
   189     switch ( command )
       
   190         {
       
   191         case ECCHServerRegister:
       
   192             {
       
   193             if( !iRegisterMessage )
       
   194                 {
       
   195                 iRegisterMessage = new (ELeave) RMessage2( aMessage );
       
   196                 }
       
   197             
       
   198             break;
       
   199             }
       
   200             
       
   201         case ECCHServerRegisterCancel:
       
   202             {
       
   203             if( iRegisterMessage )
       
   204                 {
       
   205                 iRegisterMessage->Complete( KErrCancel );
       
   206                 delete iRegisterMessage;
       
   207                 iRegisterMessage = NULL;
       
   208                 }
       
   209             aMessage.Complete( KErrNone );
       
   210             break;
       
   211             }
       
   212         case ECCHSubscribeToEvents:
       
   213             {
       
   214             CCHLOGSTRING
       
   215                 ( "CCCHSubsession::ServiceL :ECCHSubscribeToEvents" );
       
   216             iMessage = new (ELeave) RMessage2( aMessage );
       
   217             //set the service (or set of services) we are interested in
       
   218             iSubscribedService.iServiceId = iMessage->Int0();
       
   219             iSubscribedService.iType = static_cast<TCCHSubserviceType>(
       
   220                                                     iMessage->Int1() );
       
   221             //start queuing
       
   222             iQueueEvents = ETrue;
       
   223             //try to complete message
       
   224             CompleteMessage( );
       
   225             }
       
   226             break;
       
   227         case ECCHSubscribeToEventsCancel:
       
   228             {
       
   229             CCHLOGSTRING
       
   230                 ( "CCCHSubsession::ServiceL :ECCHSubscribeToEventsCancel" );
       
   231             //if ECCHSubscribeToEvents request is pending, complete & delete it
       
   232             if( iMessage )
       
   233                 {
       
   234                 iMessage->Complete( KErrCancel );    
       
   235                 delete iMessage;
       
   236                 iMessage = NULL;
       
   237                 }
       
   238             // Complete cancel request
       
   239             aMessage.Complete( KErrNone );
       
   240             //stop & reset the queue
       
   241             iQueueEvents = EFalse;
       
   242             iEventQueue.Reset();
       
   243             }
       
   244             break;
       
   245         case ECCHGetServices:
       
   246             {
       
   247             CCHLOGSTRING
       
   248                 ( "CCCHSubsession::ServiceL :ECCHGetServices" );
       
   249             iServer.RequestStorage().AddRequestL( ECCHGetServices,
       
   250                 aMessage, this );
       
   251             }
       
   252             break;
       
   253         case ECCHGetServicesCancel:
       
   254             {
       
   255             CCHLOGSTRING
       
   256                 ( "CCCHSubsession::ServiceL :ECCHGetServicesCancel" );
       
   257             iServer.RequestStorage().CompleteRequest( ECCHGetServices,
       
   258                 this, KErrCancel );
       
   259             aMessage.Complete( KErrNone );
       
   260             }
       
   261             break;
       
   262         case ECCHGetServiceState:
       
   263             {
       
   264             CCHLOGSTRING
       
   265                 ( "CCCHSubsession::ServiceL :ECCHGetServiceState" );
       
   266             TInt err( KErrNone );
       
   267             err = iServer.ServiceHandler().GetServiceState( aMessage );
       
   268             aMessage.Complete( err );
       
   269             }
       
   270             break;
       
   271         case ECCHEnableService:
       
   272             {
       
   273             CCHLOGSTRING
       
   274                 ( "CCCHSubsession::ServiceL :ECCHEnableService" );
       
   275             iServer.RequestStorage().AddRequestL( ECCHEnableService,
       
   276                 aMessage, this );
       
   277             }
       
   278             break;
       
   279         case ECCHEnableServiceCancel:
       
   280             {
       
   281             CCHLOGSTRING
       
   282                 ( "CCCHSubsession::ServiceL :ECCHEnableServiceCancel" );
       
   283             iServer.RequestStorage().CompleteRequest( ECCHEnableService,
       
   284                 this, KErrCancel );
       
   285             aMessage.Complete( KErrNone );
       
   286             }
       
   287             break;
       
   288         case ECCHDisableService:
       
   289             {
       
   290             CCHLOGSTRING
       
   291                 ( "CCCHSubsession::ServiceL :ECCHDisableService" );
       
   292             iServer.RequestStorage().AddRequestL( ECCHDisableService,
       
   293                 aMessage, this );
       
   294             }
       
   295             break;
       
   296         case ECCHDisableServiceCancel:
       
   297             {
       
   298             CCHLOGSTRING
       
   299                 ( "CCCHSubsession::ServiceL :ECCHDisableServiceCancel" );
       
   300             iServer.RequestStorage().CompleteRequest( ECCHDisableService,
       
   301                 this, KErrCancel );
       
   302             aMessage.Complete( KErrNone );
       
   303             }
       
   304             break;
       
   305         case ECCHGetServiceInfo:
       
   306             {
       
   307             CCHLOGSTRING
       
   308                 ( "CCCHSubsession::ServiceL :ECCHGetServiceInfo" );
       
   309             TInt err( KErrNone );
       
   310             err = iServer.ServiceHandler().GetServiceInfo( aMessage );
       
   311             aMessage.Complete( err );
       
   312             }
       
   313             break;
       
   314         case ECCHGetPreferredService:
       
   315             {
       
   316             CCHLOGSTRING
       
   317                 ( "CCCHSubsession::ServiceL :ECCHGetPreferredService" );
       
   318             aMessage.Complete( KErrNotSupported );
       
   319             }
       
   320             break;
       
   321         case ECCHSetConnectionInfo:
       
   322             {
       
   323             CCHLOGSTRING
       
   324                 ( "CCCHSubsession::ServiceL :ECCHSetConnectionInfo" );
       
   325             iServer.RequestStorage().AddRequestL( ECCHSetConnectionInfo,
       
   326                 aMessage, this );
       
   327             }
       
   328             break;
       
   329         case ECCHSetConnectionInfoCancel:
       
   330             {
       
   331             CCHLOGSTRING
       
   332                 ( "CCCHSubsession::ServiceL :ECCHSetConnectionInfoCancel" );
       
   333             iServer.RequestStorage().CompleteRequest( ECCHSetConnectionInfo,
       
   334                 this, KErrCancel );
       
   335             aMessage.Complete( KErrNone );
       
   336             }
       
   337             break;
       
   338         case ECCHGetConnectionInfo:
       
   339             {
       
   340             CCHLOGSTRING
       
   341                 ( "CCCHSubsession::ServiceL :ECCHGetConnectionInfo" );
       
   342             iServer.RequestStorage().AddRequestL( ECCHGetConnectionInfo,
       
   343                 aMessage, this );
       
   344             }
       
   345             break;
       
   346         case ECCHGetConnectionInfoCancel:
       
   347             {
       
   348             CCHLOGSTRING
       
   349                 ( "CCCHSubsession::ServiceL :ECCHGetConnectionInfoCancel" );
       
   350             iServer.RequestStorage().CompleteRequest( ECCHGetConnectionInfo,
       
   351                 this, KErrCancel );
       
   352             aMessage.Complete( KErrNone );
       
   353             }
       
   354             break;
       
   355         case ECCHServiceCount:
       
   356             {
       
   357             iServer.ServiceHandler().ServiceCountL( aMessage );
       
   358             aMessage.Complete( KErrNone );
       
   359             }
       
   360             break;
       
   361         case ECCHReserveService:
       
   362             {
       
   363             CCHLOGSTRING
       
   364                 ( "CCCHSubsession::ServiceL :ECCHReserveService" );
       
   365             TInt err( KErrNone );
       
   366             err = iServer.ServiceHandler().ReserveService( aMessage );
       
   367             aMessage.Complete( err );
       
   368             }
       
   369             break;
       
   370         case ECCHFreeService:
       
   371             {
       
   372             CCHLOGSTRING
       
   373                 ( "CCCHSubsession::ServiceL :ECCHFreeService" );
       
   374             TInt err( KErrNone );
       
   375             err = iServer.ServiceHandler().FreeService( aMessage );
       
   376             aMessage.Complete( err );
       
   377             }
       
   378             break;
       
   379         case ECCHIsReserved:
       
   380             {
       
   381             CCHLOGSTRING
       
   382                 ( "CCCHSubsession::ServiceL :ECCHIsReserved" );
       
   383             iServer.ServiceHandler().IsReserved( aMessage );
       
   384             aMessage.Complete( KErrNone );
       
   385             }
       
   386             break;
       
   387         default:
       
   388             {
       
   389             CCHLOGSTRING( "CCCHSubsession::ServiceL :ECCHBadRequest" );
       
   390             iServer.PanicClient( aMessage, ECCHBadRequest );
       
   391             }
       
   392         }
       
   393     CCHLOGSTRING( "CCCHSubsession::ServiceL: OUT" );
       
   394     }
       
   395 
       
   396 // ========================== OTHER EXPORTED FUNCTIONS =======================
       
   397 
       
   398 //  End of File