OSDN Git Service

tools/obexctl: Add cancel command
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 9 Sep 2013 13:31:49 +0000 (16:31 +0300)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 15 Oct 2013 13:50:20 +0000 (16:50 +0300)
Add support for cance command which can be used to cancel ongoing
transfers

tools/obexctl.c

index ee8e9d8..b66e1d6 100644 (file)
@@ -472,6 +472,46 @@ static void cmd_info(int argc, char *argv[])
        print_property(proxy, "Filename");
 }
 
+static void cancel_reply(DBusMessage *message, void *user_data)
+{
+       DBusError error;
+
+       dbus_error_init(&error);
+
+       if (dbus_set_error_from_message(&error, message) == TRUE) {
+               rl_printf("Failed to cancel: %s\n", error.name);
+               dbus_error_free(&error);
+               return;
+       }
+
+       rl_printf("Cancel successful\n");
+}
+
+static void cmd_cancel(int argc, char *argv[])
+{
+       GDBusProxy *proxy;
+
+       if (argc < 2) {
+               rl_printf("Missing transfer address argument\n");
+               return;
+       }
+
+       proxy = find_transfer(argv[1]);
+       if (!proxy) {
+               rl_printf("Transfer %s not available\n", argv[1]);
+               return;
+       }
+
+       if (g_dbus_proxy_method_call(proxy, "Cancel", NULL, cancel_reply, NULL,
+                                                       NULL) == FALSE) {
+               rl_printf("Failed to cancel transfer\n");
+               return;
+       }
+
+       rl_printf("Attempting to cancel transfer %s\n",
+                                               g_dbus_proxy_get_path(proxy));
+}
+
 static const struct {
        const char *cmd;
        const char *arg;
@@ -484,6 +524,7 @@ static const struct {
        { "show",         "[session]", cmd_show, "Session information" },
        { "select",       "<session>", cmd_select, "Select default session" },
        { "info",         "<transfer>", cmd_info, "Transfer information" },
+       { "cancel",       "<transfer>", cmd_cancel, "Cancel transfer" },
        { "quit",         NULL,       cmd_quit, "Quit program" },
        { "exit",         NULL,       cmd_quit },
        { "help" },