Commit 65253003 authored by Iain Lane's avatar Iain Lane Committed by Benjamin Berg

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.
parent 8fbbe03f
......@@ -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;
}
......@@ -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;
}
......@@ -42,10 +42,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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment