From: Marcel Holtmann Date: Wed, 17 Dec 2008 03:54:01 +0000 (+0100) Subject: Retrieve list of Bluetooth devices X-Git-Tag: accepted/2.0alpha-wayland/20121110.002834~4407 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9328a63c330a64982d2a9bc060d8985c2228d3e5;p=profile%2Fivi%2Fconnman.git Retrieve list of Bluetooth devices --- diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c index 94c8649..2b33c3a 100644 --- a/plugins/bluetooth.c +++ b/plugins/bluetooth.c @@ -175,6 +175,45 @@ done: dbus_message_unref(reply); } +static void devices_reply(DBusPendingCall *call, void *user_data) +{ + DBusMessage *message = user_data; + const char *path = dbus_message_get_path(message); + DBusMessage *reply; + DBusError error; + char **devices; + int i, num_devices; + + DBG("path %s", path); + + dbus_message_unref(message); + + reply = dbus_pending_call_steal_reply(call); + + dbus_error_init(&error); + + if (dbus_message_get_args(reply, &error, + DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, + &devices, &num_devices, + DBUS_TYPE_INVALID) == FALSE) { + if (dbus_error_is_set(&error) == TRUE) { + connman_error("%s", error.message); + dbus_error_free(&error); + } else + connman_error("Wrong arguments for device list"); + goto done; + } + + for (i = 0; i < num_devices; i++) { + DBG("device %s", devices[i]); + } + + g_strfreev(devices); + +done: + dbus_message_unref(reply); +} + static void add_adapter(DBusConnection *connection, const char *path) { struct connman_element *device; @@ -210,6 +249,20 @@ static void add_adapter(DBusConnection *connection, const char *path) } dbus_pending_call_set_notify(call, properties_reply, message, NULL); + + message = dbus_message_new_method_call(BLUEZ_SERVICE, path, + BLUEZ_ADAPTER_INTERFACE, "ListDevices"); + if (message == NULL) + return; + + if (dbus_connection_send_with_reply(connection, message, + &call, TIMEOUT) == FALSE) { + connman_error("Failed to get Bluetooth devices"); + dbus_message_unref(message); + return; + } + + dbus_pending_call_set_notify(call, devices_reply, message, NULL); } static void remove_adapter(DBusConnection *connection, const char *path)