Bug 1187249: Move Bluetooth init operators to ipc/hal, r=shuang
authorThomas Zimmermann <tdz@users.sourceforge.net>
Thu, 30 Jul 2015 10:34:51 +0200
changeset 287038 f42f6d74491744491ca35d5d1ee8df872b5cff2b
parent 287037 f82cbe9aaa134ad561966fd9821e46f91f3aef04
child 287039 845d0438feceb784d88f9e0bbed37f4fe23c147b
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshuang
bugs1187249
milestone42.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 1187249: Move Bluetooth init operators to ipc/hal, r=shuang
dom/bluetooth/BluetoothInterfaceHelpers.h
dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
ipc/hal/DaemonSocketPDUHelpers.cpp
ipc/hal/DaemonSocketPDUHelpers.h
--- a/dom/bluetooth/BluetoothInterfaceHelpers.h
+++ b/dom/bluetooth/BluetoothInterfaceHelpers.h
@@ -3,96 +3,21 @@
 /* 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_bluetoothinterfacehelpers_h
 #define mozilla_dom_bluetooth_bluetoothinterfacehelpers_h
 
 #include "BluetoothCommon.h"
-#include "nsThreadUtils.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 //
 // Conversion
 //
 
 nsresult
 Convert(nsresult aIn, BluetoothStatus& aOut);
 
-//
-// Init operators
-//
-// Below are general-purpose init operators for Bluetooth. The classes
-// of type |ConstantInitOp[1..3]| initialize results or notifications
-// with constant values.
-//
-
-template <typename T1>
-class ConstantInitOp1 final
-{
-public:
-  ConstantInitOp1(const T1& aArg1)
-  : mArg1(aArg1)
-  { }
-
-  nsresult operator () (T1& aArg1) const
-  {
-    aArg1 = mArg1;
-
-    return NS_OK;
-  }
-
-private:
-  const T1& mArg1;
-};
-
-template <typename T1, typename T2>
-class ConstantInitOp2 final
-{
-public:
-  ConstantInitOp2(const T1& aArg1, const T2& aArg2)
-  : mArg1(aArg1)
-  , mArg2(aArg2)
-  { }
-
-  nsresult operator () (T1& aArg1, T2& aArg2) const
-  {
-    aArg1 = mArg1;
-    aArg2 = mArg2;
-
-    return NS_OK;
-  }
-
-private:
-  const T1& mArg1;
-  const T2& mArg2;
-};
-
-template <typename T1, typename T2, typename T3>
-class ConstantInitOp3 final
-{
-public:
-  ConstantInitOp3(const T1& aArg1, const T2& aArg2, const T3& aArg3)
-  : mArg1(aArg1)
-  , mArg2(aArg2)
-  , mArg3(aArg3)
-  { }
-
-  nsresult operator () (T1& aArg1, T2& aArg2, T3& aArg3) const
-  {
-    aArg1 = mArg1;
-    aArg2 = mArg2;
-    aArg3 = mArg3;
-
-    return NS_OK;
-  }
-
-private:
-  const T1& mArg1;
-  const T2& mArg2;
-  const T3& mArg3;
-};
-
 END_BLUETOOTH_NAMESPACE
 
 #endif
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
@@ -1059,49 +1059,16 @@ UnpackPDU<BluetoothUuid>(DaemonSocketPDU
     UnpackReversed<UnpackArray<uint8_t>>(
       UnpackArray<uint8_t>(aOut.mValue->mUuid, sizeof(aOut.mValue->mUuid))));
 }
 
 //
 // Init operators
 //
 
-// |PDUInitOP| provides functionality for init operators that unpack PDUs.
-class PDUInitOp
-{
-protected:
-  PDUInitOp(DaemonSocketPDU& aPDU)
-  : mPDU(&aPDU)
-  { }
-
-  DaemonSocketPDU& GetPDU() const
-  {
-    return *mPDU; // cannot be nullptr
-  }
-
-  void WarnAboutTrailingData() const
-  {
-    size_t size = mPDU->GetSize();
-
-    if (MOZ_LIKELY(!size)) {
-      return;
-    }
-
-    uint8_t service, opcode;
-    uint16_t payloadSize;
-    mPDU->GetHeader(service, opcode, payloadSize);
-
-    BT_LOGR("Unpacked PDU of type (%x,%x) still contains %zu Bytes of data.",
-            service, opcode, size);
-  }
-
-private:
-  DaemonSocketPDU* mPDU; // Hold pointer to allow for constant instances
-};
-
 // |UnpackPDUInitOp| is a general-purpose init operator for all variants
 // of |BluetoothResultRunnable| and |BluetoothNotificationRunnable|. The
 // call operators of |UnpackPDUInitOp| unpack a PDU into the supplied
 // arguments.
 class UnpackPDUInitOp final : private PDUInitOp
 {
 public:
   UnpackPDUInitOp(DaemonSocketPDU& aPDU)
--- a/ipc/hal/DaemonSocketPDUHelpers.cpp
+++ b/ipc/hal/DaemonSocketPDUHelpers.cpp
@@ -2,16 +2,29 @@
 /* vim: set ts=8 sts=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 "DaemonSocketPDUHelpers.h"
 #include <limits>
 
+#ifdef CHROMIUM_LOG
+#undef CHROMIUM_LOG
+#endif
+
+#if defined(MOZ_WIDGET_GONK)
+#include <android/log.h>
+#define CHROMIUM_LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "I/O", args);
+#else
+#include <stdio.h>
+#define IODEBUG true
+#define CHROMIUM_LOG(args...) if (IODEBUG) printf(args);
+#endif
+
 namespace mozilla {
 namespace ipc {
 namespace DaemonSocketPDUHelpers {
 
 //
 // Conversion
 //
 
@@ -225,11 +238,33 @@ UnpackPDU(DaemonSocketPDU& aPDU, const U
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
   *aOut.mString = NS_ConvertUTF8toUTF16(cstring);
 
   return NS_OK;
 }
 
+//
+// Init operators
+//
+
+void
+PDUInitOp::WarnAboutTrailingData() const
+{
+  size_t size = mPDU->GetSize();
+
+  if (MOZ_LIKELY(!size)) {
+    return;
+  }
+
+  uint8_t service, opcode;
+  uint16_t payloadSize;
+  mPDU->GetHeader(service, opcode, payloadSize);
+
+  CHROMIUM_LOG(
+    "Unpacked PDU of type (%x,%x) still contains %zu Bytes of data.",
+    service, opcode, size);
+}
+
 } // namespace DaemonSocketPDUHelpers
 } // namespace ipc
 } // namespace mozilla
--- a/ipc/hal/DaemonSocketPDUHelpers.h
+++ b/ipc/hal/DaemonSocketPDUHelpers.h
@@ -205,14 +205,109 @@ struct UnpackString0
 };
 
 /* This implementation of |UnpackPDU| unpacks a 0-terminated C string
  * and converts it to wide-character encoding.
  */
 nsresult
 UnpackPDU(DaemonSocketPDU& aPDU, const UnpackString0& aOut);
 
+//
+// Init operators
+//
+
+//
+// Below are general-purpose init operators for Bluetooth. The classes
+// of type |ConstantInitOp[1..3]| initialize results or notifications
+// with constant values.
+//
+
+template <typename T1>
+class ConstantInitOp1 final
+{
+public:
+  ConstantInitOp1(const T1& aArg1)
+    : mArg1(aArg1)
+  { }
+
+  nsresult operator () (T1& aArg1) const
+  {
+    aArg1 = mArg1;
+
+    return NS_OK;
+  }
+
+private:
+  const T1& mArg1;
+};
+
+template <typename T1, typename T2>
+class ConstantInitOp2 final
+{
+public:
+  ConstantInitOp2(const T1& aArg1, const T2& aArg2)
+    : mArg1(aArg1)
+    , mArg2(aArg2)
+  { }
+
+  nsresult operator () (T1& aArg1, T2& aArg2) const
+  {
+    aArg1 = mArg1;
+    aArg2 = mArg2;
+
+    return NS_OK;
+  }
+
+private:
+  const T1& mArg1;
+  const T2& mArg2;
+};
+
+template <typename T1, typename T2, typename T3>
+class ConstantInitOp3 final
+{
+public:
+  ConstantInitOp3(const T1& aArg1, const T2& aArg2, const T3& aArg3)
+    : mArg1(aArg1)
+    , mArg2(aArg2)
+    , mArg3(aArg3)
+  { }
+
+  nsresult operator () (T1& aArg1, T2& aArg2, T3& aArg3) const
+  {
+    aArg1 = mArg1;
+    aArg2 = mArg2;
+    aArg3 = mArg3;
+
+    return NS_OK;
+  }
+
+private:
+  const T1& mArg1;
+  const T2& mArg2;
+  const T3& mArg3;
+};
+
+// |PDUInitOP| provides functionality for init operators that unpack PDUs.
+class PDUInitOp
+{
+protected:
+  PDUInitOp(DaemonSocketPDU& aPDU)
+    : mPDU(&aPDU)
+  { }
+
+  DaemonSocketPDU& GetPDU() const
+  {
+    return *mPDU; // cannot be nullptr
+  }
+
+  void WarnAboutTrailingData() const;
+
+private:
+  DaemonSocketPDU* mPDU; // Hold pointer to allow for constant instances
+};
+
 } // namespace DaemonSocketPDUHelpers
 
 } // namespace ipc
 } // namespace mozilla
 
 #endif // mozilla_ipc_DaemonSocketPDUHelpers_h