Add the info dbus message of transfer cancel 46/31246/1
authorwu zheng <wu.zheng@intel.com>
Wed, 3 Dec 2014 06:50:01 +0000 (14:50 +0800)
committerwu zheng <wu.zheng@intel.com>
Wed, 3 Dec 2014 06:50:01 +0000 (14:50 +0800)
If user cancel opp transfer, the application should get the info.
The patch add to send the info dbus message of cancel.

When cancel transfer files, the info will be sent.
At the same time, the server transfer list error is fixed.

Change-Id: I75be4f9909acc43fd23957bf010da1aa7612240d
Signed-off-by: Wu Zheng <wu.zheng@intel.com>
capi/bluetooth-obex.c
include/obex.h
lib/obex.c
src/opp.c

index 7269d42..4c81cb1 100644 (file)
@@ -493,6 +493,7 @@ static int bt_opp_register_server(const char *dir,
 
 static int bt_opp_unregister_server(void)
 {
+       DBG("");
        /* TODO: unregister agent */
        g_free(opp_server.root_folder);
        opp_server.root_folder = NULL;
@@ -753,6 +754,8 @@ int bt_opp_server_initialize_by_connection_request(const char *destination,
 
 int bt_opp_server_deinitialize(void)
 {
+       DBG("");
+
        if (opp_server_push_node) {
                g_free(opp_server_push_node);
                opp_server_push_node = NULL;
index 1de7c3f..a03f496 100644 (file)
@@ -115,6 +115,8 @@ int obex_transfer_set_notify(
                        char *transfer_path,
                        obex_transfer_state_cb cb, void *data);
 
+void obex_transfer_clear_notify(char *transfer_path);
+
 enum transfer_state obex_transfer_get_property_state(const char *path);
 
 enum transfer_state obex_transfer_get_property_state(const char *path);
index 40f0774..c8d3cb1 100644 (file)
@@ -47,6 +47,7 @@ static GDBusObjectManager *object_manager;
 
 static obex_agent_added_cb_t obex_agent_added_cb;
 static void *obex_agent_added_cb_data;
+static GList *transfer_watched_list;
 
 static GDBusConnection *_obex_get_session_dbus(void)
 {
@@ -683,6 +684,29 @@ int obex_get_transfer_id(const char *transfer_path, enum obex_role role)
        return id;
 }
 
+static struct obex_watch_result *find_watch_node(const char *path)
+{
+       struct obex_watch_result *node;
+       GList *list, *next;
+
+       DBG("path = %s", path);
+
+       if (!transfer_watched_list ||
+                       !g_list_length(transfer_watched_list))
+               return NULL;
+
+       for (list = g_list_first(transfer_watched_list);
+                                       list; list = next) {
+               next = g_list_next(list);
+               node = list->data;
+
+               if (node && !g_strcmp0(node->path, path))
+                       return node;
+       }
+
+       return NULL;
+}
+
 static void transfer_properties_changed(GDBusProxy *proxy,
                                        GVariant *changed_properties,
                                        GStrv *invalidated_properties,
@@ -761,6 +785,9 @@ done:
 
        g_signal_handler_disconnect(async_node->proxy,
                                                async_node->proxy_id);
+
+       transfer_watched_list = g_list_remove(transfer_watched_list,
+                                                       async_node);
        g_object_unref(p_proxy);
        g_object_unref(async_node->proxy);
        if (async_node->path)
@@ -810,9 +837,37 @@ int obex_transfer_set_notify(char *transfer_path,
                        G_CALLBACK(transfer_properties_changed),
                        async_node);
 
+       transfer_watched_list = g_list_append(transfer_watched_list,
+                                                       async_node);
+
        return 0;
 }
 
+void obex_transfer_clear_notify(char *transfer_path)
+{
+       struct obex_watch_result *async_node;
+
+       DBG("transfer_path = %s", transfer_path);
+
+       if (!transfer_path)
+               return;
+
+       async_node = find_watch_node(transfer_path);
+       if (!async_node)
+               return;
+
+       g_signal_handler_disconnect(async_node->proxy,
+                                       async_node->proxy_id);
+
+       transfer_watched_list = g_list_remove(transfer_watched_list,
+                                                       async_node);
+
+       g_object_unref(async_node->proxy);
+       if (async_node->path)
+               g_free(async_node->path);
+       g_free(async_node);
+}
+
 static void simple_cancle_cb(GObject *object,
                        GAsyncResult *res, gpointer user_data)
 {
@@ -844,6 +899,8 @@ void obex_transfer_cancel(const char *path)
        if (path == NULL)
                return;
 
+       DBG("path = %s", path);
+
        g_dbus_connection_call(connection, "org.bluez.obex",
                                path,
                                "org.bluez.obex.Transfer1",
index 61f8660..b872e15 100644 (file)
--- a/src/opp.c
+++ b/src/opp.c
@@ -1095,7 +1095,7 @@ static void register_relay_agent_handler(GDBusConnection *connection,
        relay_agent = create_relay_agent(sender, agent_path, NULL, pid,
                                        uid, relay_agent_watch_id);
 
-       agent_server_list = g_list_append(agent_list, relay_agent);
+       agent_server_list = g_list_append(agent_server_list, relay_agent);
 
        if (relay_agent_timeout_id > 0) {
                g_source_remove(relay_agent_timeout_id);
@@ -1534,6 +1534,7 @@ static void cancel_transfer_handler(GDBusConnection *connection,
                                gpointer user_data)
 {
        const gchar *sender;
+       gchar *name;
        guint transfer_id, agent_id = 0;
 
        DBG("");
@@ -1560,9 +1561,17 @@ static void cancel_transfer_handler(GDBusConnection *connection,
                return;
        }
 
-       if (transfer_id == agent_id)
+       if (transfer_id == agent_id) {
+               name = obex_transfer_get_property_name(
+                                       relay_agent->transfer_path);
+               if (!name)
+                       name = "";
                obex_transfer_cancel(relay_agent->transfer_path);
-       else {
+               send_pushstatus(relay_agent->address,
+                       name, 0, transfer_id, OBEX_TRANSFER_CANCELED,
+                       0, relay_agent->pid);
+               obex_transfer_clear_notify(relay_agent->transfer_path);
+       } else {
                comms_error_not_available(invocation);
                return;
        }
@@ -1577,6 +1586,7 @@ static void cancel_all_transfer_handler(GDBusConnection *connection,
 {
        const gchar *sender;
        struct pending_files *p_file;
+       guint transfer_id;
        GList *list, *next;
 
        DBG("+");
@@ -1608,8 +1618,40 @@ static void cancel_all_transfer_handler(GDBusConnection *connection,
                        obex_transfer_cancel(p_file->path);
        }
 
-       free_all_pending_files();
-       free_remove_relay_agent();
+       if (relay_client_agent) {
+               obex_session_remove_session(
+                                       relay_client_agent->session);
+
+               for (list = g_list_first(pending_p_list); list; list = next) {
+                       p_file = list->data;
+                       next = g_list_next(list);
+
+                       if (p_file == NULL)
+                               continue;
+
+                       if (p_file->path) {
+                               transfer_id = obex_get_transfer_id(
+                                               p_file->path, OBEX_CLIENT);
+                               send_pushstatus(relay_client_agent->address,
+                                       p_file->file_name, 0, transfer_id,
+                                       OBEX_TRANSFER_CANCELED, 0,
+                                       relay_client_agent->pid);
+                               obex_transfer_clear_notify(p_file->path);
+                       }
+                       free_pending_files(p_file);
+               }
+
+               free_relay_agent(relay_client_agent);
+               relay_client_agent = NULL;
+       }
+
+       if (g_list_length(agent_list) > 0) {
+               list = g_list_first(agent_list);
+               relay_client_agent = list->data;
+               agent_list = g_list_remove(agent_list, relay_client_agent);
+               obex_create_session(relay_client_agent->address,
+                                       OBEX_OPP, session_state_cb, NULL);
+       }
 
        g_dbus_method_invocation_return_value(invocation, NULL);