diff options
author | Thomas Haller <thaller@redhat.com> | 2020-03-13 18:11:56 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-03-23 09:33:01 +0100 |
commit | a7b8c82ee24c8eb8865b2debb53735b7953c0e22 (patch) | |
tree | 39317740cbca3648a07961bcb06696febfbda69d | |
parent | 1a36bdbb2c674abae4835040d52638c79f7ba819 (diff) |
libnm: add nm_client_dbus_set_property() API
Similar to nm_client_dbus_call(), but useful for setting a D-Bus
property on NetworkManager's D-Bus interface.
Note that we currently have various synchronous API for setting D-Bus
properties (like nm_client_networking_set_enabled()). Synchronous
API does not play well with the content of NMClient's cache, and was
thus deprecated. However, until now no async variant exists.
Instead of adding multiple async operations, I think it should be
sufficient to only add one nm_client_dbus_set_property() property.
It's still reasonably convenient to use for setting a property.
-rw-r--r-- | libnm/libnm.ver | 2 | ||||
-rw-r--r-- | libnm/nm-client.c | 82 | ||||
-rw-r--r-- | libnm/nm-client.h | 16 |
3 files changed, 100 insertions, 0 deletions
diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 4e7b9d9777..eafd5319eb 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1667,6 +1667,8 @@ libnm_1_24_0 { global: nm_client_dbus_call; nm_client_dbus_call_finish; + nm_client_dbus_set_property; + nm_client_dbus_set_property_finish; nm_client_get_instance_flags; nm_client_get_object_by_path; nm_client_get_permissions_state; diff --git a/libnm/nm-client.c b/libnm/nm-client.c index 397fb94cbd..ebd512199a 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -6735,6 +6735,88 @@ nm_client_dbus_call_finish (NMClient *client, /*****************************************************************************/ +/** + * nm_client_dbus_set_property: + * @client: the #NMClient + * @object_path: path of remote object + * @interface_name: D-Bus interface to invoke method on + * @property_name: the name of the property to set + * @value: a #GVariant tuple with the value to set + * @timeout_msec: the timeout in milliseconds, -1 to use the default + * timeout or %G_MAXINT for no timeout + * @cancellable: (nullable): a #GCancellable or %NULL + * @callback: (nullable): a #GAsyncReadyCallback to call when the request + * is satisfied or %NULL if you don't care about the result of the + * method invocation + * @user_data: the data to pass to @callback + * + * Like nm_client_dbus_call() but calls "Set" on the standard "org.freedesktop.DBus.Properties" + * D-Bus interface. + * + * Since: 1.24 + **/ +void +nm_client_dbus_set_property (NMClient *client, + const char *object_path, + const char *interface_name, + const char *property_name, + GVariant *value, + int timeout_msec, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_return_if_fail (NM_IS_CLIENT (client)); + g_return_if_fail (interface_name); + g_return_if_fail (property_name); + g_return_if_fail (value); + + _nm_client_dbus_call (client, + client, + nm_client_dbus_set_property, + cancellable, + callback, + user_data, + object_path, + DBUS_INTERFACE_PROPERTIES, + "Set", + g_variant_new ("(ssv)", + interface_name, + property_name, + value), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + timeout_msec == -1 + ? NM_DBUS_DEFAULT_TIMEOUT_MSEC + : timeout_msec, + nm_dbus_connection_call_finish_void_cb); +} + +/** + * nm_client_dbus_set_property_finish: + * @client: the #NMClient instance + * @result: the result passed to the #GAsyncReadyCallback + * @error: location for a #GError, or %NULL + * + * Gets the result of a call to nm_client_dbus_set_property(). + * + * Returns: %TRUE on success or %FALSE on failure. + * + * Since: 1.24 + **/ +gboolean +nm_client_dbus_set_property_finish (NMClient *client, + GAsyncResult *result, + GError **error) +{ + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, client, nm_client_dbus_set_property), FALSE); + + return g_task_propagate_boolean (G_TASK (result), error); +} + +/*****************************************************************************/ + static void _init_fetch_all (NMClient *self) { diff --git a/libnm/nm-client.h b/libnm/nm-client.h index 070d0cf162..627b228fdd 100644 --- a/libnm/nm-client.h +++ b/libnm/nm-client.h @@ -497,6 +497,22 @@ GVariant *nm_client_dbus_call_finish (NMClient *client, GAsyncResult *result, GError **error); +NM_AVAILABLE_IN_1_24 +void nm_client_dbus_set_property (NMClient *client, + const char *object_path, + const char *interface_name, + const char *property_name, + GVariant *value, + int timeout_msec, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + +NM_AVAILABLE_IN_1_24 +gboolean nm_client_dbus_set_property_finish (NMClient *client, + GAsyncResult *result, + GError **error); + G_END_DECLS #endif /* __NM_CLIENT_H__ */ |