bluetoothengine/bteng/src/btengsrvsession.cpp
branchRCL_3
changeset 10 0707dd69d236
parent 0 f63038272f30
child 19 43824b19ee35
child 35 95674584745d
equal deleted inserted replaced
6:6a29d5ad0713 10:0707dd69d236
    20 #include <e32base.h>
    20 #include <e32base.h>
    21 #include "btengsrvsession.h"
    21 #include "btengsrvsession.h"
    22 #include "btengserver.h"
    22 #include "btengserver.h"
    23 #include "btengsrvbbconnectionmgr.h"
    23 #include "btengsrvbbconnectionmgr.h"
    24 #include "btengpairman.h"
    24 #include "btengpairman.h"
       
    25 #include "btengsrvsettingsmgr.h"
    25 #include "btengclientserver.h"
    26 #include "btengclientserver.h"
    26 #include "debug.h"
    27 #include "debug.h"
    27 
    28 
    28 
    29 
    29 /**  The message argument which holds the client event package. */
    30 /**  The message argument which holds the client event package. */
    77     TRACE_FUNC_ENTRY
    78     TRACE_FUNC_ENTRY
    78     if( !iNotifyConnMessage.IsNull() )
    79     if( !iNotifyConnMessage.IsNull() )
    79         {
    80         {
    80         iNotifyConnMessage.Complete( KErrCancel );
    81         iNotifyConnMessage.Complete( KErrCancel );
    81         }
    82         }
    82     CancelPairRequest();
       
    83     if( Server() )
    83     if( Server() )
    84         {
    84         {
    85         Server()->RemoveSession( iAutoSwitchOff );
    85         Server()->RemoveSession(this, iAutoSwitchOff );
    86         }
    86         }
    87     
       
    88     delete iConnectionEventQueue;
    87     delete iConnectionEventQueue;
    89     
       
    90     TRACE_FUNC_EXIT
    88     TRACE_FUNC_EXIT
    91     }
    89     }
    92 
    90 
    93 
    91 
    94 // ---------------------------------------------------------------------------
    92 // ---------------------------------------------------------------------------
   148         TRAP_IGNORE(iConnectionEventQueue->AppendL(pkg));
   146         TRAP_IGNORE(iConnectionEventQueue->AppendL(pkg));
   149         }
   147         }
   150     }
   148     }
   151 
   149 
   152 // ---------------------------------------------------------------------------
   150 // ---------------------------------------------------------------------------
   153 // Comfirm the caller if pairing request is completed in this invoke. 
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 TInt CBTEngSrvSession::CompletePairRequest( TInt aResult )
       
   157     {
       
   158     if ( !iPairMessage.IsNull())
       
   159         {
       
   160         iPairMessage.Complete( aResult );
       
   161         return KErrNone;
       
   162         }
       
   163     return KErrNotFound;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // From class CSession2
   151 // From class CSession2
   168 // Handles servicing of a client request that has been passed to the server.
   152 // Handles servicing of a client request that has been passed to the server.
   169 // ---------------------------------------------------------------------------
   153 // ---------------------------------------------------------------------------
   170 //
   154 //
   171 void CBTEngSrvSession::ServiceL( const RMessage2& aMessage )
   155 void CBTEngSrvSession::ServiceL( const RMessage2& aMessage )
   172     {
   156     {
   173     TRAPD( err, DispatchMessageL( aMessage ) );
   157     TRAPD( err, DispatchMessageL( aMessage ) );
   174 
       
   175     if( !aMessage.IsNull() &&
   158     if( !aMessage.IsNull() &&
   176         ( err || 
   159         ( err || 
   177           ( aMessage.Function() != EBTEngNotifyConnectionEvents && 
   160           ( aMessage.Function() != EBTEngNotifyConnectionEvents && 
   178             aMessage.Function() != EBTEngPairDevice ) ) )
   161             aMessage.Function() != EBTEngPairDevice &&
       
   162             aMessage.Function() != EBTEngSetPowerState ) ) )
   179         {
   163         {
   180             // Return the error code to the client.
   164             // Return the error code to the client.
   181         aMessage.Complete( err );
   165         aMessage.Complete( err );
   182         }
   166         }
   183     }
   167     }
   204    
   188    
   205     switch( opcode )
   189     switch( opcode )
   206         {
   190         {
   207         case EBTEngSetPowerState:
   191         case EBTEngSetPowerState:
   208             {
   192             {
   209             iAutoSwitchOff = (TBool) aMessage.Int1();
   193             Server()->SetPowerStateL( aMessage );
   210             Server()->SetPowerStateL( (TBTPowerStateValue) aMessage.Int0(), 
       
   211                                        iAutoSwitchOff );
       
   212             }
   194             }
   213             break;
   195             break;
   214         case EBTEngSetVisibilityMode:
   196         case EBTEngSetVisibilityMode:
   215             {
   197             {
   216             Server()->SetVisibilityModeL( (TBTVisibilityMode) aMessage.Int0(),
   198             Server()->SettingsManager()->SetVisibilityModeL(
   217                                            aMessage.Int1() );
   199                         (TBTVisibilityMode) aMessage.Int0(),aMessage.Int1() );
   218             }
   200             }
   219             break;
   201             break;
   220         case EBTEngNotifyConnectionEvents:
   202         case EBTEngNotifyConnectionEvents:
   221             {
   203             {
   222             //ensure the message contains the correctly sized descriptor
   204             //ensure the message contains the correctly sized descriptor
   227             
   209             
   228             if(!iNotifyConnMessage.IsNull())
   210             if(!iNotifyConnMessage.IsNull())
   229                 {
   211                 {
   230                 User::Leave(KErrInUse);
   212                 User::Leave(KErrInUse);
   231                 }
   213                 }
   232             
       
   233             //save the client message
   214             //save the client message
   234             iNotifyConnMessage = RMessage2(aMessage);
   215             iNotifyConnMessage = RMessage2(aMessage);
   235             
   216             
   236             //if there is an existing connection event that the client does
   217             //if there is an existing connection event that the client does
   237             //not yet know about
   218             //not yet know about
   259         case EBTEngCancelConnectDevice:
   240         case EBTEngCancelConnectDevice:
   260         case EBTEngDisconnectDevice:
   241         case EBTEngDisconnectDevice:
   261         case EBTEngIsDeviceConnected:
   242         case EBTEngIsDeviceConnected:
   262         case EBTEngGetConnectedAddresses:
   243         case EBTEngGetConnectedAddresses:
   263             {
   244             {
   264             TBTPowerStateValue pwr = EBTPowerOff;
   245             CheckPowerOnL();
   265             Server()->GetHwPowerState( pwr );
   246             // Simply forward it to the plug-in manager
   266             if( pwr )
   247             Server()->DispatchPluginMessageL( aMessage );
   267                 {
       
   268                     // Simply forward it to the plug-in manager
       
   269                 Server()->DispatchPluginMessageL( aMessage );
       
   270                 }
       
   271             else
       
   272                 {
       
   273                 User::Leave( KErrNotReady );
       
   274                 }
       
   275             }
   248             }
   276             break;    
   249             break;    
   277         case EBTEngIsDeviceConnectable:
   250         case EBTEngIsDeviceConnectable:
   278             {
   251             {
   279             Server()->DispatchPluginMessageL( aMessage );
   252             Server()->DispatchPluginMessageL( aMessage );
   280             }
   253             }
   281             break;
   254             break;
   282         case EBTEngPrepareDiscovery:
   255         case EBTEngPrepareDiscovery:
   283             {
   256             {
   284             aMessage.Complete( KErrNone );  // Client does not have to wait.
   257             aMessage.Complete( KErrNone );  // Client does not have to wait.
   285             Server()->iBBConnMgr->ManageTopology( ETrue );
   258             Server()->BasebandConnectionManager()->ManageTopology( ETrue );
   286             }
   259             }
   287             break;
   260             break;
   288         case EBTEngSetPairingObserver:
   261         case EBTEngSetPairingObserver:
       
   262             {
       
   263             CheckPowerOnL();
       
   264             // Simply forward it to the pairing manager
       
   265             Server()->PairManager()->ProcessCommandL( aMessage );
       
   266             break;
       
   267             }
   289         case EBTEngPairDevice:
   268         case EBTEngPairDevice:
   290             {
   269             {
   291             TBTPowerStateValue pwr = EBTPowerOff;
   270             CheckPowerOnL();
   292             (void) Server()->GetHwPowerState( pwr );
   271             // Simply forward it to the pairing manager
   293             if( pwr )
   272             Server()->PairManager()->ProcessCommandL( aMessage );
   294                 {
       
   295                 // Simply forward it to the pairing manager
       
   296                 Server()->PairManager().ProcessCommandL( aMessage );
       
   297                 if ( opcode == EBTEngPairDevice )
       
   298                     {
       
   299                     iPairMessage = RMessage2( aMessage );
       
   300                     }
       
   301                 }
       
   302             else
       
   303                 {
       
   304                 User::Leave( KErrNotReady );
       
   305                 }
       
   306             break;
   273             break;
   307             }
   274             }
   308         case EBTEngCancelPairDevice:
   275         case EBTEngCancelPairDevice:
   309             {
   276             {
   310             CancelPairRequest();
   277             Server()->PairManager()->ProcessCommandL( aMessage );
   311             break;
   278             break;
   312             }
   279             }
   313         default:
   280         default:
   314             {
   281             {
   315             TRACE_INFO( ( _L( "[BTENG]\t DispatchMessageL: bad request (%d)" ), 
   282             TRACE_INFO( ( _L( "[BTENG]\t DispatchMessageL: bad request (%d)" ), aMessage.Function() ) )
   316                                 aMessage.Function() ) )
       
   317             User::Leave( KErrArgument );
   283             User::Leave( KErrArgument );
   318             }
   284             }
   319             break;
   285             break;
   320         }
   286         }
   321     TRACE_FUNC_EXIT
   287     TRACE_FUNC_EXIT
   322     }
   288     }
   323 
   289 
   324 // ---------------------------------------------------------------------------
   290 // ---------------------------------------------------------------------------
   325 // Only the originator of pairing can cancel the pairing request.
   291 // Check if power is on, and leave if it is not.
   326 // ---------------------------------------------------------------------------
   292 // ---------------------------------------------------------------------------
   327 //
   293 //
   328 void CBTEngSrvSession::CancelPairRequest()
   294 void CBTEngSrvSession::CheckPowerOnL()
   329     {
   295     {
   330     if ( !iPairMessage.IsNull() )
   296     TBTPowerState power = EBTOff;
   331         {
   297     (void) Server()->SettingsManager()->GetHwPowerState( power );
   332         Server()->PairManager().CancelCommand( iPairMessage.Function() );
   298     if ( power == EBTOff )
   333         iPairMessage.Complete( KErrCancel );
   299         {
   334         }
   300         User::Leave( KErrNotReady );
   335     }
   301         }
       
   302     }