diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2012-12-15 17:43:39 +0100 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2012-12-15 17:43:39 +0100 |
commit | 024d38c12a25dc8e8dabf32f82b9c4a3f775dc06 (patch) | |
tree | 69f366e8be94e1c2cde825f6700f98fbdc227f96 /client | |
parent | 3403e57715359ff181021b3dd5e1e2ae5e4ac5d0 (diff) | |
download | bluez-024d38c12a25dc8e8dabf32f82b9c4a3f775dc06.tar.gz |
client: Add support for removing a device/pairing
Diffstat (limited to 'client')
-rw-r--r-- | client/main.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/client/main.c b/client/main.c index a31b94bdb..7f4bbd1a7 100644 --- a/client/main.c +++ b/client/main.c @@ -647,6 +647,64 @@ static void cmd_pair(const char *arg) } } +static void remove_device_reply(DBusMessage *message, void *user_data) +{ + DBusError error; + + begin_message(); + + dbus_error_init(&error); + + if (dbus_set_error_from_message(&error, message) == TRUE) { + printf("Failed to remove device: %s\n", error.name); + dbus_error_free(&error); + goto done; + } + + printf("Device has been removed\n"); + +done: + end_message(); +} + +static void remove_device_setup(DBusMessageIter *iter, void *user_data) +{ + const char *path = user_data; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path); +} + +static void cmd_remove(const char *arg) +{ + GDBusProxy *proxy; + char *path; + + if (!arg || !strlen(arg)) { + printf("Missing device address argument\n"); + return; + } + + if (check_default_ctrl() == FALSE) + return; + + proxy = find_proxy_by_address(dev_list, arg); + if (!proxy) { + printf("Device %s not available\n", arg); + return; + } + + path = g_strdup(g_dbus_proxy_get_path(proxy)); + + if (g_dbus_proxy_method_call(default_ctrl, "RemoveDevice", + remove_device_setup, + remove_device_reply, + path, g_free) == FALSE) { + printf("Failed to remove device\n"); + g_free(path); + return; + } +} + static void cmd_name(const char *arg) { char *name; @@ -739,6 +797,8 @@ static const struct { { "scan", "<on/off>", cmd_scan, "Scan for devices" }, { "pair", "<dev>", cmd_pair, "Pair with device", dev_generator }, + { "remove", "<dev>", cmd_remove, "Remove device", + dev_generator }, { "quit", NULL, cmd_quit, "Quit program" }, { "exit", NULL, cmd_quit }, { "help" }, |