OSDN Git Service

tools/obexctl: Add rm command support for MAP messages
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 9 Oct 2013 12:03:26 +0000 (15:03 +0300)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 15 Oct 2013 13:50:21 +0000 (16:50 +0300)
Add rm command support for MAP messages which can be used to set Delete
property using Message interface.

tools/obexctl.c

index f7c64e0..931ff26 100644 (file)
@@ -1698,32 +1698,77 @@ static void delete_setup(DBusMessageIter *iter, void *user_data)
        dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &file);
 }
 
-static void cmd_rm(int argc, char *argv[])
+static void ftp_rm(GDBusProxy *proxy, int argc, char *argv[])
 {
-       GDBusProxy *proxy;
+       if (argc < 2) {
+               rl_printf("Missing file argument\n");
+               return;
+       }
 
-       if (!check_default_session())
+       if (g_dbus_proxy_method_call(proxy, "Delete", delete_setup,
+                                       delete_reply, g_strdup(argv[1]),
+                                       g_free) == FALSE) {
+               rl_printf("Failed to Delete\n");
                return;
+       }
+
+       rl_printf("Attempting to Delete\n");
+}
+
+static void set_delete_reply(const DBusError *error, void *user_data)
+{
+       if (dbus_error_is_set(error))
+               rl_printf("Failed to set Deleted: %s\n", error->name);
+       else
+               rl_printf("Set Deleted successful\n");
+}
+
+static void map_rm(GDBusProxy *proxy, int argc, char *argv[])
+{
+       GDBusProxy *msg;
+       dbus_bool_t value = TRUE;
 
        if (argc < 2) {
-               rl_printf("Missing file argument\n");
+               rl_printf("Missing message argument\n");
                return;
        }
 
+       msg = find_message(argv[1]);
+       if (msg == NULL) {
+               rl_printf("Invalid message argument\n");
+               return;
+       }
+
+       if (g_dbus_proxy_set_property_basic(msg, "Deleted", DBUS_TYPE_BOOLEAN,
+                                               &value, set_delete_reply,
+                                               NULL, NULL) == FALSE) {
+               rl_printf("Failed to set Deleted\n");
+               return;
+       }
+
+       rl_printf("Attempting to set Deleted\n");
+}
+
+static void cmd_rm(int argc, char *argv[])
+{
+       GDBusProxy *proxy;
+
+       if (!check_default_session())
+               return;
+
        proxy = find_ftp(g_dbus_proxy_get_path(default_session));
-       if (proxy == NULL) {
-               rl_printf("Command not supported\n");
+       if (proxy) {
+               ftp_rm(proxy, argc, argv);
                return;
        }
 
-       if (g_dbus_proxy_method_call(proxy, "Delete", delete_setup,
-                                       delete_reply, g_strdup(argv[1]),
-                                       g_free) == FALSE) {
-               rl_printf("Failed to Delete\n");
+       proxy = find_map(g_dbus_proxy_get_path(default_session));
+       if (proxy) {
+               map_rm(proxy, argc, argv);
                return;
        }
 
-       rl_printf("Attempting to Delete\n");
+       rl_printf("Command not supported\n");
 }
 
 static void create_folder_reply(DBusMessage *message, void *user_data)