convergedconnectionhandler/cchserver/src/cchsession.cpp
changeset 0 a4daefaec16c
child 14 be41ab7b952f
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     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:  CCCHSession implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cchlogger.h"
       
    21 #include "cchsession.h"
       
    22 #include "cchserverbase.h"
       
    23 #include "cchsubsession.h"
       
    24 #include "cchclientserverinternal.h"
       
    25 
       
    26 // EXTERNAL DATA STRUCTURES
       
    27 // None
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES
       
    30 // None
       
    31 
       
    32 // CONSTANTS
       
    33 // None
       
    34 
       
    35 // MACROS
       
    36 // None
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 // None
       
    40 
       
    41 // MODULE DATA STRUCTURES
       
    42 // None
       
    43 
       
    44 // LOCAL FUNCTION PROTOTYPES
       
    45 // None
       
    46 
       
    47 // FORWARD DECLARATIONS
       
    48 // None
       
    49 
       
    50 // ============================= LOCAL FUNCTIONS =============================
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS =============================
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CCCHSession::CCCHSession
       
    56 // C++ default constructor can NOT contain any code, that might leave.
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CCCHSession::CCCHSession( CCCHServerBase& aServer ) :
       
    60     CSession2(),
       
    61     iCCHServer( aServer )
       
    62     {
       
    63     TRAP_IGNORE( iCCHServer.NotifySessionCreatedL() );
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CCCHSession::ConstructL
       
    68 // Symbian 2nd phase constructor can leave.
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 void CCCHSession::ConstructL()
       
    72     {
       
    73     iSubsessions = iCCHServer.ObjectContainerIx().CreateL();
       
    74     iObjectIx = CObjectIx::NewL();
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CCCHSession::NewL
       
    79 // Two-phased constructor.
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CCCHSession* CCCHSession::NewL( CCCHServerBase& aServer )
       
    83     {
       
    84     CCCHSession* self = CCCHSession::NewLC( aServer );
       
    85     CleanupStack::Pop( self );
       
    86     return self;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CCCHSession::NewLC
       
    91 // Two-phased constructor.
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 CCCHSession* CCCHSession::NewLC( CCCHServerBase& aServer )
       
    95     {
       
    96     CCCHSession* self = new (ELeave) CCCHSession( aServer );
       
    97     CleanupStack::PushL( self );
       
    98     self->ConstructL();
       
    99     return self;
       
   100     }
       
   101 
       
   102 // Destructor
       
   103 CCCHSession::~CCCHSession()
       
   104     {   
       
   105     delete iObjectIx;
       
   106     iObjectIx = NULL;   
       
   107 
       
   108     iCCHServer.ObjectContainerIx().Remove( iSubsessions );
       
   109     iCCHServer.NotifySessionClosed(); 
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // CCCHSession::ServiceL
       
   114 // Handles request received from client.
       
   115 // (other items were commented in a header).
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CCCHSession::ServiceL( const RMessage2& aMessage )
       
   119     {
       
   120     CCHLOGSTRING( "CCCHSession::ServiceL: IN" );
       
   121     TInt command = aMessage.Function();
       
   122     switch ( command )
       
   123         {
       
   124         case ECCHOpenSubSession:
       
   125             {
       
   126             CCCHSubsession* subsession = CCCHSubsession::NewLC( iCCHServer );
       
   127             iSubsessions->AddL( subsession );
       
   128             const TInt handle( iObjectIx->AddL( subsession ) );
       
   129             CleanupStack::Pop( subsession );
       
   130             TPckg<TInt> handlePckg( handle );
       
   131             TRAPD( err, aMessage.WriteL( 3, handlePckg ) );
       
   132             if ( KErrNone != err )
       
   133                 {
       
   134                 // Panic client
       
   135                 iObjectIx->Remove( handle );
       
   136                 iCCHServer.PanicClient( aMessage, ECCHErrSubSessionOpen );
       
   137                 }
       
   138             aMessage.Complete( KErrNone );
       
   139             }
       
   140             break;
       
   141         case ECCHCloseSubSession:
       
   142             {
       
   143             const TInt handle( aMessage.Int3() );
       
   144             if ( iObjectIx->At( handle ) )
       
   145                 {
       
   146                 iObjectIx->Remove( handle );
       
   147                 }
       
   148             else
       
   149                 {
       
   150                 // Panic client. Handle was not valid
       
   151                 iCCHServer.PanicClient( aMessage, ECCHErrSubSessionClose );
       
   152                 }
       
   153             aMessage.Complete( KErrNone );
       
   154             }
       
   155             break;
       
   156         /**
       
   157          * CCH subsession functions
       
   158          */
       
   159         case ECCHSubscribeToEvents:
       
   160         case ECCHSubscribeToEventsCancel:
       
   161         case ECCHGetServices:
       
   162         case ECCHGetServicesCancel:
       
   163         case ECCHGetServiceState:
       
   164         case ECCHEnableService:
       
   165         case ECCHEnableServiceCancel:
       
   166         case ECCHDisableService:
       
   167         case ECCHDisableServiceCancel:
       
   168         case ECCHGetServiceInfo:
       
   169         case ECCHGetPreferredService:
       
   170         case ECCHSetConnectionInfo:
       
   171         case ECCHSetConnectionInfoCancel:
       
   172         case ECCHGetConnectionInfo:
       
   173         case ECCHGetConnectionInfoCancel:
       
   174         case ECCHReserveService:
       
   175         case ECCHFreeService:
       
   176         case ECCHIsReserved:
       
   177         case ECCHServiceCount:
       
   178         case ECCHServerRegister:
       
   179         case ECCHServerRegisterCancel:
       
   180             {
       
   181             CCCHSubsession* subsession = static_cast<CCCHSubsession*>(
       
   182                 iObjectIx->At( aMessage.Int3() ) );
       
   183             if ( subsession )
       
   184                 {
       
   185                 subsession->ServiceL( aMessage );
       
   186                 }
       
   187             else
       
   188                 {
       
   189                 // Panic client.
       
   190                 iCCHServer.PanicClient( aMessage, ECCHBadDescriptor );
       
   191                 }
       
   192             }
       
   193             break;
       
   194         default:
       
   195             {
       
   196             iCCHServer.PanicClient( aMessage, ECCHBadRequest );
       
   197             }
       
   198 
       
   199         }
       
   200     CCHLOGSTRING( "CCCHSession::ServiceL: OUT" );
       
   201     }
       
   202 
       
   203 // ========================== OTHER EXPORTED FUNCTIONS =======================
       
   204 
       
   205 //  End of File