diff options
author | Dan Winship <danw@gnome.org> | 2014-09-29 10:58:16 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-10-10 12:40:19 -0400 |
commit | 6f3d1f95262abbf5101d6f88ecfa292d575e0d4f (patch) | |
tree | bffa6c50529d46377f71da8907dcd734a8e7a366 /libnm | |
parent | c1f1e9618126e618e9f10d9a5ce74b2ef7101e76 (diff) | |
download | NetworkManager-6f3d1f95262abbf5101d6f88ecfa292d575e0d4f.tar.gz |
libnm: merge NMRemoteSettings into NMClient
Make NMRemoteSettings internal and have NMClient wrap all of its APIs,
just like it does with NMManager.
Diffstat (limited to 'libnm')
-rw-r--r-- | libnm/Makefile.am | 4 | ||||
-rw-r--r-- | libnm/NetworkManager.h | 1 | ||||
-rw-r--r-- | libnm/libnm.ver | 36 | ||||
-rw-r--r-- | libnm/nm-client.c | 683 | ||||
-rw-r--r-- | libnm/nm-client.h | 76 | ||||
-rw-r--r-- | libnm/nm-remote-settings.c | 484 | ||||
-rw-r--r-- | libnm/nm-remote-settings.h | 37 | ||||
-rw-r--r-- | libnm/tests/test-remote-settings-client.c | 174 | ||||
-rw-r--r-- | libnm/tests/test-secret-agent.c | 18 |
9 files changed, 810 insertions, 703 deletions
diff --git a/libnm/Makefile.am b/libnm/Makefile.am index f5ab2c6eee..e3945b88b6 100644 --- a/libnm/Makefile.am +++ b/libnm/Makefile.am @@ -50,7 +50,6 @@ libnminclude_HEADERS = \ nm-ip6-config.h \ nm-object.h \ nm-remote-connection.h \ - nm-remote-settings.h \ nm-secret-agent.h \ nm-vpn-connection.h \ nm-vpn-plugin.h \ @@ -64,7 +63,8 @@ libnm_la_private_headers = \ nm-manager.h \ nm-object-cache.h \ nm-object-private.h \ - nm-remote-connection-private.h + nm-remote-connection-private.h \ + nm-remote-settings.h libnm_la_csources = \ nm-access-point.c \ diff --git a/libnm/NetworkManager.h b/libnm/NetworkManager.h index d7414101ce..ce7bec74c2 100644 --- a/libnm/NetworkManager.h +++ b/libnm/NetworkManager.h @@ -50,7 +50,6 @@ #include <nm-ip6-config.h> #include <nm-object.h> #include <nm-remote-connection.h> -#include <nm-remote-settings.h> #include <nm-secret-agent.h> #include <nm-setting-8021x.h> #include <nm-setting-adsl.h> diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 08182f8c09..437cebf936 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -37,6 +37,8 @@ global: nm_client_activate_connection_finish; nm_client_add_and_activate_connection_async; nm_client_add_and_activate_connection_finish; + nm_client_add_connection_async; + nm_client_add_connection_finish; nm_client_check_connectivity; nm_client_check_connectivity_async; nm_client_check_connectivity_finish; @@ -47,6 +49,9 @@ global: nm_client_error_quark; nm_client_get_activating_connection; nm_client_get_active_connections; + nm_client_get_connection_by_id; + nm_client_get_connection_by_path; + nm_client_get_connection_by_uuid; nm_client_get_connectivity; nm_client_get_device_by_iface; nm_client_get_device_by_path; @@ -59,6 +64,10 @@ global: nm_client_get_state; nm_client_get_type; nm_client_get_version; + nm_client_list_connections; + nm_client_load_connections; + nm_client_load_connections_async; + nm_client_load_connections_finish; nm_client_networking_get_enabled; nm_client_networking_set_enabled; nm_client_new; @@ -66,6 +75,12 @@ global: nm_client_new_finish; nm_client_permission_get_type; nm_client_permission_result_get_type; + nm_client_reload_connections; + nm_client_reload_connections_async; + nm_client_reload_connections_finish; + nm_client_save_hostname; + nm_client_save_hostname_async; + nm_client_save_hostname_finish; nm_client_set_logging; nm_client_wimax_get_enabled; nm_client_wimax_hardware_get_enabled; @@ -363,27 +378,6 @@ global: nm_remote_connection_save; nm_remote_connection_save_async; nm_remote_connection_save_finish; - nm_remote_settings_add_connection_async; - nm_remote_settings_add_connection_finish; - nm_remote_settings_error_get_type; - nm_remote_settings_error_quark; - nm_remote_settings_get_connection_by_id; - nm_remote_settings_get_connection_by_path; - nm_remote_settings_get_connection_by_uuid; - nm_remote_settings_get_type; - nm_remote_settings_list_connections; - nm_remote_settings_load_connections; - nm_remote_settings_load_connections_async; - nm_remote_settings_load_connections_finish; - nm_remote_settings_new; - nm_remote_settings_new_async; - nm_remote_settings_new_finish; - nm_remote_settings_reload_connections; - nm_remote_settings_reload_connections_async; - nm_remote_settings_reload_connections_finish; - nm_remote_settings_save_hostname; - nm_remote_settings_save_hostname_async; - nm_remote_settings_save_hostname_finish; nm_secret_agent_capabilities_get_type; nm_secret_agent_delete_secrets; nm_secret_agent_error_get_type; diff --git a/libnm/nm-client.c b/libnm/nm-client.c index c0f0075086..9ecb77a1cf 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -24,6 +24,7 @@ #include "nm-client.h" #include "nm-manager.h" +#include "nm-remote-settings.h" #include "nm-device-ethernet.h" #include "nm-device-wifi.h" #include "nm-device-private.h" @@ -50,6 +51,7 @@ G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, G_TYPE_OBJECT, typedef struct { NMManager *manager; + NMRemoteSettings *settings; } NMClientPrivate; enum { @@ -70,6 +72,9 @@ enum { PROP_PRIMARY_CONNECTION, PROP_ACTIVATING_CONNECTION, PROP_DEVICES, + PROP_CONNECTIONS, + PROP_HOSTNAME, + PROP_CAN_MODIFY, LAST_PROP }; @@ -78,6 +83,8 @@ enum { DEVICE_ADDED, DEVICE_REMOVED, PERMISSION_CHANGED, + CONNECTION_ADDED, + CONNECTION_REMOVED, LAST_SIGNAL }; @@ -579,6 +586,112 @@ nm_client_check_connectivity_finish (NMClient *client, return (NMConnectivityState) g_simple_async_result_get_op_res_gssize (simple); } + +/** + * nm_client_save_hostname: + * @client: the %NMClient + * @hostname: (allow-none): the new persistent hostname to set, or %NULL to + * clear any existing persistent hostname + * @cancellable: a #GCancellable, or %NULL + * @error: return location for #GError + * + * Requests that the machine's persistent hostname be set to the specified value + * or cleared. + * + * Returns: %TRUE if the request was successful, %FALSE if it failed + **/ +gboolean +nm_client_save_hostname (NMClient *client, + const char *hostname, + GCancellable *cancellable, + GError **error) +{ + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + + return nm_remote_settings_save_hostname (NM_CLIENT_GET_PRIVATE (client)->settings, + hostname, cancellable, error); +} + +static void +save_hostname_cb (GObject *object, + GAsyncResult *result, + gpointer user_data) +{ + GSimpleAsyncResult *simple = user_data; + GError *error = NULL; + + if (nm_remote_settings_save_hostname_finish (NM_REMOTE_SETTINGS (object), result, &error)) + g_simple_async_result_set_op_res_gboolean (simple, TRUE); + else + g_simple_async_result_take_error (simple, error); + + g_simple_async_result_complete (simple); + g_object_unref (simple); +} + +/** + * nm_client_save_hostname_async: + * @client: the %NMClient + * @hostname: (allow-none): the new persistent hostname to set, or %NULL to + * clear any existing persistent hostname + * @cancellable: a #GCancellable, or %NULL + * @callback: (scope async): callback to be called when the operation completes + * @user_data: (closure): caller-specific data passed to @callback + * + * Requests that the machine's persistent hostname be set to the specified value + * or cleared. + **/ +void +nm_client_save_hostname_async (NMClient *client, + const char *hostname, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *simple; + GError *error = NULL; + + g_return_if_fail (NM_IS_CLIENT (client)); + + if (!_nm_client_check_nm_running (client, &error)) { + g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); + return; + } + + simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, + nm_client_save_hostname_async); + nm_remote_settings_save_hostname_async (NM_CLIENT_GET_PRIVATE (client)->settings, + hostname, + cancellable, save_hostname_cb, simple); +} + +/** + * nm_client_save_hostname_finish: + * @client: the %NMClient + * @result: the result passed to the #GAsyncReadyCallback + * @error: return location for #GError + * + * Gets the result of an nm_client_save_hostname_async() call. + * + * Returns: %TRUE if the request was successful, %FALSE if it failed + **/ +gboolean +nm_client_save_hostname_finish (NMClient *client, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *simple; + + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); + + simple = G_SIMPLE_ASYNC_RESULT (result); + if (g_simple_async_result_propagate_error (simple, error)) + return FALSE; + else + return g_simple_async_result_get_op_res_gboolean (simple); +} + /****************************************************************/ /* Devices */ /****************************************************************/ @@ -1034,6 +1147,419 @@ nm_client_deactivate_connection_finish (NMClient *client, } /****************************************************************/ +/* Connections */ +/****************************************************************/ + +/** + * nm_client_list_connections: + * @client: the %NMClient + * + * Returns: (transfer container) (element-type NMRemoteConnection): a + * list containing all connections provided by the remote settings service. + * Each element of the returned list is a %NMRemoteConnection instance, which is + * owned by the %NMClient object and should not be freed by the caller. + * The returned list is, however, owned by the caller and should be freed + * using g_slist_free() when no longer required. + **/ +GSList * +nm_client_list_connections (NMClient *client) +{ + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + + return nm_remote_settings_list_connections (NM_CLIENT_GET_PRIVATE (client)->settings); +} + +/** + * nm_client_get_connection_by_id: + * @client: the %NMClient + * @id: the id of the remote connection + * + * Returns the first matching %NMRemoteConnection matching a given @id. + * + * Returns: (transfer none): the remote connection object on success, or %NULL if no + * matching object was found. + **/ +NMRemoteConnection * +nm_client_get_connection_by_id (NMClient *client, const char *id) +{ + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + g_return_val_if_fail (id != NULL, NULL); + + return nm_remote_settings_get_connection_by_id (NM_CLIENT_GET_PRIVATE (client)->settings, id); +} + +/** + * nm_client_get_connection_by_path: + * @client: the %NMClient + * @path: the D-Bus object path of the remote connection + * + * Returns the %NMRemoteConnection representing the connection at @path. + * + * Returns: (transfer none): the remote connection object on success, or %NULL if the object was + * not known + **/ +NMRemoteConnection * +nm_client_get_connection_by_path (NMClient *client, const char *path) +{ + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + g_return_val_if_fail (path != NULL, NULL); + + return nm_remote_settings_get_connection_by_path (NM_CLIENT_GET_PRIVATE (client)->settings, path); +} + +/** + * nm_client_get_connection_by_uuid: + * @client: the %NMClient + * @uuid: the UUID of the remote connection + * + * Returns the %NMRemoteConnection identified by @uuid. + * + * Returns: (transfer none): the remote connection object on success, or %NULL if the object was + * not known + **/ +NMRemoteConnection * +nm_client_get_connection_by_uuid (NMClient *client, const char *uuid) +{ + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + g_return_val_if_fail (uuid != NULL, NULL); + + return nm_remote_settings_get_connection_by_uuid (NM_CLIENT_GET_PRIVATE (client)->settings, uuid); +} + +static void +add_connection_cb (GObject *object, + GAsyncResult *result, + gpointer user_data) +{ + GSimpleAsyncResult *simple = user_data; + NMRemoteConnection *conn; + GError *error = NULL; + + conn = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (object), result, &error); + if (conn) + g_simple_async_result_set_op_res_gpointer (simple, conn, g_object_unref); + else + g_simple_async_result_take_error (simple, error); + + g_simple_async_result_complete (simple); + g_object_unref (simple); +} + +/** + * nm_client_add_connection_async: + * @client: the %NMClient + * @connection: the connection to add. Note that this object's settings will be + * added, not the object itself + * @save_to_disk: whether to immediately save the connection to disk + * @cancellable: a #GCancellable, or %NULL + * @callback: (scope async): callback to be called when the add operation completes + * @user_data: (closure): caller-specific data passed to @callback + * + * Requests that the remote settings service add the given settings to a new + * connection. If @save_to_disk is %TRUE, the connection is immediately written + * to disk; otherwise it is initially only stored in memory, but may be saved + * later by calling the connection's nm_remote_connection_commit_changes() + * method. + * + * @connection is untouched by this function and only serves as a template of + * the settings to add. The #NMRemoteConnection object that represents what + * NetworkManager actually added is returned to @callback when the addition + * operation is complete. + * + * Note that the #NMRemoteConnection returned in @callback may not contain + * identical settings to @connection as NetworkManager may perform automatic + * completion and/or normalization of connection properties. + **/ +void +nm_client_add_connection_async (NMClient *client, + NMConnection *connection, + gboolean save_to_disk, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *simple; + GError *error = NULL; + + g_return_if_fail (NM_IS_CLIENT (client)); + g_return_if_fail (NM_IS_CONNECTION (connection)); + + if (!_nm_client_check_nm_running (client, &error)) { + g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); + return; + } + + simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, + nm_client_deactivate_connection_async); + nm_remote_settings_add_connection_async (NM_CLIENT_GET_PRIVATE (client)->settings, + connection, save_to_disk, + cancellable, add_connection_cb, simple); +} + +/** + * nm_client_add_connection_finish: + * @client: an #NMClient + * @result: the result passed to the #GAsyncReadyCallback + * @error: location for a #GError, or %NULL + * + * Gets the result of a call to nm_client_add_connection_async(). + * + * Returns: (transfer full): the new #NMRemoteConnection on success, %NULL on + * failure, in which case @error will be set. + **/ +NMRemoteConnection * +nm_client_add_connection_finish (NMClient *client, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *simple; + + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL); + + simple = G_SIMPLE_ASYNC_RESULT (result); + if (g_simple_async_result_propagate_error (simple, error)) + return NULL; + else + return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); +} + +/** + * nm_client_load_connections: + * @client: the %NMClient + * @filenames: %NULL-terminated array of filenames to load + * @failures: (out) (transfer full): on return, a %NULL-terminated array of + * filenames that failed to load + * @cancellable: a #GCancellable, or %NULL + * @error: return location for #GError + * + * Requests that the remote settings service load or reload the given files, + * adding or updating the connections described within. + * + * The changes to the indicated files will not yet be reflected in + * @client's connections array when the function returns. + * + * If all of the indicated files were successfully loaded, the + * function will return %TRUE, and @failures will be set to %NULL. If + * NetworkManager tried to load the files, but some (or all) failed, + * then @failures will be set to a %NULL-terminated array of the + * filenames that failed to load. + * + * Returns: %TRUE if NetworkManager at least tried to load @filenames, + * %FALSE if an error occurred (eg, permission denied). + **/ +gboolean +nm_client_load_connections (NMClient *client, + char **filenames, + char ***failures, + GCancellable *cancellable, + GError **error) +{ + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + g_return_val_if_fail (filenames != NULL, FALSE); + + if (!_nm_client_check_nm_running (client, error)) + return FALSE; + + return nm_remote_settings_load_connections (NM_CLIENT_GET_PRIVATE (client)->settings, + filenames, failures, + cancellable, error); +} + +static void +load_connections_cb (GObject *object, GAsyncResult *result, gpointer user_data) +{ + GSimpleAsyncResult *simple = user_data; + GError *error = NULL; + char **failures = NULL; + + if (nm_remote_settings_load_connections_finish (NM_REMOTE_SETTINGS (object), + &failures, result, &error)) + g_simple_async_result_set_op_res_gpointer (simple, failures, (GDestroyNotify) g_strfreev); + else + g_simple_async_result_take_error (simple, error); + + g_simple_async_result_complete (simple); + g_object_unref (simple); +} + +/** + * nm_client_load_connections_async: + * @client: the %NMClient + * @filenames: %NULL-terminated array of filenames to load + * @cancellable: a #GCancellable, or %NULL + * @callback: (scope async): callback to be called when the operation completes + * @user_data: (closure): caller-specific data passed to @callback + * + * Requests that the remote settings service asynchronously load or reload the + * given files, adding or updating the connections described within. + * + * See nm_client_load_connections() for more details. + **/ +void +nm_client_load_connections_async (NMClient *client, + char **filenames, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *simple; + GError *error = NULL; + + g_return_if_fail (NM_IS_CLIENT (client)); + g_return_if_fail (filenames != NULL); + + if (!_nm_client_check_nm_running (client, &error)) { + g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); + return; + } + + simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, + nm_client_load_connections_async); + nm_remote_settings_load_connections_async (NM_CLIENT_GET_PRIVATE (client)->settings, + filenames, + cancellable, load_connections_cb, simple); +} + +/** + * nm_client_load_connections_finish: + * @client: the %NMClient + * @failures: (out) (transfer full): on return, a %NULL-terminated array of + * filenames that failed to load + * @result: the result passed to the #GAsyncReadyCallback + * @error: location for a #GError, or %NULL + * + * Gets the result of an nm_client_load_connections_async() call. + + * See nm_client_load_connections() for more details. + * + * Returns: %TRUE if NetworkManager at least tried to load @filenames, + * %FALSE if an error occurred (eg, permission denied). + **/ +gboolean +nm_client_load_connections_finish (NMClient *client, + char ***failures, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *simple; + + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); + + simple = G_SIMPLE_ASYNC_RESULT (result); + if (g_simple_async_result_propagate_error (simple, error)) + return FALSE; + else { + if (failures) + *failures = g_strdupv (g_simple_async_result_get_op_res_gpointer (simple)); + return TRUE; + } +} + +/** + * nm_client_reload_connections: + * @client: the #NMClient + * @cancellable: a #GCancellable, or %NULL + * @error: return location for #GError + * + * Requests that the remote settings service reload all connection + * files from disk, adding, updating, and removing connections until + * the in-memory state matches the on-disk state. + * + * Return value: %TRUE on success, %FALSE on failure + **/ +gboolean +nm_client_reload_connections (NMClient *client, + GCancellable *cancellable, + GError **error) +{ + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + + if (!_nm_client_check_nm_running (client, error)) + return FALSE; + + return nm_remote_settings_reload_connections (NM_CLIENT_GET_PRIVATE (client)->settings, + cancellable, error); +} + +static void +reload_connections_cb (GObject *object, GAsyncResult *result, gpointer user_data) +{ + GSimpleAsyncResult *simple = user_data; + GError *error = NULL; + + if (nm_remote_settings_reload_connections_finish (NM_REMOTE_SETTINGS (object), + result, &error)) + g_simple_async_result_set_op_res_gboolean (simple, TRUE); + else + g_simple_async_result_take_error (simple, error); + + g_simple_async_result_complete (simple); + g_object_unref (simple); +} + +/** + * nm_client_reload_connections_async: + * @client: the #NMClient + * @cancellable: a #GCancellable, or %NULL + * @callback: (scope async): callback to be called when the reload operation completes + * @user_data: (closure): caller-specific data passed to @callback + * + * Requests that the remote settings service begin reloading all connection + * files from disk, adding, updating, and removing connections until the + * in-memory state matches the on-disk state. + **/ +void +nm_client_reload_connections_async (NMClient *client, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *simple; + GError *error = NULL; + + g_return_if_fail (NM_IS_CLIENT (client)); + + if (!_nm_client_check_nm_running (client, &error)) { + g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); + return; + } + + simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, + nm_client_reload_connections_async); + nm_remote_settings_reload_connections_async (NM_CLIENT_GET_PRIVATE (client)->settings, + cancellable, reload_connections_cb, simple); +} + +/** + * nm_client_reload_connections_finish: + * @client: the #NMClient + * @result: the result passed to the #GAsyncReadyCallback + * @error: return location for #GError + * + * Gets the result of an nm_client_reload_connections_async() call. + * + * Return value: %TRUE on success, %FALSE on failure + **/ +gboolean +nm_client_reload_connections_finish (NMClient *client, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *simple; + + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); + + simple = G_SIMPLE_ASYNC_RESULT (result); + if (g_simple_async_result_propagate_error (simple, error)) + return FALSE; + else + return g_simple_async_result_get_op_res_gboolean (simple); +} + +/****************************************************************/ /** * nm_client_new: @@ -1046,10 +1572,6 @@ nm_client_deactivate_connection_finish (NMClient *client, * client. You can use nm_client_new_async() if you want to avoid * that. * - * NOTE: #NMClient provides information about devices and a mechanism to - * control them. To access and modify network configuration data, use the - * #NMRemoteSettings object. - * * Returns: a new #NMClient or NULL on an error **/ NMClient * @@ -1084,10 +1606,6 @@ client_inited (GObject *source, GAsyncResult *result, gpointer user_data) * @callback will be called when it is done; use * nm_client_new_finish() to get the result. Note that on an error, * the callback can be invoked with two first parameters as NULL. - * - * NOTE: #NMClient provides information about devices and a mechanism to - * control them. To access and modify network configuration data, use the - * #NMRemoteSettings object. **/ void nm_client_new_async (GCancellable *cancellable, @@ -1137,9 +1655,9 @@ nm_client_new_finish (GAsyncResult *result, GError **error) } static void -manager_notify (GObject *object, - GParamSpec *pspec, - gpointer client) +subobject_notify (GObject *object, + GParamSpec *pspec, + gpointer client) { if (!g_str_has_suffix (pspec->name, "-internal")) g_object_notify (client, pspec->name); @@ -1170,6 +1688,21 @@ manager_permission_changed (NMManager *manager, } static void +settings_connection_added (NMRemoteSettings *manager, + NMRemoteConnection *connection, + gpointer client) +{ + g_signal_emit (client, signals[CONNECTION_ADDED], 0, connection); +} +static void +settings_connection_removed (NMRemoteSettings *manager, + NMRemoteConnection *connection, + gpointer client) +{ + g_signal_emit (client, signals[CONNECTION_REMOVED], 0, connection); +} + +static void constructed (GObject *object) { NMClient *client = NM_CLIENT (object); @@ -1178,9 +1711,8 @@ constructed (GObject *object) priv->manager = g_object_new (NM_TYPE_MANAGER, NM_OBJECT_PATH, NM_DBUS_PATH, NULL); - g_signal_connect (priv->manager, "notify", - G_CALLBACK (manager_notify), client); + G_CALLBACK (subobject_notify), client); g_signal_connect (priv->manager, "device-added", G_CALLBACK (manager_device_added), client); g_signal_connect (priv->manager, "device-removed", @@ -1188,6 +1720,16 @@ constructed (GObject *object) g_signal_connect (priv->manager, "permission-changed", G_CALLBACK (manager_permission_changed), client); + priv->settings = g_object_new (NM_TYPE_REMOTE_SETTINGS, + NM_OBJECT_PATH, NM_DBUS_PATH_SETTINGS, + NULL); + g_signal_connect (priv->settings, "notify", + G_CALLBACK (subobject_notify), client); + g_signal_connect (priv->settings, "connection-added", + G_CALLBACK (settings_connection_added), client); + g_signal_connect (priv->settings, "connection-removed", + G_CALLBACK (settings_connection_removed), client); + G_OBJECT_CLASS (nm_client_parent_class)->constructed (object); } @@ -1199,6 +1741,8 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) if (!g_initable_init (G_INITABLE (priv->manager), cancellable, error)) return FALSE; + if (!g_initable_init (G_INITABLE (priv->settings), cancellable, error)) + return FALSE; return TRUE; } @@ -1207,6 +1751,8 @@ typedef struct { NMClient *client; GCancellable *cancellable; GSimpleAsyncResult *result; + gboolean manager_inited; + gboolean settings_inited; } NMClientInitData; static void @@ -1224,12 +1770,26 @@ init_async_inited_manager (GObject *object, GAsyncResult *result, gpointer user_ NMClientInitData *init_data = user_data; GError *error = NULL; - if (g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error)) - g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE); - else + if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error)) + g_simple_async_result_take_error (init_data->result, error); + + init_data->manager_inited = TRUE; + if (init_data->settings_inited) + init_async_complete (init_data); +} + +static void +init_async_inited_settings (GObject *object, GAsyncResult *result, gpointer user_data) +{ + NMClientInitData *init_data = user_data; + GError *error = NULL; + + if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error)) g_simple_async_result_take_error (init_data->result, error); - init_async_complete (init_data); + init_data->settings_inited = TRUE; + if (init_data->manager_inited) + init_async_complete (init_data); } static void @@ -1248,6 +1808,9 @@ init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_d g_async_initable_init_async (G_ASYNC_INITABLE (priv->manager), G_PRIORITY_DEFAULT, init_data->cancellable, init_async_inited_manager, init_data); + g_async_initable_init_async (G_ASYNC_INITABLE (priv->settings), + G_PRIORITY_DEFAULT, init_data->cancellable, + init_async_inited_settings, init_data); } static void @@ -1292,6 +1855,7 @@ dispose (GObject *object) NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object); g_clear_object (&priv->manager); + g_clear_object (&priv->settings); G_OBJECT_CLASS (nm_client_parent_class)->dispose (object); } @@ -1338,6 +1902,12 @@ get_property (GObject *object, guint prop_id, g_object_get_property (G_OBJECT (NM_CLIENT_GET_PRIVATE (object)->manager), pspec->name, value); break; + case PROP_CONNECTIONS: + case PROP_HOSTNAME: + case PROP_CAN_MODIFY: + g_object_get_property (G_OBJECT (NM_CLIENT_GET_PRIVATE (object)->settings), + pspec->name, value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1559,6 +2129,48 @@ nm_client_class_init (NMClientClass *client_class) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + /** + * NMClient:connections: + * + * The list of configured connections that are available to the user. (Note + * that this differs from the underlying D-Bus property, which may also + * contain the object paths of connections that the user does not have + * permission to read the details of.) + * + * Element-type: NMRemoteConnection + */ + g_object_class_install_property + (object_class, PROP_CONNECTIONS, + g_param_spec_boxed (NM_CLIENT_CONNECTIONS, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + /** + * NMClient:hostname: + * + * The machine hostname stored in persistent configuration. This can be + * modified by calling nm_client_save_hostname(). + */ + g_object_class_install_property + (object_class, PROP_HOSTNAME, + g_param_spec_string (NM_CLIENT_HOSTNAME, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + /** + * NMClient:can-modify: + * + * If %TRUE, adding and modifying connections is supported. + */ + g_object_class_install_property + (object_class, PROP_CAN_MODIFY, + g_param_spec_boolean (NM_CLIENT_CAN_MODIFY, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + /* signals */ /** @@ -1569,7 +2181,7 @@ nm_client_class_init (NMClientClass *client_class) * Notifies that a #NMDevice is added. **/ signals[DEVICE_ADDED] = - g_signal_new ("device-added", + g_signal_new (NM_CLIENT_DEVICE_ADDED, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMClientClass, device_added), @@ -1585,7 +2197,7 @@ nm_client_class_init (NMClientClass *client_class) * Notifies that a #NMDevice is removed. **/ signals[DEVICE_REMOVED] = - g_signal_new ("device-removed", + g_signal_new (NM_CLIENT_DEVICE_REMOVED, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMClientClass, device_removed), @@ -1602,11 +2214,42 @@ nm_client_class_init (NMClientClass *client_class) * Notifies that a permission has changed **/ signals[PERMISSION_CHANGED] = - g_signal_new ("permission-changed", + g_signal_new (NM_CLIENT_PERMISSION_CHANGED, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); + /** + * NMClient::connection-added: + * @client: the settings object that received the signal + * @connection: the new connection + * + * Notifies that a #NMConnection has been added. + **/ + signals[CONNECTION_ADDED] = + g_signal_new (NM_CLIENT_CONNECTION_ADDED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMClientClass, connection_added), + NULL, NULL, NULL, + G_TYPE_NONE, 1, + NM_TYPE_REMOTE_CONNECTION); + + /** + * NMClient::connection-removed: + * @client: the settings object that received the signal + * @connection: the removed connection + * + * Notifies that a #NMConnection has been removed. + **/ + signals[CONNECTION_REMOVED] = + g_signal_new (NM_CLIENT_CONNECTION_REMOVED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMClientClass, connection_removed), + NULL, NULL, NULL, + G_TYPE_NONE, 1, + NM_TYPE_REMOTE_CONNECTION); } static void diff --git a/libnm/nm-client.h b/libnm/nm-client.h index bcb897eada..99de7e003a 100644 --- a/libnm/nm-client.h +++ b/libnm/nm-client.h @@ -29,9 +29,11 @@ #include <glib.h> #include <glib-object.h> #include <gio/gio.h> + #include <nm-dbus-interface.h> #include "nm-device.h" #include "nm-active-connection.h" +#include "nm-remote-connection.h" #include "nm-vpn-connection.h" G_BEGIN_DECLS @@ -59,6 +61,15 @@ G_BEGIN_DECLS #define NM_CLIENT_PRIMARY_CONNECTION "primary-connection" #define NM_CLIENT_ACTIVATING_CONNECTION "activating-connection" #define NM_CLIENT_DEVICES "devices" +#define NM_CLIENT_CONNECTIONS "connections" +#define NM_CLIENT_HOSTNAME "hostname" +#define NM_CLIENT_CAN_MODIFY "can-modify" + +#define NM_CLIENT_DEVICE_ADDED "device-added" +#define NM_CLIENT_DEVICE_REMOVED "device-removed" +#define NM_CLIENT_PERMISSION_CHANGED "permission-changed" +#define NM_CLIENT_CONNECTION_ADDED "connection-added" +#define NM_CLIENT_CONNECTION_REMOVED "connection-removed" /** * NMClientPermission: @@ -131,12 +142,18 @@ typedef enum { * @NM_CLIENT_ERROR_UNKNOWN: unknown or unclassified error * @NM_CLIENT_ERROR_MANAGER_NOT_RUNNING: an operation that requires NetworkManager * failed because NetworkManager is not running + * @NM_CLIENT_ERROR_CONNECTION_REMOVED: the #NMRemoteConnection object + * was removed before it was completely initialized + * @NM_CLIENT_ERROR_CONNECTION_UNAVAILABLE: the #NMRemoteConnection object + * is not visible or otherwise unreadable * * Describes errors that may result from operations involving a #NMClient. **/ typedef enum { NM_CLIENT_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/ NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, /*< nick=ManagerNotRunning >*/ + NM_CLIENT_ERROR_CONNECTION_REMOVED, /*< nick=ConnectionRemoved >*/ + NM_CLIENT_ERROR_CONNECTION_UNAVAILABLE, /*< nick=ConnectionUnavailable >*/ } NMClientError; #define NM_CLIENT_ERROR nm_client_error_quark () @@ -155,6 +172,8 @@ typedef struct { void (*permission_changed) (NMClient *client, NMClientPermission permission, NMClientPermissionResult result); + void (*connection_added) (NMClient *client, NMRemoteConnection *connection); + void (*connection_removed) (NMClient *client, NMRemoteConnection *connection); /*< private >*/ gpointer padding[8]; @@ -218,6 +237,19 @@ NMConnectivityState nm_client_check_connectivity_finish (NMClient *client, GAsyncResult *result, GError **error); +gboolean nm_client_save_hostname (NMClient *client, + const char *hostname, + GCancellable *cancellable, + GError **error); +void nm_client_save_hostname_async (NMClient *client, + const char *hostname, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean nm_client_save_hostname_finish (NMClient *client, + GAsyncResult *result, + GError **error); + /* Devices */ const GPtrArray *nm_client_get_devices (NMClient *client); @@ -266,6 +298,50 @@ gboolean nm_client_deactivate_connection_finish (NMClient *client, GAsyncResult *result, GError **error); +/* Connections */ + +GSList *nm_client_list_connections (NMClient *client); + +NMRemoteConnection *nm_client_get_connection_by_id (NMClient *client, const char *id); +NMRemoteConnection *nm_client_get_connection_by_path (NMClient *client, const char *path); +NMRemoteConnection *nm_client_get_connection_by_uuid (NMClient *client, const char *uuid); + +void nm_client_add_connection_async (NMClient *client, + NMConnection *connection, + gboolean save_to_disk, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +NMRemoteConnection *nm_client_add_connection_finish (NMClient *client, + GAsyncResult *result, + GError **error); + +gboolean nm_client_load_connections (NMClient *client, + char **filenames, + char ***failures, + GCancellable *cancellable, + GError **error); +void nm_client_load_connections_async (NMClient *client, + char **filenames, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean nm_client_load_connections_finish (NMClient *client, + char ***failures, + GAsyncResult *result, + GError **error); + +gboolean nm_client_reload_connections (NMClient *client, + GCancellable *cancellable, + GError **error); +void nm_client_reload_connections_async (NMClient *client, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean nm_client_reload_connections_finish (NMClient *client, + GAsyncResult *result, + GError **error); + G_END_DECLS #endif /* __NM_CLIENT_H__ */ diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c index 5ed6d03949..12e5450375 100644 --- a/libnm/nm-remote-settings.c +++ b/libnm/nm-remote-settings.c @@ -24,6 +24,7 @@ #include <nm-connection.h> #include "nm-remote-settings.h" +#include "nm-client.h" #include "nm-remote-connection-private.h" #include "nm-object-private.h" #include "nm-dbus-helpers.h" @@ -33,99 +34,6 @@ #include "nmdbus-settings.h" -/** - * SECTION:nm-remote-settings - * @Short_description: A helper for NetworkManager's settings API - * @Title: NMRemoteSettings - * @See_also:#NMRemoteConnection, #NMClient - * - * The #NMRemoteSettings object represents NetworkManager's "settings" service, - * which stores network configuration and allows authenticated clients to - * add, delete, and modify that configuration. The data required to connect - * to a specific network is called a "connection" and encapsulated by the - * #NMConnection object. Once a connection is known to NetworkManager, having - * either been added by a user or read from on-disk storage, the - * #NMRemoteSettings object creates a #NMRemoteConnection object which - * represents this stored connection. Use the #NMRemoteConnection object to - * perform any operations like modification or deletion. - * - * To add a new network connection to the NetworkManager settings service, first - * build up a template #NMConnection object. Since this connection is not yet - * added to NetworkManager, it is known only to your program and is not yet - * an #NMRemoteConnection. Then ask #NMRemoteSettings to add your connection. - * When the connection is added successfully, the supplied callback is called - * and returns to your program the new #NMRemoteConnection which represents - * the stored object known to NetworkManager. - * - * |[<!-- language="C" --> - * static void - * added_cb (GObject *object, - * GAsyncResult *result, - * gpointer user_data) - * { - * NMRemoteConnection *remote; - * GError *error = NULL; - * - * remote = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (object), - * result, &error); - * if (error) { - * g_print ("Error adding connection: %s", error->message); - * g_clear_error (&error); - * } else { - * g_print ("Added: %s\n", nm_connection_get_path (NM_CONNECTION (remote))); - * /* Use 'remote' with nm_remote_connection_commit_changes() to save - * * changes and nm_remote_connection_delete() to delete the connection */ - * } - * } - * - * static gboolean - * add_wired_connection (const char *human_name) - * { - * NMConnection *connection; - * NMSettingConnection *s_con; - * NMSettingWired *s_wired; - * char *uuid; - * gboolean success; - * - * connection = nm_simple_connection_new (); - * - * /* Build up the 'connection' setting */ - * s_con = (NMSettingConnection *) nm_setting_connection_new (); - * uuid = nm_utils_uuid_generate (); - * g_object_set (G_OBJECT (s_con), - * NM_SETTING_CONNECTION_UUID, uuid, - * NM_SETTING_CONNECTION_ID, human_name, - * NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, - * NULL); - * g_free (uuid); - * nm_connection_add_setting (connection, NM_SETTING (s_con)); - * - * /* Add the required 'wired' setting as this is a wired connection */ - * nm_connection_add_setting (connection, nm_setting_wired_new ()); - * - * /* Add an 'ipv4' setting using AUTO configuration (eg DHCP) */ - * s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); - * g_object_set (G_OBJECT (s_ip4), - * NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, - * NULL); - * nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - * - * /* Ask NetworkManager to store the connection */ - * success = nm_remote_settings_add_connection_async (settings, connection, - * NULL, added_cb, NULL); - * - * /* Release the template connection; the actual stored connection will - * * be returned in added_cb() */ - * g_object_unref (connection); - * - * /* Let glib event loop run and added_cb() will be called when NetworkManager - * * is done adding the new connection. */ - * - * return success; - * } - * ]| - */ - G_DEFINE_TYPE (NMRemoteSettings, nm_remote_settings, NM_TYPE_OBJECT) #define NM_REMOTE_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsPrivate)) @@ -144,7 +52,6 @@ typedef struct { enum { PROP_0, - PROP_NM_RUNNING, PROP_CONNECTIONS, PROP_HOSTNAME, PROP_CAN_MODIFY, @@ -163,25 +70,6 @@ static guint signals[LAST_SIGNAL] = { 0 }; /**********************************************************************/ -/** - * nm_remote_settings_error_quark: - * - * Registers an error quark for #NMRemoteSettings if necessary. - * - * Returns: the error quark used for #NMRemoteSettings errors. - **/ -GQuark -nm_remote_settings_error_quark (void) -{ - static GQuark quark; - - if (G_UNLIKELY (!quark)) - quark = g_quark_from_static_string ("nm-remote-settings-error-quark"); - return quark; -} - -/**********************************************************************/ - typedef struct { NMRemoteSettings *self; GSimpleAsyncResult *simple; @@ -255,16 +143,6 @@ get_connection_by_string (NMRemoteSettings *settings, return NULL; } -/** - * nm_remote_settings_get_connection_by_id: - * @settings: the %NMRemoteSettings - * @id: the id of the remote connection - * - * Returns the first matching %NMRemoteConnection matching a given @id. - * - * Returns: (transfer none): the remote connection object on success, or %NULL if no - * matching object was found. - **/ NMRemoteConnection * nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, const char *id) { @@ -274,16 +152,6 @@ nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, const char return get_connection_by_string (settings, id, nm_connection_get_id); } -/** - * nm_remote_settings_get_connection_by_path: - * @settings: the %NMRemoteSettings - * @path: the D-Bus object path of the remote connection - * - * Returns the %NMRemoteConnection representing the connection at @path. - * - * Returns: (transfer none): the remote connection object on success, or %NULL if the object was - * not known - **/ NMRemoteConnection * nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, const char *path) { @@ -293,16 +161,6 @@ nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, const cha return get_connection_by_string (settings, path, nm_connection_get_path); } -/** - * nm_remote_settings_get_connection_by_uuid: - * @settings: the %NMRemoteSettings - * @uuid: the UUID of the remote connection - * - * Returns the %NMRemoteConnection identified by @uuid. - * - * Returns: (transfer none): the remote connection object on success, or %NULL if the object was - * not known - **/ NMRemoteConnection * nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings, const char *uuid) { @@ -393,25 +251,14 @@ object_creation_failed (NMObject *object, GError *error, char *failed_path) addinfo = add_connection_info_find (self, failed_path); if (addinfo) { - add_error = g_error_new_literal (NM_REMOTE_SETTINGS_ERROR, - NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED, + add_error = g_error_new_literal (NM_CLIENT_ERROR, + NM_CLIENT_ERROR_CONNECTION_REMOVED, "Connection removed before it was initialized"); add_connection_info_complete (self, addinfo, NULL, add_error); g_error_free (add_error); } } -/** - * nm_remote_settings_list_connections: - * @settings: the %NMRemoteSettings - * - * Returns: (transfer container) (element-type NMRemoteConnection): a - * list containing all connections provided by the remote settings service. - * Each element of the returned list is a %NMRemoteConnection instance, which is - * owned by the %NMRemoteSettings object and should not be freed by the caller. - * The returned list is, however, owned by the caller and should be freed - * using g_slist_free() when no longer required. - **/ GSList * nm_remote_settings_list_connections (NMRemoteSettings *settings) { @@ -432,18 +279,6 @@ nm_remote_settings_list_connections (NMRemoteSettings *settings) return list; } -static gboolean -settings_service_is_running (NMRemoteSettings *settings, GError **error) -{ - if (!_nm_object_get_nm_running (NM_OBJECT (settings))) { - g_set_error_literal (error, NM_REMOTE_SETTINGS_ERROR, - NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE, - "NetworkManager is not running."); - return FALSE; - } else - return TRUE; -} - static void add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data) { @@ -470,31 +305,6 @@ add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data) */ } -/** - * nm_remote_settings_add_connection_async: - * @settings: the %NMRemoteSettings - * @connection: the connection to add. Note that this object's settings will be - * added, not the object itself - * @save_to_disk: whether to immediately save the connection to disk - * @cancellable: a #GCancellable, or %NULL - * @callback: (scope async): callback to be called when the add operation completes - * @user_data: (closure): caller-specific data passed to @callback - * - * Requests that the remote settings service add the given settings to a new - * connection. If @save_to_disk is %TRUE, the connection is immediately written - * to disk; otherwise it is initially only stored in memory, but may be saved - * later by calling the connection's nm_remote_connection_commit_changes() - * method. - * - * @connection is untouched by this function and only serves as a template of - * the settings to add. The #NMRemoteConnection object that represents what - * NetworkManager actually added is returned to @callback when the addition - * operation is complete. - * - * Note that the #NMRemoteConnection returned in @callback may not contain - * identical settings to @connection as NetworkManager may perform automatic - * completion and/or normalization of connection properties. - **/ void nm_remote_settings_add_connection_async (NMRemoteSettings *settings, NMConnection *connection, @@ -506,18 +316,12 @@ nm_remote_settings_add_connection_async (NMRemoteSettings *settings, NMRemoteSettingsPrivate *priv; AddConnectionInfo *info; GVariant *new_settings; - GError *error = NULL; g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings)); g_return_if_fail (NM_IS_CONNECTION (connection)); priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - if (!settings_service_is_running (settings, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (settings), callback, user_data, error); - return; - } - info = g_slice_new0 (AddConnectionInfo); info->self = settings; info->simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data, @@ -541,17 +345,6 @@ nm_remote_settings_add_connection_async (NMRemoteSettings *settings, priv->add_list = g_slist_append (priv->add_list, info); } -/** - * nm_remote_settings_add_connection_finish: - * @settings: an #NMRemoteSettings - * @result: the result passed to the #GAsyncReadyCallback - * @error: location for a #GError, or %NULL - * - * Gets the result of a call to nm_remote_settings_add_connection_async(). - * - * Returns: (transfer full): the new #NMRemoteConnection on success, %NULL on - * failure, in which case @error will be set. - **/ NMRemoteConnection * nm_remote_settings_add_connection_finish (NMRemoteSettings *settings, GAsyncResult *result, @@ -568,30 +361,6 @@ nm_remote_settings_add_connection_finish (NMRemoteSettings *settings, return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); } -/** - * nm_remote_settings_load_connections: - * @settings: the %NMRemoteSettings - * @filenames: %NULL-terminated array of filenames to load - * @failures: (out) (transfer full): on return, a %NULL-terminated array of - * filenames that failed to load - * @cancellable: a #GCancellable, or %NULL - * @error: return location for #GError - * - * Requests that the remote settings service load or reload the given files, - * adding or updating the connections described within. - * - * The changes to the indicated files will not yet be reflected in - * @settings's connections array when the function returns. - * - * If all of the indicated files were successfully loaded, the - * function will return %TRUE, and @failures will be set to %NULL. If - * NetworkManager tried to load the files, but some (or all) failed, - * then @failures will be set to a %NULL-terminated array of the - * filenames that failed to load. - * - * Returns: %TRUE if NetworkManager at least tried to load @filenames, - * %FALSE if an error occurred (eg, permission denied). - **/ gboolean nm_remote_settings_load_connections (NMRemoteSettings *settings, char **filenames, @@ -607,9 +376,6 @@ nm_remote_settings_load_connections (NMRemoteSettings *settings, priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - if (!settings_service_is_running (settings, error)) - return FALSE; - if (!nmdbus_settings_call_load_connections_sync (priv->proxy, (const char * const *) filenames, &success, @@ -639,19 +405,6 @@ load_connections_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) g_object_unref (simple); } -/** - * nm_remote_settings_load_connections_async: - * @settings: the %NMRemoteSettings - * @filenames: %NULL-terminated array of filenames to load - * @cancellable: a #GCancellable, or %NULL - * @callback: (scope async): callback to be called when the operation completes - * @user_data: (closure): caller-specific data passed to @callback - * - * Requests that the remote settings service asynchronously load or reload the - * given files, adding or updating the connections described within. - * - * See nm_remote_settings_load_connections() for more details. - **/ void nm_remote_settings_load_connections_async (NMRemoteSettings *settings, char **filenames, @@ -661,7 +414,6 @@ nm_remote_settings_load_connections_async (NMRemoteSettings *settings, { NMRemoteSettingsPrivate *priv; GSimpleAsyncResult *simple; - GError *error = NULL; g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings)); g_return_if_fail (filenames != NULL); @@ -671,33 +423,11 @@ nm_remote_settings_load_connections_async (NMRemoteSettings *settings, simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data, nm_remote_settings_load_connections_async); - if (!settings_service_is_running (settings, &error)) { - g_simple_async_result_take_error (simple, error); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); - return; - } - nmdbus_settings_call_load_connections (priv->proxy, (const char * const *) filenames, cancellable, load_connections_cb, simple); } -/** - * nm_remote_settings_load_connections_finish: - * @settings: the %NMRemoteSettings - * @failures: (out) (transfer full): on return, a %NULL-terminated array of - * filenames that failed to load - * @result: the result passed to the #GAsyncReadyCallback - * @error: location for a #GError, or %NULL - * - * Gets the result of an nm_remote_settings_load_connections_async() call. - - * See nm_remote_settings_load_connections() for more details. - * - * Returns: %TRUE if NetworkManager at least tried to load @filenames, - * %FALSE if an error occurred (eg, permission denied). - **/ gboolean nm_remote_settings_load_connections_finish (NMRemoteSettings *settings, char ***failures, @@ -717,18 +447,6 @@ nm_remote_settings_load_connections_finish (NMRemoteSettings *settings, } } -/** - * nm_remote_settings_reload_connections: - * @settings: the #NMRemoteSettings - * @cancellable: a #GCancellable, or %NULL - * @error: return location for #GError - * - * Requests that the remote settings service reload all connection - * files from disk, adding, updating, and removing connections until - * the in-memory state matches the on-disk state. - * - * Return value: %TRUE on success, %FALSE on failure - **/ gboolean nm_remote_settings_reload_connections (NMRemoteSettings *settings, GCancellable *cancellable, @@ -741,9 +459,6 @@ nm_remote_settings_reload_connections (NMRemoteSettings *settings, priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - if (!settings_service_is_running (settings, error)) - return FALSE; - if (!nmdbus_settings_call_reload_connections_sync (priv->proxy, &success, cancellable, error)) success = FALSE; @@ -769,17 +484,6 @@ reload_connections_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) g_object_unref (simple); } -/** - * nm_remote_settings_reload_connections_async: - * @settings: the #NMRemoteSettings - * @cancellable: a #GCancellable, or %NULL - * @callback: (scope async): callback to be called when the reload operation completes - * @user_data: (closure): caller-specific data passed to @callback - * - * Requests that the remote settings service begin reloading all connection - * files from disk, adding, updating, and removing connections until the - * in-memory state matches the on-disk state. - **/ void nm_remote_settings_reload_connections_async (NMRemoteSettings *settings, GCancellable *cancellable, @@ -788,7 +492,6 @@ nm_remote_settings_reload_connections_async (NMRemoteSettings *settings, { NMRemoteSettingsPrivate *priv; GSimpleAsyncResult *simple; - GError *error = NULL; g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings)); @@ -797,27 +500,10 @@ nm_remote_settings_reload_connections_async (NMRemoteSettings *settings, simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data, nm_remote_settings_reload_connections_async); - if (!settings_service_is_running (settings, &error)) { - g_simple_async_result_take_error (simple, error); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); - return; - } - nmdbus_settings_call_reload_connections (priv->proxy, cancellable, reload_connections_cb, simple); } -/** - * nm_remote_settings_reload_connections_finish: - * @settings: the #NMRemoteSettings - * @result: the result passed to the #GAsyncReadyCallback - * @error: return location for #GError - * - * Gets the result of an nm_remote_settings_reload_connections_async() call. - * - * Return value: %TRUE on success, %FALSE on failure - **/ gboolean nm_remote_settings_reload_connections_finish (NMRemoteSettings *settings, GAsyncResult *result, @@ -834,19 +520,6 @@ nm_remote_settings_reload_connections_finish (NMRemoteSettings *settings, return g_simple_async_result_get_op_res_gboolean (simple); } -/** - * nm_remote_settings_save_hostname: - * @settings: the %NMRemoteSettings - * @hostname: (allow-none): the new persistent hostname to set, or %NULL to - * clear any existing persistent hostname - * @cancellable: a #GCancellable, or %NULL - * @error: return location for #GError - * - * Requests that the machine's persistent hostname be set to the specified value - * or cleared. - * - * Returns: %TRUE if the request was successful, %FALSE if it failed - **/ gboolean nm_remote_settings_save_hostname (NMRemoteSettings *settings, const char *hostname, @@ -859,9 +532,6 @@ nm_remote_settings_save_hostname (NMRemoteSettings *settings, priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - if (!settings_service_is_running (settings, error)) - return FALSE; - return nmdbus_settings_call_save_hostname_sync (priv->proxy, hostname ? hostname : "", cancellable, error); @@ -883,18 +553,6 @@ save_hostname_cb (GObject *proxy, g_object_unref (simple); } -/** - * nm_remote_settings_save_hostname_async: - * @settings: the %NMRemoteSettings - * @hostname: (allow-none): the new persistent hostname to set, or %NULL to - * clear any existing persistent hostname - * @cancellable: a #GCancellable, or %NULL - * @callback: (scope async): callback to be called when the operation completes - * @user_data: (closure): caller-specific data passed to @callback - * - * Requests that the machine's persistent hostname be set to the specified value - * or cleared. - **/ void nm_remote_settings_save_hostname_async (NMRemoteSettings *settings, const char *hostname, @@ -904,7 +562,6 @@ nm_remote_settings_save_hostname_async (NMRemoteSettings *settings, { NMRemoteSettingsPrivate *priv; GSimpleAsyncResult *simple; - GError *error = NULL; g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings)); @@ -913,28 +570,11 @@ nm_remote_settings_save_hostname_async (NMRemoteSettings *settings, simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data, nm_remote_settings_save_hostname_async); - if (!settings_service_is_running (settings, &error)) { - g_simple_async_result_take_error (simple, error); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); - return; - } - nmdbus_settings_call_save_hostname (priv->proxy, hostname ? hostname : "", cancellable, save_hostname_cb, simple); } -/** - * nm_remote_settings_save_hostname_finish: - * @settings: the %NMRemoteSettings - * @result: the result passed to the #GAsyncReadyCallback - * @error: return location for #GError - * - * Gets the result of an nm_remote_settings_save_hostname_async() call. - * - * Returns: %TRUE if the request was successful, %FALSE if it failed - **/ gboolean nm_remote_settings_save_hostname_finish (NMRemoteSettings *settings, GAsyncResult *result, @@ -954,15 +594,12 @@ nm_remote_settings_save_hostname_finish (NMRemoteSettings *settings, static void updated_properties (GObject *object, GAsyncResult *result, gpointer user_data) { - NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data); GError *error = NULL; if (!_nm_object_reload_properties_finish (NM_OBJECT (object), result, &error)) { g_warning ("%s: error reading NMRemoteSettings properties: %s", __func__, error->message); g_error_free (error); } - - g_object_notify (G_OBJECT (self), NM_REMOTE_SETTINGS_NM_RUNNING); } static void @@ -999,7 +636,6 @@ nm_running_changed (GObject *object, } _nm_object_suppress_property_updates (NM_OBJECT (self), TRUE); - g_object_notify (G_OBJECT (self), NM_REMOTE_SETTINGS_NM_RUNNING); } else { _nm_object_suppress_property_updates (NM_OBJECT (self), FALSE); _nm_object_reload_properties_async (NM_OBJECT (self), updated_properties, self); @@ -1010,70 +646,6 @@ nm_running_changed (GObject *object, /****************************************************************/ -/** - * nm_remote_settings_new: - * @cancellable: a #GCancellable, or %NULL - * @error: location for a #GError, or %NULL - * - * Creates a new object representing the remote settings service. - * - * Note that this will do blocking D-Bus calls to initialize the - * settings object. You can use nm_remote_settings_new_async() if you - * want to avoid that. - * - * Returns: the new remote settings object on success, or %NULL on failure - **/ -NMRemoteSettings * -nm_remote_settings_new (GCancellable *cancellable, - GError **error) -{ - return g_initable_new (NM_TYPE_REMOTE_SETTINGS, cancellable, error, - NULL); -} - -/** - * nm_remote_settings_new_async: - * @cancellable: a #GCancellable, or %NULL - * @callback: callback to call when the settings object is created - * @user_data: data for @callback - * - * Creates a new object representing the remote settings service and - * begins asynchronously initializing it. @callback will be called - * when it is done; use nm_remote_settings_new_finish() to get the - * result. - **/ -void -nm_remote_settings_new_async (GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_async_initable_new_async (NM_TYPE_REMOTE_SETTINGS, G_PRIORITY_DEFAULT, cancellable, - callback, user_data, - NULL); -} - -/** - * nm_remote_settings_new_finish: - * @result: a #GAsyncResult - * @error: location for a #GError, or %NULL - * - * Gets the result of an nm_remote_settings_new_async() call. - * - * Returns: a new #NMRemoteSettings object, or %NULL on error - **/ -NMRemoteSettings * -nm_remote_settings_new_finish (GAsyncResult *result, GError **error) -{ - GObject *source; - NMRemoteSettings *settings; - - source = g_async_result_get_source_object (result); - settings = (NMRemoteSettings *) g_async_initable_new_finish (G_ASYNC_INITABLE (source), result, error); - g_object_unref (source); - - return settings; -} - static void nm_remote_settings_init (NMRemoteSettings *self) { @@ -1160,9 +732,6 @@ get_property (GObject *object, guint prop_id, NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object); switch (prop_id) { - case PROP_NM_RUNNING: - g_value_set_boolean (value, _nm_object_get_nm_running (NM_OBJECT (object))); - break; case PROP_CONNECTIONS: g_value_take_boxed (value, _nm_utils_copy_object_array (priv->visible_connections)); break; @@ -1202,28 +771,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class) /* Properties */ - /** - * NMRemoteSettings:nm-running: - * - * Whether the NetworkManager settings service is running. - */ - g_object_class_install_property - (object_class, PROP_NM_RUNNING, - g_param_spec_boolean (NM_REMOTE_SETTINGS_NM_RUNNING, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - /** - * NMRemoteSettings:connections: - * - * The list of configured connections that are available to the user. (Note - * that this differs from the underlying D-Bus property, which may also - * contain the object paths of connections that the user does not have - * permission to read the details of.) - * - * Element-type: NMRemoteConnection - */ g_object_class_install_property (object_class, PROP_CONNECTIONS, g_param_spec_boxed (NM_REMOTE_SETTINGS_CONNECTIONS, "", "", @@ -1231,12 +778,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - /** - * NMRemoteSettings:hostname: - * - * The machine hostname stored in persistent configuration. This can be - * modified by calling nm_remote_settings_save_hostname(). - */ g_object_class_install_property (object_class, PROP_HOSTNAME, g_param_spec_string (NM_REMOTE_SETTINGS_HOSTNAME, "", "", @@ -1244,11 +785,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - /** - * NMRemoteSettings:can-modify: - * - * If %TRUE, adding and modifying connections is supported. - */ g_object_class_install_property (object_class, PROP_CAN_MODIFY, g_param_spec_boolean (NM_REMOTE_SETTINGS_CAN_MODIFY, "", "", @@ -1257,13 +793,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class) G_PARAM_STATIC_STRINGS)); /* Signals */ - /** - * NMRemoteSettings::connection-added: - * @settings: the settings object that received the signal - * @connection: the new connection - * - * Notifies that a #NMConnection has been added. - **/ signals[CONNECTION_ADDED] = g_signal_new (NM_REMOTE_SETTINGS_CONNECTION_ADDED, G_OBJECT_CLASS_TYPE (object_class), @@ -1273,13 +802,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class) G_TYPE_NONE, 1, NM_TYPE_REMOTE_CONNECTION); - /** - * NMRemoteSettings::connection-removed: - * @settings: the settings object that received the signal - * @connection: the removed connection - * - * Notifies that a #NMConnection has been removed. - **/ signals[CONNECTION_REMOVED] = g_signal_new (NM_REMOTE_SETTINGS_CONNECTION_REMOVED, G_OBJECT_CLASS_TYPE (object_class), diff --git a/libnm/nm-remote-settings.h b/libnm/nm-remote-settings.h index 1ada9a21dd..bed6a495e4 100644 --- a/libnm/nm-remote-settings.h +++ b/libnm/nm-remote-settings.h @@ -22,10 +22,6 @@ #ifndef __NM_REMOTE_SETTINGS_H__ #define __NM_REMOTE_SETTINGS_H__ -#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION) -#error "Only <NetworkManager.h> can be included directly." -#endif - #include <gio/gio.h> #include <nm-object.h> #include <nm-connection.h> @@ -40,30 +36,6 @@ G_BEGIN_DECLS #define NM_IS_REMOTE_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_REMOTE_SETTINGS)) #define NM_REMOTE_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsClass)) -/** - * NMRemoteSettingsError: - * @NM_REMOTE_SETTINGS_ERROR_UNKNOWN: unknown or unclassified error - * @NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED: the #NMRemoteConnection object - * was removed before it was completely initialized - * @NM_REMOTE_SETTINGS_ERROR_CONNECTION_UNAVAILABLE: the #NMRemoteConnection object - * is not visible or otherwise unreadable - * @NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE: NetworkManager is not running. - * - * Describes errors that may result from operations involving a #NMRemoteSettings. - * - **/ -typedef enum { - NM_REMOTE_SETTINGS_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/ - NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED, /*< nick=ConnectionRemoved >*/ - NM_REMOTE_SETTINGS_ERROR_CONNECTION_UNAVAILABLE, /*< nick=ConnectionUnavailable >*/ - NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE, /*< nick=ServiceUnavailable >*/ -} NMRemoteSettingsError; - -#define NM_REMOTE_SETTINGS_ERROR nm_remote_settings_error_quark () -GQuark nm_remote_settings_error_quark (void); - - -#define NM_REMOTE_SETTINGS_NM_RUNNING "nm-running" #define NM_REMOTE_SETTINGS_CONNECTIONS "connections" #define NM_REMOTE_SETTINGS_HOSTNAME "hostname" #define NM_REMOTE_SETTINGS_CAN_MODIFY "can-modify" @@ -93,15 +65,6 @@ struct _NMRemoteSettingsClass { GType nm_remote_settings_get_type (void); -NMRemoteSettings *nm_remote_settings_new (GCancellable *cancellable, - GError **error); - -void nm_remote_settings_new_async (GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -NMRemoteSettings *nm_remote_settings_new_finish (GAsyncResult *result, - GError **error); - GSList *nm_remote_settings_list_connections (NMRemoteSettings *settings); NMRemoteConnection *nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c index 1561ef9e42..ca0f03f6d4 100644 --- a/libnm/tests/test-remote-settings-client.c +++ b/libnm/tests/test-remote-settings-client.c @@ -30,7 +30,7 @@ #include "nm-test-utils.h" static NMTestServiceInfo *sinfo; -static NMRemoteSettings *settings = NULL; +static NMClient *client = NULL; GDBusConnection *bus = NULL; NMRemoteConnection *remote = NULL; @@ -44,14 +44,14 @@ add_cb (GObject *s, gboolean *done = user_data; GError *error = NULL; - remote = nm_remote_settings_add_connection_finish (settings, result, &error); + remote = nm_client_add_connection_finish (client, result, &error); g_assert_no_error (error); *done = TRUE; g_object_add_weak_pointer (G_OBJECT (remote), (void **) &remote); - /* nm_remote_settings_add_connection_finish() adds a ref to @remote, but we - * want the weak pointer to be cleared as soon as @settings drops its own ref. + /* nm_client_add_connection_finish() adds a ref to @remote, but we + * want the weak pointer to be cleared as soon as @client drops its own ref. * So drop ours. */ g_object_unref (remote); @@ -68,12 +68,12 @@ test_add_connection (void) connection = nmtst_create_minimal_connection (TEST_CON_ID, NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - nm_remote_settings_add_connection_async (settings, - connection, - TRUE, - NULL, - add_cb, - &done); + nm_client_add_connection_async (client, + connection, + TRUE, + NULL, + add_cb, + &done); start = time (NULL); do { @@ -113,7 +113,7 @@ visible_changed_cb (GObject *object, GParamSpec *pspec, gboolean *done) } static void -connection_removed_cb (NMRemoteSettings *s, NMRemoteConnection *connection, gboolean *done) +connection_removed_cb (NMClient *s, NMRemoteConnection *connection, gboolean *done) { if (connection == remote) *done = TRUE; @@ -143,7 +143,7 @@ test_make_invisible (void) /* Listen for the remove event when the connection becomes invisible */ g_signal_connect (remote, "notify::" NM_REMOTE_CONNECTION_VISIBLE, G_CALLBACK (visible_changed_cb), &visible_changed); - g_signal_connect (settings, "connection-removed", G_CALLBACK (connection_removed_cb), &connection_removed); + g_signal_connect (client, "connection-removed", G_CALLBACK (connection_removed_cb), &connection_removed); path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote))); proxy = g_dbus_proxy_new_sync (bus, @@ -156,7 +156,7 @@ test_make_invisible (void) NULL); g_assert (proxy != NULL); - /* Bypass the NMRemoteSettings object so we can test it independently */ + /* Bypass the NMClient object so we can test it independently */ g_dbus_proxy_call (proxy, "SetVisible", g_variant_new ("(b)", FALSE), @@ -174,10 +174,10 @@ test_make_invisible (void) g_assert (connection_removed == TRUE); g_signal_handlers_disconnect_by_func (remote, G_CALLBACK (visible_changed_cb), &visible_changed); - g_signal_handlers_disconnect_by_func (settings, G_CALLBACK (connection_removed_cb), &connection_removed); + g_signal_handlers_disconnect_by_func (client, G_CALLBACK (connection_removed_cb), &connection_removed); - /* Ensure NMRemoteSettings no longer has the connection */ - list = nm_remote_settings_list_connections (settings); + /* Ensure NMClient no longer has the connection */ + list = nm_client_list_connections (client); for (iter = list; iter; iter = g_slist_next (iter)) { NMConnection *candidate = NM_CONNECTION (iter->data); @@ -199,7 +199,7 @@ test_make_invisible (void) /*******************************************************************/ static void -vis_new_connection_cb (NMRemoteSettings *foo, +vis_new_connection_cb (NMClient *foo, NMRemoteConnection *connection, NMRemoteConnection **new) { @@ -219,7 +219,7 @@ test_make_visible (void) g_assert (remote != NULL); /* Wait for the new-connection signal when the connection is visible again */ - g_signal_connect (settings, NM_REMOTE_SETTINGS_CONNECTION_ADDED, + g_signal_connect (client, NM_CLIENT_CONNECTION_ADDED, G_CALLBACK (vis_new_connection_cb), &new); path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote))); @@ -233,7 +233,7 @@ test_make_visible (void) NULL); g_assert (proxy != NULL); - /* Bypass the NMRemoteSettings object so we can test it independently */ + /* Bypass the NMClient object so we can test it independently */ g_dbus_proxy_call (proxy, "SetVisible", g_variant_new ("(b)", TRUE), @@ -252,10 +252,10 @@ test_make_visible (void) g_assert (new); g_assert (new == remote); - g_signal_handlers_disconnect_by_func (settings, G_CALLBACK (vis_new_connection_cb), &new); + g_signal_handlers_disconnect_by_func (client, G_CALLBACK (vis_new_connection_cb), &new); - /* Ensure NMRemoteSettings has the connection */ - list = nm_remote_settings_list_connections (settings); + /* Ensure NMClient has the connection */ + list = nm_client_list_connections (client); for (iter = list; iter; iter = g_slist_next (iter)) { NMConnection *candidate = NM_CONNECTION (iter->data); @@ -288,7 +288,7 @@ deleted_cb (GObject *proxy, } static void -removed_cb (NMRemoteSettings *s, NMRemoteConnection *connection, gboolean *done) +removed_cb (NMClient *s, NMRemoteConnection *connection, gboolean *done) { if (connection == remote) *done = TRUE; @@ -305,14 +305,14 @@ test_remove_connection (void) char *path; /* Find a connection to delete */ - list = nm_remote_settings_list_connections (settings); + list = nm_client_list_connections (client); g_assert_cmpint (g_slist_length (list), >, 0); connection = NM_REMOTE_CONNECTION (list->data); g_assert (connection); g_assert (remote == connection); path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection))); - g_signal_connect (settings, "connection-removed", G_CALLBACK (removed_cb), &done); + g_signal_connect (client, "connection-removed", G_CALLBACK (removed_cb), &done); proxy = g_dbus_proxy_new_sync (bus, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, @@ -324,7 +324,7 @@ test_remove_connection (void) NULL); g_assert (proxy != NULL); - /* Bypass the NMRemoteSettings object so we can test it independently */ + /* Bypass the NMClient object so we can test it independently */ g_dbus_proxy_call (proxy, "Delete", NULL, @@ -341,8 +341,8 @@ test_remove_connection (void) g_assert (!remote); - /* Ensure NMRemoteSettings no longer has the connection */ - list = nm_remote_settings_list_connections (settings); + /* Ensure NMClient no longer has the connection */ + list = nm_client_list_connections (client); for (iter = list; iter; iter = g_slist_next (iter)) { NMConnection *candidate = NM_CONNECTION (iter->data); @@ -367,8 +367,8 @@ add_remove_cb (GObject *s, gboolean *done = user_data; GError *error = NULL; - connection = nm_remote_settings_add_connection_finish (settings, result, &error); - g_assert_error (error, NM_REMOTE_SETTINGS_ERROR, NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED); + connection = nm_client_add_connection_finish (client, result, &error); + g_assert_error (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_CONNECTION_REMOVED); g_assert (connection == NULL); *done = TRUE; @@ -396,12 +396,12 @@ test_add_remove_connection (void) g_variant_unref (ret); connection = nmtst_create_minimal_connection (TEST_ADD_REMOVE_ID, NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - nm_remote_settings_add_connection_async (settings, - connection, - TRUE, - NULL, - add_remove_cb, - &done); + nm_client_add_connection_async (client, + connection, + TRUE, + NULL, + add_remove_cb, + &done); start = time (NULL); do { @@ -415,91 +415,6 @@ test_add_remove_connection (void) /*******************************************************************/ -static GMainLoop *loop; - -static gboolean -loop_quit (gpointer user_data) -{ - g_main_loop_quit (loop); - return G_SOURCE_REMOVE; -} - -static void -settings_nm_running_changed (GObject *client, - GParamSpec *pspec, - gpointer user_data) -{ - int *running_changed = user_data; - - (*running_changed)++; - g_main_loop_quit (loop); -} - -static void -test_nm_running (void) -{ - NMRemoteSettings *settings2; - guint quit_id; - int running_changed = 0; - gboolean running; - GError *error = NULL; - - loop = g_main_loop_new (NULL, FALSE); - - g_object_get (G_OBJECT (settings), - NM_REMOTE_SETTINGS_NM_RUNNING, &running, - NULL); - g_assert (running == TRUE); - - /* Now kill the test service. */ - nm_test_service_cleanup (sinfo); - - settings2 = nm_remote_settings_new (NULL, &error); - g_assert_no_error (error); - g_assert (settings2 != NULL); - - /* settings2 should know that NM is running, but the previously-created - * settings hasn't gotten the news yet. - */ - g_object_get (G_OBJECT (settings2), - NM_REMOTE_SETTINGS_NM_RUNNING, &running, - NULL); - g_assert (running == FALSE); - g_object_get (G_OBJECT (settings), - NM_REMOTE_SETTINGS_NM_RUNNING, &running, - NULL); - g_assert (running == TRUE); - - g_signal_connect (settings, "notify::" NM_REMOTE_SETTINGS_NM_RUNNING, - G_CALLBACK (settings_nm_running_changed), &running_changed); - quit_id = g_timeout_add_seconds (5, loop_quit, loop); - g_main_loop_run (loop); - g_assert_cmpint (running_changed, ==, 1); - g_source_remove (quit_id); - - g_object_get (G_OBJECT (settings2), - NM_REMOTE_SETTINGS_NM_RUNNING, &running, - NULL); - g_assert (running == FALSE); - - /* Now restart it */ - sinfo = nm_test_service_init (); - - quit_id = g_timeout_add_seconds (5, loop_quit, loop); - g_main_loop_run (loop); - g_assert_cmpint (running_changed, ==, 2); - g_source_remove (quit_id); - - g_object_get (G_OBJECT (settings2), - NM_REMOTE_SETTINGS_NM_RUNNING, &running, - NULL); - g_assert (running == TRUE); - - g_object_unref (settings2); -} - -/*******************************************************************/ - int main (int argc, char **argv) { @@ -519,24 +434,23 @@ main (int argc, char **argv) sinfo = nm_test_service_init (); - settings = nm_remote_settings_new (NULL, &error); + client = nm_client_new (NULL, &error); g_assert_no_error (error); - g_assert (settings != NULL); + g_assert (client != NULL); /* FIXME: these tests assume that they get run in order, but g_test_run() * does not actually guarantee that! */ - g_test_add_func ("/remote_settings/add_connection", test_add_connection); - g_test_add_func ("/remote_settings/make_invisible", test_make_invisible); - g_test_add_func ("/remote_settings/make_visible", test_make_visible); - g_test_add_func ("/remote_settings/remove_connection", test_remove_connection); - g_test_add_func ("/remote_settings/add_remove_connection", test_add_remove_connection); - g_test_add_func ("/remote_settings/nm_running", test_nm_running); + g_test_add_func ("/client/add_connection", test_add_connection); + g_test_add_func ("/client/make_invisible", test_make_invisible); + g_test_add_func ("/client/make_visible", test_make_visible); + g_test_add_func ("/client/remove_connection", test_remove_connection); + g_test_add_func ("/client/add_remove_connection", test_add_remove_connection); ret = g_test_run (); nm_test_service_cleanup (sinfo); - g_object_unref (settings); + g_object_unref (client); g_object_unref (bus); return ret; diff --git a/libnm/tests/test-secret-agent.c b/libnm/tests/test-secret-agent.c index c4eafd7a40..de49893c75 100644 --- a/libnm/tests/test-secret-agent.c +++ b/libnm/tests/test-secret-agent.c @@ -182,7 +182,6 @@ test_secret_agent_new (void) typedef struct { NMTestServiceInfo *sinfo; NMClient *client; - NMRemoteSettings *settings; NMSecretAgent *agent; NMDevice *device; @@ -227,7 +226,7 @@ connection_added_cb (GObject *s, NMRemoteConnection *connection; GError *error = NULL; - connection = nm_remote_settings_add_connection_finish (sadata->settings, result, &error); + connection = nm_client_add_connection_finish (sadata->client, result, &error); g_assert_no_error (error); g_assert_cmpstr (nm_connection_get_id (NM_CONNECTION (connection)), ==, sadata->con_id); @@ -268,8 +267,6 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data) sadata->sinfo = nm_test_service_init (); sadata->client = nm_client_new (NULL, &error); g_assert_no_error (error); - sadata->settings = nm_remote_settings_new (NULL, &error); - g_assert_no_error (error); sadata->loop = g_main_loop_new (NULL, FALSE); sadata->timeout_id = g_timeout_add_seconds (5, timeout_assert, NULL); @@ -316,12 +313,12 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data) NULL); nm_connection_add_setting (connection, s_wsec); - nm_remote_settings_add_connection_async (sadata->settings, - connection, - TRUE, - NULL, - connection_added_cb, - sadata); + nm_client_add_connection_async (sadata->client, + connection, + TRUE, + NULL, + connection_added_cb, + sadata); g_object_unref (connection); g_main_loop_run (sadata->loop); @@ -358,7 +355,6 @@ test_cleanup (TestSecretAgentData *sadata, gconstpointer test_data) g_object_unref (sadata->connection); g_object_unref (sadata->client); - g_object_unref (sadata->settings); ret = g_dbus_proxy_call_sync (sadata->sinfo->proxy, "RemoveDevice", |