libnm: split nm-dbus-helpers utils into sync/async versions

dbus-glib's functions to get a DBusGConnection or a DBusGProxy return
right away, but gdbus's corresponding functions do some initial setup
and communication as part of initialization, and so either block or
run async. So split _nm_dbus_new_connection() and
_nm_dbus_new_proxy_for_connection() into sync and async versions now,
and update NMObject to use the correct one depending on whether it is
working synchronously or asynchronously.
This commit is contained in:
Dan Winship
2014-09-10 09:29:51 -04:00
parent b3c4917b0f
commit acf4b5a572
4 changed files with 369 additions and 141 deletions

View File

@@ -25,12 +25,33 @@
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h> #include <dbus/dbus-glib-lowlevel.h>
DBusGConnection *_nm_dbus_new_connection (GError **error); DBusGConnection *_nm_dbus_new_connection (GCancellable *cancellable,
GError **error);
void _nm_dbus_new_connection_async (GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
DBusGConnection *_nm_dbus_new_connection_finish (GAsyncResult *result,
GError **error);
gboolean _nm_dbus_is_connection_private (DBusGConnection *connection); gboolean _nm_dbus_is_connection_private (DBusGConnection *connection);
DBusGProxy * _nm_dbus_new_proxy_for_connection (DBusGConnection *connection, void _nm_dbus_register_proxy_type (const char *interface,
GType proxy_type);
DBusGProxy *_nm_dbus_new_proxy_for_connection (DBusGConnection *connection,
const char *path, const char *path,
const char *interface); const char *interface,
GCancellable *cancellable,
GError **error);
void _nm_dbus_new_proxy_for_connection_async (DBusGConnection *connection,
const char *path,
const char *interface,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
DBusGProxy *_nm_dbus_new_proxy_for_connection_finish (GAsyncResult *result,
GError **error);
#endif /* __NM_DBUS_HELPERS_PRIVATE_H__ */ #endif /* __NM_DBUS_HELPERS_PRIVATE_H__ */

View File

@@ -46,7 +46,8 @@ _ensure_nm_dbus_helpers_inited (void)
} }
DBusGConnection * DBusGConnection *
_nm_dbus_new_connection (GError **error) _nm_dbus_new_connection (GCancellable *cancellable,
GError **error)
{ {
DBusGConnection *connection = NULL; DBusGConnection *connection = NULL;
@@ -75,6 +76,39 @@ _nm_dbus_new_connection (GError **error)
return connection; return connection;
} }
void
_nm_dbus_new_connection_async (GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
DBusGConnection *connection;
GError *error = NULL;
simple = g_simple_async_result_new (NULL, callback, user_data,
_nm_dbus_new_connection_async);
connection = _nm_dbus_new_connection (cancellable, &error);
if (connection)
g_simple_async_result_set_op_res_gpointer (simple, connection, (GDestroyNotify) dbus_g_connection_unref);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
}
DBusGConnection *
_nm_dbus_new_connection_finish (GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return NULL;
return dbus_g_connection_ref (g_simple_async_result_get_op_res_gpointer (simple));
}
gboolean gboolean
_nm_dbus_is_connection_private (DBusGConnection *connection) _nm_dbus_is_connection_private (DBusGConnection *connection)
{ {
@@ -86,7 +120,9 @@ _nm_dbus_is_connection_private (DBusGConnection *connection)
DBusGProxy * DBusGProxy *
_nm_dbus_new_proxy_for_connection (DBusGConnection *connection, _nm_dbus_new_proxy_for_connection (DBusGConnection *connection,
const char *path, const char *path,
const char *interface) const char *interface,
GCancellable *cancellable,
GError **error)
{ {
/* Private connections can't use dbus_g_proxy_new_for_name() or /* Private connections can't use dbus_g_proxy_new_for_name() or
* dbus_g_proxy_new_for_name_owner() because peer-to-peer connections don't * dbus_g_proxy_new_for_name_owner() because peer-to-peer connections don't
@@ -98,3 +134,40 @@ _nm_dbus_new_proxy_for_connection (DBusGConnection *connection,
return dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, path, interface); return dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, path, interface);
} }
void
_nm_dbus_new_proxy_for_connection_async (DBusGConnection *connection,
const char *path,
const char *interface,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
DBusGProxy *proxy;
GError *error = NULL;
simple = g_simple_async_result_new (NULL, callback, user_data,
_nm_dbus_new_proxy_for_connection_async);
proxy = _nm_dbus_new_proxy_for_connection (connection, path, interface,
cancellable, &error);
if (proxy)
g_simple_async_result_set_op_res_gpointer (simple, proxy, g_object_unref);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
}
DBusGProxy *
_nm_dbus_new_proxy_for_connection_finish (GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return NULL;
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
}

View File

@@ -153,38 +153,10 @@ nm_object_init (NMObject *object)
priv->proxies = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); priv->proxies = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
} }
static gboolean
init_common (NMObject *self, GError **error)
{
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
if (!priv->path) {
g_set_error_literal (error, NM_OBJECT_ERROR, NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE,
_("Caller did not specify D-Bus path for object"));
return FALSE;
}
NM_OBJECT_GET_CLASS (self)->init_dbus (self);
return TRUE;
}
static void static void
init_dbus (NMObject *object) init_dbus (NMObject *object)
{ {
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
NMObjectClassPrivate *cpriv = NM_OBJECT_CLASS_GET_PRIVATE (NM_OBJECT_GET_CLASS (object));
GSList *iter;
for (iter = cpriv->interfaces; iter; iter = iter->next) {
const char *interface = iter->data;
DBusGProxy *proxy;
proxy = _nm_dbus_new_proxy_for_connection (priv->connection, priv->path, interface);
g_hash_table_insert (priv->proxies, (char *) interface, proxy);
}
priv->properties_proxy = _nm_dbus_new_proxy_for_connection (priv->connection, priv->path, DBUS_INTERFACE_PROPERTIES);
if (_nm_dbus_is_connection_private (priv->connection)) if (_nm_dbus_is_connection_private (priv->connection))
priv->nm_running = TRUE; priv->nm_running = TRUE;
@@ -210,12 +182,39 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
{ {
NMObject *self = NM_OBJECT (initable); NMObject *self = NM_OBJECT (initable);
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
NMObjectClassPrivate *cpriv = NM_OBJECT_CLASS_GET_PRIVATE (NM_OBJECT_GET_CLASS (self));
GSList *iter;
priv->connection = _nm_dbus_new_connection (error); if (!priv->path) {
g_set_error_literal (error, NM_OBJECT_ERROR, NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE,
_("Caller did not specify D-Bus path for object"));
return FALSE;
}
priv->connection = _nm_dbus_new_connection (cancellable, error);
if (!priv->connection) if (!priv->connection)
return FALSE; return FALSE;
if (!init_common (self, error))
/* Create proxies */
for (iter = cpriv->interfaces; iter; iter = iter->next) {
const char *interface = iter->data;
DBusGProxy *proxy;
proxy = _nm_dbus_new_proxy_for_connection (priv->connection, priv->path, interface,
cancellable, error);
if (!proxy)
return FALSE; return FALSE;
g_hash_table_insert (priv->proxies, (char *) interface, proxy);
}
priv->properties_proxy = _nm_dbus_new_proxy_for_connection (priv->connection,
priv->path,
DBUS_INTERFACE_PROPERTIES,
cancellable, error);
if (!priv->properties_proxy)
return FALSE;
NM_OBJECT_GET_CLASS (self)->init_dbus (self);
if (priv->bus_proxy) { if (priv->bus_proxy) {
if (!dbus_g_proxy_call (priv->bus_proxy, if (!dbus_g_proxy_call (priv->bus_proxy,
@@ -230,52 +229,132 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
return _nm_object_reload_properties (self, error); return _nm_object_reload_properties (self, error);
} }
/* Takes ownership of @error */ typedef struct {
NMObject *object;
GSimpleAsyncResult *simple;
GCancellable *cancellable;
int proxies_pending;
GError *error;
} NMObjectInitData;
static void static void
init_async_complete (GSimpleAsyncResult *simple, GError *error) init_async_complete (NMObjectInitData *init_data)
{ {
if (error) if (init_data->error)
g_simple_async_result_take_error (simple, error); g_simple_async_result_take_error (init_data->simple, init_data->error);
else else
g_simple_async_result_set_op_res_gboolean (simple, TRUE); g_simple_async_result_set_op_res_gboolean (init_data->simple, TRUE);
g_simple_async_result_complete (simple); g_simple_async_result_complete (init_data->simple);
g_object_unref (simple); g_object_unref (init_data->simple);
g_clear_object (&init_data->cancellable);
g_slice_free (NMObjectInitData, init_data);
} }
static void static void
init_async_got_properties (GObject *object, GAsyncResult *result, gpointer user_data) init_async_got_properties (GObject *object, GAsyncResult *result, gpointer user_data)
{ {
GSimpleAsyncResult *simple = user_data; NMObjectInitData *init_data = user_data;
GError *error = NULL;
if (!_nm_object_reload_properties_finish (NM_OBJECT (object), result, &error)) _nm_object_reload_properties_finish (NM_OBJECT (object), result, &init_data->error);
g_assert (error); init_async_complete (init_data);
init_async_complete (simple, error); }
static void
init_async_get_properties (NMObjectInitData *init_data)
{
_nm_object_reload_properties_async (init_data->object, init_async_got_properties, init_data);
} }
static void static void
init_async_got_nm_running (DBusGProxy *proxy, DBusGProxyCall *call, init_async_got_nm_running (DBusGProxy *proxy, DBusGProxyCall *call,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *simple = user_data; NMObjectInitData *init_data = user_data;
NMObject *self; NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (init_data->object);
NMObjectPrivate *priv;
GError *error = NULL;
self = NM_OBJECT (g_async_result_get_source_object (G_ASYNC_RESULT (simple))); if (!dbus_g_proxy_end_call (proxy, call, &init_data->error,
priv = NM_OBJECT_GET_PRIVATE (self);
if (!dbus_g_proxy_end_call (proxy, call, &error,
G_TYPE_BOOLEAN, &priv->nm_running, G_TYPE_BOOLEAN, &priv->nm_running,
G_TYPE_INVALID)) { G_TYPE_INVALID)) {
init_async_complete (simple, error); init_async_complete (init_data);
} else if (!priv->nm_running) } else if (!priv->nm_running)
init_async_complete (simple, NULL); init_async_complete (init_data);
else else
_nm_object_reload_properties_async (self, init_async_got_properties, simple); init_async_get_properties (init_data);
}
/* g_async_result_get_source_object() adds a ref */ static void
g_object_unref (self); init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
{
NMObjectInitData *init_data = user_data;
NMObject *self = init_data->object;
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
DBusGProxy *proxy;
if (!init_data->error) {
proxy = _nm_dbus_new_proxy_for_connection_finish (result, &init_data->error);
if (proxy) {
const char *interface = dbus_g_proxy_get_interface (proxy);
if (!strcmp (interface, DBUS_INTERFACE_PROPERTIES))
priv->properties_proxy = proxy;
else
g_hash_table_insert (priv->proxies, (char *) interface, proxy);
}
}
init_data->proxies_pending--;
if (init_data->proxies_pending)
return;
if (init_data->error) {
init_async_complete (init_data);
return;
}
NM_OBJECT_GET_CLASS (self)->init_dbus (self);
if (_nm_dbus_is_connection_private (priv->connection)) {
priv->nm_running = TRUE;
init_async_get_properties (init_data);
} else {
dbus_g_proxy_begin_call (priv->bus_proxy, "NameHasOwner",
init_async_got_nm_running,
init_data, NULL,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID);
}
}
static void
init_async_got_bus (GObject *object, GAsyncResult *result, gpointer user_data)
{
NMObjectInitData *init_data = user_data;
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (init_data->object);
NMObjectClassPrivate *cpriv = NM_OBJECT_CLASS_GET_PRIVATE (NM_OBJECT_GET_CLASS (init_data->object));
GSList *iter;
priv->connection = _nm_dbus_new_connection_finish (result, &init_data->error);
if (!priv->connection) {
init_async_complete (init_data);
return;
}
for (iter = cpriv->interfaces; iter; iter = iter->next) {
const char *interface = iter->data;
_nm_dbus_new_proxy_for_connection_async (priv->connection,
priv->path, interface,
init_data->cancellable,
init_async_got_proxy, init_data);
init_data->proxies_pending++;
}
_nm_dbus_new_proxy_for_connection_async (priv->connection,
priv->path,
DBUS_INTERFACE_PROPERTIES,
init_data->cancellable,
init_async_got_proxy, init_data);
init_data->proxies_pending++;
} }
static void static void
@@ -285,34 +364,24 @@ init_async (GAsyncInitable *initable, int io_priority,
{ {
NMObject *self = NM_OBJECT (initable); NMObject *self = NM_OBJECT (initable);
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
GSimpleAsyncResult *simple; NMObjectInitData *init_data;
GError *error = NULL;
simple = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, init_async); if (!priv->path) {
g_simple_async_report_error_in_idle (G_OBJECT (initable),
priv->connection = _nm_dbus_new_connection (&error); callback, user_data,
if (!priv->connection) { NM_OBJECT_ERROR,
g_simple_async_result_take_error (simple, error); NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE,
g_simple_async_result_complete_in_idle (simple); "%s",
g_object_unref (simple); _("Caller did not specify D-Bus path for object"));
return;
}
if (!init_common (self, &error)) {
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return; return;
} }
if (priv->bus_proxy) { init_data = g_slice_new0 (NMObjectInitData);
/* Check if NM is running */ init_data->object = self;
dbus_g_proxy_begin_call (priv->bus_proxy, "NameHasOwner", init_data->simple = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, init_async);
init_async_got_nm_running, init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
simple, NULL,
G_TYPE_STRING, NM_DBUS_SERVICE, _nm_dbus_new_connection_async (cancellable, init_async_got_bus, init_data);
G_TYPE_INVALID);
} else
_nm_object_reload_properties_async (self, init_async_got_properties, simple);
} }
static gboolean static gboolean
@@ -624,9 +693,12 @@ _nm_object_create (GType type, DBusGConnection *connection, const char *path)
DBusGProxy *proxy; DBusGProxy *proxy;
GValue value = G_VALUE_INIT; GValue value = G_VALUE_INIT;
proxy = _nm_dbus_new_proxy_for_connection (connection, path, DBUS_INTERFACE_PROPERTIES); proxy = _nm_dbus_new_proxy_for_connection (connection, path,
DBUS_INTERFACE_PROPERTIES,
NULL, &error);
if (!proxy) { if (!proxy) {
g_warning ("Could not create proxy for %s.", path); g_warning ("Could not create proxy for %s: %s.", path, error->message);
g_error_free (error);
return G_TYPE_INVALID; return G_TYPE_INVALID;
} }
@@ -766,6 +838,28 @@ create_async_got_property (DBusGProxy *proxy, DBusGProxyCall *call, gpointer use
create_async_got_type (async_data, type); create_async_got_type (async_data, type);
} }
static void
create_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
{
NMObjectTypeAsyncData *async_data = user_data;
DBusGProxy *proxy;
GError *error = NULL;
proxy = _nm_dbus_new_proxy_for_connection_finish (result, &error);
if (!proxy) {
g_warning ("Could not create proxy for %s: %s.", async_data->path, error->message);
g_error_free (error);
create_async_complete (NULL, async_data);
return;
}
dbus_g_proxy_begin_call (proxy, "Get",
create_async_got_property, async_data, NULL,
G_TYPE_STRING, async_data->type_data->interface,
G_TYPE_STRING, async_data->type_data->property,
G_TYPE_INVALID);
}
static void static void
_nm_object_create_async (GType type, DBusGConnection *connection, const char *path, _nm_object_create_async (GType type, DBusGConnection *connection, const char *path,
NMObjectCreateCallbackFunc callback, gpointer user_data) NMObjectCreateCallbackFunc callback, gpointer user_data)
@@ -779,14 +873,10 @@ _nm_object_create_async (GType type, DBusGConnection *connection, const char *pa
async_data->type_data = g_hash_table_lookup (type_funcs, GSIZE_TO_POINTER (type)); async_data->type_data = g_hash_table_lookup (type_funcs, GSIZE_TO_POINTER (type));
if (async_data->type_data) { if (async_data->type_data) {
DBusGProxy *proxy; _nm_dbus_new_proxy_for_connection_async (connection, path,
DBUS_INTERFACE_PROPERTIES,
proxy = _nm_dbus_new_proxy_for_connection (connection, path, DBUS_INTERFACE_PROPERTIES); NULL,
dbus_g_proxy_begin_call (proxy, "Get", create_async_got_proxy, async_data);
create_async_got_property, async_data, NULL,
G_TYPE_STRING, async_data->type_data->interface,
G_TYPE_STRING, async_data->type_data->property,
G_TYPE_INVALID);
return; return;
} }

View File

@@ -1101,23 +1101,20 @@ nm_secret_agent_init (NMSecretAgent *self)
{ {
} }
static gboolean static void
init_common (NMSecretAgent *self, GError **error) init_common (NMSecretAgent *self)
{ {
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
DBusGConnection *session_bus; DBusGConnection *session_bus;
priv->bus = _nm_dbus_new_connection (error);
if (!priv->bus)
return FALSE;
priv->private_bus = _nm_dbus_is_connection_private (priv->bus);
session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL); session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
if (priv->bus == session_bus) if (priv->bus == session_bus)
priv->session_bus = TRUE; priv->session_bus = TRUE;
if (session_bus) if (session_bus)
dbus_g_connection_unref (session_bus); dbus_g_connection_unref (session_bus);
priv->private_bus = _nm_dbus_is_connection_private (priv->bus);
if (priv->private_bus == FALSE) { if (priv->private_bus == FALSE) {
priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus, priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus,
DBUS_SERVICE_DBUS, DBUS_SERVICE_DBUS,
@@ -1139,17 +1136,6 @@ init_common (NMSecretAgent *self, GError **error)
get_nm_owner (self); get_nm_owner (self);
} }
priv->manager_proxy = _nm_dbus_new_proxy_for_connection (priv->bus,
NM_DBUS_PATH_AGENT_MANAGER,
NM_DBUS_INTERFACE_AGENT_MANAGER);
if (!priv->manager_proxy) {
g_set_error_literal (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
"Couldn't create NM agent manager proxy.");
return FALSE;
}
return TRUE;
} }
static gboolean static gboolean
@@ -1158,29 +1144,97 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
NMSecretAgent *self = NM_SECRET_AGENT (initable); NMSecretAgent *self = NM_SECRET_AGENT (initable);
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
if (!init_common (self, error)) priv->bus = _nm_dbus_new_connection (cancellable, error);
if (!priv->bus)
return FALSE; return FALSE;
priv->manager_proxy = _nm_dbus_new_proxy_for_connection (priv->bus,
NM_DBUS_PATH_AGENT_MANAGER,
NM_DBUS_INTERFACE_AGENT_MANAGER,
cancellable, error);
if (!priv->manager_proxy)
return FALSE;
init_common (self);
if (priv->auto_register) if (priv->auto_register)
return nm_secret_agent_register (self, cancellable, error); return nm_secret_agent_register (self, cancellable, error);
else else
return TRUE; return TRUE;
} }
typedef struct {
NMSecretAgent *self;
GCancellable *cancellable;
GSimpleAsyncResult *simple;
} NMSecretAgentInitData;
static void static void
init_async_registered (GObject *initable, GAsyncResult *result, gpointer user_data) init_async_complete (NMSecretAgentInitData *init_data, GError *error)
{ {
NMSecretAgent *self = NM_SECRET_AGENT (initable); if (!error)
GSimpleAsyncResult *simple = user_data; g_simple_async_result_set_op_res_gboolean (init_data->simple, TRUE);
else
g_simple_async_result_take_error (init_data->simple, error);
g_simple_async_result_complete_in_idle (init_data->simple);
g_object_unref (init_data->simple);
g_clear_object (&init_data->cancellable);
g_slice_free (NMSecretAgentInitData, init_data);
}
static void
init_async_registered (GObject *object, GAsyncResult *result, gpointer user_data)
{
NMSecretAgent *self = NM_SECRET_AGENT (object);
NMSecretAgentInitData *init_data = user_data;
GError *error = NULL; GError *error = NULL;
if (nm_secret_agent_register_finish (self, result, &error)) nm_secret_agent_register_finish (self, result, &error);
g_simple_async_result_set_op_res_gboolean (simple, TRUE); init_async_complete (init_data, error);
else }
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete_in_idle (simple); static void
g_object_unref (simple); init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
{
NMSecretAgentInitData *init_data = user_data;
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (init_data->self);
GError *error = NULL;
priv->manager_proxy = _nm_dbus_new_proxy_for_connection_finish (result, &error);
if (!priv->manager_proxy) {
init_async_complete (init_data, error);
return;
}
init_common (init_data->self);
if (priv->auto_register) {
nm_secret_agent_register_async (init_data->self, init_data->cancellable,
init_async_registered, init_data);
} else
init_async_complete (init_data, NULL);
}
static void
init_async_got_bus (GObject *initable, GAsyncResult *result, gpointer user_data)
{
NMSecretAgentInitData *init_data = user_data;
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (init_data->self);
GError *error = NULL;
priv->bus = _nm_dbus_new_connection_finish (result, &error);
if (!priv->bus) {
init_async_complete (init_data, error);
return;
}
_nm_dbus_new_proxy_for_connection_async (priv->bus,
NM_DBUS_PATH_AGENT_MANAGER,
NM_DBUS_INTERFACE_AGENT_MANAGER,
init_data->cancellable,
init_async_got_proxy, init_data);
} }
static void static void
@@ -1189,26 +1243,16 @@ init_async (GAsyncInitable *initable, int io_priority,
gpointer user_data) gpointer user_data)
{ {
NMSecretAgent *self = NM_SECRET_AGENT (initable); NMSecretAgent *self = NM_SECRET_AGENT (initable);
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); NMSecretAgentInitData *init_data;
GSimpleAsyncResult *simple;
GError *error = NULL;
simple = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, init_async); init_data = g_slice_new (NMSecretAgentInitData);
init_data->self = self;
init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
if (!init_common (self, &error)) { init_data->simple = g_simple_async_result_new (G_OBJECT (initable), callback,
g_simple_async_result_take_error (simple, error); user_data, init_async);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return;
}
if (priv->auto_register) _nm_dbus_new_connection_async (cancellable, init_async_got_bus, init_data);
nm_secret_agent_register_async (self, cancellable, init_async_registered, simple);
else {
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
}
} }
static gboolean static gboolean