Bug 811946 - remove annoying compiler warnings and define a more structured interface for Bluetooth uuid, r=qdot
authorEric Chou <echou@mozilla.com>
Tue, 27 Nov 2012 14:12:19 +0800
changeset 114187 16da7572338e2b508054f1b2e234e75651e0269b
parent 114186 e37de84261fde584cc5c7b9759a968854e6600fd
child 114188 62bb8cc3277b602dc1512b8542467a4af0abd923
push id18619
push userechou@mozilla.com
push dateTue, 27 Nov 2012 06:13:29 +0000
treeherdermozilla-inbound@16da7572338e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs811946
milestone20.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 811946 - remove annoying compiler warnings and define a more structured interface for Bluetooth uuid, r=qdot
dom/bluetooth/BluetoothAdapter.cpp
dom/bluetooth/BluetoothDevice.cpp
dom/bluetooth/BluetoothHfpManager.cpp
dom/bluetooth/BluetoothOppManager.cpp
dom/bluetooth/BluetoothScoManager.cpp
dom/bluetooth/BluetoothServiceUuid.h
dom/bluetooth/BluetoothUuid.cpp
dom/bluetooth/BluetoothUuid.h
dom/bluetooth/Makefile.in
dom/bluetooth/linux/BluetoothDBusService.cpp
--- a/dom/bluetooth/BluetoothAdapter.cpp
+++ b/dom/bluetooth/BluetoothAdapter.cpp
@@ -5,17 +5,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "base/basictypes.h"
 #include "BluetoothAdapter.h"
 #include "BluetoothDevice.h"
 #include "BluetoothPropertyEvent.h"
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothService.h"
-#include "BluetoothServiceUuid.h"
 #include "BluetoothUtils.h"
 #include "GeneratedEvents.h"
 
 #include "nsContentUtils.h"
 #include "nsDOMClassInfo.h"
 #include "nsDOMEvent.h"
 #include "nsIDOMBluetoothDeviceAddressEvent.h"
 #include "nsIDOMBluetoothDeviceEvent.h"
--- a/dom/bluetooth/BluetoothDevice.cpp
+++ b/dom/bluetooth/BluetoothDevice.cpp
@@ -5,17 +5,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "base/basictypes.h"
 #include "BluetoothDevice.h"
 #include "BluetoothPropertyEvent.h"
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothService.h"
 #include "BluetoothUtils.h"
-#include "BluetoothServiceUuid.h"
 
 #include "nsIDOMDOMRequest.h"
 #include "nsDOMClassInfo.h"
 #include "nsContentUtils.h"
 #include "nsTArrayHelpers.h"
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 
 USING_BLUETOOTH_NAMESPACE
--- a/dom/bluetooth/BluetoothHfpManager.cpp
+++ b/dom/bluetooth/BluetoothHfpManager.cpp
@@ -6,34 +6,32 @@
 
 #include "base/basictypes.h" 
 
 #include "BluetoothHfpManager.h"
 
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothScoManager.h"
 #include "BluetoothService.h"
-#include "BluetoothServiceUuid.h"
 #include "BluetoothUtils.h"
+#include "BluetoothUuid.h"
 
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "nsContentUtils.h"
 #include "nsIAudioManager.h"
 #include "nsIObserverService.h"
 #include "nsISettingsService.h"
 #include "nsIRadioInterfaceLayer.h"
 
 #include <unistd.h> /* usleep() */
 
 #define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
 #define AUDIO_VOLUME_BT_SCO "audio.volume.bt_sco"
-#define HANDSFREE_UUID mozilla::dom::bluetooth::BluetoothServiceUuidStr::Handsfree
-#define HEADSET_UUID mozilla::dom::bluetooth::BluetoothServiceUuidStr::Headset
 
 using namespace mozilla;
 using namespace mozilla::ipc;
 USING_BLUETOOTH_NAMESPACE
 
 /* CallState for sCINDItems[CINDType::CALL].value
  * - NO_CALL: there are no calls in progress
  * - IN_PROGRESS: at least one call is in progress
@@ -618,27 +616,27 @@ BluetoothHfpManager::Connect(const nsASt
     return false;
   }
 
   CloseSocket();
 
   BluetoothService* bs = BluetoothService::Get();
   NS_ENSURE_TRUE(bs, false);
 
-  nsString serviceUuidStr;
+  nsString uuid;
   if (aIsHandsfree) {
-    serviceUuidStr = NS_ConvertUTF8toUTF16(HANDSFREE_UUID);
+    BluetoothUuidHelper::GetString(BluetoothServiceClass::HANDSFREE, uuid);
   } else {
-    serviceUuidStr = NS_ConvertUTF8toUTF16(HEADSET_UUID);
+    BluetoothUuidHelper::GetString(BluetoothServiceClass::HEADSET, uuid);
   }
 
   mRunnable = aRunnable;
 
   nsresult rv = bs->GetSocketViaService(aDevicePath,
-                                        serviceUuidStr,
+                                        uuid,
                                         BluetoothSocketType::RFCOMM,
                                         true,
                                         true,
                                         this,
                                         mRunnable);
 
   return NS_FAILED(rv) ? false : true;
 }
@@ -653,21 +651,22 @@ BluetoothHfpManager::Listen()
     return false;
   }
 
   CloseSocket();
 
   BluetoothService* bs = BluetoothService::Get();
   NS_ENSURE_TRUE(bs, false);
 
-  nsresult rv = bs->ListenSocketViaService(BluetoothReservedChannels::HANDSFREE_AG,
-                                           BluetoothSocketType::RFCOMM,
-                                           true,
-                                           true,
-                                           this);
+  nsresult rv =
+    bs->ListenSocketViaService(BluetoothReservedChannels::CHANNEL_HANDSFREE_AG,
+                               BluetoothSocketType::RFCOMM,
+                               true,
+                               true,
+                               this);
 
   mSocketStatus = GetConnectionStatus();
 
   return NS_FAILED(rv) ? false : true;
 }
 
 void
 BluetoothHfpManager::Disconnect()
--- a/dom/bluetooth/BluetoothOppManager.cpp
+++ b/dom/bluetooth/BluetoothOppManager.cpp
@@ -4,18 +4,18 @@
  * 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 "base/basictypes.h"
 #include "BluetoothOppManager.h"
 
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothService.h"
-#include "BluetoothServiceUuid.h"
 #include "BluetoothUtils.h"
+#include "BluetoothUuid.h"
 #include "ObexBase.h"
 
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "nsCExternalHandlerService.h"
 #include "nsIObserver.h"
@@ -202,23 +202,23 @@ BluetoothOppManager::Connect(const nsASt
   CloseSocket();
 
   BluetoothService* bs = BluetoothService::Get();
   if (!bs) {
     NS_WARNING("BluetoothService not available!");
     return false;
   }
 
-  nsString serviceUuidStr =
-    NS_ConvertUTF8toUTF16(BluetoothServiceUuidStr::ObjectPush);
+  nsString uuid;
+  BluetoothUuidHelper::GetString(BluetoothServiceClass::OBJECT_PUSH, uuid);
 
   mRunnable = aRunnable;
 
   nsresult rv = bs->GetSocketViaService(aDeviceObjectPath,
-                                        serviceUuidStr,
+                                        uuid,
                                         BluetoothSocketType::RFCOMM,
                                         true,
                                         true,
                                         this,
                                         mRunnable);
 
   return NS_FAILED(rv) ? false : true;
 }
@@ -252,21 +252,22 @@ BluetoothOppManager::Listen()
   CloseSocket();
 
   BluetoothService* bs = BluetoothService::Get();
   if (!bs) {
     NS_WARNING("BluetoothService not available!");
     return false;
   }
 
-  nsresult rv = bs->ListenSocketViaService(BluetoothReservedChannels::OPUSH,
-                                           BluetoothSocketType::RFCOMM,
-                                           true,
-                                           true,
-                                           this);
+  nsresult rv =
+    bs->ListenSocketViaService(BluetoothReservedChannels::CHANNEL_OPUSH,
+                               BluetoothSocketType::RFCOMM,
+                               true,
+                               true,
+                               this);
   mSocketStatus = GetConnectionStatus();
 
   return NS_FAILED(rv) ? false : true;
 }
 
 bool
 BluetoothOppManager::SendFile(BlobParent* aActor)
 {
--- a/dom/bluetooth/BluetoothScoManager.cpp
+++ b/dom/bluetooth/BluetoothScoManager.cpp
@@ -5,17 +5,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "base/basictypes.h"
 
 #include "BluetoothScoManager.h"
 
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothService.h"
-#include "BluetoothServiceUuid.h"
 #include "BluetoothUtils.h"
 
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 #include "nsContentUtils.h"
 #include "nsIAudioManager.h"
 #include "nsIObserverService.h"
deleted file mode 100644
--- a/dom/bluetooth/BluetoothServiceUuid.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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/. */
-
-#ifndef mozilla_dom_bluetooth_bluetoothuuid_h__
-#define mozilla_dom_bluetooth_bluetoothuuid_h__
-
-namespace mozilla {
-namespace dom {
-namespace bluetooth {
-
-namespace BluetoothServiceUuid {
-  static unsigned long long Headset      = 0x0000110800000000;
-  static unsigned long long HeadsetAG    = 0x0000111200000000;
-  static unsigned long long Handsfree    = 0x0000111E00000000;
-  static unsigned long long HandsfreeAG  = 0x0000111F00000000;
-  static unsigned long long ObjectPush   = 0x0000110500000000;
-
-  static unsigned long long BaseMSB     = 0x0000000000001000;
-  static unsigned long long BaseLSB     = 0x800000805F9B34FB;
-}
-
-namespace BluetoothServiceUuidStr {
-  static const char* Headset       = "00001108-0000-1000-8000-00805F9B34FB";
-  static const char* HeadsetAG     = "00001112-0000-1000-8000-00805F9B34FB";
-  static const char* Handsfree     = "0000111E-0000-1000-8000-00805F9B34FB";
-  static const char* HandsfreeAG   = "0000111F-0000-1000-8000-00805F9B34FB";
-  static const char* ObjectPush    = "00001105-0000-1000-8000-00805F9B34FB";
-}
-
-// TODO/qdot: Move these back into gonk and make the service handler deal with
-// it there.
-//
-// Gotten from reading the "u8" values in B2G/external/bluez/src/adapter.c
-// These were hardcoded into android
-enum BluetoothReservedChannels {
-  DIALUP_NETWORK = 1,
-  HANDSFREE_AG = 10,
-  HEADSET_AG = 11,
-  OPUSH = 12,
-  SIM_ACCESS = 15,
-  PBAP_PSE = 19,
-  FTP = 20,
-};
-
-}
-}
-}
-
-#endif
-
new file mode 100644
--- /dev/null
+++ b/dom/bluetooth/BluetoothUuid.cpp
@@ -0,0 +1,20 @@
+/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
+/* vim: set ts=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 "BluetoothUuid.h"
+
+USING_BLUETOOTH_NAMESPACE
+
+void
+BluetoothUuidHelper::GetString(BluetoothServiceClass aServiceClassUuid,
+                               nsAString& aRetUuidStr)
+{
+  aRetUuidStr.Truncate();
+
+  aRetUuidStr.AppendLiteral("0000");
+  aRetUuidStr.AppendInt(aServiceClassUuid, 16);
+  aRetUuidStr.AppendLiteral("-0000-1000-8000-00805F9B34FB");
+}
new file mode 100644
--- /dev/null
+++ b/dom/bluetooth/BluetoothUuid.h
@@ -0,0 +1,63 @@
+/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
+/* vim: set ts=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/. */
+
+#ifndef mozilla_dom_bluetooth_bluetoothuuid_h__
+#define mozilla_dom_bluetooth_bluetoothuuid_h__
+
+#include "BluetoothCommon.h"
+
+BEGIN_BLUETOOTH_NAMESPACE
+
+/*
+ * Service classes and Profile Identifiers
+ *
+ * Supported Bluetooth services for v1 are listed as below.
+ *
+ * The value of each service class is defined in "AssignedNumbers/Service
+ * Discovery Protocol (SDP)/Service classes and Profile Identifiers" in the
+ * Bluetooth Core Specification.
+ */
+enum BluetoothServiceClass
+{
+  HEADSET       = 0x1108,
+  HEADSET_AG    = 0x1112,
+  HANDSFREE     = 0x111E,
+  HANDSFREE_AG  = 0x111F,
+  OBJECT_PUSH   = 0x1105
+};
+
+class BluetoothUuidHelper
+{
+public:
+  /**
+   * Get a 128-bit uuid string calculated from a 16-bit service class UUID and
+   * BASE_UUID
+   *
+   * @param aServiceClassUuid  16-bit service class UUID
+   * @param aRetUuidStr  out parameter, 128-bit uuid string
+   */
+  static void
+  GetString(BluetoothServiceClass aServiceClassUuid, nsAString& aRetUuidStr);
+};
+
+// TODO/qdot: Move these back into gonk and make the service handler deal with
+// it there.
+//
+// Gotten from reading the "u8" values in B2G/external/bluez/src/adapter.c
+// These were hardcoded into android
+enum BluetoothReservedChannels {
+  CHANNEL_DIALUP_NETWORK = 1,
+  CHANNEL_HANDSFREE_AG = 10,
+  CHANNEL_HEADSET_AG = 11,
+  CHANNEL_OPUSH = 12,
+  CHANNEL_SIM_ACCESS = 15,
+  CHANNEL_PBAP_PSE = 19,
+  CHANNEL_FTP = 20,
+};
+
+END_BLUETOOTH_NAMESPACE
+
+#endif
--- a/dom/bluetooth/Makefile.in
+++ b/dom/bluetooth/Makefile.in
@@ -51,16 +51,17 @@ CPPSRCS += \
   BluetoothChild.cpp \
   BluetoothParent.cpp \
   BluetoothServiceChildProcess.cpp \
   BluetoothUnixSocketConnector.cpp \
   BluetoothHfpManager.cpp \
   BluetoothOppManager.cpp \
   ObexBase.cpp \
   BluetoothScoManager.cpp \
+  BluetoothUuid.cpp \
   $(NULL)
 
 ifdef MOZ_B2G_RIL
 CPPSRCS += BluetoothRilListener.cpp
 endif
 
 XPIDLSRCS = \
   nsIDOMNavigatorBluetooth.idl \
--- a/dom/bluetooth/linux/BluetoothDBusService.cpp
+++ b/dom/bluetooth/linux/BluetoothDBusService.cpp
@@ -17,19 +17,19 @@
 */
 
 #include "base/basictypes.h"
 #include "BluetoothDBusService.h"
 #include "BluetoothHfpManager.h"
 #include "BluetoothOppManager.h"
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothScoManager.h"
-#include "BluetoothServiceUuid.h"
 #include "BluetoothUnixSocketConnector.h"
 #include "BluetoothUtils.h"
+#include "BluetoothUuid.h"
 
 #include <cstdio>
 #include <dbus/dbus.h>
 
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 #include "nsDebug.h"
 #include "nsDataHashtable.h"
@@ -761,19 +761,19 @@ public:
 
   NS_IMETHOD
   Run()
   {
     MOZ_ASSERT(!NS_IsMainThread());
 
     nsTArray<uint32_t> uuids;
 
-    uuids.AppendElement((uint32_t)(BluetoothServiceUuid::HandsfreeAG >> 32));
-    uuids.AppendElement((uint32_t)(BluetoothServiceUuid::HeadsetAG >> 32));
-    uuids.AppendElement((uint32_t)(BluetoothServiceUuid::ObjectPush >> 32));
+    uuids.AppendElement(BluetoothServiceClass::HANDSFREE_AG);
+    uuids.AppendElement(BluetoothServiceClass::HEADSET_AG);
+    uuids.AppendElement(BluetoothServiceClass::OBJECT_PUSH);
 
     // TODO/qdot: This needs to be held for the life of the bluetooth connection
     // so we could clean it up. For right now though, we can throw it away.
     nsTArray<uint32_t> handles;
 
     if (!BluetoothDBusService::AddReservedServicesInternal(mPath, uuids, handles)) {
       NS_WARNING("Failed to add reserved services");
 #ifdef MOZ_WIDGET_GONK
@@ -2308,31 +2308,31 @@ BluetoothDBusService::Connect(const nsAS
                               const nsAString& aAdapterPath,
                               const uint16_t aProfileId,
                               BluetoothReplyRunnable* aRunnable)
 {
   NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
 
   BluetoothValue v;
   nsString errorStr;
-  if (aProfileId == (uint16_t)(BluetoothServiceUuid::Handsfree >> 32)) {
+  if (aProfileId == BluetoothServiceClass::HANDSFREE) {
     BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
     if (!hfp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
                       true, aRunnable)) {
       errorStr.AssignLiteral("BluetoothHfpManager has connected/is connecting to a headset!");
       DispatchBluetoothReply(aRunnable, v, errorStr);
     }
-  } else if (aProfileId == (uint16_t)(BluetoothServiceUuid::Headset >> 32)) {
+  } else if (aProfileId == BluetoothServiceClass::HEADSET) {
     BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
     if (!hfp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
                       false, aRunnable)) {
       errorStr.AssignLiteral("BluetoothHfpManager has connected/is connecting to a headset!");
       DispatchBluetoothReply(aRunnable, v, errorStr);
     }
-  } else if (aProfileId == (uint16_t)(BluetoothServiceUuid::ObjectPush >> 32)) {
+  } else if (aProfileId == BluetoothServiceClass::OBJECT_PUSH) {
     BluetoothOppManager* opp = BluetoothOppManager::Get();
     if (!opp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
                       aRunnable)) {
       errorStr.AssignLiteral("BluetoothOppManager has connected/is connecting!");
       DispatchBluetoothReply(aRunnable, v, errorStr);
     }
   }
 
@@ -2340,21 +2340,21 @@ BluetoothDBusService::Connect(const nsAS
   NS_WARNING("Unknown Profile");
 #endif
 }
 
 void
 BluetoothDBusService::Disconnect(const uint16_t aProfileId,
                                  BluetoothReplyRunnable* aRunnable)
 {
-  if (aProfileId == (uint16_t)(BluetoothServiceUuid::Handsfree >> 32) ||
-      aProfileId == (uint16_t)(BluetoothServiceUuid::Headset >> 32)) {
+  if (aProfileId == BluetoothServiceClass::HANDSFREE ||
+      aProfileId == BluetoothServiceClass::HEADSET) {
     BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
     hfp->Disconnect();
-  } else if (aProfileId == (uint16_t)(BluetoothServiceUuid::ObjectPush >> 32)) {
+  } else if (aProfileId == BluetoothServiceClass::OBJECT_PUSH) {
     BluetoothOppManager* opp = BluetoothOppManager::Get();
     opp->Disconnect();
   } else {
     NS_WARNING("Unknown profile");
     return;
   }
 
   // Currently, just fire success because Disconnect() doesn't fail, 
@@ -2365,21 +2365,21 @@ BluetoothDBusService::Disconnect(const u
   DispatchBluetoothReply(aRunnable, v, replyError);
 }
 
 bool
 BluetoothDBusService::IsConnected(const uint16_t aProfileId)
 {
   NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
 
-  if (aProfileId == (uint16_t)(BluetoothServiceUuid::Handsfree >> 32)
-      || aProfileId == (uint16_t)(BluetoothServiceUuid::Headset >> 32)) {
+  if (aProfileId == BluetoothServiceClass::HANDSFREE ||
+      aProfileId == BluetoothServiceClass::HEADSET) {
     BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
     return hfp->GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED;
-  } else if (aProfileId == (uint16_t)(BluetoothServiceUuid::ObjectPush >> 32)) {
+  } else if (aProfileId == BluetoothServiceClass::OBJECT_PUSH) {
     BluetoothOppManager* opp = BluetoothOppManager::Get();
     return opp->GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED;
   }
 
   return false;
 }
 
 class ConnectBluetoothSocketRunnable : public nsRunnable