Bug 1029390: Add A2DP/AVRCP result-handler infrastructure, r=shuang
authorThomas Zimmermann <tdz@users.sourceforge.net>
Wed, 23 Jul 2014 07:56:18 +0200
changeset 195573 55aeb3ffaf0dbca39c6f1778afaf134b736a6a02
parent 195572 bf3cbc841d58b05a909a3099c27a58efc17de038
child 195574 332edac38e3cab15c3858137188090f09390eb28
push id27187
push usercbook@mozilla.com
push dateWed, 23 Jul 2014 10:59:56 +0000
treeherdermozilla-central@d0f6259e8446 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshuang
bugs1029390
milestone34.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 1029390: Add A2DP/AVRCP result-handler infrastructure, r=shuang
dom/bluetooth/bluedroid/BluetoothInterface.cpp
dom/bluetooth/bluedroid/BluetoothInterface.h
--- a/dom/bluetooth/bluedroid/BluetoothInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothInterface.cpp
@@ -842,16 +842,47 @@ struct interface_traits<BluetoothA2dpInt
   typedef const btav_interface_t const_interface_type;
 
   static const char* profile_id()
   {
     return BT_PROFILE_ADVANCED_AUDIO_ID;
   }
 };
 
+typedef
+  BluetoothInterfaceRunnable0<BluetoothA2dpResultHandler, void>
+  BluetoothA2dpResultRunnable;
+
+typedef
+  BluetoothInterfaceRunnable1<BluetoothA2dpResultHandler, void, bt_status_t>
+  BluetoothA2dpErrorRunnable;
+
+static nsresult
+DispatchBluetoothA2dpResult(
+  BluetoothA2dpResultHandler* aRes,
+  void (BluetoothA2dpResultHandler::*aMethod)(),
+  bt_status_t aStatus)
+{
+  MOZ_ASSERT(aRes);
+
+  nsRunnable* runnable;
+
+  if (aStatus == BT_STATUS_SUCCESS) {
+    runnable = new BluetoothA2dpResultRunnable(aRes, aMethod);
+  } else {
+    runnable = new BluetoothA2dpErrorRunnable(aRes,
+      &BluetoothA2dpResultHandler::OnError, aStatus);
+  }
+  nsresult rv = NS_DispatchToMainThread(runnable);
+  if (NS_FAILED(rv)) {
+    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
+  }
+  return rv;
+}
+
 BluetoothA2dpInterface::BluetoothA2dpInterface(
   const btav_interface_t* aInterface)
 : mInterface(aInterface)
 {
   MOZ_ASSERT(mInterface);
 }
 
 BluetoothA2dpInterface::~BluetoothA2dpInterface()
@@ -892,16 +923,47 @@ struct interface_traits<BluetoothAvrcpIn
   typedef const btrc_interface_t const_interface_type;
 
   static const char* profile_id()
   {
     return BT_PROFILE_AV_RC_ID;
   }
 };
 
+typedef
+  BluetoothInterfaceRunnable0<BluetoothAvrcpResultHandler, void>
+  BluetoothAvrcpResultRunnable;
+
+typedef
+  BluetoothInterfaceRunnable1<BluetoothAvrcpResultHandler, void, bt_status_t>
+  BluetoothAvrcpErrorRunnable;
+
+static nsresult
+DispatchBluetoothAvrcpResult(
+  BluetoothAvrcpResultHandler* aRes,
+  void (BluetoothAvrcpResultHandler::*aMethod)(),
+  bt_status_t aStatus)
+{
+  MOZ_ASSERT(aRes);
+
+  nsRunnable* runnable;
+
+  if (aStatus == BT_STATUS_SUCCESS) {
+    runnable = new BluetoothAvrcpResultRunnable(aRes, aMethod);
+  } else {
+    runnable = new BluetoothAvrcpErrorRunnable(aRes,
+      &BluetoothAvrcpResultHandler::OnError, aStatus);
+  }
+  nsresult rv = NS_DispatchToMainThread(runnable);
+  if (NS_FAILED(rv)) {
+    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
+  }
+  return rv;
+}
+
 BluetoothAvrcpInterface::BluetoothAvrcpInterface(
   const btrc_interface_t* aInterface)
 : mInterface(aInterface)
 {
   MOZ_ASSERT(mInterface);
 }
 
 BluetoothAvrcpInterface::~BluetoothAvrcpInterface()
--- a/dom/bluetooth/bluedroid/BluetoothInterface.h
+++ b/dom/bluetooth/bluedroid/BluetoothInterface.h
@@ -176,16 +176,34 @@ protected:
 private:
   const bthf_interface_t* mInterface;
 };
 
 //
 // Bluetooth Advanced Audio Interface
 //
 
+class BluetoothA2dpResultHandler
+{
+public:
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BluetoothA2dpResultHandler)
+
+  virtual ~BluetoothA2dpResultHandler() { }
+
+  virtual void OnError(bt_status_t aStatus)
+  {
+    BT_WARNING("received error code %d", (int)aStatus);
+  }
+
+  virtual void Init() { }
+  virtual void Cleanup() { }
+  virtual void Connect() { }
+  virtual void Disconnect() { }
+};
+
 class BluetoothA2dpInterface
 {
 public:
   friend class BluetoothInterface;
 
   bt_status_t Init(btav_callbacks_t *aCallbacks);
   void        Cleanup();
 
@@ -199,16 +217,49 @@ protected:
 private:
   const btav_interface_t* mInterface;
 };
 
 //
 // Bluetooth AVRCP Interface
 //
 
+class BluetoothAvrcpResultHandler
+{
+public:
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BluetoothAvrcpResultHandler)
+
+  virtual ~BluetoothAvrcpResultHandler() { }
+
+  virtual void OnError(bt_status_t aStatus)
+  {
+    BT_WARNING("received error code %d", (int)aStatus);
+  }
+
+  virtual void Init() { }
+  virtual void Cleanup() { }
+
+  virtual void GetPlayStatusRsp() { }
+
+  virtual void ListPlayerAppAttrRsp() { }
+  virtual void ListPlayerAppValueRsp() { }
+
+  virtual void GetPlayerAppValueRsp() { }
+  virtual void GetPlayerAppAttrTextRsp() { }
+  virtual void GetPlayerAppValueTextRsp() { }
+
+  virtual void GetElementAttrRsp() { }
+
+  virtual void SetPlayerAppValueRsp() { }
+
+  virtual void RegisterNotificationRsp() { }
+
+  virtual void SetVolume() { }
+};
+
 class BluetoothAvrcpInterface
 {
 #if ANDROID_VERSION >= 18
 public:
   friend class BluetoothInterface;
 
   bt_status_t Init(btrc_callbacks_t* aCallbacks);
   void        Cleanup();