OSDN Git Service

tools/obexctl: Add send command support for MAP messages
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Sat, 5 Oct 2013 13:18:11 +0000 (16:18 +0300)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 15 Oct 2013 13:50:21 +0000 (16:50 +0300)
Add send command support for MAP messages which can be used to push
messages using MessageAccess interface.

tools/obexctl.c

index 2f9d946..f7c64e0 100644 (file)
@@ -588,6 +588,20 @@ static GDBusProxy *find_opp(const char *path)
        return NULL;
 }
 
+static GDBusProxy *find_map(const char *path)
+{
+       GSList *l;
+
+       for (l = maps; l; l = g_slist_next(l)) {
+               GDBusProxy *proxy = l->data;
+
+               if (strcmp(path, g_dbus_proxy_get_path(proxy)) == 0)
+                       return proxy;
+       }
+
+       return NULL;
+}
+
 static void print_dict_iter(DBusMessageIter *iter)
 {
        DBusMessageIter dict;
@@ -658,26 +672,70 @@ static void send_setup(DBusMessageIter *iter, void *user_data)
        dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &file);
 }
 
-static void cmd_send(int argc, char *argv[])
+static void opp_send(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, "SendFile", send_setup, send_reply,
+                                       g_strdup(argv[1]), g_free) == FALSE) {
+               rl_printf("Failed to send\n");
                return;
+       }
 
-       proxy = find_opp(g_dbus_proxy_get_path(default_session));
-       if (proxy == NULL) {
-               rl_printf("Command not supported\n");
+       rl_printf("Attempting to send %s to %s\n", argv[1],
+                                               g_dbus_proxy_get_path(proxy));
+}
+
+static void push_reply(DBusMessage *message, void *user_data)
+{
+       DBusMessageIter iter;
+       DBusError error;
+
+       dbus_error_init(&error);
+
+       if (dbus_set_error_from_message(&error, message) == TRUE) {
+               rl_printf("Failed to PushMessage: %s\n", error.name);
+               dbus_error_free(&error);
                return;
        }
 
+       dbus_message_iter_init(message, &iter);
+
+       print_transfer_iter(&iter);
+}
+
+static void push_setup(DBusMessageIter *iter, void *user_data)
+{
+       const char *file = user_data;
+       const char *folder = "";
+       DBusMessageIter dict;
+
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &file);
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &folder);
+
+       dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+                                       DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+                                       DBUS_TYPE_STRING_AS_STRING
+                                       DBUS_TYPE_VARIANT_AS_STRING
+                                       DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+                                       &dict);
+
+       dbus_message_iter_close_container(iter, &dict);
+}
+
+static void map_send(GDBusProxy *proxy, int argc, char *argv[])
+{
        if (argc < 2) {
                rl_printf("Missing file argument\n");
                return;
        }
 
-       if (g_dbus_proxy_method_call(proxy, "SendFile", send_setup, send_reply,
-                                       g_strdup(argv[1]), g_free) == FALSE) {
+       if (g_dbus_proxy_method_call(proxy, "PushMessage", push_setup,
+                                       push_reply, g_strdup(argv[1]),
+                                       g_free) == FALSE) {
                rl_printf("Failed to send\n");
                return;
        }
@@ -686,6 +744,28 @@ static void cmd_send(int argc, char *argv[])
                                                g_dbus_proxy_get_path(proxy));
 }
 
+static void cmd_send(int argc, char *argv[])
+{
+       GDBusProxy *proxy;
+
+       if (!check_default_session())
+               return;
+
+       proxy = find_opp(g_dbus_proxy_get_path(default_session));
+       if (proxy) {
+               opp_send(proxy, argc, argv);
+               return;
+       }
+
+       proxy = find_map(g_dbus_proxy_get_path(default_session));
+       if (proxy) {
+               map_send(proxy, argc, argv);
+               return;
+       }
+
+       rl_printf("Command not supported\n");
+}
+
 static void change_folder_reply(DBusMessage *message, void *user_data)
 {
        DBusError error;
@@ -785,20 +865,6 @@ static GDBusProxy *find_pbap(const char *path)
        return NULL;
 }
 
-static GDBusProxy *find_map(const char *path)
-{
-       GSList *l;
-
-       for (l = maps; l; l = g_slist_next(l)) {
-               GDBusProxy *proxy = l->data;
-
-               if (strcmp(path, g_dbus_proxy_get_path(proxy)) == 0)
-                       return proxy;
-       }
-
-       return NULL;
-}
-
 static void ftp_cd(GDBusProxy *proxy, int argc, char *argv[])
 {
        if (argc < 2) {