Bug 1036977: Add result handler for Bluetooth Socket interface (under bluetooth2/), r=btian
authorThomas Zimmermann <tdz@users.sourceforge.net>
Wed, 16 Jul 2014 10:23:35 +0200
changeset 216351 50fe2ac159dfc7e991cb01dbbc07385801a6484c
parent 216350 81eedce71bbf9c471a6e047c9156ae3acee3566b
child 216352 13fce7913cc4a5e2ade4712cbf8ebd7465651b0c
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbtian
bugs1036977
milestone33.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 1036977: Add result handler for Bluetooth Socket interface (under bluetooth2/), r=btian
dom/bluetooth2/bluedroid/BluetoothInterface.cpp
dom/bluetooth2/bluedroid/BluetoothInterface.h
--- a/dom/bluetooth2/bluedroid/BluetoothInterface.cpp
+++ b/dom/bluetooth2/bluedroid/BluetoothInterface.cpp
@@ -79,16 +79,46 @@ struct interface_traits<BluetoothSocketI
   typedef const btsock_interface_t const_interface_type;
 
   static const char* profile_id()
   {
     return BT_PROFILE_SOCKETS_ID;
   }
 };
 
+typedef
+  BluetoothInterfaceRunnable1<BluetoothSocketResultHandler, void, int>
+  BluetoothSocketIntResultRunnable;
+
+typedef
+  BluetoothInterfaceRunnable1<BluetoothSocketResultHandler, void, bt_status_t>
+  BluetoothSocketErrorRunnable;
+
+static nsresult
+DispatchBluetoothSocketResult(BluetoothSocketResultHandler* aRes,
+                              void (BluetoothSocketResultHandler::*aMethod)(int),
+                              int aArg, bt_status_t aStatus)
+{
+  MOZ_ASSERT(aRes);
+
+  nsRunnable* runnable;
+
+  if (aStatus == BT_STATUS_SUCCESS) {
+    runnable = new BluetoothSocketIntResultRunnable(aRes, aMethod, aArg);
+  } else {
+    runnable = new BluetoothSocketErrorRunnable(aRes,
+      &BluetoothSocketResultHandler::OnError, aStatus);
+  }
+  nsresult rv = NS_DispatchToMainThread(runnable);
+  if (NS_FAILED(rv)) {
+    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
+  }
+  return rv;
+}
+
 bt_status_t
 BluetoothSocketInterface::Listen(btsock_type_t aType,
                                  const char* aServiceName,
                                  const uint8_t* aServiceUuid, int aChannel,
                                  int& aSockFd, int aFlags)
 {
   return mInterface->listen(aType, aServiceName, aServiceUuid, aChannel,
                            &aSockFd, aFlags);
--- a/dom/bluetooth2/bluedroid/BluetoothInterface.h
+++ b/dom/bluetooth2/bluedroid/BluetoothInterface.h
@@ -19,16 +19,32 @@
 BEGIN_BLUETOOTH_NAMESPACE
 
 class BluetoothInterface;
 
 //
 // Socket Interface
 //
 
+class BluetoothSocketResultHandler
+{
+public:
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BluetoothSocketResultHandler)
+
+  virtual ~BluetoothSocketResultHandler() { }
+
+  virtual void OnError(bt_status_t aStatus)
+  {
+    BT_WARNING("Received error code %d", (int)aStatus);
+  }
+
+  virtual void Listen(int aSockFd) { }
+  virtual void Connect(int aSockFd) { }
+};
+
 class BluetoothSocketInterface
 {
 public:
   friend BluetoothInterface;
 
   // Init and Cleanup is handled by BluetoothInterface
 
   bt_status_t Listen(btsock_type_t aType,