diff options
author | Andy Kling <andreas.kling@peiker-cee.de> | 2019-02-21 11:06:55 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2019-07-15 15:18:09 +0000 |
commit | b56c4c5eb2095f7bc684f270735c24ac28d36363 (patch) | |
tree | 6a99b287e87722caadc4c1b63bc0c2a77a71aa77 | |
parent | 6b5443fc7df7231f759e7d7a5eed072ae3d89590 (diff) | |
download | NetworkManager-b56c4c5eb2095f7bc684f270735c24ac28d36363.tar.gz |
supplicant-interface: add async disconnect
allow to call dbus method "Disconnect" and handle a callback given by
the caller. This allows graceful disconnects that require to wait for
the operation to complete.
-rw-r--r-- | src/supplicant/nm-supplicant-interface.c | 60 | ||||
-rw-r--r-- | src/supplicant/nm-supplicant-interface.h | 10 |
2 files changed, 70 insertions, 0 deletions
diff --git a/src/supplicant/nm-supplicant-interface.c b/src/supplicant/nm-supplicant-interface.c index b1197a743b..461c113b61 100644 --- a/src/supplicant/nm-supplicant-interface.c +++ b/src/supplicant/nm-supplicant-interface.c @@ -80,6 +80,12 @@ typedef struct _AddNetworkData { AssocData *assoc_data; } AddNetworkData; +typedef struct { + NMSupplicantInterface *self; + NMSupplicantInterfaceDisconnectCb callback; + gpointer user_data; +} DisconnectData; + enum { STATE, /* change in the interface's state */ REMOVED, /* interface was removed by the supplicant */ @@ -2134,6 +2140,60 @@ nm_supplicant_interface_disconnect (NMSupplicantInterface * self) } static void +disconnect_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) +{ + DisconnectData *disconnect_data = user_data; + gs_unref_object NMSupplicantInterface *self = disconnect_data->self; + gs_unref_variant GVariant *reply = NULL; + gs_free_error GError *error = NULL; + + reply = g_dbus_proxy_call_finish (proxy, result, &error); + + /* an already disconnected interface is not an error*/ + if ( !reply + && !strstr (error->message, "fi.w1.wpa_supplicant1.NotConnected")) { + g_clear_error(&error); + } + + disconnect_data->callback(self, error, disconnect_data->user_data); + g_slice_free (DisconnectData, disconnect_data); +} + +void +nm_supplicant_interface_disconnect_async ( NMSupplicantInterface * self, + GCancellable * cancellable, + NMSupplicantInterfaceDisconnectCb callback, + gpointer user_data) +{ + NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + DisconnectData *disconnect_data; + + /* Don't do anything if there is no connection to the supplicant yet. */ + if (!priv->iface_proxy) + return; + + g_return_if_fail (NM_IS_SUPPLICANT_INTERFACE (self)); + g_return_if_fail (NULL != callback); + + disconnect_data = g_slice_new0(DisconnectData); + + /* Keep interface alive until disconnect finishes */ + disconnect_data->self = g_object_ref (self); + disconnect_data->callback = callback; + disconnect_data->user_data = user_data; + + /* Disconnect the interface */ + g_dbus_proxy_call (priv->iface_proxy, + "Disconnect", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + cancellable, + (GAsyncReadyCallback) disconnect_cb, + disconnect_data); +} + +static void assoc_select_network_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) { NMSupplicantInterface *self; diff --git a/src/supplicant/nm-supplicant-interface.h b/src/supplicant/nm-supplicant-interface.h index 70fe6b5a8f..d1cd52b31f 100644 --- a/src/supplicant/nm-supplicant-interface.h +++ b/src/supplicant/nm-supplicant-interface.h @@ -114,6 +114,16 @@ nm_supplicant_interface_assoc (NMSupplicantInterface *self, void nm_supplicant_interface_disconnect (NMSupplicantInterface * iface); +typedef void (*NMSupplicantInterfaceDisconnectCb) (NMSupplicantInterface *iface, + GError *error, + gpointer user_data); + +void +nm_supplicant_interface_disconnect_async (NMSupplicantInterface * self, + GCancellable * cancellable, + NMSupplicantInterfaceDisconnectCb callback, + gpointer user_data); + const char *nm_supplicant_interface_get_object_path (NMSupplicantInterface * iface); void nm_supplicant_interface_request_scan (NMSupplicantInterface *self, |