From 8369d15ca8f1ceda30adb5c488c6c982a9f5c3f0 Mon Sep 17 00:00:00 2001 From: Vinicius Gomes Date: Thu, 13 Mar 2008 18:26:08 +0000 Subject: Adapter: adding the new FindDevice method and documentation. --- doc/adapter-api.txt | 7 +++++++ hcid/adapter.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt index 79062e6a..0ddc1a42 100644 --- a/doc/adapter-api.txt +++ b/doc/adapter-api.txt @@ -26,6 +26,13 @@ Methods dict GetProperties() TBD + object FindDevice(string address) + + Returns the object path of a device given an address. + + Possible Errors: org.bluez.Error.DoesNotExist + org.bluez.Error.InvalidArguments + void DiscoverDevices() This method starts the device discovery procedure. This diff --git a/hcid/adapter.c b/hcid/adapter.c index 52cb2b8a..603097ad 100644 --- a/hcid/adapter.c +++ b/hcid/adapter.c @@ -3503,6 +3503,40 @@ static DBusHandlerResult remove_device(DBusConnection *conn, return send_message_and_unref(conn, reply); } +static DBusHandlerResult find_device(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + struct adapter *adapter = data; + struct device *device; + DBusMessage *reply; + const gchar *address; + GSList *l; + + if (!hcid_dbus_use_experimental()) + return error_unknown_method(conn, msg); + + if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, + DBUS_TYPE_INVALID)) + return error_invalid_arguments(conn, msg, NULL); + + l = g_slist_find_custom(adapter->devices, + address, (GCompareFunc) device_address_cmp); + if (!l) + return error_device_does_not_exist(conn, msg); + + device = l->data; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + dbus_message_append_args(reply, + DBUS_TYPE_OBJECT_PATH, &device->path, + DBUS_TYPE_INVALID); + + return send_message_and_unref(conn, reply); +} + const char *major_class_str(uint32_t class) { uint8_t index = (class >> 8) & 0x1F; @@ -3603,6 +3637,7 @@ static DBusMethodVTable adapter_methods[] = { { "ListDevices", list_devices, "", "ao" }, { "CreateDevice", create_device, "s", "o" }, { "RemoveDevice", remove_device, "o", "" }, + { "FindDevice", find_device, "s", "o" }, /* Deprecated */ { "GetInfo", adapter_get_info, "", "a{sv}" }, -- cgit