[gnome-online-accounts/wip/rishi/libsecret-workaround: 6/7] daemon: Make it fallible
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts/wip/rishi/libsecret-workaround: 6/7] daemon: Make it fallible
- Date: Mon, 3 Jul 2017 17:12:05 +0000 (UTC)
commit afc19100d9676ad8300915c15d03ae60eb35b449
Author: Debarshi Ray <debarshir gnome org>
Date: Mon Jul 3 17:51:07 2017 +0200
daemon: Make it fallible
In a subsequent commit, GoaDaemon will instantiate a new SecretService
proxy during its construction. Since GoaDaemon cannot work without
the proxy, the construction should fail if the proxy cannot be created.
src/daemon/goadaemon.c | 24 +++++++++++++++++++++---
src/daemon/goadaemon.h | 4 +++-
src/daemon/main.c | 16 +++++++++++++++-
3 files changed, 39 insertions(+), 5 deletions(-)
---
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index 4616e5e..069b2e8 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -89,7 +89,10 @@ static void ensure_credentials_queue_check (GoaDaemon *self);
static void goa_daemon_check_credentials (GoaDaemon *self);
static void goa_daemon_reload_configuration (GoaDaemon *self);
-G_DEFINE_TYPE (GoaDaemon, goa_daemon, G_TYPE_OBJECT);
+static void goa_daemon_initable_iface_init (GInitableIface *initable_iface);
+
+G_DEFINE_TYPE_WITH_CODE (GoaDaemon, goa_daemon, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, goa_daemon_initable_iface_init));
/* ---------------------------------------------------------------------------------------------------- */
@@ -389,11 +392,26 @@ goa_daemon_class_init (GoaDaemonClass *klass)
G_PARAM_WRITABLE));
}
+static gboolean
+goa_daemon_initable_init (GInitable *initable, GCancellable *cancellable, GError **error)
+{
+ return TRUE;
+}
+
+static void
+goa_daemon_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = goa_daemon_initable_init;
+}
+
GoaDaemon *
-goa_daemon_new (GDBusConnection *connection)
+goa_daemon_new (GDBusConnection *connection, GCancellable *cancellable, GError **error)
{
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
- return GOA_DAEMON (g_object_new (GOA_TYPE_DAEMON, "connection", connection, NULL));
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ return GOA_DAEMON (g_initable_new (GOA_TYPE_DAEMON, cancellable, error, "connection", connection, NULL));
}
diff --git a/src/daemon/goadaemon.h b/src/daemon/goadaemon.h
index f968dd8..88e737c 100644
--- a/src/daemon/goadaemon.h
+++ b/src/daemon/goadaemon.h
@@ -26,7 +26,9 @@ G_BEGIN_DECLS
#define GOA_TYPE_DAEMON (goa_daemon_get_type ())
G_DECLARE_FINAL_TYPE (GoaDaemon, goa_daemon, GOA, DAEMON, GObject);
-GoaDaemon *goa_daemon_new (GDBusConnection *connection);
+GoaDaemon *goa_daemon_new (GDBusConnection *connection,
+ GCancellable *cancellable,
+ GError **error);
G_END_DECLS
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 9f9ac8f..22d114b 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -45,11 +45,25 @@ on_bus_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
+ GError *error;
+
g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
g_return_if_fail (name != NULL && name[0] != '\0');
- the_daemon = goa_daemon_new (connection);
g_debug ("Connected to the session bus");
+
+ error = NULL;
+ the_daemon = goa_daemon_new (connection, NULL, &error);
+ if (error != NULL)
+ {
+ g_warning ("Unable to initialize GoaDaemon: %s (%s, %d)",
+ error->message,
+ g_quark_to_string (error->domain),
+ error->code);
+
+ g_main_loop_quit (loop);
+ g_error_free (error);
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]