Bug 789428: Fix object path setting for BluetoothDevice; r=echou
authorKyle Machulis <kyle@nonpolynomial.com>
Tue, 25 Sep 2012 11:48:51 -0700
changeset 108181 c544d6a5e993a66385d9579575662222284ad00c
parent 108180 c88496e8454fdcf57b9c69282cecc89aefb57ee1
child 108182 a43ed8da00acdee3d9e2e2ec6bf280a1155b1ab7
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersechou
bugs789428
milestone18.0a1
Bug 789428: Fix object path setting for BluetoothDevice; r=echou
dom/bluetooth/BluetoothDevice.cpp
dom/bluetooth/linux/BluetoothDBusService.cpp
--- a/dom/bluetooth/BluetoothDevice.cpp
+++ b/dom/bluetooth/BluetoothDevice.cpp
@@ -56,16 +56,27 @@ BluetoothDevice::BluetoothDevice(nsPIDOM
   mAdapterPath(aAdapterPath),
   mIsRooted(false)
 {
   BindToOwner(aOwner);
   const InfallibleTArray<BluetoothNamedValue>& values =
     aValue.get_ArrayOfBluetoothNamedValue();
   for (uint32_t i = 0; i < values.Length(); ++i) {
     SetPropertyByValue(values[i]);
+    if (values[i].name().EqualsLiteral("Path")) {
+      // Since this is our signal handler string, set it as we set the property
+      // in the object. Odd place to do it, but makes more sense than in
+      // SetPropertyByValue.
+      BluetoothService* bs = BluetoothService::Get();
+      if (!bs) {
+        NS_WARNING("BluetoothService not available!");
+      } else {
+        bs->RegisterBluetoothSignalHandler(mPath, this);
+      }
+    }
   }
 }
 
 BluetoothDevice::~BluetoothDevice()
 {
   BluetoothService* bs = BluetoothService::Get();
   // bs can be null on shutdown, where destruction might happen.
   if (bs) {
@@ -95,24 +106,18 @@ BluetoothDevice::Unroot()
 void
 BluetoothDevice::SetPropertyByValue(const BluetoothNamedValue& aValue)
 {
   const nsString& name = aValue.name();
   const BluetoothValue& value = aValue.value();
   if (name.EqualsLiteral("Name")) {
     mName = value.get_nsString();
   } else if (name.EqualsLiteral("Path")) {
+    MOZ_ASSERT(value.get_nsString().Length() > 0);
     mPath = value.get_nsString();
-    NS_WARNING(NS_ConvertUTF16toUTF8(mPath).get());
-    BluetoothService* bs = BluetoothService::Get();
-    if (!bs) {
-      NS_WARNING("BluetoothService not available!");
-    } else {
-      bs->RegisterBluetoothSignalHandler(mPath, this);
-    }
   } else if (name.EqualsLiteral("Address")) {
     mAddress = value.get_nsString();
   } else if (name.EqualsLiteral("Class")) {
     mClass = value.get_uint32_t();
   } else if (name.EqualsLiteral("Icon")) {
     mIcon = value.get_nsString();
   } else if (name.EqualsLiteral("Connected")) {
 #ifdef MOZ_WIDGET_GONK
--- a/dom/bluetooth/linux/BluetoothDBusService.cpp
+++ b/dom/bluetooth/linux/BluetoothDBusService.cpp
@@ -1151,19 +1151,29 @@ EventFilter(DBusConnection* aConn, DBusM
                       ArrayLength(sDeviceProperties));
       if (v.type() == BluetoothValue::TArrayOfBluetoothNamedValue)
       {
         // The DBus DeviceFound message actually passes back a key value object
         // with the address as the key and the rest of the device properties as
         // a dict value. After we parse out the properties, we need to go back
         // and add the address to the ipdl dict we've created to make sure we
         // have all of the information to correctly build the device.
+        nsString addrstr = NS_ConvertUTF8toUTF16(addr);
+        nsString path = GetObjectPathFromAddress(signalPath, addrstr);
+
         v.get_ArrayOfBluetoothNamedValue()
           .AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("Address"),
-                                             NS_ConvertUTF8toUTF16(addr)));
+                                             addrstr));
+
+        // We also need to create a path for the device, to make sure we know
+        // where to access it later.
+        v.get_ArrayOfBluetoothNamedValue()
+          .AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("Path"),
+                                             path));
+
       }
     } else {
       errorStr.AssignLiteral("DBus device found message structure not as expected!");
     }
   } else if (dbus_message_is_signal(aMsg, DBUS_ADAPTER_IFACE, "DeviceDisappeared")) {
     const char* str;
     if (!dbus_message_get_args(aMsg, &err,
                                DBUS_TYPE_STRING, &str,
@@ -1566,18 +1576,25 @@ public:
     }
 
     InfallibleTArray<BluetoothNamedValue> properties = prop.get_ArrayOfBluetoothNamedValue();
     if (v.type() == BluetoothValue::TArrayOfBluetoothNamedValue) {
       // Return original dbus message parameters and also device name
       // for agent events "RequestConfirmation", "RequestPinCode", and "RequestPasskey"
       InfallibleTArray<BluetoothNamedValue> parameters = v.get_ArrayOfBluetoothNamedValue();
 
+      // For consistency, append path
+      nsString path = parameters[0].value();
+      BluetoothNamedValue pathprop;
+      pathprop.name().AssignLiteral("Path");
+      pathprop.value() = path;
+      parameters.AppendElement(pathprop);
+
       // Replace object path with device address
-      nsString address = GetAddressFromObjectPath(parameters[0].value());
+      nsString address = GetAddressFromObjectPath(path);
       parameters[0].value() = address;
 
       uint8_t i;
       for (i = 0; i < properties.Length(); i++) {
         // Append device name
         if (properties[i].name().EqualsLiteral("Name")) {
           properties[i].name().AssignLiteral("name");
           parameters.AppendElement(properties[i]);