summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-09-11 16:12:40 -0400
committerDan Winship <danw@gnome.org>2014-09-25 09:29:20 -0400
commit6ca10677d67c129d43b82e5563e20c4c5f2e5727 (patch)
tree306a2322df2b18dbc5876065cd2f2eea8680bf60
parentdfdb4b8e6f547b8d8119ce75b7477d94b35eeb34 (diff)
downloadNetworkManager-6ca10677d67c129d43b82e5563e20c4c5f2e5727.tar.gz
libnm: merge saved and unsaved connection methods
Merge nm_remote_settings_add_connection() and nm_remote_settings_add_connection_unsaved(), and likewise nm_remote_connection_commit_changes() and nm_remote_connection_commit_changes_unsaved(), by adding a boolean flag to each saying whether to save to disk.
-rw-r--r--clients/cli/connections.c10
-rw-r--r--clients/tui/nmt-editor.c4
-rw-r--r--examples/C/glib/add-connection-libnm.c2
-rw-r--r--libnm/libnm.ver2
-rw-r--r--libnm/nm-remote-connection.c79
-rw-r--r--libnm/nm-remote-connection.h5
-rw-r--r--libnm/nm-remote-settings.c100
-rw-r--r--libnm/nm-remote-settings.h6
-rw-r--r--libnm/tests/test-remote-settings-client.c2
-rw-r--r--libnm/tests/test-secret-agent.c1
10 files changed, 74 insertions, 137 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index 28fa8f778a..985336e024 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -4896,10 +4896,7 @@ add_new_connection (gboolean persistent,
NMRemoteSettingsAddConnectionFunc callback,
gpointer user_data)
{
- if (persistent)
- return nm_remote_settings_add_connection (settings, connection, callback, user_data);
- else
- return nm_remote_settings_add_connection_unsaved (settings, connection, callback, user_data);
+ return nm_remote_settings_add_connection (settings, connection, persistent, callback, user_data);
}
static void
@@ -4908,10 +4905,7 @@ update_connection (gboolean persistent,
NMRemoteConnectionResultFunc callback,
gpointer user_data)
{
- if (persistent)
- nm_remote_connection_commit_changes (connection, callback, user_data);
- else
- nm_remote_connection_commit_changes_unsaved (connection, callback, user_data);
+ nm_remote_connection_commit_changes (connection, persistent, callback, user_data);
}
static char *
diff --git a/clients/tui/nmt-editor.c b/clients/tui/nmt-editor.c
index 0f35f48f04..46710efeae 100644
--- a/clients/tui/nmt-editor.c
+++ b/clients/tui/nmt-editor.c
@@ -133,7 +133,7 @@ save_connection_and_exit (NmtNewtButton *button,
nmt_sync_op_init (&op);
if (NM_IS_REMOTE_CONNECTION (priv->orig_connection)) {
- nm_remote_connection_commit_changes (NM_REMOTE_CONNECTION (priv->orig_connection),
+ nm_remote_connection_commit_changes (NM_REMOTE_CONNECTION (priv->orig_connection), TRUE,
connection_updated, &op);
if (!nmt_sync_op_wait_boolean (&op, &error)) {
nmt_newt_message_dialog (_("Unable to save connection: %s"),
@@ -147,7 +147,7 @@ save_connection_and_exit (NmtNewtButton *button,
*/
nm_connection_clear_secrets (priv->orig_connection);
} else {
- nm_remote_settings_add_connection (nm_settings, priv->orig_connection,
+ nm_remote_settings_add_connection (nm_settings, priv->orig_connection, TRUE,
connection_added, &op);
if (!nmt_sync_op_wait_boolean (&op, &error)) {
nmt_newt_message_dialog (_("Unable to add new connection: %s"),
diff --git a/examples/C/glib/add-connection-libnm.c b/examples/C/glib/add-connection-libnm.c
index 2b0143d35a..59632955b8 100644
--- a/examples/C/glib/add-connection-libnm.c
+++ b/examples/C/glib/add-connection-libnm.c
@@ -89,7 +89,7 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam
/* Ask the settings service to add the new connection; we'll quit the
* mainloop and exit when the callback is called.
*/
- success = nm_remote_settings_add_connection (settings, connection, added_cb, loop);
+ success = nm_remote_settings_add_connection (settings, connection, TRUE, added_cb, loop);
if (!success)
g_print ("Error adding connection\n");
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index c9329cc51a..3fe542932e 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -337,7 +337,6 @@ global:
nm_object_get_path;
nm_object_get_type;
nm_remote_connection_commit_changes;
- nm_remote_connection_commit_changes_unsaved;
nm_remote_connection_delete;
nm_remote_connection_error_get_type;
nm_remote_connection_error_quark;
@@ -347,7 +346,6 @@ global:
nm_remote_connection_get_visible;
nm_remote_connection_save;
nm_remote_settings_add_connection;
- nm_remote_settings_add_connection_unsaved;
nm_remote_settings_error_get_type;
nm_remote_settings_error_quark;
nm_remote_settings_get_connection_by_id;
diff --git a/libnm/nm-remote-connection.c b/libnm/nm-remote-connection.c
index 9c581928f9..6da5e180a9 100644
--- a/libnm/nm-remote-connection.c
+++ b/libnm/nm-remote-connection.c
@@ -63,6 +63,7 @@ struct RemoteCall {
RemoteCallFetchResultCb fetch_result_cb;
GFunc callback;
gpointer user_data;
+ gpointer call_data;
};
typedef struct {
@@ -131,9 +132,13 @@ update_result_cb (RemoteCall *call, GAsyncResult *result)
{
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self);
NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback;
+ gboolean save_to_disk = GPOINTER_TO_INT (call->call_data);
GError *error = NULL;
- nmdbus_settings_connection_call_update_finish (priv->proxy, result, &error);
+ if (save_to_disk)
+ nmdbus_settings_connection_call_update_finish (priv->proxy, result, &error);
+ else
+ nmdbus_settings_connection_call_update_unsaved_finish (priv->proxy, result, &error);
if (func)
(*func) (call->self, error, call->user_data);
g_clear_error (&error);
@@ -142,15 +147,21 @@ update_result_cb (RemoteCall *call, GAsyncResult *result)
/**
* nm_remote_connection_commit_changes:
* @connection: the #NMRemoteConnection
+ * @save_to_disk: whether to persist the changes to disk
* @callback: (scope async) (allow-none): a function to be called when the
* commit completes
* @user_data: (closure): caller-specific data to be passed to @callback
*
* Send any local changes to the settings and properties of this connection to
- * NetworkManager, which will immediately save them to disk.
+ * NetworkManager.
+ *
+ * If @save_to_disk is %TRUE, the changes will immediately be saved to disk.
+ * If %FALSE, then only the in-memory version is changed. (It can be saved to
+ * disk later with nm_remote_connection_save().)
**/
void
nm_remote_connection_commit_changes (NMRemoteConnection *self,
+ gboolean save_to_disk,
NMRemoteConnectionResultFunc callback,
gpointer user_data)
{
@@ -165,61 +176,21 @@ nm_remote_connection_commit_changes (NMRemoteConnection *self,
call = remote_call_new (self, update_result_cb, (GFunc) callback, user_data);
if (!call)
return;
+ call->call_data = GINT_TO_POINTER (save_to_disk);
settings = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ALL);
- nmdbus_settings_connection_call_update (priv->proxy,
- settings,
- NULL,
- remote_call_dbus_cb, call);
-}
-
-static void
-update_unsaved_result_cb (RemoteCall *call, GAsyncResult *result)
-{
- NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self);
- NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback;
- GError *error = NULL;
-
- nmdbus_settings_connection_call_update_unsaved_finish (priv->proxy, result, &error);
- if (func)
- (*func) (call->self, error, call->user_data);
- g_clear_error (&error);
-}
-/**
- * nm_remote_connection_commit_changes_unsaved:
- * @connection: the #NMRemoteConnection
- * @callback: (scope async) (allow-none): a function to be called when the
- * commit completes
- * @user_data: (closure): caller-specific data to be passed to @callback
- *
- * Send any local changes to the settings and properties of this connection to
- * NetworkManager. The changes are not saved to disk until either
- * nm_remote_connection_save() or nm_remote_connection_commit_changes() is
- * called.
- **/
-void
-nm_remote_connection_commit_changes_unsaved (NMRemoteConnection *connection,
- NMRemoteConnectionResultFunc callback,
- gpointer user_data)
-{
- NMRemoteConnectionPrivate *priv;
- GVariant *settings;
- RemoteCall *call;
-
- g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
-
- priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
-
- call = remote_call_new (connection, update_unsaved_result_cb, (GFunc) callback, user_data);
- if (!call)
- return;
-
- settings = nm_connection_to_dbus (NM_CONNECTION (connection), NM_CONNECTION_SERIALIZE_ALL);
- nmdbus_settings_connection_call_update_unsaved (priv->proxy,
- settings,
- NULL,
- remote_call_dbus_cb, call);
+ if (save_to_disk) {
+ nmdbus_settings_connection_call_update (priv->proxy,
+ settings,
+ NULL,
+ remote_call_dbus_cb, call);
+ } else {
+ nmdbus_settings_connection_call_update_unsaved (priv->proxy,
+ settings,
+ NULL,
+ remote_call_dbus_cb, call);
+ }
}
static void
diff --git a/libnm/nm-remote-connection.h b/libnm/nm-remote-connection.h
index fc5b87d8a0..5c6bebf65a 100644
--- a/libnm/nm-remote-connection.h
+++ b/libnm/nm-remote-connection.h
@@ -105,13 +105,10 @@ typedef void (*NMRemoteConnectionGetSecretsFunc) (NMRemoteConnection *connection
GType nm_remote_connection_get_type (void);
void nm_remote_connection_commit_changes (NMRemoteConnection *connection,
+ gboolean save_to_disk,
NMRemoteConnectionResultFunc callback,
gpointer user_data);
-void nm_remote_connection_commit_changes_unsaved (NMRemoteConnection *connection,
- NMRemoteConnectionResultFunc callback,
- gpointer user_data);
-
void nm_remote_connection_save (NMRemoteConnection *connection,
NMRemoteConnectionResultFunc callback,
gpointer user_data);
diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c
index 8c9eb0940f..a867f638b3 100644
--- a/libnm/nm-remote-settings.c
+++ b/libnm/nm-remote-settings.c
@@ -181,6 +181,7 @@ typedef struct {
NMRemoteSettingsAddConnectionFunc callback;
gpointer callback_data;
char *path;
+ gboolean saved;
} AddConnectionInfo;
static AddConnectionInfo *
@@ -430,14 +431,24 @@ add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data)
AddConnectionInfo *info = user_data;
GError *error = NULL;
- if (nmdbus_settings_call_add_connection_finish (NMDBUS_SETTINGS (proxy),
- &info->path,
- result, &error)) {
- /* Wait until this connection is fully initialized before calling the callback */
+ if (info->saved) {
+ nmdbus_settings_call_add_connection_finish (NMDBUS_SETTINGS (proxy),
+ &info->path,
+ result, &error);
} else {
+ nmdbus_settings_call_add_connection_unsaved_finish (NMDBUS_SETTINGS (proxy),
+ &info->path,
+ result, &error);
+ }
+
+ if (error) {
add_connection_info_complete (info->self, info, NULL, error);
g_clear_error (&error);
}
+
+ /* On success, we still have to wait until the connection is fully
+ * initialized before calling the callback.
+ */
}
/**
@@ -445,14 +456,20 @@ add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data)
* @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
* @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. The connection is immediately written to disk. @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.
+ * 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
@@ -463,6 +480,7 @@ add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data)
gboolean
nm_remote_settings_add_connection (NMRemoteSettings *settings,
NMConnection *connection,
+ gboolean save_to_disk,
NMRemoteSettingsAddConnectionFunc callback,
gpointer user_data)
{
@@ -483,68 +501,28 @@ nm_remote_settings_add_connection (NMRemoteSettings *settings,
info->self = settings;
info->callback = callback;
info->callback_data = user_data;
+ info->saved = save_to_disk;
new_settings = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
- nmdbus_settings_call_add_connection (priv->proxy,
- new_settings,
- NULL,
- add_connection_done, info);
- priv->add_list = g_slist_append (priv->add_list, info);
-
- return TRUE;
-}
-
-/**
- * nm_remote_settings_add_connection_unsaved:
- * @settings: the %NMRemoteSettings
- * @connection: the connection to add. Note that this object's settings will be
- * added, not the object itself
- * @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. The connection is not written to disk, which may be done at
- * a later time by calling the connection's nm_remote_connection_commit_changes()
- * method.
- *
- * Returns: %TRUE if the request was successful, %FALSE if it failed
- **/
-gboolean
-nm_remote_settings_add_connection_unsaved (NMRemoteSettings *settings,
- NMConnection *connection,
- NMRemoteSettingsAddConnectionFunc callback,
- gpointer user_data)
-{
- NMRemoteSettingsPrivate *priv;
- AddConnectionInfo *info;
- GVariant *new_settings;
-
- g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
- g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
- g_return_val_if_fail (callback != NULL, FALSE);
-
- priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
-
- if (!_nm_object_get_nm_running (NM_OBJECT (settings)))
- return FALSE;
-
- info = g_malloc0 (sizeof (AddConnectionInfo));
- info->self = settings;
- info->callback = callback;
- info->callback_data = user_data;
-
- new_settings = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
- nmdbus_settings_call_add_connection_unsaved (priv->proxy,
- new_settings,
- NULL,
- add_connection_done, info);
+ if (save_to_disk) {
+ nmdbus_settings_call_add_connection (priv->proxy,
+ new_settings,
+ NULL,
+ add_connection_done, info);
+ } else {
+ nmdbus_settings_call_add_connection_unsaved (priv->proxy,
+ new_settings,
+ NULL,
+ add_connection_done, info);
+ }
priv->add_list = g_slist_append (priv->add_list, info);
return TRUE;
}
+
/**
* nm_remote_settings_load_connections:
* @settings: the %NMRemoteSettings
diff --git a/libnm/nm-remote-settings.h b/libnm/nm-remote-settings.h
index afda60628e..11c4955bb2 100644
--- a/libnm/nm-remote-settings.h
+++ b/libnm/nm-remote-settings.h
@@ -131,14 +131,10 @@ NMRemoteConnection *nm_remote_settings_get_connection_by_uuid (NMRemoteSettings
gboolean nm_remote_settings_add_connection (NMRemoteSettings *settings,
NMConnection *connection,
+ gboolean save_to_disk,
NMRemoteSettingsAddConnectionFunc callback,
gpointer user_data);
-gboolean nm_remote_settings_add_connection_unsaved (NMRemoteSettings *settings,
- NMConnection *connection,
- NMRemoteSettingsAddConnectionFunc callback,
- gpointer user_data);
-
gboolean nm_remote_settings_load_connections (NMRemoteSettings *settings,
char **filenames,
char ***failures,
diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c
index 7543d2cf6e..4f8d873bbc 100644
--- a/libnm/tests/test-remote-settings-client.c
+++ b/libnm/tests/test-remote-settings-client.c
@@ -63,6 +63,7 @@ test_add_connection (void)
success = nm_remote_settings_add_connection (settings,
connection,
+ TRUE,
add_cb,
&done);
g_assert (success == TRUE);
@@ -387,6 +388,7 @@ test_add_remove_connection (void)
connection = nmtst_create_minimal_connection (TEST_ADD_REMOVE_ID, NULL, NM_SETTING_WIRED_SETTING_NAME, NULL);
success = nm_remote_settings_add_connection (settings,
connection,
+ TRUE,
add_remove_cb,
&done);
g_assert (success == TRUE);
diff --git a/libnm/tests/test-secret-agent.c b/libnm/tests/test-secret-agent.c
index 27b844d1d4..4bb99a7a24 100644
--- a/libnm/tests/test-secret-agent.c
+++ b/libnm/tests/test-secret-agent.c
@@ -316,6 +316,7 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data)
success = nm_remote_settings_add_connection (sadata->settings,
connection,
+ TRUE,
connection_added_cb,
sadata);
g_assert (success == TRUE);