Bug 1207649: Convert Bluetooth Socket backend to |BluetoothAddress|, r=brsun
☠☠ backed out by eb96b66e39e1 ☠ ☠
authorThomas Zimmermann <tdz@users.sourceforge.net>
Tue, 29 Sep 2015 14:07:01 +0200
changeset 265049 f03f71a3de8a647d7bfff0c1b6f42a11736f72df
parent 265048 9c647b56f37c13d05265848d19a11fbeb4bc60ff
child 265050 b906ed92f33a97060ae57711747f55dd789b3c70
push id65832
push userkwierso@gmail.com
push dateTue, 29 Sep 2015 23:14:05 +0000
treeherdermozilla-inbound@00ac696cdc86 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbrsun
bugs1207649
milestone44.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 1207649: Convert Bluetooth Socket backend to |BluetoothAddress|, r=brsun This patch converts all methods in Bluetooth's Socket interface to |BluetoothAddress|.
dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.h
dom/bluetooth/bluedroid/BluetoothSocket.cpp
dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.cpp
dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.h
dom/bluetooth/common/BluetoothInterface.cpp
dom/bluetooth/common/BluetoothInterface.h
--- a/dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.cpp
@@ -49,31 +49,31 @@ BluetoothDaemonSocketModule::ListenCmd(B
   if (NS_FAILED(rv)) {
     return rv;
   }
   unused << pdu.forget();
   return rv;
 }
 
 nsresult
-BluetoothDaemonSocketModule::ConnectCmd(const nsAString& aBdAddr,
+BluetoothDaemonSocketModule::ConnectCmd(const BluetoothAddress& aBdAddr,
                                         BluetoothSocketType aType,
                                         const BluetoothUuid& aServiceUuid,
                                         int aChannel, bool aEncrypt,
                                         bool aAuth,
                                         BluetoothSocketResultHandler* aRes)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   nsAutoPtr<DaemonSocketPDU> pdu(
     new DaemonSocketPDU(SERVICE_ID, OPCODE_CONNECT,
                         0));
 
   nsresult rv = PackPDU(
-    PackConversion<nsAString, BluetoothAddress>(aBdAddr),
+    aBdAddr,
     aType,
     aServiceUuid,
     PackConversion<int, int32_t>(aChannel),
     SocketFlags(aEncrypt, aAuth), *pdu);
   if (NS_FAILED(rv)) {
     return rv;
   }
   rv = Send(pdu, aRes);
@@ -116,20 +116,21 @@ class BluetoothDaemonSocketModule::Accep
 public:
   AcceptWatcher(int aFd, BluetoothSocketResultHandler* aRes)
   : SocketMessageWatcher(aFd, aRes)
   { }
 
   void Proceed(BluetoothStatus aStatus) override
   {
     if (aStatus == STATUS_SUCCESS) {
-      IntStringIntResultRunnable::Dispatch(
+      AcceptResultRunnable::Dispatch(
         GetResultHandler(), &BluetoothSocketResultHandler::Accept,
-        ConstantInitOp3<int, nsString, int>(GetClientFd(), GetBdAddress(),
-                                            GetConnectionStatus()));
+        ConstantInitOp3<int, BluetoothAddress, int>(GetClientFd(),
+                                                    GetBdAddress(),
+                                                    GetConnectionStatus()));
     } else {
       ErrorRunnable::Dispatch(GetResultHandler(),
                               &BluetoothSocketResultHandler::OnError,
                               ConstantInitOp1<BluetoothStatus>(aStatus));
     }
 
     MessageLoopForIO::current()->PostTask(
       FROM_HERE, new DeleteTask<AcceptWatcher>(this));
@@ -230,17 +231,17 @@ public:
   }
 };
 
 void
 BluetoothDaemonSocketModule::ListenRsp(const DaemonSocketPDUHeader& aHeader,
                                        DaemonSocketPDU& aPDU,
                                        BluetoothSocketResultHandler* aRes)
 {
-  IntResultRunnable::Dispatch(
+  ListenResultRunnable::Dispatch(
     aRes, &BluetoothSocketResultHandler::Listen, ListenInitOp(aPDU));
 }
 
 /* |ConnectWatcher| specializes SocketMessageWatcher for
  * connect operations by reading the socket messages from
  * Bluedroid and forwarding the connected socket to the
  * resource handler.
  */
@@ -250,20 +251,21 @@ class BluetoothDaemonSocketModule::Conne
 public:
   ConnectWatcher(int aFd, BluetoothSocketResultHandler* aRes)
   : SocketMessageWatcher(aFd, aRes)
   { }
 
   void Proceed(BluetoothStatus aStatus) override
   {
     if (aStatus == STATUS_SUCCESS) {
-      IntStringIntResultRunnable::Dispatch(
+      ConnectResultRunnable::Dispatch(
         GetResultHandler(), &BluetoothSocketResultHandler::Connect,
-        ConstantInitOp3<int, nsString, int>(GetFd(), GetBdAddress(),
-                                            GetConnectionStatus()));
+        ConstantInitOp3<int, BluetoothAddress, int>(GetFd(),
+                                                    GetBdAddress(),
+                                                    GetConnectionStatus()));
     } else {
       ErrorRunnable::Dispatch(GetResultHandler(),
                               &BluetoothSocketResultHandler::OnError,
                               ConstantInitOp1<BluetoothStatus>(aStatus));
     }
 
     MessageLoopForIO::current()->PostTask(
       FROM_HERE, new DeleteTask<ConnectWatcher>(this));
@@ -315,17 +317,17 @@ BluetoothDaemonSocketInterface::Listen(B
   nsresult rv = mModule->ListenCmd(aType, aServiceName, aServiceUuid,
                                    aChannel, aEncrypt, aAuth, aRes);
   if (NS_FAILED(rv))  {
     DispatchError(aRes, rv);
   }
 }
 
 void
-BluetoothDaemonSocketInterface::Connect(const nsAString& aBdAddr,
+BluetoothDaemonSocketInterface::Connect(const BluetoothAddress& aBdAddr,
                                         BluetoothSocketType aType,
                                         const BluetoothUuid& aServiceUuid,
                                         int aChannel, bool aEncrypt,
                                         bool aAuth,
                                         BluetoothSocketResultHandler* aRes)
 {
   MOZ_ASSERT(mModule);
 
--- a/dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.h
@@ -39,17 +39,17 @@ public:
   //
 
   nsresult ListenCmd(BluetoothSocketType aType,
                      const nsAString& aServiceName,
                      const BluetoothUuid& aServiceUuid,
                      int aChannel, bool aEncrypt, bool aAuth,
                      BluetoothSocketResultHandler* aRes);
 
-  nsresult ConnectCmd(const nsAString& aBdAddr,
+  nsresult ConnectCmd(const BluetoothAddress& aBdAddr,
                       BluetoothSocketType aType,
                       const BluetoothUuid& aServiceUuid,
                       int aChannel, bool aEncrypt, bool aAuth,
                       BluetoothSocketResultHandler* aRes);
 
   nsresult AcceptCmd(int aFd, BluetoothSocketResultHandler* aRes);
 
   nsresult CloseCmd(BluetoothSocketResultHandler* aRes);
@@ -64,32 +64,37 @@ private:
   class ConnectWatcher;
   class ListenInitOp;
 
   uint8_t SocketFlags(bool aEncrypt, bool aAuth);
 
   // Responses
   //
 
-  typedef mozilla::ipc::DaemonResultRunnable0<
-    BluetoothSocketResultHandler, void>
-    ResultRunnable;
+  typedef mozilla::ipc::DaemonResultRunnable3<
+    BluetoothSocketResultHandler, void, int, BluetoothAddress, int, int,
+    const BluetoothAddress&, int>
+    AcceptResultRunnable;
 
-  typedef mozilla::ipc::DaemonResultRunnable1<
-    BluetoothSocketResultHandler, void, int, int>
-    IntResultRunnable;
+  typedef mozilla::ipc::DaemonResultRunnable3<
+    BluetoothSocketResultHandler, void, int, BluetoothAddress, int, int,
+    const BluetoothAddress&, int>
+    ConnectResultRunnable;
 
   typedef mozilla::ipc::DaemonResultRunnable1<
     BluetoothSocketResultHandler, void, BluetoothStatus, BluetoothStatus>
     ErrorRunnable;
 
-  typedef mozilla::ipc::DaemonResultRunnable3<
-    BluetoothSocketResultHandler, void, int, nsString, int, int,
-    const nsAString_internal&, int>
-    IntStringIntResultRunnable;
+  typedef mozilla::ipc::DaemonResultRunnable1<
+    BluetoothSocketResultHandler, void, int, int>
+    ListenResultRunnable;
+
+  typedef mozilla::ipc::DaemonResultRunnable0<
+    BluetoothSocketResultHandler, void>
+    ResultRunnable;
 
   void ErrorRsp(const DaemonSocketPDUHeader& aHeader,
                 DaemonSocketPDU& aPDU,
                 BluetoothSocketResultHandler* aRes);
 
   void ListenRsp(const DaemonSocketPDUHeader& aHeader,
                  DaemonSocketPDU& aPDU,
                  BluetoothSocketResultHandler* aRes);
@@ -107,17 +112,17 @@ public:
   ~BluetoothDaemonSocketInterface();
 
   void Listen(BluetoothSocketType aType,
               const nsAString& aServiceName,
               const BluetoothUuid& aServiceUuid,
               int aChannel, bool aEncrypt, bool aAuth,
               BluetoothSocketResultHandler* aRes) override;
 
-  void Connect(const nsAString& aBdAddr,
+  void Connect(const BluetoothAddress& aBdAddr,
                BluetoothSocketType aType,
                const BluetoothUuid& aServiceUuid,
                int aChannel, bool aEncrypt, bool aAuth,
                BluetoothSocketResultHandler* aRes) override;
 
   void Accept(int aFd, BluetoothSocketResultHandler* aRes) override;
 
   void Close(BluetoothSocketResultHandler* aRes) override;
--- a/dom/bluetooth/bluedroid/BluetoothSocket.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothSocket.cpp
@@ -381,34 +381,37 @@ class AcceptResultHandler final : public
 {
 public:
   AcceptResultHandler(DroidSocketImpl* aImpl)
   : mImpl(aImpl)
   {
     MOZ_ASSERT(mImpl);
   }
 
-  void Accept(int aFd, const nsAString& aBdAddress,
+  void Accept(int aFd, const BluetoothAddress& aBdAddress,
               int aConnectionStatus) override
   {
     MOZ_ASSERT(mImpl->IsConsumerThread());
 
     mozilla::ScopedClose fd(aFd); // Close received socket fd on error
 
     if (mImpl->IsShutdownOnConsumerThread()) {
       BT_LOGD("mConsumer is null, aborting receive!");
       return;
     }
 
     if (aConnectionStatus != 0) {
       mImpl->mConsumer->NotifyError();
       return;
     }
 
-    mImpl->mConsumer->SetAddress(aBdAddress);
+    nsAutoString addressStr;
+    AddressToString(aBdAddress, addressStr);
+
+    mImpl->mConsumer->SetAddress(addressStr);
     mImpl->GetIOLoop()->PostTask(FROM_HERE,
                                  new AcceptTask(mImpl, fd.forget()));
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
     MOZ_ASSERT(mImpl->IsConsumerThread());
     BT_LOGR("BluetoothSocketInterface::Accept failed: %d", (int)aStatus);
@@ -602,32 +605,35 @@ class ConnectSocketResultHandler final :
 {
 public:
   ConnectSocketResultHandler(DroidSocketImpl* aImpl)
   : mImpl(aImpl)
   {
     MOZ_ASSERT(mImpl);
   }
 
-  void Connect(int aFd, const nsAString& aBdAddress,
+  void Connect(int aFd, const BluetoothAddress& aBdAddress,
                int aConnectionStatus) override
   {
     MOZ_ASSERT(mImpl->IsConsumerThread());
 
     if (mImpl->IsShutdownOnConsumerThread()) {
       BT_LOGD("mConsumer is null, aborting send!");
       return;
     }
 
     if (aConnectionStatus != 0) {
       mImpl->mConsumer->NotifyError();
       return;
     }
 
-    mImpl->mConsumer->SetAddress(aBdAddress);
+    nsAutoString addressStr;
+    AddressToString(aBdAddress, addressStr);
+
+    mImpl->mConsumer->SetAddress(addressStr);
     mImpl->GetIOLoop()->PostTask(FROM_HERE,
                                  new SocketConnectTask(mImpl, aFd));
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
     MOZ_ASSERT(mImpl->IsConsumerThread());
     BT_WARNING("Connect failed: %d", (int)aStatus);
@@ -658,18 +664,24 @@ BluetoothSocket::Connect(const nsAString
 
   SetConnectionStatus(SOCKET_CONNECTING);
 
   mImpl = new DroidSocketImpl(aConsumerLoop, aIOLoop, this);
 
   BluetoothSocketResultHandler* res = new ConnectSocketResultHandler(mImpl);
   SetCurrentResultHandler(res);
 
+  BluetoothAddress deviceAddress;
+  nsresult rv = StringToAddress(aDeviceAddress, deviceAddress);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+
   sBluetoothSocketInterface->Connect(
-    aDeviceAddress, aType,
+    deviceAddress, aType,
     aServiceUuid, aChannel,
     aEncrypt, aAuth, res);
 
   return NS_OK;
 }
 
 nsresult
 BluetoothSocket::Connect(const nsAString& aDeviceAddress,
--- a/dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.cpp
@@ -130,20 +130,20 @@ SocketMessageWatcher::GetChannel1() cons
 }
 
 int32_t
 SocketMessageWatcher::GetSize() const
 {
   return ReadInt16(OFF_SIZE);
 }
 
-nsString
+BluetoothAddress
 SocketMessageWatcher::GetBdAddress() const
 {
-  nsString bdAddress;
+  BluetoothAddress bdAddress;
   ReadBdAddress(OFF_BDADDRESS, bdAddress);
   return bdAddress;
 }
 
 int32_t
 SocketMessageWatcher::GetChannel2() const
 {
   return ReadInt32(OFF_CHANNEL2);
@@ -254,34 +254,24 @@ SocketMessageWatcher::ReadInt32(unsigned
   return (static_cast<int32_t>(mBuf[aOffset + 3]) << 24) |
          (static_cast<int32_t>(mBuf[aOffset + 2]) << 16) |
          (static_cast<int32_t>(mBuf[aOffset + 1]) << 8) |
           static_cast<int32_t>(mBuf[aOffset]);
 }
 
 void
 SocketMessageWatcher::ReadBdAddress(unsigned long aOffset,
-                                    nsAString& aBdAddress) const
+                                    BluetoothAddress& aBdAddress) const
 {
-  char str[BLUETOOTH_ADDRESS_LENGTH + 1];
-
-  int res = snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
-                     static_cast<int>(mBuf[aOffset + 0]),
-                     static_cast<int>(mBuf[aOffset + 1]),
-                     static_cast<int>(mBuf[aOffset + 2]),
-                     static_cast<int>(mBuf[aOffset + 3]),
-                     static_cast<int>(mBuf[aOffset + 4]),
-                     static_cast<int>(mBuf[aOffset + 5]));
-  if (res < 0) {
-    aBdAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
-  } else if ((size_t)res >= sizeof(str)) { /* string buffer too small */
-    aBdAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
-  } else {
-    aBdAddress = NS_ConvertUTF8toUTF16(str);
-  }
+  aBdAddress = BluetoothAddress(mBuf[aOffset + 0],
+                                mBuf[aOffset + 1],
+                                mBuf[aOffset + 2],
+                                mBuf[aOffset + 3],
+                                mBuf[aOffset + 4],
+                                mBuf[aOffset + 5]);
 }
 
 //
 // SocketMessageWatcherTask
 //
 
 SocketMessageWatcherTask::SocketMessageWatcherTask(
   SocketMessageWatcher* aWatcher)
--- a/dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.h
+++ b/dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.h
@@ -47,36 +47,36 @@ public:
   void OnFileCanReadWithoutBlocking(int aFd) override;
   void OnFileCanWriteWithoutBlocking(int aFd) override;
 
   void Watch();
   void StopWatching();
 
   bool IsComplete() const;
 
-  int      GetFd() const;
-  int32_t  GetChannel1() const;
-  int32_t  GetSize() const;
-  nsString GetBdAddress() const;
-  int32_t  GetChannel2() const;
-  int32_t  GetConnectionStatus() const;
-  int      GetClientFd() const;
+  int              GetFd() const;
+  int32_t          GetChannel1() const;
+  int32_t          GetSize() const;
+  BluetoothAddress GetBdAddress() const;
+  int32_t          GetChannel2() const;
+  int32_t          GetConnectionStatus() const;
+  int              GetClientFd() const;
 
   BluetoothSocketResultHandler* GetResultHandler() const;
 
 protected:
   SocketMessageWatcher(int aFd, BluetoothSocketResultHandler* aRes);
 
 private:
   BluetoothStatus RecvMsg1();
   BluetoothStatus RecvMsg2();
 
   int16_t ReadInt16(unsigned long aOffset) const;
   int32_t ReadInt32(unsigned long aOffset) const;
-  void    ReadBdAddress(unsigned long aOffset, nsAString& aBdAddress) const;
+  void    ReadBdAddress(unsigned long aOffset, BluetoothAddress& aBdAddress) const;
 
   MessageLoopForIO::FileDescriptorWatcher mWatcher;
   int mFd;
   int mClientFd;
   unsigned char mLen;
   uint8_t mBuf[MSG1_SIZE + MSG2_SIZE];
   nsRefPtr<BluetoothSocketResultHandler> mRes;
 };
--- a/dom/bluetooth/common/BluetoothInterface.cpp
+++ b/dom/bluetooth/common/BluetoothInterface.cpp
@@ -53,23 +53,23 @@ BluetoothSocketResultHandler::OnError(Bl
 }
 
 void
 BluetoothSocketResultHandler::Listen(int aSockFd)
 { }
 
 void
 BluetoothSocketResultHandler::Connect(int aSockFd,
-                                      const nsAString& aBdAddress,
+                                      const BluetoothAddress& aBdAddress,
                                       int aConnectionState)
 { }
 
 void
 BluetoothSocketResultHandler::Accept(int aSockFd,
-                                     const nsAString& aBdAddress,
+                                     const BluetoothAddress& aBdAddress,
                                      int aConnectionState)
 { }
 
 // Interface
 //
 
 BluetoothSocketInterface::~BluetoothSocketInterface()
 { }
--- a/dom/bluetooth/common/BluetoothInterface.h
+++ b/dom/bluetooth/common/BluetoothInterface.h
@@ -36,19 +36,19 @@ protected:
 
 class BluetoothSocketResultHandler
   : public mozilla::ipc::DaemonSocketResultHandler
 {
 public:
   virtual void OnError(BluetoothStatus aStatus);
 
   virtual void Listen(int aSockFd);
-  virtual void Connect(int aSockFd, const nsAString& aBdAddress,
+  virtual void Connect(int aSockFd, const BluetoothAddress& aBdAddress,
                        int aConnectionState);
-  virtual void Accept(int aSockFd, const nsAString& aBdAddress,
+  virtual void Accept(int aSockFd, const BluetoothAddress& aBdAddress,
                       int aConnectionState);
 
 protected:
   virtual ~BluetoothSocketResultHandler() { }
 };
 
 class BluetoothSocketInterface
 {
@@ -56,17 +56,17 @@ public:
   // Init and Cleanup is handled by BluetoothInterface
 
   virtual void Listen(BluetoothSocketType aType,
                       const nsAString& aServiceName,
                       const BluetoothUuid& aServiceUuid,
                       int aChannel, bool aEncrypt, bool aAuth,
                       BluetoothSocketResultHandler* aRes) = 0;
 
-  virtual void Connect(const nsAString& aBdAddr,
+  virtual void Connect(const BluetoothAddress& aBdAddr,
                        BluetoothSocketType aType,
                        const BluetoothUuid& aServiceUuid,
                        int aChannel, bool aEncrypt, bool aAuth,
                        BluetoothSocketResultHandler* aRes) = 0;
 
   virtual void Accept(int aFd, BluetoothSocketResultHandler* aRes) = 0;
 
   virtual void Close(BluetoothSocketResultHandler* aRes) = 0;