Bug 792823 - patch 2: BluetoothOppManager interface and prototype, r=qdot
authorEric Chou <echou@mozilla.com>
Fri, 28 Sep 2012 19:46:37 +0800
changeset 108478 5ce162e8bb474510854e0a4e7acc9a63ca4df038
parent 108477 9946c7e4dd92a9053445fb1b0bab394f99b37553
child 108479 927bda3a494770537a20b97c42a1e5c1db4f85c7
push id23564
push useremorley@mozilla.com
push dateFri, 28 Sep 2012 23:09:34 +0000
treeherdermozilla-central@b62b229a4d41 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs792823
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 792823 - patch 2: BluetoothOppManager interface and prototype, r=qdot
dom/bluetooth/BluetoothOppManager.cpp
dom/bluetooth/BluetoothOppManager.h
dom/bluetooth/Makefile.in
new file mode 100644
--- /dev/null
+++ b/dom/bluetooth/BluetoothOppManager.cpp
@@ -0,0 +1,99 @@
+/* -*- 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 "base/basictypes.h"
+#include "BluetoothOppManager.h"
+
+#include "BluetoothReplyRunnable.h"
+#include "BluetoothService.h"
+#include "BluetoothServiceUuid.h"
+
+#include "mozilla/dom/ipc/Blob.h"
+#include "mozilla/RefPtr.h"
+
+USING_BLUETOOTH_NAMESPACE
+using namespace mozilla::ipc;
+
+static mozilla::RefPtr<BluetoothOppManager> sInstance;
+
+BluetoothOppManager::BluetoothOppManager()
+{
+}
+
+BluetoothOppManager::~BluetoothOppManager()
+{
+}
+
+//static
+BluetoothOppManager*
+BluetoothOppManager::Get()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  if (sInstance == nullptr) {
+    sInstance = new BluetoothOppManager();
+  }
+
+  return sInstance;
+}
+
+bool
+BluetoothOppManager::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::ObjectPush);
+
+  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
+BluetoothOppManager::Disconnect()
+{
+  CloseSocket();
+}
+
+bool
+BluetoothOppManager::SendFile(BlobParent* aParent,
+                              BluetoothReplyRunnable* aRunnable)
+{
+  // will implement in another patch.
+  return true;
+}
+
+bool
+BluetoothOppManager::StopSendingFile(BluetoothReplyRunnable* aRunnable)
+{
+  // will implement in another patch.
+  return true;
+}
+
+// Virtual function of class SocketConsumer
+void
+BluetoothOppManager::ReceiveSocketData(UnixSocketRawData* aMessage)
+{
+  // will implement in another patch.
+}
+
new file mode 100644
--- /dev/null
+++ b/dom/bluetooth/BluetoothOppManager.h
@@ -0,0 +1,58 @@
+/* -*- 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_bluetoothoppmanager_h__
+#define mozilla_dom_bluetooth_bluetoothoppmanager_h__
+
+#include "BluetoothCommon.h"
+#include "mozilla/ipc/UnixSocket.h"
+
+BEGIN_BLUETOOTH_NAMESPACE
+
+class BluetoothReplyRunnable;
+class BlobParent;
+
+class BluetoothOppManager : public mozilla::ipc::UnixSocketConsumer
+{
+public:
+  /*
+   * Channel of reserved services are fixed values, please check
+   * function add_reserved_service_records() in
+   * external/bluetooth/bluez/src/adapter.c for more information.
+   */
+  static const int DEFAULT_OPP_CHANNEL = 10;
+
+  ~BluetoothOppManager();
+  static BluetoothOppManager* Get();
+  void ReceiveSocketData(mozilla::ipc::UnixSocketRawData* aMessage);
+
+  /*
+   * If a application wnats to send a file, first, it needs to
+   * call Connect() to create a valid RFCOMM connection. After
+   * that, call SendFile()/StopSendingFile() to control file-sharing
+   * process. During the file transfering process, the application
+   * will receive several system messages which contain the processed
+   * percentage of file. At the end, the application will get another
+   * system message indicating that te process is complete, then it can
+   * either call Disconnect() to close RFCOMM connection or start another
+   * file-sending thread via calling SendFile() again.
+   */
+  bool Connect(const nsAString& aDeviceObjectPath,
+               BluetoothReplyRunnable* aRunnable);
+  void Disconnect();
+
+  bool SendFile(BlobParent* aBlob,
+                BluetoothReplyRunnable* aRunnable);
+
+  bool StopSendingFile(BluetoothReplyRunnable* aRunnable);
+
+private:
+  BluetoothOppManager();
+};
+
+END_BLUETOOTH_NAMESPACE
+
+#endif
--- a/dom/bluetooth/Makefile.in
+++ b/dom/bluetooth/Makefile.in
@@ -48,16 +48,17 @@ CPPSRCS += \
   BluetoothReplyRunnable.cpp \
   BluetoothPropertyContainer.cpp \
   BluetoothUtils.cpp \
   BluetoothChild.cpp \
   BluetoothParent.cpp \
   BluetoothServiceChildProcess.cpp \
   BluetoothUnixSocketConnector.cpp \
   BluetoothHfpManager.cpp \
+  BluetoothOppManager.cpp \
   $(NULL)
 
 ifdef MOZ_B2G_RIL
 CPPSRCS += BluetoothRilListener.cpp
 endif
 
 XPIDLSRCS = \
   nsIDOMNavigatorBluetooth.idl \