Bug 794514 - patch 3: added requests and completed call flow, r=qdot
authorEric Chou <echou@mozilla.com>
Sat, 29 Sep 2012 18:26:46 +0800
changeset 108727 81b8598fb470d41430eb71767d292dbbb055e03f
parent 108726 36d770df9bc64548a75db600bd902a94fbca5ede
child 108728 9f22813d133f4b93717e07569a37c2c3f1643a34
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersqdot
bugs794514
milestone18.0a1
Bug 794514 - patch 3: added requests and completed call flow, r=qdot
dom/bluetooth/ipc/BluetoothParent.cpp
dom/bluetooth/ipc/BluetoothParent.h
dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
dom/bluetooth/ipc/PBluetooth.ipdl
dom/bluetooth/linux/BluetoothDBusService.cpp
--- a/dom/bluetooth/ipc/BluetoothParent.cpp
+++ b/dom/bluetooth/ipc/BluetoothParent.cpp
@@ -208,16 +208,24 @@ BluetoothParent::RecvPBluetoothRequestCo
     case Request::TConfirmPairingConfirmationRequest:
       return actor->DoRequest(aRequest.get_ConfirmPairingConfirmationRequest());
     case Request::TConfirmAuthorizationRequest:
       return actor->DoRequest(aRequest.get_ConfirmAuthorizationRequest());
     case Request::TDenyPairingConfirmationRequest:
       return actor->DoRequest(aRequest.get_DenyPairingConfirmationRequest());
     case Request::TDenyAuthorizationRequest:
       return actor->DoRequest(aRequest.get_DenyAuthorizationRequest());
+    case Request::TConnectHeadsetRequest:
+      return actor->DoRequest(aRequest.get_ConnectHeadsetRequest());
+    case Request::TConnectObjectPushRequest:
+      return actor->DoRequest(aRequest.get_ConnectObjectPushRequest());
+    case Request::TDisconnectHeadsetRequest:
+      return actor->DoRequest(aRequest.get_DisconnectHeadsetRequest());
+    case Request::TDisconnectObjectPushRequest:
+      return actor->DoRequest(aRequest.get_DisconnectObjectPushRequest());
     default:
       MOZ_NOT_REACHED("Unknown type!");
       return false;
   }
 
   MOZ_NOT_REACHED("Should never get here!");
   return false;
 }
@@ -481,8 +489,52 @@ BluetoothRequestParent::DoRequest(const 
     mService->SetAuthorizationInternal(aRequest.path(),
                                        false,
                                        mReplyRunnable.get());
 
   NS_ENSURE_TRUE(result, false);
 
   return true;
 }
+
+bool
+BluetoothRequestParent::DoRequest(const ConnectHeadsetRequest& aRequest)
+{
+  MOZ_ASSERT(mService);
+  MOZ_ASSERT(mRequestType == Request::TConnectHeadsetRequest);
+
+  return mService->ConnectHeadset(aRequest.address(),
+                                  aRequest.adapterPath(),
+                                  mReplyRunnable.get());
+}
+
+bool
+BluetoothRequestParent::DoRequest(const ConnectObjectPushRequest& aRequest)
+{
+  MOZ_ASSERT(mService);
+  MOZ_ASSERT(mRequestType == Request::TConnectObjectPushRequest);
+
+  return mService->ConnectObjectPush(aRequest.address(),
+                                     aRequest.adapterPath(),
+                                     mReplyRunnable.get());
+}
+
+bool
+BluetoothRequestParent::DoRequest(const DisconnectHeadsetRequest& aRequest)
+{
+  MOZ_ASSERT(mService);
+  MOZ_ASSERT(mRequestType == Request::TDisconnectHeadsetRequest);
+
+  mService->DisconnectHeadset(mReplyRunnable.get());
+
+  return true;
+}
+
+bool
+BluetoothRequestParent::DoRequest(const DisconnectObjectPushRequest& aRequest)
+{
+  MOZ_ASSERT(mService);
+  MOZ_ASSERT(mRequestType == Request::TDenyAuthorizationRequest);
+
+  mService->DisconnectObjectPush(mReplyRunnable.get());
+
+  return true;
+}
--- a/dom/bluetooth/ipc/BluetoothParent.h
+++ b/dom/bluetooth/ipc/BluetoothParent.h
@@ -160,13 +160,25 @@ protected:
   bool
   DoRequest(const DenyPairingConfirmationRequest& aRequest);
 
   bool
   DoRequest(const ConfirmAuthorizationRequest& aRequest);
 
   bool
   DoRequest(const DenyAuthorizationRequest& aRequest);
+
+  bool
+  DoRequest(const ConnectHeadsetRequest& aRequest);
+
+  bool
+  DoRequest(const ConnectObjectPushRequest& aRequest);
+
+  bool
+  DoRequest(const DisconnectHeadsetRequest& aRequest);
+
+  bool
+  DoRequest(const DisconnectObjectPushRequest& aRequest);
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif // mozilla_dom_bluetooth_ipc_bluetoothparent_h__
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
+++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
@@ -288,40 +288,47 @@ BluetoothServiceChildProcess::PrepareAda
 }
 
 bool
 BluetoothServiceChildProcess::ConnectHeadset(
   const nsAString& aDeviceAddress,
   const nsAString& aAdapterPath,
   BluetoothReplyRunnable* aRunnable)
 {
+  SendRequest(aRunnable,
+              ConnectHeadsetRequest(nsString(aDeviceAddress), 
+                                    nsString(aAdapterPath)));
+
   return true;
 }
 
 void
 BluetoothServiceChildProcess::DisconnectHeadset(
   BluetoothReplyRunnable* aRunnable)
 {
-  return;
+  SendRequest(aRunnable, DisconnectHeadsetRequest());
 }
 
 bool
 BluetoothServiceChildProcess::ConnectObjectPush(
   const nsAString& aDeviceAddress,
   const nsAString& aAdapterPath,
   BluetoothReplyRunnable* aRunnable)
 {
+  SendRequest(aRunnable,
+              ConnectObjectPushRequest(nsString(aDeviceAddress), 
+                                       nsString(aAdapterPath)));
   return true;
 }
 
 void
 BluetoothServiceChildProcess::DisconnectObjectPush(
   BluetoothReplyRunnable* aRunnable)
 {
-  return;
+  SendRequest(aRunnable, DisconnectObjectPushRequest());
 }
 
 nsresult
 BluetoothServiceChildProcess::HandleStartup()
 {
   // Don't need to do anything here for startup since our Create function takes
   // care of the actor machinery.
   return NS_OK;
--- a/dom/bluetooth/ipc/PBluetooth.ipdl
+++ b/dom/bluetooth/ipc/PBluetooth.ipdl
@@ -92,32 +92,54 @@ struct DenyAuthorizationRequest
   nsString path;
 };
 
 struct DevicePropertiesRequest
 {
   nsString[] addresses;
 };
 
+struct ConnectHeadsetRequest
+{
+  nsString address;
+  nsString adapterPath;
+};
+
+struct ConnectObjectPushRequest
+{
+  nsString address;
+  nsString adapterPath;
+};
+
+struct DisconnectHeadsetRequest
+{};
+
+struct DisconnectObjectPushRequest
+{};
+
 union Request
 {
   DefaultAdapterPathRequest;
   SetPropertyRequest;
   GetPropertyRequest;
   StartDiscoveryRequest;
   StopDiscoveryRequest;
   PairRequest;
   UnpairRequest;
   SetPinCodeRequest;
   SetPasskeyRequest;
   ConfirmPairingConfirmationRequest;
   DenyPairingConfirmationRequest;
   ConfirmAuthorizationRequest;
   DenyAuthorizationRequest;
   DevicePropertiesRequest;
+  ConnectHeadsetRequest;
+  ConnectObjectPushRequest;
+  DisconnectHeadsetRequest;
+  DisconnectObjectPushRequest;
 };
 
 protocol PBluetooth
 {
   manager PContent;
   manages PBluetoothRequest;
 
   /**
--- a/dom/bluetooth/linux/BluetoothDBusService.cpp
+++ b/dom/bluetooth/linux/BluetoothDBusService.cpp
@@ -14,19 +14,20 @@
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.
 */
 
 #include "base/basictypes.h"
 #include "BluetoothDBusService.h"
 #include "BluetoothHfpManager.h"
+#include "BluetoothOppManager.h"
+#include "BluetoothReplyRunnable.h"
 #include "BluetoothScoManager.h"
 #include "BluetoothServiceUuid.h"
-#include "BluetoothReplyRunnable.h"
 #include "BluetoothUnixSocketConnector.h"
 
 #include <cstdio>
 #include <dbus/dbus.h>
 
 #include "nsIDOMDOMRequest.h"
 #include "nsIObserverService.h"
 #include "AudioManager.h"
@@ -2198,37 +2199,57 @@ BluetoothDBusService::PrepareAdapterInte
   return NS_OK;
 }
 
 bool
 BluetoothDBusService::ConnectHeadset(const nsAString& aDeviceAddress,
                                      const nsAString& aAdapterPath,
                                      BluetoothReplyRunnable* aRunnable)
 {
-  return true;
+  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
+  return hfp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
+                      aRunnable);
 }
 
 void
 BluetoothDBusService::DisconnectHeadset(BluetoothReplyRunnable* aRunnable)
 {
-  return;
+  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
+  hfp->Disconnect();
+
+  // Currently, just fire success because Disconnect() doesn't fail, 
+  // but we still make aRunnable pass into this function for future
+  // once Disconnect will fail.
+  nsString replyError;
+  BluetoothValue v = true;
+  DispatchBluetoothReply(aRunnable, v, replyError);
 }
 
 bool
 BluetoothDBusService::ConnectObjectPush(const nsAString& aDeviceAddress,
                                         const nsAString& aAdapterPath,
                                         BluetoothReplyRunnable* aRunnable)
 {
-  return true;
+  BluetoothOppManager* opp = BluetoothOppManager::Get();
+  return opp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
+                      aRunnable);
 }
 
 void
 BluetoothDBusService::DisconnectObjectPush(BluetoothReplyRunnable* aRunnable)
 {
-  return;
+  BluetoothOppManager* opp = BluetoothOppManager::Get();
+  opp->Disconnect();
+  
+  // Currently, just fire success because Disconnect() doesn't fail, 
+  // but we still make aRunnable pass into this function for future
+  // once Disconnect will fail.
+  nsString replyError;
+  BluetoothValue v = true;
+  DispatchBluetoothReply(aRunnable, v, replyError);
 }
 class CreateBluetoothScoSocket : public nsRunnable
 {
 public: 
   CreateBluetoothScoSocket(UnixSocketConsumer* aConsumer,
                            const nsAString& aObjectPath,
                            bool aAuth,
                            bool aEncrypt)