[gnome-settings-daemon/wip/benzea/systemd-user: 1/2] common: Have plugins claim a name on the bus when they are ready
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/wip/benzea/systemd-user: 1/2] common: Have plugins claim a name on the bus when they are ready
- Date: Fri, 19 Apr 2019 22:52:26 +0000 (UTC)
commit 8ae62f1ce985981f074a8ffc4e7989a59ed92d63
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 d26d6950..6253c44c 100644
--- a/plugins/common/daemon-skeleton-gtk.h
+++ b/plugins/common/daemon-skeleton-gtk.h
@@ -215,10 +215,35 @@ install_signal_handler (void)
g_source_attach (source, NULL);
}
+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");
@@ -275,11 +300,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 7f099927..49a3d930 100644
--- a/plugins/common/daemon-skeleton.h
+++ b/plugins/common/daemon-skeleton.h
@@ -24,6 +24,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"
@@ -192,12 +196,37 @@ install_signal_handler (GMainLoop *loop)
g_source_attach (source, NULL);
}
+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");
@@ -248,11 +277,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]