[gnome-settings-daemon/wip/laney/systemd-user: 27/29] common: Have plugins claim a name on the bus when they are ready
- From: Iain Lane <iainl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/wip/laney/systemd-user: 27/29] common: Have plugins claim a name on the bus when they are ready
- Date: Tue, 11 Dec 2018 18:03:37 +0000 (UTC)
commit 7298ea31c89c9b38fc4b416e6739542f20fa1dac
Author: Iain Lane <iain orangesquash org uk>
Date: Fri Dec 15 15:03:55 2017 +0000
common: Have plugins claim a name on the bus when they are ready
The plugins are about to switch to being activated by systemd. We need a
way for them to signal to systemd when they are ready. We'd like to
avoid linking to libsystemd, so sd_notify() is out - let's have the
plugins claim a name on the bus and then we can create Type=dbus units.
plugins/common/daemon-skeleton-gtk.h | 36 ++++++++++++++++++++++++++++++++
plugins/common/daemon-skeleton.h | 40 ++++++++++++++++++++++++++++++++++++
plugins/meson.build | 2 ++
3 files changed, 78 insertions(+)
---
diff --git a/plugins/common/daemon-skeleton-gtk.h b/plugins/common/daemon-skeleton-gtk.h
index 49c7ad5d..ab5c7833 100644
--- a/plugins/common/daemon-skeleton-gtk.h
+++ b/plugins/common/daemon-skeleton-gtk.h
@@ -187,10 +187,35 @@ set_empty_gtk_theme (gboolean set)
}
}
+static void
+bus_acquired_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data G_GNUC_UNUSED)
+{
+ g_debug ("%s: acquired bus %p for name %s", G_STRFUNC, connection, name);
+}
+
+static void
+name_acquired_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data G_GNUC_UNUSED)
+{
+ g_debug ("%s: acquired name %s on bus %p", G_STRFUNC, name, connection);
+}
+
+static void
+name_lost_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data G_GNUC_UNUSED)
+{
+ g_debug ("%s: lost name %s on bus %p", G_STRFUNC, name, connection);
+}
+
int
main (int argc, char **argv)
{
GError *error;
+ guint name_own_id;
bindtextdomain (GETTEXT_PACKAGE, GNOME_SETTINGS_LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -245,11 +270,22 @@ main (int argc, char **argv)
}
}
+ name_own_id = g_bus_own_name (G_BUS_TYPE_SESSION,
+ PLUGIN_DBUS_NAME,
+ G_BUS_NAME_OWNER_FLAGS_DO_NOT_QUEUE,
+ bus_acquired_cb,
+ name_acquired_cb,
+ name_lost_cb,
+ NULL, /* user_data */
+ NULL /* user_data_free_func */);
+
gtk_main ();
if (should_run ())
STOP (manager);
+
g_object_unref (manager);
+ g_bus_unown_name (name_own_id);
return 0;
}
diff --git a/plugins/common/daemon-skeleton.h b/plugins/common/daemon-skeleton.h
index 367ac1ec..23befb78 100644
--- a/plugins/common/daemon-skeleton.h
+++ b/plugins/common/daemon-skeleton.h
@@ -23,6 +23,10 @@
#error Include PLUGIN_CFLAGS in the daemon s CFLAGS
#endif /* !PLUGIN_NAME */
+#ifndef PLUGIN_DBUS_NAME
+#error Include PLUGIN_DBUS_NAME in the daemon s CFLAGS
+#endif /* !PLUGIN_DBUS_NAME */
+
#define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager"
#define GNOME_SESSION_CLIENT_PRIVATE_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate"
@@ -162,12 +166,37 @@ register_with_gnome_session (GMainLoop *loop)
loop);
}
+static void
+bus_acquired_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data G_GNUC_UNUSED)
+{
+ g_debug ("%s: acquired bus %p for name %s", G_STRFUNC, connection, name);
+}
+
+static void
+name_acquired_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data G_GNUC_UNUSED)
+{
+ g_debug ("%s: acquired name %s on bus %p", G_STRFUNC, name, connection);
+}
+
+static void
+name_lost_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data G_GNUC_UNUSED)
+{
+ g_debug ("%s: lost name %s on bus %p", G_STRFUNC, name, connection);
+}
+
int
main (int argc, char **argv)
{
GError *error = NULL;
GOptionContext *context;
GMainLoop *loop;
+ guint name_own_id;
bindtextdomain (GETTEXT_PACKAGE, GNOME_SETTINGS_LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -216,11 +245,22 @@ main (int argc, char **argv)
}
}
+ name_own_id = g_bus_own_name (G_BUS_TYPE_SESSION,
+ PLUGIN_DBUS_NAME,
+ G_BUS_NAME_OWNER_FLAGS_DO_NOT_QUEUE,
+ bus_acquired_cb,
+ name_acquired_cb,
+ name_lost_cb,
+ NULL, /* user_data */
+ NULL /* user_data_free_func */);
+
g_main_loop_run (loop);
if (should_run ())
STOP (manager);
+
g_object_unref (manager);
+ g_bus_unown_name (name_own_id);
return 0;
}
diff --git a/plugins/meson.build b/plugins/meson.build
index 3db69da7..5ff476a0 100644
--- a/plugins/meson.build
+++ b/plugins/meson.build
@@ -40,10 +40,12 @@ plugins_cflags = ['-DGNOME_SETTINGS_LOCALEDIR="@0@"'.format(gsd_localedir)]
foreach plugin: [['common', '']] + enabled_plugins
plugin_name = plugin[0]
+ plugin_dbus_name = plugin[1]
cflags = [
'-DG_LOG_DOMAIN="@0@-plugin"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
+ '-DPLUGIN_DBUS_NAME="org.gnome.SettingsDaemon.@0@"'.format(plugin_dbus_name),
] + plugins_cflags
if not ['common', 'dummy'].contains(plugin_name)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]