Bug 1220121: Prepare IPDL support for additional Bluetooth types, r=brsun
authorThomas Zimmermann <tdz@users.sourceforge.net>
Fri, 13 Nov 2015 15:26:50 +0100
changeset 272644 8cb55973ad98b5d1b2c70609c22f23ba36eac165
parent 272643 3bb32aa4fb4fc0031ace9319cc61b6a3ff687994
child 272645 5efc2a3519836391c8f289fda23d1841cef8f004
push id29681
push userkwierso@gmail.com
push dateMon, 16 Nov 2015 23:39:08 +0000
treeherdermozilla-central@ffe020f91452 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbrsun
bugs1220121
milestone45.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 1220121: Prepare IPDL support for additional Bluetooth types, r=brsun This patch adds IPDL helpers for transfering |BluetoothAddress|, |BluetoothPinCode|, and |ControlPlayStatus|.
dom/bluetooth/ipc/BluetoothMessageUtils.h
--- a/dom/bluetooth/ipc/BluetoothMessageUtils.h
+++ b/dom/bluetooth/ipc/BluetoothMessageUtils.h
@@ -8,24 +8,83 @@
 #define mozilla_dom_bluetooth_ipc_BluetoothMessageUtils_h
 
 #include "mozilla/dom/bluetooth/BluetoothCommon.h"
 #include "ipc/IPCMessageUtils.h"
 
 namespace IPC {
 
 template <>
+struct ParamTraits<mozilla::dom::bluetooth::BluetoothAddress>
+{
+  typedef mozilla::dom::bluetooth::BluetoothAddress paramType;
+
+  static void Write(Message* aMsg, const paramType& aParam)
+  {
+    for (size_t i = 0; i < MOZ_ARRAY_LENGTH(aParam.mAddr); ++i) {
+      WriteParam(aMsg, aParam.mAddr[i]);
+    }
+  }
+
+  static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
+  {
+    for (size_t i = 0; i < MOZ_ARRAY_LENGTH(aResult->mAddr); ++i) {
+      if (!ReadParam(aMsg, aIter, aResult->mAddr + i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+};
+
+template <>
 struct ParamTraits<mozilla::dom::bluetooth::BluetoothObjectType>
   : public ContiguousEnumSerializer<
              mozilla::dom::bluetooth::BluetoothObjectType,
              mozilla::dom::bluetooth::TYPE_MANAGER,
              mozilla::dom::bluetooth::NUM_TYPE>
 { };
 
 template <>
+struct ParamTraits<mozilla::dom::bluetooth::BluetoothPinCode>
+{
+  typedef mozilla::dom::bluetooth::BluetoothPinCode paramType;
+
+  static void Write(Message* aMsg, const paramType& aParam)
+  {
+    WriteParam(aMsg, aParam.mLength);
+    for (uint8_t i = 0; i < aParam.mLength; ++i) {
+      WriteParam(aMsg, aParam.mPinCode[i]);
+    }
+  }
+
+  static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
+  {
+    if (!ReadParam(aMsg, aIter, &aResult->mLength)) {
+      return false;
+    }
+
+    auto maxLength = MOZ_ARRAY_LENGTH(aResult->mPinCode);
+
+    if (aResult->mLength > maxLength) {
+      return false;
+    }
+    for (uint8_t i = 0; i < aResult->mLength; ++i) {
+      if (!ReadParam(aMsg, aIter, aResult->mPinCode + i)) {
+        return false;
+      }
+    }
+    for (uint8_t i = aResult->mLength; i < maxLength; ++i) {
+      aResult->mPinCode[i] = 0;
+    }
+    return true;
+  }
+};
+
+template <>
 struct ParamTraits<mozilla::dom::bluetooth::BluetoothSspVariant>
   : public ContiguousEnumSerializer<
              mozilla::dom::bluetooth::BluetoothSspVariant,
              mozilla::dom::bluetooth::SSP_VARIANT_PASSKEY_CONFIRMATION,
              mozilla::dom::bluetooth::NUM_SSP_VARIANT>
 { };
 
 template <>
@@ -193,11 +252,47 @@ struct ParamTraits<mozilla::dom::bluetoo
       if (!ReadParam(aMsg, aIter, &(aResult->mValue[i]))) {
         return false;
       }
     }
 
     return true;
   }
 };
+
+template <>
+struct ParamTraits<mozilla::dom::bluetooth::ControlPlayStatus>
+{
+  typedef mozilla::dom::bluetooth::ControlPlayStatus paramType;
+
+  static void Write(Message* aMsg, const paramType& aParam)
+  {
+    WriteParam(aMsg, static_cast<uint8_t>(aParam));
+  }
+
+  static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
+  {
+    uint8_t value;
+    if (!ReadParam(aMsg, aIter, &value)) {
+      return false;
+    }
+
+    mozilla::dom::bluetooth::ControlPlayStatus result =
+      static_cast<mozilla::dom::bluetooth::ControlPlayStatus>(value);
+
+    switch (result) {
+      case mozilla::dom::bluetooth::ControlPlayStatus::PLAYSTATUS_STOPPED:
+      case mozilla::dom::bluetooth::ControlPlayStatus::PLAYSTATUS_PLAYING:
+      case mozilla::dom::bluetooth::ControlPlayStatus::PLAYSTATUS_PAUSED:
+      case mozilla::dom::bluetooth::ControlPlayStatus::PLAYSTATUS_FWD_SEEK:
+      case mozilla::dom::bluetooth::ControlPlayStatus::PLAYSTATUS_REV_SEEK:
+      case mozilla::dom::bluetooth::ControlPlayStatus::PLAYSTATUS_ERROR:
+        *aResult = result;
+        return true;
+      default:
+        return false;
+    }
+  }
+};
+
 } // namespace IPC
 
 #endif // mozilla_dom_bluetooth_ipc_BluetoothMessageUtils_h