Bug 1105308: Merge BluetoothUtils.{cpp,h}, r=btian
authorThomas Zimmermann <tdz@users.sourceforge.net>
Fri, 28 Nov 2014 11:49:40 +0100
changeset 243877 10ecf1e770b1348ad41bcfe716d9c74c80c4490f
parent 243876 6230fb3f608aa0ce33773c083488e90dfc87010f
child 243878 c3f675ce84260a2af9da2849f89381055ff94c32
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbtian
bugs1105308
milestone36.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 1105308: Merge BluetoothUtils.{cpp,h}, r=btian This patch merges BluetoothUtils.{cpp,h} from BlueZ and Bluedroid backends. The resulting files of the same name are located in the generic code's directory. This change requires a rebuild of dependency information, so the patch touches CLOBBER as well.
CLOBBER
dom/bluetooth/BluetoothUtils.cpp
dom/bluetooth/BluetoothUtils.h
dom/bluetooth/bluedroid/BluetoothUtils.cpp
dom/bluetooth/bluedroid/BluetoothUtils.h
dom/bluetooth/bluez/BluetoothUtils.cpp
dom/bluetooth/bluez/BluetoothUtils.h
dom/bluetooth/moz.build
--- a/CLOBBER
+++ b/CLOBBER
@@ -17,9 +17,12 @@
 #
 # Modifying this file will now automatically clobber the buildbot machines \o/
 #
 
 # Are you updating CLOBBER because you think it's needed for your WebIDL
 # changes to stick? As of bug 928195, this shouldn't be necessary! Please
 # don't change CLOBBER for WebIDL changes any more.
 
-Bug 1102488 - Changes to Android build system.
+Bug 1105308 - Cleanup BluetoothUtils.{cpp,h}
+
+This patch set moves some files around and requires a rebuild
+of the build system's dependency information.
rename from dom/bluetooth/bluedroid/BluetoothUtils.cpp
rename to dom/bluetooth/BluetoothUtils.cpp
--- a/dom/bluetooth/bluedroid/BluetoothUtils.cpp
+++ b/dom/bluetooth/BluetoothUtils.cpp
@@ -1,28 +1,21 @@
 /* -*- 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 "base/basictypes.h"
-
+#include "BluetoothUtils.h"
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothService.h"
-#include "BluetoothServiceBluedroid.h"
-#include "BluetoothUtils.h"
 #include "jsapi.h"
-#include "mozilla/Scoped.h"
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 #include "nsContentUtils.h"
-#include "nsIScriptContext.h"
 #include "nsISystemMessagesInternal.h"
-#include "nsString.h"
-#include "nsTArray.h"
 #include "nsServiceManagerUtils.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 bool
 SetJsObject(JSContext* aContext,
             const BluetoothValue& aValue,
             JS::Handle<JSObject*> aObj)
@@ -109,16 +102,47 @@ BroadcastSystemMessage(const nsAString& 
   }
 
   systemMessenger->BroadcastMessage(aType, value,
                                     JS::UndefinedHandleValue);
 
   return true;
 }
 
+bool
+BroadcastSystemMessage(const nsAString& aType,
+                       const InfallibleTArray<BluetoothNamedValue>& aData)
+{
+  mozilla::AutoSafeJSContext cx;
+  NS_ASSERTION(!::JS_IsExceptionPending(cx),
+      "Shouldn't get here when an exception is pending!");
+
+  JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(),
+                                             JS::NullPtr()));
+  if (!obj) {
+    BT_WARNING("Failed to new JSObject for system message!");
+    return false;
+  }
+
+  if (!SetJsObject(cx, aData, obj)) {
+    BT_WARNING("Failed to set properties of system message!");
+    return false;
+  }
+
+  nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
+    do_GetService("@mozilla.org/system-message-internal;1");
+  NS_ENSURE_TRUE(systemMessenger, false);
+
+  JS::Rooted<JS::Value> value(cx, JS::ObjectValue(*obj));
+  systemMessenger->BroadcastMessage(aType, value,
+                                    JS::UndefinedHandleValue);
+
+  return true;
+}
+
 void
 DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,
                        const BluetoothValue& aValue,
                        const nsAString& aErrorStr)
 {
   // Reply will be deleted by the runnable after running on main thread
   BluetoothReply* reply;
   if (!aErrorStr.IsEmpty()) {
rename from dom/bluetooth/bluedroid/BluetoothUtils.h
rename to dom/bluetooth/BluetoothUtils.h
--- a/dom/bluetooth/bluedroid/BluetoothUtils.h
+++ b/dom/bluetooth/BluetoothUtils.h
@@ -1,16 +1,16 @@
 /* -*- 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_bluetoothutils_h__
-#define mozilla_dom_bluetooth_bluetoothutils_h__
+#ifndef mozilla_dom_bluetooth_bluetoothutils_h
+#define mozilla_dom_bluetooth_bluetoothutils_h
 
 #include "BluetoothCommon.h"
 #include "js/TypeDecls.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 class BluetoothNamedValue;
 class BluetoothValue;
@@ -20,16 +20,20 @@ bool
 SetJsObject(JSContext* aContext,
             const BluetoothValue& aValue,
             JS::Handle<JSObject*> aObj);
 
 bool
 BroadcastSystemMessage(const nsAString& aType,
                        const BluetoothValue& aData);
 
+bool
+BroadcastSystemMessage(const nsAString& aType,
+                       const InfallibleTArray<BluetoothNamedValue>& aData);
+
 void
 DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,
                        const BluetoothValue& aValue,
                        const nsAString& aErrorStr);
 
 void
 DispatchStatusChangedEvent(const nsAString& aType,
                            const nsAString& aDeviceAddress,
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothUtils.cpp
+++ /dev/null
@@ -1,146 +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/. */
-
-#include "base/basictypes.h"
-
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-#include "jsapi.h"
-#include "mozilla/Scoped.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "nsContentUtils.h"
-#include "nsIScriptContext.h"
-#include "nsISystemMessagesInternal.h"
-#include "nsString.h"
-#include "nsTArray.h"
-#include "nsServiceManagerUtils.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-bool
-SetJsObject(JSContext* aContext,
-            const BluetoothValue& aValue,
-            JS::Handle<JSObject*> aObj)
-{
-  MOZ_ASSERT(aContext && aObj);
-
-  if (aValue.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
-    BT_WARNING("SetJsObject: Invalid parameter type");
-    return false;
-  }
-
-  const nsTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  for (uint32_t i = 0; i < arr.Length(); i++) {
-    JS::Rooted<JS::Value> val(aContext);
-    const BluetoothValue& v = arr[i].value();
-
-    switch(v.type()) {
-       case BluetoothValue::TnsString: {
-        JSString* jsData = JS_NewUCStringCopyN(aContext,
-                                     v.get_nsString().BeginReading(),
-                                     v.get_nsString().Length());
-        NS_ENSURE_TRUE(jsData, false);
-        val = STRING_TO_JSVAL(jsData);
-        break;
-      }
-      case BluetoothValue::Tuint32_t:
-        val = INT_TO_JSVAL(v.get_uint32_t());
-        break;
-      case BluetoothValue::Tbool:
-        val = BOOLEAN_TO_JSVAL(v.get_bool());
-        break;
-      default:
-        BT_WARNING("SetJsObject: Parameter is not handled");
-        break;
-    }
-
-    if (!JS_SetProperty(aContext, aObj,
-                        NS_ConvertUTF16toUTF8(arr[i].name()).get(),
-                        val)) {
-      BT_WARNING("Failed to set property");
-      return false;
-    }
-  }
-
-  return true;
-}
-
-bool
-BroadcastSystemMessage(const nsAString& aType,
-                       const InfallibleTArray<BluetoothNamedValue>& aData)
-{
-  mozilla::AutoSafeJSContext cx;
-  NS_ASSERTION(!::JS_IsExceptionPending(cx),
-      "Shouldn't get here when an exception is pending!");
-
-  JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(),
-                                             JS::NullPtr()));
-  if (!obj) {
-    BT_WARNING("Failed to new JSObject for system message!");
-    return false;
-  }
-
-  if (!SetJsObject(cx, aData, obj)) {
-    BT_WARNING("Failed to set properties of system message!");
-    return false;
-  }
-
-  nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
-    do_GetService("@mozilla.org/system-message-internal;1");
-  NS_ENSURE_TRUE(systemMessenger, false);
-
-  JS::Rooted<JS::Value> value(cx, JS::ObjectValue(*obj));
-  systemMessenger->BroadcastMessage(aType, value,
-                                    JS::UndefinedHandleValue);
-
-  return true;
-}
-
-void
-DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,
-                       const BluetoothValue& aValue,
-                       const nsAString& aErrorStr)
-{
-  // Reply will be deleted by the runnable after running on main thread
-  BluetoothReply* reply;
-  if (!aErrorStr.IsEmpty()) {
-    nsString err(aErrorStr);
-    reply = new BluetoothReply(BluetoothReplyError(err));
-  } else {
-    MOZ_ASSERT(aValue.type() != BluetoothValue::T__None);
-    reply = new BluetoothReply(BluetoothReplySuccess(aValue));
-  }
-
-  aRunnable->SetReply(reply);
-  if (NS_FAILED(NS_DispatchToMainThread(aRunnable))) {
-    BT_WARNING("Failed to dispatch to main thread!");
-  }
-}
-
-void
-DispatchStatusChangedEvent(const nsAString& aType,
-                           const nsAString& aAddress,
-                           bool aStatus)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  InfallibleTArray<BluetoothNamedValue> data;
-  data.AppendElement(
-    BluetoothNamedValue(NS_LITERAL_STRING("address"), nsString(aAddress)));
-  data.AppendElement(
-    BluetoothNamedValue(NS_LITERAL_STRING("status"), aStatus));
-
-  BluetoothSignal signal(nsString(aType), NS_LITERAL_STRING(KEY_ADAPTER), data);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-  bs->DistributeSignal(signal);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothUtils.h
+++ /dev/null
@@ -1,40 +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_bluetoothutils_h__
-#define mozilla_dom_bluetooth_bluetoothutils_h__
-
-#include "BluetoothCommon.h"
-#include "js/TypeDecls.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothNamedValue;
-class BluetoothValue;
-class BluetoothReplyRunnable;
-
-bool
-SetJsObject(JSContext* aContext,
-            const BluetoothValue& aValue,
-            JS::Handle<JSObject*> aObj);
-
-bool
-BroadcastSystemMessage(const nsAString& aType,
-                       const InfallibleTArray<BluetoothNamedValue>& aData);
-
-void
-DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,
-                       const BluetoothValue& aValue,
-                       const nsAString& aErrorStr);
-
-void
-DispatchStatusChangedEvent(const nsAString& aType,
-                           const nsAString& aDeviceAddress,
-                           bool aStatus);
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
--- a/dom/bluetooth/moz.build
+++ b/dom/bluetooth/moz.build
@@ -10,16 +10,17 @@ if CONFIG['MOZ_B2G_BT']:
         'BluetoothDevice.cpp',
         'BluetoothHidManager.cpp',
         'BluetoothInterface.cpp',
         'BluetoothManager.cpp',
         'BluetoothProfileController.cpp',
         'BluetoothPropertyContainer.cpp',
         'BluetoothReplyRunnable.cpp',
         'BluetoothService.cpp',
+        'BluetoothUtils.cpp',
         'BluetoothUuid.cpp',
         'ipc/BluetoothChild.cpp',
         'ipc/BluetoothParent.cpp',
         'ipc/BluetoothServiceChildProcess.cpp',
         'ObexBase.cpp'
     ]
 
     if CONFIG['MOZ_B2G_RIL']:
@@ -31,18 +32,17 @@ if CONFIG['MOZ_B2G_BT']:
         if CONFIG['MOZ_B2G_BT_BLUEZ']:
             CXXFLAGS += CONFIG['MOZ_DBUS_CFLAGS']
             SOURCES += [
                 'bluez/BluetoothA2dpManager.cpp',
                 'bluez/BluetoothDBusService.cpp',
                 'bluez/BluetoothHfpManager.cpp',
                 'bluez/BluetoothOppManager.cpp',
                 'bluez/BluetoothSocket.cpp',
-                'bluez/BluetoothUnixSocketConnector.cpp',
-                'bluez/BluetoothUtils.cpp',
+                'bluez/BluetoothUnixSocketConnector.cpp'
             ]
             LOCAL_INCLUDES += [
                 'bluez',
             ]
             DEFINES['MOZ_B2G_BT_BLUEZ'] = True
         elif CONFIG['MOZ_B2G_BT_BLUEDROID']:
             SOURCES += [
                 'bluedroid/BluetoothA2dpHALInterface.cpp',
@@ -55,18 +55,17 @@ if CONFIG['MOZ_B2G_BT']:
                 'bluedroid/BluetoothDaemonSocketInterface.cpp',
                 'bluedroid/BluetoothHALHelpers.cpp',
                 'bluedroid/BluetoothHALInterface.cpp',
                 'bluedroid/BluetoothHandsfreeHALInterface.cpp',
                 'bluedroid/BluetoothOppManager.cpp',
                 'bluedroid/BluetoothServiceBluedroid.cpp',
                 'bluedroid/BluetoothSocket.cpp',
                 'bluedroid/BluetoothSocketHALInterface.cpp',
-                'bluedroid/BluetoothSocketMessageWatcher.cpp',
-                'bluedroid/BluetoothUtils.cpp',
+                'bluedroid/BluetoothSocketMessageWatcher.cpp'
             ]
             LOCAL_INCLUDES += [
                 'bluedroid',
             ]
 
             if CONFIG['MOZ_B2G_RIL']:
                 SOURCES += [
                     'bluedroid/hfp/BluetoothHfpManager.cpp',