Commit c619365e authored by Dan Winship's avatar Dan Winship Committed by Dan Williams

libnm-glib: asyncify NMRemoteSettings

Add nm_remote_settings_new_async/_finish, and misc other fixes
parent 7844ead1
......@@ -157,6 +157,8 @@ global:
nm_remote_settings_get_type;
nm_remote_settings_list_connections;
nm_remote_settings_new;
nm_remote_settings_new_async;
nm_remote_settings_new_finish;
nm_remote_settings_save_hostname;
nm_secret_agent_delete_secrets;
nm_secret_agent_error_get_type;
......
......@@ -22,6 +22,7 @@
*/
#include <string.h>
#include <gio/gio.h>
#include <NetworkManager.h>
#include <nm-utils.h>
......@@ -32,12 +33,17 @@
#define NM_REMOTE_CONNECTION_BUS "bus"
G_DEFINE_TYPE (NMRemoteConnection, nm_remote_connection, NM_TYPE_CONNECTION)
static void nm_remote_connection_initable_iface_init (GInitableIface *iface);
static void nm_remote_connection_async_initable_iface_init (GAsyncInitableIface *iface);
G_DEFINE_TYPE_WITH_CODE (NMRemoteConnection, nm_remote_connection, NM_TYPE_CONNECTION,
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_remote_connection_initable_iface_init);
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_remote_connection_async_initable_iface_init);
)
enum {
PROP_0,
PROP_BUS,
PROP_INIT_RESULT,
LAST_PROP
};
......@@ -64,7 +70,6 @@ typedef struct {
DBusGProxy *proxy;
GSList *calls;
NMRemoteConnectionInitResult init_result;
gboolean visible;
gboolean disposed;
} NMRemoteConnectionPrivate;
......@@ -267,38 +272,6 @@ replace_settings (NMRemoteConnection *self, GHashTable *new_settings)
}
}
static void
init_get_settings_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
NMRemoteConnection *self = user_data;
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
GHashTable *new_settings;
GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &new_settings,
G_TYPE_INVALID);
if (error) {
g_error_free (error);
/* Connection doesn't exist, or isn't visible to this user */
if (dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.Settings.PermissionDenied"))
priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_INVISIBLE;
else
priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_ERROR;
g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_INIT_RESULT);
} else {
priv->visible = TRUE;
replace_settings (self, new_settings);
g_hash_table_destroy (new_settings);
priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_SUCCESS;
g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_INIT_RESULT);
}
}
static void
updated_get_settings_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
......@@ -403,10 +376,76 @@ constructed (GObject *object)
dbus_g_proxy_add_signal (priv->proxy, "Removed", G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->proxy, "Removed", G_CALLBACK (removed_cb), object, NULL);
}
static gboolean
init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
{
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable);
GHashTable *settings;
if (!dbus_g_proxy_call (priv->proxy, "GetSettings", error,
G_TYPE_STRING, NM_DBUS_IFACE_SETTINGS,
G_TYPE_INVALID,
DBUS_TYPE_G_MAP_OF_VARIANT, &settings,
G_TYPE_INVALID))
return FALSE;
priv->visible = TRUE;
replace_settings (NM_REMOTE_CONNECTION (initable), settings);
g_hash_table_destroy (settings);
return TRUE;
}
typedef struct {
NMRemoteConnection *connection;
GSimpleAsyncResult *result;
} NMRemoteConnectionInitData;
static void
init_get_settings_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
NMRemoteConnectionInitData *init_data = user_data;
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection);
GHashTable *settings;
GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings,
G_TYPE_INVALID);
if (error) {
g_simple_async_result_take_error (init_data->result, error);
} else {
priv->visible = TRUE;
replace_settings (init_data->connection, settings);
g_hash_table_destroy (settings);
g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE);
}
g_simple_async_result_complete (init_data->result);
g_slice_free (NMRemoteConnectionInitData, init_data);
}
static void
init_async (GAsyncInitable *initable, int io_priority,
GCancellable *cancellable, GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteConnectionInitData *init_data;
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable);
init_data = g_slice_new0 (NMRemoteConnectionInitData);
init_data->connection = NM_REMOTE_CONNECTION (initable);
init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback,
user_data, init_async);
dbus_g_proxy_begin_call (priv->proxy, "GetSettings",
init_get_settings_cb, object, NULL,
init_get_settings_cb, init_data, NULL,
G_TYPE_INVALID);
}
static void
......@@ -431,23 +470,6 @@ set_property (GObject *object, guint prop_id,
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMRemoteConnection *self = NM_REMOTE_CONNECTION (object);
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
switch (prop_id) {
case PROP_INIT_RESULT:
g_value_set_uint (value, priv->init_result);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
dispose (GObject *object)
{
......@@ -476,7 +498,6 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class)
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->constructed = constructed;
......@@ -489,16 +510,6 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class)
DBUS_TYPE_G_CONNECTION,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_INIT_RESULT,
g_param_spec_uint (NM_REMOTE_CONNECTION_INIT_RESULT,
"Initialization result (PRIVATE)",
"Initialization result (PRIVATE)",
NM_REMOTE_CONNECTION_INIT_RESULT_UNKNOWN,
NM_REMOTE_CONNECTION_INIT_RESULT_ERROR,
NM_REMOTE_CONNECTION_INIT_RESULT_UNKNOWN,
G_PARAM_READABLE));
/* Signals */
/**
* NMRemoteConnection::updated:
......@@ -541,3 +552,15 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class)
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
}
static void
nm_remote_connection_initable_iface_init (GInitableIface *iface)
{
iface->init = init_sync;
}
static void
nm_remote_connection_async_initable_iface_init (GAsyncInitableIface *iface)
{
iface->init_async = init_async;
}
This diff is collapsed.
......@@ -24,7 +24,7 @@
#ifndef NM_REMOTE_SETTINGS_H
#define NM_REMOTE_SETTINGS_H
#include <glib.h>
#include <gio/gio.h>
#include <dbus/dbus-glib.h>
#include <nm-connection.h>
#include <nm-remote-connection.h>
......@@ -110,6 +110,13 @@ GType nm_remote_settings_get_type (void);
NMRemoteSettings *nm_remote_settings_new (DBusGConnection *bus);
void nm_remote_settings_new_async (DBusGConnection *bus,
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_path (NMRemoteSettings *settings,
......
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