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
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 *
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"),
*/
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"),
/* 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");
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;
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;
RemoteCallFetchResultCb fetch_result_cb;
GFunc callback;
gpointer user_data;
+ gpointer call_data;
};
typedef struct {
{
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);
/**
* 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)
{
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
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);
NMRemoteSettingsAddConnectionFunc callback;
gpointer callback_data;
char *path;
+ gboolean saved;
} AddConnectionInfo;
static AddConnectionInfo *
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.
+ */
}
/**
* @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
gboolean
nm_remote_settings_add_connection (NMRemoteSettings *settings,
NMConnection *connection,
+ gboolean save_to_disk,
NMRemoteSettingsAddConnectionFunc callback,
gpointer user_data)
{
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
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,
success = nm_remote_settings_add_connection (settings,
connection,
+ TRUE,
add_cb,
&done);
g_assert (success == TRUE);
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);
success = nm_remote_settings_add_connection (sadata->settings,
connection,
+ TRUE,
connection_added_cb,
sadata);
g_assert (success == TRUE);