bluetoothengine/bteng/src/btengsrvsession.cpp
branchRCL_3
changeset 8 0707dd69d236
parent 0 f63038272f30
child 16 95674584745d
--- a/bluetoothengine/bteng/src/btengsrvsession.cpp	Fri Feb 19 22:59:18 2010 +0200
+++ b/bluetoothengine/bteng/src/btengsrvsession.cpp	Fri Mar 12 15:43:23 2010 +0200
@@ -22,6 +22,7 @@
 #include "btengserver.h"
 #include "btengsrvbbconnectionmgr.h"
 #include "btengpairman.h"
+#include "btengsrvsettingsmgr.h"
 #include "btengclientserver.h"
 #include "debug.h"
 
@@ -79,14 +80,11 @@
         {
         iNotifyConnMessage.Complete( KErrCancel );
         }
-    CancelPairRequest();
     if( Server() )
         {
-        Server()->RemoveSession( iAutoSwitchOff );
+        Server()->RemoveSession(this, iAutoSwitchOff );
         }
-    
     delete iConnectionEventQueue;
-    
     TRACE_FUNC_EXIT
     }
 
@@ -150,20 +148,6 @@
     }
 
 // ---------------------------------------------------------------------------
-// Comfirm the caller if pairing request is completed in this invoke. 
-// ---------------------------------------------------------------------------
-//
-TInt CBTEngSrvSession::CompletePairRequest( TInt aResult )
-    {
-    if ( !iPairMessage.IsNull())
-        {
-        iPairMessage.Complete( aResult );
-        return KErrNone;
-        }
-    return KErrNotFound;
-    }
-
-// ---------------------------------------------------------------------------
 // From class CSession2
 // Handles servicing of a client request that has been passed to the server.
 // ---------------------------------------------------------------------------
@@ -171,11 +155,11 @@
 void CBTEngSrvSession::ServiceL( const RMessage2& aMessage )
     {
     TRAPD( err, DispatchMessageL( aMessage ) );
-
     if( !aMessage.IsNull() &&
         ( err || 
           ( aMessage.Function() != EBTEngNotifyConnectionEvents && 
-            aMessage.Function() != EBTEngPairDevice ) ) )
+            aMessage.Function() != EBTEngPairDevice &&
+            aMessage.Function() != EBTEngSetPowerState ) ) )
         {
             // Return the error code to the client.
         aMessage.Complete( err );
@@ -206,15 +190,13 @@
         {
         case EBTEngSetPowerState:
             {
-            iAutoSwitchOff = (TBool) aMessage.Int1();
-            Server()->SetPowerStateL( (TBTPowerStateValue) aMessage.Int0(), 
-                                       iAutoSwitchOff );
+            Server()->SetPowerStateL( aMessage );
             }
             break;
         case EBTEngSetVisibilityMode:
             {
-            Server()->SetVisibilityModeL( (TBTVisibilityMode) aMessage.Int0(),
-                                           aMessage.Int1() );
+            Server()->SettingsManager()->SetVisibilityModeL(
+                        (TBTVisibilityMode) aMessage.Int0(),aMessage.Int1() );
             }
             break;
         case EBTEngNotifyConnectionEvents:
@@ -229,7 +211,6 @@
                 {
                 User::Leave(KErrInUse);
                 }
-            
             //save the client message
             iNotifyConnMessage = RMessage2(aMessage);
             
@@ -261,17 +242,9 @@
         case EBTEngIsDeviceConnected:
         case EBTEngGetConnectedAddresses:
             {
-            TBTPowerStateValue pwr = EBTPowerOff;
-            Server()->GetHwPowerState( pwr );
-            if( pwr )
-                {
-                    // Simply forward it to the plug-in manager
-                Server()->DispatchPluginMessageL( aMessage );
-                }
-            else
-                {
-                User::Leave( KErrNotReady );
-                }
+            CheckPowerOnL();
+            // Simply forward it to the plug-in manager
+            Server()->DispatchPluginMessageL( aMessage );
             }
             break;    
         case EBTEngIsDeviceConnectable:
@@ -282,38 +255,31 @@
         case EBTEngPrepareDiscovery:
             {
             aMessage.Complete( KErrNone );  // Client does not have to wait.
-            Server()->iBBConnMgr->ManageTopology( ETrue );
+            Server()->BasebandConnectionManager()->ManageTopology( ETrue );
             }
             break;
         case EBTEngSetPairingObserver:
+            {
+            CheckPowerOnL();
+            // Simply forward it to the pairing manager
+            Server()->PairManager()->ProcessCommandL( aMessage );
+            break;
+            }
         case EBTEngPairDevice:
             {
-            TBTPowerStateValue pwr = EBTPowerOff;
-            (void) Server()->GetHwPowerState( pwr );
-            if( pwr )
-                {
-                // Simply forward it to the pairing manager
-                Server()->PairManager().ProcessCommandL( aMessage );
-                if ( opcode == EBTEngPairDevice )
-                    {
-                    iPairMessage = RMessage2( aMessage );
-                    }
-                }
-            else
-                {
-                User::Leave( KErrNotReady );
-                }
+            CheckPowerOnL();
+            // Simply forward it to the pairing manager
+            Server()->PairManager()->ProcessCommandL( aMessage );
             break;
             }
         case EBTEngCancelPairDevice:
             {
-            CancelPairRequest();
+            Server()->PairManager()->ProcessCommandL( aMessage );
             break;
             }
         default:
             {
-            TRACE_INFO( ( _L( "[BTENG]\t DispatchMessageL: bad request (%d)" ), 
-                                aMessage.Function() ) )
+            TRACE_INFO( ( _L( "[BTENG]\t DispatchMessageL: bad request (%d)" ), aMessage.Function() ) )
             User::Leave( KErrArgument );
             }
             break;
@@ -322,14 +288,15 @@
     }
 
 // ---------------------------------------------------------------------------
-// Only the originator of pairing can cancel the pairing request.
+// Check if power is on, and leave if it is not.
 // ---------------------------------------------------------------------------
 //
-void CBTEngSrvSession::CancelPairRequest()
+void CBTEngSrvSession::CheckPowerOnL()
     {
-    if ( !iPairMessage.IsNull() )
+    TBTPowerState power = EBTOff;
+    (void) Server()->SettingsManager()->GetHwPowerState( power );
+    if ( power == EBTOff )
         {
-        Server()->PairManager().CancelCommand( iPairMessage.Function() );
-        iPairMessage.Complete( KErrCancel );
+        User::Leave( KErrNotReady );
         }
     }