From 3b1ee2b0653f5b833388bb996a01db0a25bb66b6 Mon Sep 17 00:00:00 2001 From: Kyle Machulis Date: Tue, 25 Sep 2012 11:48:51 -0700 Subject: [PATCH] Bug 789428: Fix object path setting for BluetoothDevice; r=echou --HG-- extra : rebase_source : 7712835dfa55640910721f9a04bb4ee48e8168b4 --- dom/bluetooth/BluetoothDevice.cpp | 19 +++++++++++------- dom/bluetooth/linux/BluetoothDBusService.cpp | 21 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/dom/bluetooth/BluetoothDevice.cpp b/dom/bluetooth/BluetoothDevice.cpp index 27bd017c237..ddb10371c2a 100644 --- a/dom/bluetooth/BluetoothDevice.cpp +++ b/dom/bluetooth/BluetoothDevice.cpp @@ -61,6 +61,17 @@ BluetoothDevice::BluetoothDevice(nsPIDOMWindow* aOwner, 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); + } + } } } @@ -100,14 +111,8 @@ BluetoothDevice::SetPropertyByValue(const BluetoothNamedValue& aValue) 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")) { diff --git a/dom/bluetooth/linux/BluetoothDBusService.cpp b/dom/bluetooth/linux/BluetoothDBusService.cpp index c830b105cf2..c8e0fd54d17 100644 --- a/dom/bluetooth/linux/BluetoothDBusService.cpp +++ b/dom/bluetooth/linux/BluetoothDBusService.cpp @@ -1156,9 +1156,19 @@ EventFilter(DBusConnection* aConn, DBusMessage* aMsg, void* aData) // 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!"); @@ -1571,8 +1581,15 @@ public: // for agent events "RequestConfirmation", "RequestPinCode", and "RequestPasskey" InfallibleTArray 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;