Commit c41bd345 authored by Dan Williams's avatar Dan Williams

libnm-glib: add support for new connection unsaved functionality

parent 59222e56
......@@ -213,11 +213,15 @@ 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_get_secrets;
nm_remote_connection_get_type;
nm_remote_connection_get_unsaved;
nm_remote_connection_new;
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_path;
......
This diff is collapsed.
......@@ -38,6 +38,10 @@ G_BEGIN_DECLS
#define NM_IS_REMOTE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_REMOTE_CONNECTION))
#define NM_REMOTE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_REMOTE_CONNECTION, NMRemoteConnectionClass))
/* Properties */
#define NM_REMOTE_CONNECTION_UNSAVED "unsaved"
/* Signals */
#define NM_REMOTE_CONNECTION_UPDATED "updated"
#define NM_REMOTE_CONNECTION_REMOVED "removed"
......@@ -64,30 +68,21 @@ typedef struct {
} NMRemoteConnectionClass;
/**
* NMRemoteConnectionCommitFunc:
* @connection: the connection for which updates are to be committed
* NMRemoteConnectionResultFunc:
* @connection: the connection for which an operation was performed
* @error: on failure, a descriptive error
* @user_data: user data passed to nm_remote_connection_commit_changes()
* @user_data: user data passed to function which began the operation
*
* Called when NetworkManager has committed outstanding changes to a connection
* to backing storage as a result of nm_remote_connection_commit_changes().
* Called when NetworkManager has finished an asynchronous operation on a
* connection, like commit changes, deleting, saving, etc.
*/
typedef void (*NMRemoteConnectionCommitFunc) (NMRemoteConnection *connection,
typedef void (*NMRemoteConnectionResultFunc) (NMRemoteConnection *connection,
GError *error,
gpointer user_data);
/**
* NMRemoteConnectionDeleteFunc:
* @connection: the connection to be deleted
* @error: on failure, a descriptive error
* @user_data: user data passed to nm_remote_connection_delete()
*
* Called when NetworkManager has deleted a connection as a result of
* nm_remote_connection_delete().
*/
typedef void (*NMRemoteConnectionDeleteFunc) (NMRemoteConnection *connection,
GError *error,
gpointer user_data);
/* Backwards compatibility */
typedef NMRemoteConnectionResultFunc NMRemoteConnectionCommitFunc;
typedef NMRemoteConnectionResultFunc NMRemoteConnectionDeleteFunc;
/**
* NMRemoteConnectionGetSecretsFunc:
......@@ -112,17 +107,28 @@ NMRemoteConnection *nm_remote_connection_new (DBusGConnection *bus,
const char *path);
void nm_remote_connection_commit_changes (NMRemoteConnection *connection,
NMRemoteConnectionCommitFunc callback,
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);
void nm_remote_connection_delete (NMRemoteConnection *connection,
NMRemoteConnectionDeleteFunc callback,
NMRemoteConnectionResultFunc callback,
gpointer user_data);
void nm_remote_connection_get_secrets (NMRemoteConnection *connection,
const char *setting_name,
NMRemoteConnectionGetSecretsFunc callback,
gpointer user_data);
gboolean nm_remote_connection_get_unsaved (NMRemoteConnection *connection);
G_END_DECLS
#endif /* __NM_REMOTE_CONNECTION__ */
......
......@@ -363,9 +363,10 @@ connection_inited (GObject *source, GAsyncResult *result, gpointer user_data)
g_signal_emit (self, signals[NEW_CONNECTION], 0, remote);
} else {
if (addinfo) {
local = g_error_new_literal (NM_REMOTE_SETTINGS_ERROR,
NM_REMOTE_SETTINGS_ERROR_CONNECTION_UNAVAILABLE,
"Connection not visible or not available");
local = g_error_new (NM_REMOTE_SETTINGS_ERROR,
NM_REMOTE_SETTINGS_ERROR_CONNECTION_UNAVAILABLE,
"Connection not visible or not available: %s",
error ? error->message : "(unknown)");
add_connection_info_complete (self, addinfo, local);
g_error_free (local);
}
......@@ -527,7 +528,7 @@ add_connection_done (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data
* @user_data: (closure): caller-specific data passed to @callback
*
* Requests that the remote settings service add the given settings to a new
* connection.
* connection. The connection is immediately written to disk.
*
* Returns: TRUE if the request was successful, FALSE if it failed
**/
......@@ -571,6 +572,63 @@ nm_remote_settings_add_connection (NMRemoteSettings *settings,
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
*
* Since: 0.9.10
**/
gboolean
nm_remote_settings_add_connection_unsaved (NMRemoteSettings *settings,
NMConnection *connection,
NMRemoteSettingsAddConnectionFunc callback,
gpointer user_data)
{
NMRemoteSettingsPrivate *priv;
AddConnectionInfo *info;
GHashTable *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);
_nm_remote_settings_ensure_inited (settings);
if (!priv->service_running)
return FALSE;
info = g_malloc0 (sizeof (AddConnectionInfo));
info->self = settings;
info->callback = callback;
info->callback_data = user_data;
new_settings = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);
dbus_g_proxy_begin_call (priv->proxy, "AddConnectionUnsaved",
add_connection_done,
info,
NULL,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, new_settings,
G_TYPE_INVALID);
g_hash_table_destroy (new_settings);
priv->add_list = g_slist_append (priv->add_list, info);
return TRUE;
}
static void
clear_one_hash (GHashTable *table)
{
......
......@@ -127,6 +127,11 @@ gboolean nm_remote_settings_add_connection (NMRemoteSettings *settings,
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_save_hostname (NMRemoteSettings *settings,
const char *hostname,
NMRemoteSettingsSaveHostnameFunc callback,
......
......@@ -31,7 +31,25 @@ class Connection(dbus.service.Object):
self.settings = settings
self.remove_func = remove_func
self.visible = True
self.props = {}
self.props['Unsaved'] = False
# Properties interface
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}')
def GetAll(self, iface):
if iface != IFACE_CONNECTION:
raise UnknownInterfaceException()
return self.props
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v')
def Get(self, iface, name):
if iface != IFACE_CONNECTION:
raise UnknownInterfaceException()
if not name in self.props.keys():
raise UnknownPropertyException()
return self.props[name]
# Connection methods
@dbus.service.method(dbus_interface=IFACE_CONNECTION, in_signature='', out_signature='a{sa{sv}}')
def GetSettings(self):
if not self.visible:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment