Bug 791197 - [b2g-bluetooth] BluetoothHfpManager prototype, r=qdot
authorEric Chou <echou@mozilla.com>
Wed, 26 Sep 2012 21:34:55 +0800
changeset 108141 4dfa1754f818d123305f55c3e9fee6449a0294eb
parent 108140 15cd63bd65d53094a4f1b41495aec6d057c78348
child 108142 490abcc57fec9442db09c9ebbb745fd102484cd1
push id23539
push userryanvm@gmail.com
push dateWed, 26 Sep 2012 22:55:55 +0000
treeherderautoland@ec079fd92224 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs791197
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 791197 - [b2g-bluetooth] BluetoothHfpManager prototype, r=qdot
dom/bluetooth/BluetoothHfpManager.cpp
dom/bluetooth/BluetoothHfpManager.h
dom/bluetooth/Makefile.in
new file mode 100644
--- /dev/null
+++ b/dom/bluetooth/BluetoothHfpManager.cpp
@@ -0,0 +1,80 @@
+/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "BluetoothHfpManager.h"
+
+#include "BluetoothReplyRunnable.h"
+#include "BluetoothService.h"
+#include "BluetoothServiceUuid.h"
+
+USING_BLUETOOTH_NAMESPACE
+using namespace mozilla::ipc;
+
+static nsRefPtr<BluetoothHfpManager> sInstance = nullptr;
+
+BluetoothHfpManager::BluetoothHfpManager()
+{
+}
+
+BluetoothHfpManager::~BluetoothHfpManager()
+{
+}
+
+//static
+BluetoothHfpManager*
+BluetoothHfpManager::Get()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  if (sInstance == nullptr) {
+    sInstance = new BluetoothHfpManager();
+  }
+
+  return sInstance;
+}
+
+// Virtual function of class SocketConsumer
+void
+BluetoothHfpManager::ReceiveSocketData(UnixSocketRawData* aMessage)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+}
+
+bool
+BluetoothHfpManager::Connect(const nsAString& aDeviceObjectPath,
+                             BluetoothReplyRunnable* aRunnable)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  BluetoothService* bs = BluetoothService::Get();
+  if (!bs) {
+    NS_WARNING("BluetoothService not available!");
+    return false;
+  }
+
+  nsString serviceUuidStr =
+    NS_ConvertUTF8toUTF16(mozilla::dom::bluetooth::BluetoothServiceUuidStr::Handsfree);
+
+  nsRefPtr<BluetoothReplyRunnable> runnable = aRunnable;
+
+  nsresult rv = bs->GetSocketViaService(aDeviceObjectPath,
+                                        serviceUuidStr,
+                                        BluetoothSocketType::RFCOMM,
+                                        true,
+                                        false,
+                                        this,
+                                        runnable);
+
+  runnable.forget();
+  return NS_FAILED(rv) ? false : true;
+}
+
+void
+BluetoothHfpManager::Disconnect()
+{
+  CloseSocket();
+}
+
new file mode 100644
--- /dev/null
+++ b/dom/bluetooth/BluetoothHfpManager.h
@@ -0,0 +1,35 @@
+/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_dom_bluetooth_bluetoothhfpmanager_h__
+#define mozilla_dom_bluetooth_bluetoothhfpmanager_h__
+
+#include "BluetoothCommon.h"
+#include "mozilla/ipc/UnixSocket.h"
+
+BEGIN_BLUETOOTH_NAMESPACE
+
+class BluetoothReplyRunnable;
+
+class BluetoothHfpManager : public mozilla::ipc::UnixSocketConsumer
+{
+public:
+  ~BluetoothHfpManager();
+
+  static BluetoothHfpManager* Get();
+  void ReceiveSocketData(mozilla::ipc::UnixSocketRawData* aMessage);
+
+  bool Connect(const nsAString& aDeviceObjectPath,
+               BluetoothReplyRunnable* aRunnable);
+  void Disconnect();
+
+private:
+  BluetoothHfpManager();
+};
+
+END_BLUETOOTH_NAMESPACE
+
+#endif
--- a/dom/bluetooth/Makefile.in
+++ b/dom/bluetooth/Makefile.in
@@ -47,16 +47,17 @@ CPPSRCS += \
   BluetoothPropertyEvent.cpp \
   BluetoothReplyRunnable.cpp \
   BluetoothPropertyContainer.cpp \
   BluetoothUtils.cpp \
   BluetoothChild.cpp \
   BluetoothParent.cpp \
   BluetoothServiceChildProcess.cpp \
   BluetoothUnixSocketConnector.cpp \
+  BluetoothHfpManager.cpp \
   $(NULL)
 
 XPIDLSRCS = \
   nsIDOMNavigatorBluetooth.idl \
   nsIDOMBluetoothManager.idl \
   nsIDOMBluetoothAdapter.idl \
   nsIDOMBluetoothDevice.idl \
   nsIDOMBluetoothDeviceEvent.idl \