[gnome-online-accounts] daemon: Pass the GDBusConnection when instantiating a GoaDaemon
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts] daemon: Pass the GDBusConnection when instantiating a GoaDaemon
- Date: Fri, 14 Jul 2017 10:39:20 +0000 (UTC)
commit 7d11c24b8bcd4c9bd1eaa67f988632d74d88bab4
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Jun 30 19:59:37 2017 +0200
daemon: Pass the GDBusConnection when instantiating a GoaDaemon
I find this to be slightly nicer and obviously David thought so too.
src/daemon/goadaemon.c | 64 +++++++++++++++++++++++++++++++++++++++---------
src/daemon/goadaemon.h | 4 +-
src/daemon/main.c | 2 +-
3 files changed, 55 insertions(+), 15 deletions(-)
---
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index 89b6019..4616e5e 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -55,6 +55,12 @@ struct _GoaDaemon
guint credentials_timeout_id;
};
+enum
+{
+ PROP_0,
+ PROP_CONNECTION
+};
+
static void on_file_monitor_changed (GFileMonitor *monitor,
GFile *file,
GFile *other_file,
@@ -132,6 +138,20 @@ get_all_providers_sync (GCancellable *cancellable,
/* ---------------------------------------------------------------------------------------------------- */
static void
+goa_daemon_constructed (GObject *object)
+{
+ GoaDaemon *self = GOA_DAEMON (object);
+
+ G_OBJECT_CLASS (goa_daemon_parent_class)->constructed (object);
+
+ /* prime the list of accounts */
+ goa_daemon_reload_configuration (self);
+
+ /* Export objects */
+ g_dbus_object_manager_server_set_connection (self->object_manager, self->connection);
+}
+
+static void
goa_daemon_finalize (GObject *object)
{
GoaDaemon *self = GOA_DAEMON (object);
@@ -167,6 +187,23 @@ goa_daemon_finalize (GObject *object)
G_OBJECT_CLASS (goa_daemon_parent_class)->finalize (object);
}
+static void
+goa_daemon_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ GoaDaemon *self = GOA_DAEMON (object);
+
+ switch (prop_id)
+ {
+ case PROP_CONNECTION:
+ self->connection = G_DBUS_CONNECTION (g_value_dup_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
static GFileMonitor *
create_monitor (const gchar *path, gboolean is_dir)
{
@@ -282,9 +319,6 @@ goa_daemon_init (GoaDaemon *self)
goa_provider_initialize (provider);
}
- /* TODO: maybe nicer to pass in a GDBusConnection* construct property */
- self->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
-
/* Create object manager */
self->object_manager = g_dbus_object_manager_server_new ("/org/gnome/OnlineAccounts");
@@ -321,9 +355,6 @@ goa_daemon_init (GoaDaemon *self)
g_signal_connect (self->template_file_monitor, "changed", G_CALLBACK (on_file_monitor_changed),
self);
}
- /* prime the list of accounts */
- goa_daemon_reload_configuration (self);
-
self->network_monitor = g_network_monitor_get_default ();
g_signal_connect_object (self->network_monitor,
"network-changed",
@@ -332,10 +363,6 @@ goa_daemon_init (GoaDaemon *self)
G_CONNECT_SWAPPED);
self->ensure_credentials_queue = g_queue_new ();
-
- /* Export objects */
- g_dbus_object_manager_server_set_connection (self->object_manager, self->connection);
-
queue_check_credentials (self);
g_list_free_full (providers, g_object_unref);
@@ -347,13 +374,26 @@ goa_daemon_class_init (GoaDaemonClass *klass)
GObjectClass *gobject_class;
gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->constructed = goa_daemon_constructed;
gobject_class->finalize = goa_daemon_finalize;
+ gobject_class->set_property = goa_daemon_set_property;
+
+ g_object_class_install_property (gobject_class,
+ PROP_CONNECTION,
+ g_param_spec_object ("connection",
+ "GDBusConnection object",
+ "A connection to a message bus",
+ G_TYPE_DBUS_CONNECTION,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_WRITABLE));
}
GoaDaemon *
-goa_daemon_new (void)
+goa_daemon_new (GDBusConnection *connection)
{
- return GOA_DAEMON (g_object_new (GOA_TYPE_DAEMON, NULL));
+ g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
+ return GOA_DAEMON (g_object_new (GOA_TYPE_DAEMON, "connection", connection, NULL));
}
diff --git a/src/daemon/goadaemon.h b/src/daemon/goadaemon.h
index 2b5e69a..f968dd8 100644
--- a/src/daemon/goadaemon.h
+++ b/src/daemon/goadaemon.h
@@ -19,14 +19,14 @@
#ifndef __GOA_DAEMON_H__
#define __GOA_DAEMON_H__
-#include <glib-object.h>
+#include <gio/gio.h>
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 (void);
+GoaDaemon *goa_daemon_new (GDBusConnection *connection);
G_END_DECLS
diff --git a/src/daemon/main.c b/src/daemon/main.c
index ae8c22d..6e9d549 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -46,7 +46,7 @@ on_bus_acquired (GDBusConnection *connection,
gpointer user_data)
{
if (connection != NULL)
- the_daemon = goa_daemon_new ();
+ the_daemon = goa_daemon_new (connection);
g_debug ("Connected to the session bus");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]