Bug 758504 - Final: patch1: Implement function to add reserved services. r=qdot

This commit is contained in:
Eric Chou 2012-08-10 11:17:06 +08:00
Родитель 0fa6eef4e1
Коммит 4596320121
3 изменённых файлов: 61 добавлений и 0 удалений

Просмотреть файл

@ -192,6 +192,10 @@ public:
const nsAString& aPattern,
int aAttributeId) = 0;
virtual nsTArray<PRUint32>
AddReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<PRUint32>& aServices) = 0;
/**
* Due to the fact that some operations require multiple calls, a
* CommandThread is created that can run blocking, platform-specific calls

Просмотреть файл

@ -988,3 +988,56 @@ BluetoothDBusService::GetDeviceServiceChannelInternal(const nsAString& aObjectPa
return reply ? dbus_returns_int32(reply) : -1;
}
static void
ExtractHandles(DBusMessage *aReply, nsTArray<PRUint32>& 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<PRUint32>
BluetoothDBusService::AddReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<PRUint32>& aServices)
{
MOZ_ASSERT(!NS_IsMainThread());
nsTArray<PRUint32> 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;
}

Просмотреть файл

@ -49,6 +49,10 @@ public:
const nsAString& aPattern,
int aAttributeId);
virtual nsTArray<PRUint32>
AddReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<PRUint32>& aServices);
private:
nsresult SendGetPropertyMessage(const nsAString& aPath,
const char* aInterface,