Bug 834551 - Add Bluetooth debugging flag, r=qdot
authorEric Chou <echou@mozilla.com>
Tue, 29 Jan 2013 18:37:51 +0800
changeset 130061 901abfff0d3474b9b387ad3a92790b5a20b7c1d4
parent 130060 2b9ae5e6cd9b026dfdc94b8236b17d066c310963
child 130062 07fb7c433d4aad1f904bf5fe0409bbe550f1588c
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs834551
milestone21.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 834551 - Add Bluetooth debugging flag, r=qdot
dom/bluetooth/BluetoothCommon.h
dom/bluetooth/BluetoothService.cpp
--- a/dom/bluetooth/BluetoothCommon.h
+++ b/dom/bluetooth/BluetoothCommon.h
@@ -6,16 +6,38 @@
 
 #ifndef mozilla_dom_bluetooth_bluetoothcommon_h__
 #define mozilla_dom_bluetooth_bluetoothcommon_h__
 
 #include "mozilla/Observer.h"
 #include "nsStringGlue.h"
 #include "nsTArray.h"
 
+extern bool gBluetoothDebugFlag;
+
+#define SWITCH_BT_DEBUG(V) (gBluetoothDebugFlag = V)
+
+#undef BT_LOG
+#if defined(MOZ_WIDGET_GONK)
+#include <android/log.h>
+#define BT_LOG(args...)                                              \
+  do {                                                               \
+    if (gBluetoothDebugFlag) {                                       \
+      __android_log_print(ANDROID_LOG_INFO, "GeckoBluetooth", args); \
+    }                                                                \
+  } while(0)
+#else
+#define BT_LOG(args...)                                              \
+  do {                                                               \
+    if (gBluetoothDebugFlag) {                                       \
+      printf(args);                                                  \
+    }                                                                \
+  } while(0)
+#endif
+
 #define BEGIN_BLUETOOTH_NAMESPACE \
   namespace mozilla { namespace dom { namespace bluetooth {
 #define END_BLUETOOTH_NAMESPACE \
   } /* namespace bluetooth */ } /* namespace dom */ } /* namespace mozilla */
 #define USING_BLUETOOTH_NAMESPACE \
   using namespace mozilla::dom::bluetooth;
 
 #define LOCAL_AGENT_PATH  "/B2G/bluetooth/agent"
--- a/dom/bluetooth/BluetoothService.cpp
+++ b/dom/bluetooth/BluetoothService.cpp
@@ -35,21 +35,24 @@
 #  include "BluetoothGonkService.h"
 # elif defined(MOZ_BLUETOOTH_DBUS)
 #  include "BluetoothDBusService.h"
 # else
 #  error No_suitable_backend_for_bluetooth!
 # endif
 #endif
 
-#define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
-#define BLUETOOTH_ENABLED_SETTING "bluetooth.enabled"
+#define MOZSETTINGS_CHANGED_ID      "mozsettings-changed"
+#define BLUETOOTH_ENABLED_SETTING   "bluetooth.enabled"
+#define BLUETOOTH_DEBUGGING_SETTING "bluetooth.debugging.enabled"
 
 #define DEFAULT_SHUTDOWN_TIMER_MS 5000
 
+bool gBluetoothDebugFlag = false;
+
 using namespace mozilla;
 using namespace mozilla::dom;
 USING_BLUETOOTH_NAMESPACE
 
 namespace {
 
 StaticRefPtr<BluetoothService> gBluetoothService;
 
@@ -548,47 +551,68 @@ BluetoothService::HandleSettingsChanged(
     MOZ_ASSERT(!JS_IsExceptionPending(cx));
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   if (!key.isString()) {
     return NS_OK;
   }
 
+  // First, check if the string equals to BLUETOOTH_DEBUGGING_SETTING
   JSBool match;
-  if (!JS_StringEqualsAscii(cx, key.toString(), BLUETOOTH_ENABLED_SETTING,
-                            &match)) {
+  if (!JS_StringEqualsAscii(cx, key.toString(), BLUETOOTH_DEBUGGING_SETTING, &match)) {
     MOZ_ASSERT(!JS_IsExceptionPending(cx));
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  if (!match) {
+  if (match) {
+    JS::Value value;
+    if (!JS_GetProperty(cx, &obj, "value", &value)) {
+      MOZ_ASSERT(!JS_IsExceptionPending(cx));
+      return NS_ERROR_OUT_OF_MEMORY;
+    }
+
+    if (!value.isBoolean()) {
+      MOZ_ASSERT(false, "Expecting a boolean for 'bluetooth.debugging.enabled'!");
+      return NS_ERROR_UNEXPECTED;
+    }
+
+    SWITCH_BT_DEBUG(value.toBoolean());
+
     return NS_OK;
   }
 
-  JS::Value value;
-  if (!JS_GetProperty(cx, &obj, "value", &value)) {
+  // Second, check if the string is BLUETOOTH_ENABLED_SETTING
+  if (!JS_StringEqualsAscii(cx, key.toString(), BLUETOOTH_ENABLED_SETTING, &match)) {
     MOZ_ASSERT(!JS_IsExceptionPending(cx));
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  if (!value.isBoolean()) {
-    MOZ_ASSERT(false, "Expecting a boolean for 'bluetooth.enabled'!");
-    return NS_ERROR_UNEXPECTED;
-  }
+  if (match) {
+    JS::Value value;
+    if (!JS_GetProperty(cx, &obj, "value", &value)) {
+      MOZ_ASSERT(!JS_IsExceptionPending(cx));
+      return NS_ERROR_OUT_OF_MEMORY;
+    }
 
-  if (gToggleInProgress || value.toBoolean() == IsEnabled()) {
-    // Nothing to do here.
-    return NS_OK;
-  }
+    if (!value.isBoolean()) {
+      MOZ_ASSERT(false, "Expecting a boolean for 'bluetooth.enabled'!");
+      return NS_ERROR_UNEXPECTED;
+    }
 
-  gToggleInProgress = true;
+    if (gToggleInProgress || value.toBoolean() == IsEnabled()) {
+      // Nothing to do here.
+      return NS_OK;
+    }
 
-  nsresult rv = StartStopBluetooth(value.toBoolean());
-  NS_ENSURE_SUCCESS(rv, rv);
+    gToggleInProgress = true;
+
+    nsresult rv = StartStopBluetooth(value.toBoolean());
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   return NS_OK;
 }
 
 nsresult
 BluetoothService::HandleShutdown()
 {
   MOZ_ASSERT(NS_IsMainThread());