phoneclientserver/phoneserver/Src/CommandHandler/CPhSrvSubSessionCommandHandler.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2003-2005 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:  Sub Session Command handler.
       
    15 *                The stub version of this file can be found from file
       
    16 *                CPhSrvSubSessionCommandHandlerStub.cpp
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include    "cphsrvsubsessioncommandhandler.h" 
       
    24 #include    "cphsrvsession.h" 
       
    25 #include    "cphsrvserver.h" 
       
    26 #include    <phclttypes.h> 
       
    27 #include    "mphsrvcomhandnegotiators.h" 
       
    28 
       
    29 
       
    30 
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CPhSrvSubSessionCommandHandler::CPhSrvSubSessionCommandHandler
       
    36 // 
       
    37 // Constructor.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CPhSrvSubSessionCommandHandler::CPhSrvSubSessionCommandHandler( 
       
    41     CPhSrvSession& aSession )
       
    42 :   CPhSrvSubSessionBase( aSession, EPhSrvSubSessionTypeComHand )
       
    43     {
       
    44     }
       
    45 
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CPhSrvSubSessionCommandHandler::NewL
       
    49 // 
       
    50 // Two-phased constructor.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CPhSrvSubSessionBase* CPhSrvSubSessionCommandHandler::NewL(
       
    54     CPhSrvSession& aSession )
       
    55     {
       
    56     CPhSrvSubSessionBase* self = 
       
    57         new( ELeave ) CPhSrvSubSessionCommandHandler( aSession );
       
    58     
       
    59     return self;
       
    60     }
       
    61 
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CPhSrvSubSessionCommandHandler::PhSrvMessageDecoderCanProcessMessage
       
    65 // 
       
    66 // Framework function. Returns ETrue for the op codes that
       
    67 // this subsession can handle.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 TBool CPhSrvSubSessionCommandHandler::PhSrvMessageDecoderCanProcessMessage( 
       
    71     TInt aFunction )
       
    72     {
       
    73     switch( aFunction )
       
    74         {
       
    75         case EPhoneServerComHandSubSessionOpen:
       
    76         case EPhoneServerComHandSubSessionClose:
       
    77         case EPhoneServerComHandSubSessionAtd:
       
    78         case EPhoneServerComHandSubSessionAta:
       
    79         case EPhoneServerComHandSubSessionChld:
       
    80         case EPhoneServerComHandSubSessionChup:
       
    81         case EPhoneServerComHandSubSessionVts:
       
    82         case EPhoneServerComHandSubSessionCancel:
       
    83         case EPhoneServerComHandSubSessionMuteMic:
       
    84         case EPhoneServerComHandSubSessionMuteRingingTone:
       
    85             return ETrue;
       
    86             
       
    87         default:
       
    88             return EFalse;
       
    89         }
       
    90     }
       
    91 
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CPhSrvSubSessionCommandHandler::PhSrvMessageProcessorHandleMessageL
       
    95 // 
       
    96 // Framework function. Handle any op-codes here.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CPhSrvSubSessionCommandHandler::PhSrvMessageProcessorHandleMessageL( 
       
   100     const RMessage2& aMessage )
       
   101     {
       
   102     TBool permissionStatus ( EFalse );
       
   103     
       
   104     // Check needed capabilities    
       
   105     TBool hasCapNetworkControlAndServices( EFalse );
       
   106     TBool hasCapNetworkServices( EFalse );
       
   107     TBool hasCapWriteDeviceData( EFalse );
       
   108     hasCapNetworkControlAndServices = aMessage.HasCapability( ECapabilityNetworkControl, 
       
   109                                                               ECapabilityNetworkServices  );
       
   110     hasCapNetworkServices = aMessage.HasCapability( ECapabilityNetworkServices );
       
   111     hasCapWriteDeviceData = aMessage.HasCapability( ECapabilityWriteDeviceData );
       
   112     
       
   113     switch( aMessage.Function() )
       
   114         {
       
   115         case EPhoneServerComHandSubSessionClose:
       
   116             CmdSubSessionClose( aMessage );
       
   117             permissionStatus = ETrue;
       
   118             break;
       
   119 
       
   120         case EPhoneServerComHandSubSessionAtd:
       
   121             if ( hasCapNetworkControlAndServices )
       
   122                 {        
       
   123                 CmdSubSessionComHandAtdL( aMessage );
       
   124                 permissionStatus = ETrue;
       
   125                 }
       
   126             break;
       
   127 
       
   128         case EPhoneServerComHandSubSessionAta:
       
   129             if ( hasCapNetworkControlAndServices )
       
   130                 {        
       
   131                 CmdSubSessionComHandAtaL( aMessage );
       
   132                 permissionStatus = ETrue;
       
   133                 }
       
   134             break;
       
   135 
       
   136         case EPhoneServerComHandSubSessionChld:
       
   137             if ( hasCapNetworkServices )
       
   138                 {
       
   139                 CmdSubSessionComHandChldL( aMessage );
       
   140                 permissionStatus = ETrue;
       
   141                 }    
       
   142              break;
       
   143 
       
   144         case EPhoneServerComHandSubSessionChup:
       
   145             if ( hasCapNetworkServices )
       
   146                 {
       
   147                 CmdSubSessionComHandChupL( aMessage );
       
   148                 permissionStatus = ETrue;
       
   149                 }        
       
   150              break;
       
   151 
       
   152         case EPhoneServerComHandSubSessionVts:
       
   153             if ( hasCapNetworkServices )
       
   154                 {
       
   155                 CmdSubSessionComHandVtsL( aMessage );
       
   156                 permissionStatus = ETrue;
       
   157                 }        
       
   158             break;
       
   159                   
       
   160         case EPhoneServerComHandSubSessionCancel:
       
   161                     
       
   162             if ( IsCancelAllowed( aMessage ) )
       
   163                 {
       
   164                 CmdSubSessionComHandCancelL( aMessage );
       
   165                 permissionStatus = ETrue;
       
   166                 }
       
   167             break;
       
   168 
       
   169         case EPhoneServerComHandSubSessionMuteMic:
       
   170             if ( hasCapWriteDeviceData )
       
   171                 {
       
   172                 CmdSubSessionComHandMuteMicL( aMessage );
       
   173                 permissionStatus = ETrue;
       
   174                 }        
       
   175             break;
       
   176         
       
   177         case EPhoneServerComHandSubSessionMuteRingingTone:
       
   178             if ( hasCapWriteDeviceData )
       
   179                 {
       
   180                 CmdSubSessionComHandMuteRingingToneL( aMessage );
       
   181                 permissionStatus = ETrue;
       
   182                 }        
       
   183             break;
       
   184 
       
   185         default:
       
   186             PhoneSession().PanicClient(
       
   187                 aMessage,
       
   188                 EPhCltServerInitiatedPanicInvalidRequest );
       
   189             break;
       
   190         }
       
   191      
       
   192     // If caps are not ok
       
   193     if( !permissionStatus )
       
   194         {
       
   195         aMessage.Complete( KErrPermissionDenied );
       
   196         }        
       
   197     }
       
   198 
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CPhSrvSubSessionIhf::CmdSubSessionClose
       
   202 // 
       
   203 // Close the sub-session.
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CPhSrvSubSessionCommandHandler::CmdSubSessionClose( 
       
   207     const RMessage2& aMessage )
       
   208     {
       
   209     PhoneSession().CloseSubSession( aMessage );
       
   210     }
       
   211 
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CPhSrvSubSessionCommandHandler::CmdSubSessionComHandAtdL
       
   215 // 
       
   216 // Handle command handler client's Atd request.
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 void CPhSrvSubSessionCommandHandler::CmdSubSessionComHandAtdL( 
       
   220     const RMessage2& aMessage )
       
   221     {
       
   222     CmdSubSessionComHandForwardRequestL( aMessage );
       
   223     }
       
   224 
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CPhSrvSubSessionCommandHandler::CmdSubSessionComHandAtaL
       
   228 // 
       
   229 // Handle command handler client's Ata request.
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void CPhSrvSubSessionCommandHandler::CmdSubSessionComHandAtaL( 
       
   233     const RMessage2& aMessage )
       
   234     {
       
   235     CmdSubSessionComHandForwardRequestL( aMessage );
       
   236     }
       
   237 
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CPhSrvSubSessionCommandHandler::CmdSubSessionComHandChldL
       
   241 // 
       
   242 // Handle command handler client's Chld request.
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CPhSrvSubSessionCommandHandler::CmdSubSessionComHandChldL( 
       
   246     const RMessage2& aMessage )
       
   247     {
       
   248     CmdSubSessionComHandForwardRequestL( aMessage );
       
   249     }
       
   250 
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CPhSrvSubSessionCommandHandler::CmdSubSessionComHandChupL
       
   254 // 
       
   255 // Handle command handler client's Chup request.
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void CPhSrvSubSessionCommandHandler::CmdSubSessionComHandChupL( 
       
   259     const RMessage2& aMessage )
       
   260     {
       
   261     CmdSubSessionComHandForwardRequestL( aMessage );
       
   262     }
       
   263 
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CPhSrvSubSessionCommandHandler::CmdSubSessionComHandVtsL
       
   267 // 
       
   268 // Handle command handler client's Vts request.
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 void CPhSrvSubSessionCommandHandler::CmdSubSessionComHandVtsL( 
       
   272     const RMessage2& aMessage )
       
   273     {
       
   274     CmdSubSessionComHandForwardRequestL( aMessage );
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CPhSrvSubSessionCommandHandler::CmdSubSessionComHandCancelL
       
   279 // 
       
   280 // Handle command handler client's cancel request.
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CPhSrvSubSessionCommandHandler::CmdSubSessionComHandCancelL( 
       
   284     const RMessage2& aMessage )
       
   285     {
       
   286     // Ask the command handler negotiator to delete any pending request for 
       
   287     // this subsession. It will panic the client if one can't be found.
       
   288     MPhSrvComHandNegotiator& comHandNegotiator = 
       
   289         PhoneSession().PhoneServer().ComHandNegotiatorL();
       
   290 
       
   291     comHandNegotiator.NegotiatorRequestCancel( *this );
       
   292     aMessage.Complete( KErrNone );
       
   293     }
       
   294 
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CPhSrvSubSessionCommandHandler::CmdSubSessionComHandForwardRequestL
       
   298 // 
       
   299 // Setup an asynchronous request to handle external interface
       
   300 // command handler requests.
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 void CPhSrvSubSessionCommandHandler::CmdSubSessionComHandForwardRequestL(
       
   304     const RMessage2& aMessage )
       
   305     {
       
   306     // Read parameters from client's address space.
       
   307     TPhCltComHandCommandParameters comHandParams;
       
   308     TPckg< TPhCltComHandCommandParameters > 
       
   309         pComHandParams( comHandParams );
       
   310     Read(
       
   311         aMessage,
       
   312         0,
       
   313         pComHandParams );
       
   314 
       
   315     // Submit a new request to the command handler manager.
       
   316     MPhSrvComHandNegotiator& comHandNegotiator = 
       
   317         PhoneSession().PhoneServer().ComHandNegotiatorL();
       
   318 
       
   319     comHandNegotiator.NegotiatorRequestL( aMessage, comHandParams, *this );
       
   320     }
       
   321 
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CPhSrvSubSessionCommandHandler::CmdSubSessionComHandMuteMicL
       
   325 // 
       
   326 // Handle command handler client's mute mic request.
       
   327 // -----------------------------------------------------------------------------
       
   328 //
       
   329 void CPhSrvSubSessionCommandHandler::CmdSubSessionComHandMuteMicL( 
       
   330     const RMessage2& aMessage )
       
   331     {
       
   332     CmdSubSessionComHandForwardRequestL( aMessage );
       
   333     }
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CPhSrvSubSessionCommandHandler::CmdSubSessionComHandMuteRingingToneL
       
   337 // 
       
   338 // Handle command handler client's mute ringing tone request.
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 void CPhSrvSubSessionCommandHandler::CmdSubSessionComHandMuteRingingToneL( 
       
   342     const RMessage2& aMessage )
       
   343     {
       
   344     CmdSubSessionComHandForwardRequestL( aMessage );
       
   345     }
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CPhSrvSubSessionCommandHandler::IsCancelAllowed
       
   349 // 
       
   350 // Handle cancel command capability check
       
   351 // -----------------------------------------------------------------------------
       
   352 //    
       
   353 TBool CPhSrvSubSessionCommandHandler::IsCancelAllowed(
       
   354     const RMessage2& aMessage ) 
       
   355     {
       
   356     TBool permissionStatus ( EFalse );
       
   357     
       
   358     TBool hasCapNetworkControlAndServices( EFalse );
       
   359     TBool hasCapNetworkServices( EFalse );
       
   360     hasCapNetworkControlAndServices = aMessage.HasCapability( ECapabilityNetworkControl, 
       
   361                                                               ECapabilityNetworkServices  );
       
   362     hasCapNetworkServices = aMessage.HasCapability( ECapabilityNetworkServices );
       
   363  
       
   364     
       
   365     // Read parameters from client's address space.
       
   366     TPhCltComHandCommandParameters comHandParams;
       
   367     TPckg< TPhCltComHandCommandParameters > 
       
   368         pComHandParams( comHandParams );
       
   369     Read(
       
   370         aMessage,
       
   371         0,
       
   372         pComHandParams );
       
   373         
       
   374     switch ( comHandParams.iCommandHandlerCommand )    
       
   375         {
       
   376         case EPhCltCommandAtd:
       
   377         case EPhCltCommandAta:
       
   378             if ( hasCapNetworkControlAndServices )
       
   379                 {
       
   380                 permissionStatus = ETrue;
       
   381                 }
       
   382             break;
       
   383         case EPhCltCommandChld:
       
   384         case EPhCltCommandChup:
       
   385         case EPhCltCommandVts:
       
   386             if ( hasCapNetworkServices )
       
   387                 {
       
   388                 permissionStatus = ETrue;
       
   389                 }
       
   390             break;
       
   391         default:
       
   392             break;
       
   393         }
       
   394     
       
   395     return permissionStatus;
       
   396     }    
       
   397 
       
   398 // End of File