diff --git a/dom/bluetooth/BluetoothService.h b/dom/bluetooth/BluetoothService.h index 1c687ef61d8d..aaf6bf043e11 100644 --- a/dom/bluetooth/BluetoothService.h +++ b/dom/bluetooth/BluetoothService.h @@ -192,6 +192,10 @@ public: const nsAString& aPattern, int aAttributeId) = 0; + virtual nsTArray + AddReservedServicesInternal(const nsAString& aAdapterPath, + const nsTArray& aServices) = 0; + /** * Due to the fact that some operations require multiple calls, a * CommandThread is created that can run blocking, platform-specific calls diff --git a/dom/bluetooth/linux/BluetoothDBusService.cpp b/dom/bluetooth/linux/BluetoothDBusService.cpp index 36da9827e80b..7a54a3e0c126 100644 --- a/dom/bluetooth/linux/BluetoothDBusService.cpp +++ b/dom/bluetooth/linux/BluetoothDBusService.cpp @@ -988,3 +988,56 @@ BluetoothDBusService::GetDeviceServiceChannelInternal(const nsAString& aObjectPa return reply ? dbus_returns_int32(reply) : -1; } + +static void +ExtractHandles(DBusMessage *aReply, nsTArray& aOutHandles) +{ + uint32_t* handles = NULL; + int len; + + DBusError err; + dbus_error_init(&err); + + if (dbus_message_get_args(aReply, &err, + DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &handles, &len, + DBUS_TYPE_INVALID)) { + if (!handles) { + LOG("Null array in extract_handles"); + } else { + for (int i = 0; i < len; ++i) { + aOutHandles.AppendElement(handles[i]); + } + } + } else { + LOG_AND_FREE_DBUS_ERROR(&err); + } +} + +nsTArray +BluetoothDBusService::AddReservedServicesInternal(const nsAString& aAdapterPath, + const nsTArray& aServices) +{ + MOZ_ASSERT(!NS_IsMainThread()); + + nsTArray ret; + const char* adapterPath = NS_ConvertUTF16toUTF8(aAdapterPath).get(); + + int length = aServices.Length(); + if (length == 0) return ret; + + const uint32_t* services = aServices.Elements(); + DBusMessage* reply = + dbus_func_args(gThreadConnection->GetConnection(), + adapterPath, + DBUS_ADAPTER_IFACE, "AddReservedServiceRecords", + DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, + &services, length, DBUS_TYPE_INVALID); + + if (!reply) { + LOG("Null DBus message. Couldn't extract handles."); + return ret; + } + + ExtractHandles(reply, ret); + return ret; +} diff --git a/dom/bluetooth/linux/BluetoothDBusService.h b/dom/bluetooth/linux/BluetoothDBusService.h index 0d0153f8f0e8..abe71c66184c 100644 --- a/dom/bluetooth/linux/BluetoothDBusService.h +++ b/dom/bluetooth/linux/BluetoothDBusService.h @@ -49,6 +49,10 @@ public: const nsAString& aPattern, int aAttributeId); + virtual nsTArray + AddReservedServicesInternal(const nsAString& aAdapterPath, + const nsTArray& aServices); + private: nsresult SendGetPropertyMessage(const nsAString& aPath, const char* aInterface,