summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2012-06-05 11:29:04 -0500
committerDan Williams <dcbw@redhat.com>2012-09-11 17:17:58 -0500
commitd42d41c1ac646e7668f28c0cb14093edb9e03e23 (patch)
treea179998481ae7191f25950513836040c10540ec4
parent15ca7cd56cedf03d43b9dc2efb10dc669abb3146 (diff)
core: add cancelation to dispatcher calls
-rw-r--r--src/nm-dispatcher.c29
-rw-r--r--src/nm-dispatcher.h34
2 files changed, 42 insertions, 21 deletions
diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c
index a3674a15..0f17ed93 100644
--- a/src/nm-dispatcher.c
+++ b/src/nm-dispatcher.c
@@ -30,6 +30,8 @@
#include "nm-dbus-manager.h"
#include "nm-dbus-glib-types.h"
+static GSList *requests = NULL;
+
static void
dump_object_to_props (GObject *object, GHashTable *hash)
{
@@ -137,6 +139,7 @@ typedef struct {
static void
dispatcher_info_free (DispatchInfo *info)
{
+ requests = g_slist_remove (requests, info);
g_object_unref (info->dbus_mgr);
g_free (info);
}
@@ -206,7 +209,7 @@ dispatcher_done_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
}
if (info->callback)
- info->callback (call, info->user_data);
+ info->callback (info, info->user_data);
g_clear_error (&error);
g_object_unref (proxy);
@@ -240,7 +243,7 @@ action_to_string (DispatcherAction action)
g_assert_not_reached ();
}
-static gpointer
+static gconstpointer
_dispatcher_call (DispatcherAction action,
NMConnection *connection,
NMDevice *device,
@@ -349,10 +352,13 @@ _dispatcher_call (DispatcherAction action,
g_hash_table_destroy (vpn_ip4_props);
g_hash_table_destroy (vpn_ip6_props);
- return call;
+ /* Track the request in case of cancelation */
+ requests = g_slist_append (requests, info);
+
+ return info;
}
-gpointer
+gconstpointer
nm_dispatcher_call (DispatcherAction action,
NMConnection *connection,
NMDevice *device,
@@ -362,7 +368,7 @@ nm_dispatcher_call (DispatcherAction action,
return _dispatcher_call (action, connection, device, NULL, NULL, NULL, callback, user_data);
}
-gpointer
+gconstpointer
nm_dispatcher_call_vpn (DispatcherAction action,
NMConnection *connection,
NMDevice *device,
@@ -375,3 +381,16 @@ nm_dispatcher_call_vpn (DispatcherAction action,
return _dispatcher_call (action, connection, device, vpn_iface, vpn_ip4_config, vpn_ip6_config, callback, user_data);
}
+void
+nm_dispatcher_call_cancel (gconstpointer call)
+{
+ /* 'call' is really a DispatchInfo pointer, just opaque to callers.
+ * Look it up in our requests list, but don't access it directly before
+ * we've made sure it's a valid request,since it may have long since been
+ * freed. Canceling just means the callback doesn't get called, so set
+ * the DispatcherInfo's callback to NULL.
+ */
+ if (g_slist_find (requests, call))
+ ((DispatchInfo *) call)->callback = NULL;
+}
+
diff --git a/src/nm-dispatcher.h b/src/nm-dispatcher.h
index 8514ba2c..05a6c875 100644
--- a/src/nm-dispatcher.h
+++ b/src/nm-dispatcher.h
@@ -42,21 +42,23 @@ typedef enum {
DISPATCHER_ACTION_DHCP6_CHANGE
} DispatcherAction;
-typedef void (*DispatcherFunc) (gpointer call, gpointer user_data);
-
-gpointer nm_dispatcher_call (DispatcherAction action,
- NMConnection *connection,
- NMDevice *device,
- DispatcherFunc callback,
- gpointer user_data);
-
-gpointer nm_dispatcher_call_vpn (DispatcherAction action,
- NMConnection *connection,
- NMDevice *device,
- const char *vpn_iface,
- NMIP4Config *vpn_ip4_config,
- NMIP6Config *vpn_ip6_config,
- DispatcherFunc callback,
- gpointer user_data);
+typedef void (*DispatcherFunc) (gconstpointer call, gpointer user_data);
+
+gconstpointer nm_dispatcher_call (DispatcherAction action,
+ NMConnection *connection,
+ NMDevice *device,
+ DispatcherFunc callback,
+ gpointer user_data);
+
+gconstpointer nm_dispatcher_call_vpn (DispatcherAction action,
+ NMConnection *connection,
+ NMDevice *device,
+ const char *vpn_iface,
+ NMIP4Config *vpn_ip4_config,
+ NMIP6Config *vpn_ip6_config,
+ DispatcherFunc callback,
+ gpointer user_data);
+
+void nm_dispatcher_call_cancel (gconstpointer call);
#endif /* NM_DISPATCHER_H */