diff options
Diffstat (limited to 'libnm')
-rw-r--r-- | libnm/libnm.ver | 3 | ||||
-rw-r--r-- | libnm/nm-device.c | 173 | ||||
-rw-r--r-- | libnm/nm-device.h | 18 |
3 files changed, 194 insertions, 0 deletions
diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 3867c3df0e..944c49bef3 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -875,6 +875,9 @@ global: nm_connection_get_setting_vxlan; nm_connection_verify_secrets; nm_device_ethernet_get_s390_subchannels; + nm_device_get_applied_connection; + nm_device_get_applied_connection_async; + nm_device_get_applied_connection_finish; nm_device_get_lldp_neighbors; nm_device_get_metered; nm_device_get_nm_plugin_missing; diff --git a/libnm/nm-device.c b/libnm/nm-device.c index e1e77efc58..242fe7e197 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -2299,6 +2299,179 @@ nm_device_reapply_finish (NMDevice *device, return g_simple_async_result_get_op_res_gboolean (simple); } +/*****************************************************************************/ + +/** + * nm_device_get_applied_connection: + * @device: a #NMDevice + * @flags: the flags argument. Currently this value must always be zero. + * @version_id: (out): (allow-none): returns the current version id of + * the applied connection + * @cancellable: a #GCancellable, or %NULL + * @error: location for a #GError, or %NULL + * + * Fetch the currently applied connection on the device. + * + * Returns: (transfer-full): a %NMConnection with the currently applied settings + * or %NULL on error. + * + * Since: 1.2 + **/ +NMConnection * +nm_device_get_applied_connection (NMDevice *device, + guint32 flags, + guint64 *version_id, + GCancellable *cancellable, + GError **error) +{ + gs_unref_variant GVariant *dict = NULL; + guint64 my_version_id; + gboolean success; + NMConnection *connection; + + g_return_val_if_fail (NM_IS_DEVICE (device), NULL); + g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL); + g_return_val_if_fail (!error || !*error, NULL); + + success = nmdbus_device_call_get_applied_connection_sync (NM_DEVICE_GET_PRIVATE (device)->proxy, + flags, &dict, &my_version_id, cancellable, error); + if (!success) { + if (error && *error) + g_dbus_error_strip_remote_error (*error); + return NULL; + } + + connection = nm_simple_connection_new_from_dbus (dict, error); + if (!connection) + return NULL; + + NM_SET_OUT (version_id, my_version_id); + return connection; +} + +typedef struct { + NMConnection *connection; + guint64 version_id; +} GetAppliedConnectionData; + +static void +device_get_applied_connection_data_free (gpointer user_data) +{ + GetAppliedConnectionData *data = user_data; + + g_return_if_fail (data); + + g_object_unref (data->connection); + g_slice_free (GetAppliedConnectionData, data); +} + +static void +device_get_applied_connection_cb (GObject *proxy, + GAsyncResult *result, + gpointer user_data) +{ + gs_unref_object GSimpleAsyncResult *simple = user_data; + gs_unref_variant GVariant *dict = NULL; + guint64 my_version_id; + GError *error = NULL; + NMConnection *connection; + GetAppliedConnectionData *data; + + if (!nmdbus_device_call_get_applied_connection_finish (NMDBUS_DEVICE (proxy), &dict, &my_version_id, result, &error)) { + g_dbus_error_strip_remote_error (error); + g_simple_async_result_take_error (simple, error); + goto out; + } + + connection = nm_simple_connection_new_from_dbus (dict, &error); + if (!connection) { + g_simple_async_result_take_error (simple, error); + goto out; + } + + data = g_slice_new (GetAppliedConnectionData); + data->connection = connection; + data->version_id = my_version_id; + g_simple_async_result_set_op_res_gpointer (simple, data, device_get_applied_connection_data_free); + +out: + g_simple_async_result_complete (simple); +} + +/** + * nm_device_get_applied_connection_async: + * @device: a #NMDevice + * @flags: the flags argument. Currently this value must always be zero. + * @cancellable: a #GCancellable, or %NULL + * @callback: callback to be called when the reapply operation completes + * @user_data: caller-specific data passed to @callback + * + * Asynchronously begins an get the a currently applied connection. + * + * Since: 1.2 + **/ +void +nm_device_get_applied_connection_async (NMDevice *device, + guint32 flags, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *simple; + + g_return_if_fail (NM_IS_DEVICE (device)); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); + + simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data, + nm_device_get_applied_connection_async); + + nmdbus_device_call_get_applied_connection (NM_DEVICE_GET_PRIVATE (device)->proxy, + flags, cancellable, + device_get_applied_connection_cb, simple); +} + +/** + * nm_device_get_applied_connection_finish: + * @device: a #NMDevice + * @result: the result passed to the #GAsyncReadyCallback + * @version_id: (out): (allow-none): the current version id of the applied + * connection. + * @error: location for a #GError, or %NULL + * + * Gets the result of a call to nm_device_get_applied_connection_async(). + * + * Returns: (transfer-full): a currently applied %NMConnection or %NULL in case + * of error. + * + * Since: 1.2 + **/ +NMConnection * +nm_device_get_applied_connection_finish (NMDevice *device, + GAsyncResult *result, + guint64 *version_id, + GError **error) +{ + GSimpleAsyncResult *simple; + GetAppliedConnectionData *data; + + g_return_val_if_fail (NM_IS_DEVICE (device), NULL); + g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_get_applied_connection_async), NULL); + g_return_val_if_fail (!error || !*error, NULL); + + simple = G_SIMPLE_ASYNC_RESULT (result); + if (g_simple_async_result_propagate_error (simple, error)) + return NULL; + + data = g_simple_async_result_get_op_res_gpointer (simple); + g_return_val_if_fail (data, NULL); + g_return_val_if_fail (NM_IS_CONNECTION (data->connection), NULL); + + NM_SET_OUT (version_id, data->version_id); + return g_object_ref (data->connection); +} + +/*****************************************************************************/ + /** * nm_device_disconnect: * @device: a #NMDevice diff --git a/libnm/nm-device.h b/libnm/nm-device.h index 816acb7483..87fcb0335e 100644 --- a/libnm/nm-device.h +++ b/libnm/nm-device.h @@ -157,6 +157,24 @@ gboolean nm_device_reapply_finish (NMDevice *device, GAsyncResult *result, GError **error); +NM_AVAILABLE_IN_1_2 +NMConnection *nm_device_get_applied_connection (NMDevice *device, + guint32 flags, + guint64 *version_id, + GCancellable *cancellable, + GError **error); +NM_AVAILABLE_IN_1_2 +void nm_device_get_applied_connection_async (NMDevice *device, + guint32 flags, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +NM_AVAILABLE_IN_1_2 +NMConnection *nm_device_get_applied_connection_finish (NMDevice *device, + GAsyncResult *result, + guint64 *version_id, + GError **error); + gboolean nm_device_disconnect (NMDevice *device, GCancellable *cancellable, GError **error); |