[gdm/wip/slave-connection: 14/17] daemon: Port GdmManager to GDBus
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdm/wip/slave-connection: 14/17] daemon: Port GdmManager to GDBus
- Date: Sat, 7 Jul 2012 07:22:40 +0000 (UTC)
commit dacceb01da949ba95b1b6b7c937d1502e6fbb237
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Tue May 15 18:16:19 2012 +0200
daemon: Port GdmManager to GDBus
The GdmManager object controls the GdmLocalDisplayFactory and
GdmXdmcpDisplayFactory singleton objects, which manage displays on local
VTs and displays on remote machines respectively.
Another role of the GdmManager object is to aggregate and export the
displays currently being managed by those display factories over the
system bus.
This commit moves GdmManager over to using GDBus and the
GDBusObjectManager interface for display enumeration.
https://bugzilla.gnome.org/show_bug.cgi?id=622888
daemon/Makefile.am | 6 -
daemon/gdm-display-store.c | 29 ----
daemon/gdm-display.c | 30 ++++-
daemon/gdm-local-display-factory.c | 49 +++++---
daemon/gdm-manager.c | 136 +++++++------------
daemon/gdm-manager.h | 6 +
daemon/gdm-manager.xml | 14 --
daemon/gdm-session.c | 6 +-
daemon/gdm-slave.c | 32 +++--
daemon/gdm-slave.h | 4 +
daemon/gdm-xdmcp-chooser-display.c | 6 +-
daemon/gdm-xdmcp-display-factory.c | 5 +
daemon/main.c | 260 ++++++++++++------------------------
daemon/test-session.c | 3 +-
14 files changed, 234 insertions(+), 352 deletions(-)
---
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index c85e940..6c8c5bd 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -31,7 +31,6 @@ AM_CPPFLAGS = \
BUILT_SOURCES = \
gdm-slave-glue.h \
gdm-xdmcp-chooser-slave-glue.h \
- gdm-manager-glue.h \
gdm-display-glue.h \
gdm-xdmcp-display-glue.h \
gdm-static-display-glue.h \
@@ -41,9 +40,6 @@ BUILT_SOURCES = \
gdm-session-glue.h \
$(NULL)
-gdm-manager-glue.h: gdm-manager.xml Makefile.am
- dbus-binding-tool --prefix=gdm_manager --mode=glib-server --output=gdm-manager-glue.h $(srcdir)/gdm-manager.xml
-
gdm-display-glue.c gdm-display-glue.h: gdm-display.xml Makefile.am
$(AM_V_GEN)gdbus-codegen \
--c-namespace=GdmDBus \
@@ -393,8 +389,6 @@ EXTRA_DIST = \
gdm-slave.xml \
gdm-simple-slave.xml \
gdm-xdmcp-chooser-slave.xml \
- gdm-session.xml \
- gdm-manager.xml \
gdm-display.xml \
gdm-xdmcp-display.xml \
gdm-static-display.xml \
diff --git a/daemon/gdm-display-store.c b/daemon/gdm-display-store.c
index 62d7e93..fa2015d 100644
--- a/daemon/gdm-display-store.c
+++ b/daemon/gdm-display-store.c
@@ -40,14 +40,6 @@ struct GdmDisplayStorePrivate
GHashTable *displays;
};
-enum {
- DISPLAY_ADDED,
- DISPLAY_REMOVED,
- LAST_SIGNAL
-};
-
-static guint signals [LAST_SIGNAL] = { 0, };
-
static void gdm_display_store_class_init (GdmDisplayStoreClass *klass);
static void gdm_display_store_init (GdmDisplayStore *display_store);
static void gdm_display_store_finalize (GObject *object);
@@ -167,27 +159,6 @@ gdm_display_store_class_init (GdmDisplayStoreClass *klass)
object_class->finalize = gdm_display_store_finalize;
- signals [DISPLAY_ADDED] =
- g_signal_new ("display-added",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GdmDisplayStoreClass, display_added),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE,
- 1, G_TYPE_STRING);
- signals [DISPLAY_REMOVED] =
- g_signal_new ("display-removed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GdmDisplayStoreClass, display_removed),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE,
- 1, G_TYPE_STRING);
-
g_type_class_add_private (klass, sizeof (GdmDisplayStorePrivate));
}
diff --git a/daemon/gdm-display.c b/daemon/gdm-display.c
index 34974cb..cf541f6 100644
--- a/daemon/gdm-display.c
+++ b/daemon/gdm-display.c
@@ -70,6 +70,7 @@ struct GdmDisplayPrivate
GdmSlaveProxy *slave_proxy;
char *slave_bus_name;
+ int slave_name_id;
GDBusConnection *connection;
GdmDisplayAccessFile *user_access_file;
@@ -94,6 +95,7 @@ enum {
static void gdm_display_class_init (GdmDisplayClass *klass);
static void gdm_display_init (GdmDisplay *display);
static void gdm_display_finalize (GObject *object);
+static void queue_finish (GdmDisplay *display);
G_DEFINE_ABSTRACT_TYPE (GdmDisplay, gdm_display, G_TYPE_OBJECT)
@@ -279,6 +281,14 @@ gdm_display_add_user_authorization (GdmDisplay *display,
return ret;
}
+static void
+on_name_vanished (GDBusConnection *connection,
+ const char *name,
+ gpointer user_data)
+{
+ queue_finish (GDM_DISPLAY (user_data));
+}
+
static gboolean
gdm_display_real_set_slave_bus_name (GdmDisplay *display,
const char *name,
@@ -287,6 +297,16 @@ gdm_display_real_set_slave_bus_name (GdmDisplay *display,
g_free (display->priv->slave_bus_name);
display->priv->slave_bus_name = g_strdup (name);
+ if (display->priv->slave_name_id > 0)
+ g_bus_unwatch_name (display->priv->slave_name_id);
+
+ g_bus_watch_name_on_connection (display->priv->connection,
+ name,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ NULL, /* name appeared */
+ on_name_vanished,
+ g_object_ref (display),
+ NULL);
return TRUE;
}
@@ -1207,7 +1227,7 @@ register_display (GdmDisplay *display)
}
/*
- dbus-send --system --print-reply --dest=org.gnome.DisplayManager /org/gnome/DisplayManager/Display1 org.freedesktop.DBus.Introspectable.Introspect
+ dbus-send --system --print-reply --dest=org.gnome.DisplayManager /org/gnome/DisplayManager/Displays/1 org.freedesktop.DBus.Introspectable.Introspect
*/
static GObject *
@@ -1223,7 +1243,7 @@ gdm_display_constructor (GType type,
construct_properties));
g_free (display->priv->id);
- display->priv->id = g_strdup_printf ("/org/gnome/DisplayManager/Display%u", get_next_display_serial ());
+ display->priv->id = g_strdup_printf ("/org/gnome/DisplayManager/Displays/%u", get_next_display_serial ());
res = register_display (display);
if (! res) {
@@ -1264,6 +1284,11 @@ gdm_display_dispose (GObject *object)
display->priv->access_file = NULL;
}
+ if (display->priv->slave_name_id > 0) {
+ g_bus_unwatch_name (display->priv->slave_name_id);
+ display->priv->slave_name_id = 0;
+ }
+
G_OBJECT_CLASS (gdm_display_parent_class)->dispose (object);
}
@@ -1397,6 +1422,7 @@ gdm_display_finalize (GObject *object)
g_free (display->priv->x11_display_name);
g_free (display->priv->x11_cookie);
g_free (display->priv->slave_command);
+ g_free (display->priv->slave_bus_name);
g_clear_object (&display->priv->display_skeleton);
g_clear_object (&display->priv->object_skeleton);
diff --git a/daemon/gdm-local-display-factory.c b/daemon/gdm-local-display-factory.c
index caf4212..043dbdc 100644
--- a/daemon/gdm-local-display-factory.c
+++ b/daemon/gdm-local-display-factory.c
@@ -32,6 +32,7 @@
#include <systemd/sd-daemon.h>
#endif
+#include "gdm-manager.h"
#include "gdm-display-factory.h"
#include "gdm-local-display-factory.h"
#include "gdm-local-display-factory-glue.h"
@@ -77,6 +78,10 @@ static void gdm_local_display_factory_finalize (GObject
static GdmDisplay *create_display (GdmLocalDisplayFactory *factory,
const char *seat_id);
+static void on_display_status_changed (GdmDisplay *display,
+ GParamSpec *arg1,
+ GdmLocalDisplayFactory *factory);
+
static gpointer local_display_factory_object = NULL;
G_DEFINE_TYPE (GdmLocalDisplayFactory, gdm_local_display_factory, GDM_TYPE_DISPLAY_FACTORY)
@@ -171,6 +176,8 @@ on_display_disposed (GdmLocalDisplayFactory *factory,
GdmDisplay *display)
{
g_debug ("GdmLocalDisplayFactory: Display %p disposed", display);
+
+ gdm_manager_display_removed (gdm_manager_new (), display);
}
static void
@@ -180,6 +187,9 @@ store_display (GdmLocalDisplayFactory *factory,
{
GdmDisplayStore *store;
+ g_signal_connect (display, "notify::status",
+ G_CALLBACK (on_display_status_changed), factory);
+
g_object_weak_ref (G_OBJECT (display), (GWeakNotify)on_display_disposed, factory);
store = gdm_display_factory_get_display_store (GDM_DISPLAY_FACTORY (factory));
@@ -187,6 +197,9 @@ store_display (GdmLocalDisplayFactory *factory,
/* now fill our reserved spot */
g_hash_table_insert (factory->priv->displays, GUINT_TO_POINTER (num), NULL);
+
+ /* finally, signal dbus */
+ gdm_manager_display_added (gdm_manager_new (), display);
}
static const char *
@@ -255,9 +268,9 @@ gdm_local_display_factory_create_transient_display (GdmLocalDisplayFactory *fact
}
static void
-on_static_display_status_changed (GdmDisplay *display,
- GParamSpec *arg1,
- GdmLocalDisplayFactory *factory)
+on_display_status_changed (GdmDisplay *display,
+ GParamSpec *arg1,
+ GdmLocalDisplayFactory *factory)
{
int status;
GdmDisplayStore *store;
@@ -274,7 +287,7 @@ on_static_display_status_changed (GdmDisplay *display,
status = gdm_display_get_status (display);
- g_debug ("GdmLocalDisplayFactory: static display status changed: %d", status);
+ g_debug ("GdmLocalDisplayFactory: display status changed: %d", status);
switch (status) {
case GDM_DISPLAY_FINISHED:
/* remove the display number from factory->priv->displays
@@ -283,20 +296,27 @@ on_static_display_status_changed (GdmDisplay *display,
gdm_display_store_remove (store, display);
/* reset num failures */
factory->priv->num_failures = 0;
- create_display (factory, seat_id);
+
+ /* Create a new equivalent display if it was static */
+ if (GDM_IS_STATIC_DISPLAY (display))
+ create_display (factory, seat_id);
break;
case GDM_DISPLAY_FAILED:
/* leave the display number in factory->priv->displays
so that it doesn't get reused */
gdm_display_store_remove (store, display);
factory->priv->num_failures++;
- if (factory->priv->num_failures > MAX_DISPLAY_FAILURES) {
- /* oh shit */
- g_warning ("GdmLocalDisplayFactory: maximum number of X display failures reached: check X server log for errors");
- /* FIXME: should monitor hardware changes to
- try again when seats change */
- } else {
- create_display (factory, seat_id);
+
+ /* Create a new equivalent display if it was static */
+ if (GDM_IS_STATIC_DISPLAY (display)) {
+ if (factory->priv->num_failures > MAX_DISPLAY_FAILURES) {
+ /* oh shit */
+ g_warning ("GdmLocalDisplayFactory: maximum number of X display failures reached: check X server log for errors");
+ /* FIXME: should monitor hardware changes to
+ try again when seats change */
+ } else {
+ create_display (factory, seat_id);
+ }
}
break;
case GDM_DISPLAY_UNMANAGED:
@@ -354,11 +374,6 @@ create_display (GdmLocalDisplayFactory *factory,
g_object_set (display, "seat-id", seat_id, NULL);
- g_signal_connect (display,
- "notify::status",
- G_CALLBACK (on_static_display_status_changed),
- factory);
-
store_display (factory, num, display);
/* let store own the ref */
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
index ab0c9c1..07f44cc 100644
--- a/daemon/gdm-manager.c
+++ b/daemon/gdm-manager.c
@@ -33,14 +33,10 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <glib-object.h>
-#define DBUS_API_SUBJECT_TO_CHANGE
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include "gdm-common.h"
#include "gdm-manager.h"
-#include "gdm-manager-glue.h"
#include "gdm-display-store.h"
#include "gdm-display-factory.h"
#include "gdm-local-display-factory.h"
@@ -49,7 +45,7 @@
#define GDM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_MANAGER, GdmManagerPrivate))
#define GDM_DBUS_PATH "/org/gnome/DisplayManager"
-#define GDM_MANAGER_DBUS_PATH GDM_DBUS_PATH "/Manager"
+#define GDM_MANAGER_DBUS_PATH GDM_DBUS_PATH "/Displays"
#define GDM_MANAGER_DBUS_NAME "org.gnome.DisplayManager.Manager"
struct GdmManagerPrivate
@@ -65,8 +61,9 @@ struct GdmManagerPrivate
gboolean wait_for_go;
gboolean no_console;
- DBusGProxy *bus_proxy;
- DBusGConnection *connection;
+ GDBusProxy *bus_proxy;
+ GDBusConnection *connection;
+ GDBusObjectManagerServer *object_manager;
};
enum {
@@ -116,8 +113,8 @@ listify_display_ids (const char *id,
Example:
dbus-send --system --dest=org.gnome.DisplayManager \
--type=method_call --print-reply --reply-timeout=2000 \
- /org/gnome/DisplayManager/Manager \
- org.gnome.DisplayManager.Manager.GetDisplays
+ /org/gnome/DisplayManager/Displays \
+ org.freedesktop.ObjectManager.GetAll
*/
gboolean
gdm_manager_get_displays (GdmManager *manager,
@@ -199,89 +196,23 @@ gdm_manager_set_wait_for_go (GdmManager *manager,
}
}
-typedef struct {
- const char *service_name;
- GdmManager *manager;
-} RemoveDisplayData;
-
-static gboolean
-remove_display_for_connection (char *id,
- GdmDisplay *display,
- RemoveDisplayData *data)
-{
- g_assert (display != NULL);
- g_assert (data->service_name != NULL);
-
- /* FIXME: compare service name to that of display */
-#if 0
- if (strcmp (info->service_name, data->service_name) == 0) {
- remove_session_for_cookie (data->manager, cookie, NULL);
- leader_info_cancel (info);
- return TRUE;
- }
-#endif
-
- return FALSE;
-}
-
-static void
-remove_displays_for_connection (GdmManager *manager,
- const char *service_name)
-{
- RemoveDisplayData data;
-
- data.service_name = service_name;
- data.manager = manager;
-
- gdm_display_store_foreach_remove (manager->priv->display_store,
- (GdmDisplayStoreFunc)remove_display_for_connection,
- &data);
-}
-
-static void
-bus_name_owner_changed (DBusGProxy *bus_proxy,
- const char *service_name,
- const char *old_service_name,
- const char *new_service_name,
- GdmManager *manager)
-{
- if (strlen (new_service_name) == 0) {
- remove_displays_for_connection (manager, old_service_name);
- }
-}
-
static gboolean
register_manager (GdmManager *manager)
{
GError *error = NULL;
+ GDBusObjectManagerServer *object_server;
error = NULL;
- manager->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ manager->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (manager->priv->connection == NULL) {
- if (error != NULL) {
- g_critical ("error getting system bus: %s", error->message);
- g_error_free (error);
- }
+ g_critical ("error getting system bus: %s", error->message);
+ g_error_free (error);
exit (1);
}
- manager->priv->bus_proxy = dbus_g_proxy_new_for_name (manager->priv->connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
- dbus_g_proxy_add_signal (manager->priv->bus_proxy,
- "NameOwnerChanged",
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (manager->priv->bus_proxy,
- "NameOwnerChanged",
- G_CALLBACK (bus_name_owner_changed),
- manager,
- NULL);
-
- dbus_g_connection_register_g_object (manager->priv->connection, GDM_MANAGER_DBUS_PATH, G_OBJECT (manager));
+ object_server = g_dbus_object_manager_server_new (GDM_MANAGER_DBUS_PATH);
+ g_dbus_object_manager_server_set_connection (object_server, manager->priv->connection);
+ manager->priv->object_manager = object_server;
return TRUE;
}
@@ -415,8 +346,6 @@ gdm_manager_class_init (GdmManagerClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_type_class_add_private (klass, sizeof (GdmManagerPrivate));
-
- dbus_g_object_type_install_info (GDM_TYPE_MANAGER, &dbus_glib_gdm_manager_object_info);
}
static void
@@ -441,10 +370,12 @@ gdm_manager_finalize (GObject *object)
g_return_if_fail (manager->priv != NULL);
#ifdef HAVE_LIBXDMCP
- if (manager->priv->xdmcp_factory != NULL) {
- g_object_unref (manager->priv->xdmcp_factory);
- }
+ g_clear_object (&manager->priv->xdmcp_factory);
#endif
+ g_clear_object (&manager->priv->local_factory);
+
+ g_clear_object (&manager->priv->connection);
+ g_clear_object (&manager->priv->object_manager);
gdm_display_store_clear (manager->priv->display_store);
g_object_unref (manager->priv->display_store);
@@ -452,6 +383,37 @@ gdm_manager_finalize (GObject *object)
G_OBJECT_CLASS (gdm_manager_parent_class)->finalize (object);
}
+void
+gdm_manager_display_removed (GdmManager *manager,
+ GdmDisplay *display)
+{
+ char *id;
+
+ g_object_get (display, "id", &id, NULL);
+
+ g_dbus_object_manager_server_unexport (manager->priv->object_manager, id);
+
+ g_signal_emit (manager, signals[DISPLAY_REMOVED], 0, id);
+
+ g_free (id);
+}
+
+void
+gdm_manager_display_added (GdmManager *manager,
+ GdmDisplay *display)
+{
+ char *id;
+
+ g_object_get (display, "id", &id, NULL);
+
+ g_dbus_object_manager_server_export (manager->priv->object_manager,
+ gdm_display_get_object_skeleton (display));
+
+ g_signal_emit (manager, signals[DISPLAY_ADDED], 0, id);
+
+ g_free (id);
+}
+
GdmManager *
gdm_manager_new (void)
{
diff --git a/daemon/gdm-manager.h b/daemon/gdm-manager.h
index c479d93..7b68b0e 100644
--- a/daemon/gdm-manager.h
+++ b/daemon/gdm-manager.h
@@ -23,6 +23,7 @@
#define __GDM_MANAGER_H
#include <glib-object.h>
+#include "gdm-display.h"
G_BEGIN_DECLS
@@ -73,6 +74,11 @@ gboolean gdm_manager_get_displays (GdmManager *mana
GPtrArray **displays,
GError **error);
+void gdm_manager_display_added (GdmManager *manager,
+ GdmDisplay *display);
+void gdm_manager_display_removed (GdmManager *manager,
+ GdmDisplay *display);
+
G_END_DECLS
diff --git a/daemon/gdm-session.c b/daemon/gdm-session.c
index a3563d9..d8734b4 100644
--- a/daemon/gdm-session.c
+++ b/daemon/gdm-session.c
@@ -2382,13 +2382,13 @@ gdm_session_constructor (GType type,
if (self->priv->display_id != NULL) {
/* Always match the session id with the master */
id = NULL;
- if (g_str_has_prefix (self->priv->display_id, "/org/gnome/DisplayManager/Display")) {
- id = self->priv->display_id + strlen ("/org/gnome/DisplayManager/Display");
+ if (g_str_has_prefix (self->priv->display_id, "/org/gnome/DisplayManager/Displays/")) {
+ id = self->priv->display_id + strlen ("/org/gnome/DisplayManager/Displays/");
}
g_assert (id != NULL);
- self->priv->id = g_strdup_printf ("/org/gnome/DisplayManager/Session%s", id);
+ self->priv->id = g_strdup_printf ("/org/gnome/DisplayManager/Sessions/%s", id);
g_debug ("GdmSession: Registering %s", self->priv->id);
#if 0
diff --git a/daemon/gdm-slave.c b/daemon/gdm-slave.c
index 946dc97..d86caff 100644
--- a/daemon/gdm-slave.c
+++ b/daemon/gdm-slave.c
@@ -103,7 +103,6 @@ struct GdmSlavePrivate
GdmDBusDisplay *display_proxy;
GDBusConnection *connection;
- GDBusObjectSkeleton *object_skeleton;
GdmDBusSlave *skeleton;
};
@@ -879,9 +878,7 @@ gdm_slave_real_stop (GdmSlave *slave)
{
g_debug ("GdmSlave: Stopping slave");
- if (slave->priv->display_proxy != NULL) {
- g_object_unref (slave->priv->display_proxy);
- }
+ g_clear_object (&slave->priv->display_proxy);
return TRUE;
}
@@ -1368,6 +1365,7 @@ gdm_slave_get_primary_session_id_for_user_from_ck (GdmSlave *slave,
char *primary_ssid;
uid_t uid;
GVariant *reply;
+ GVariant *array;
GVariantIter iter;
char *ssid;
@@ -1422,7 +1420,8 @@ gdm_slave_get_primary_session_id_for_user_from_ck (GdmSlave *slave,
return NULL;
}
- g_variant_iter_init (&iter, reply);
+ array = g_variant_get_child_value (reply, 0);
+ g_variant_iter_init (&iter, array);
while (g_variant_iter_loop (&iter, "(&s)", &ssid)) {
if (x11_session_is_on_seat (slave, ssid, slave->priv->display_seat_id)) {
primary_ssid = g_strdup (ssid);
@@ -1431,6 +1430,7 @@ gdm_slave_get_primary_session_id_for_user_from_ck (GdmSlave *slave,
}
g_variant_unref (reply);
+ g_variant_unref (array);
return primary_ssid;
}
#endif
@@ -1813,11 +1813,9 @@ register_slave (GdmSlave *slave)
exit (1);
}
- slave->priv->object_skeleton = g_dbus_object_skeleton_new (slave->priv->id);
slave->priv->skeleton = GDM_DBUS_SLAVE (gdm_dbus_slave_skeleton_new ());
-
- g_dbus_object_skeleton_add_interface (slave->priv->object_skeleton,
- G_DBUS_INTERFACE_SKELETON (slave->priv->skeleton));
+ gdm_slave_export_interface (slave,
+ G_DBUS_INTERFACE_SKELETON (slave->priv->skeleton));
return TRUE;
}
@@ -1837,13 +1835,13 @@ gdm_slave_constructor (GType type,
/* Always match the slave id with the master */
id = NULL;
- if (g_str_has_prefix (slave->priv->display_id, "/org/gnome/DisplayManager/Display")) {
- id = slave->priv->display_id + strlen ("/org/gnome/DisplayManager/Display");
+ if (g_str_has_prefix (slave->priv->display_id, "/org/gnome/DisplayManager/Displays/")) {
+ id = slave->priv->display_id + strlen ("/org/gnome/DisplayManager/Displays/");
}
g_assert (id != NULL);
- slave->priv->id = g_strdup_printf ("/org/gnome/DisplayManager/Slave%s", id);
+ slave->priv->id = g_strdup_printf ("/org/gnome/DisplayManager/Slaves/%s", id);
g_debug ("GdmSlave: Registering %s", slave->priv->id);
res = register_slave (slave);
@@ -1969,3 +1967,13 @@ gdm_slave_finalize (GObject *object)
G_OBJECT_CLASS (gdm_slave_parent_class)->finalize (object);
}
+
+void
+gdm_slave_export_interface (GdmSlave *slave,
+ GDBusInterfaceSkeleton *interface)
+{
+ g_dbus_interface_skeleton_export (interface,
+ slave->priv->connection,
+ slave->priv->id,
+ NULL);
+}
diff --git a/daemon/gdm-slave.h b/daemon/gdm-slave.h
index aaaa8f2..58a727b 100644
--- a/daemon/gdm-slave.h
+++ b/daemon/gdm-slave.h
@@ -23,6 +23,7 @@
#define __GDM_SLAVE_H
#include <glib-object.h>
+#include <gio/gio.h>
G_BEGIN_DECLS
@@ -84,6 +85,9 @@ gboolean gdm_slave_run_script (GdmSlave *slave,
const char *username);
void gdm_slave_stopped (GdmSlave *slave);
+void gdm_slave_export_interface (GdmSlave *slave,
+ GDBusInterfaceSkeleton *interface);
+
G_END_DECLS
#endif /* __GDM_SLAVE_H */
diff --git a/daemon/gdm-xdmcp-chooser-display.c b/daemon/gdm-xdmcp-chooser-display.c
index f5f2e10..e44ac98 100644
--- a/daemon/gdm-xdmcp-chooser-display.c
+++ b/daemon/gdm-xdmcp-chooser-display.c
@@ -102,11 +102,11 @@ gdm_xdmcp_chooser_display_set_slave_bus_name (GdmDisplay *display,
g_object_get (display, "id", &display_id, NULL);
- if (g_str_has_prefix (display_id, "/org/gnome/DisplayManager/Display")) {
- slave_num = display_id + strlen ("/org/gnome/DisplayManager/Display");
+ if (g_str_has_prefix (display_id, "/org/gnome/DisplayManager/Displays/")) {
+ slave_num = display_id + strlen ("/org/gnome/DisplayManager/Displays/");
}
- slave_id = g_strdup_printf ("/org/gnome/DisplayManager/Slave%s", slave_num);
+ slave_id = g_strdup_printf ("/org/gnome/DisplayManager/Slaves/%s", slave_num);
local_error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &local_error);
diff --git a/daemon/gdm-xdmcp-display-factory.c b/daemon/gdm-xdmcp-display-factory.c
index a54a734..cd5b276 100644
--- a/daemon/gdm-xdmcp-display-factory.c
+++ b/daemon/gdm-xdmcp-display-factory.c
@@ -52,6 +52,7 @@
#include <X11/Xdmcp.h>
#include "gdm-common.h"
+#include "gdm-manager.h"
#include "gdm-xdmcp-greeter-display.h"
#include "gdm-xdmcp-chooser-display.h"
#include "gdm-display-factory.h"
@@ -2053,9 +2054,11 @@ on_display_status_changed (GdmDisplay *display,
switch (status) {
case GDM_DISPLAY_FINISHED:
gdm_display_store_remove (store, display);
+ gdm_manager_display_removed (gdm_manager_new (), display);
break;
case GDM_DISPLAY_FAILED:
gdm_display_store_remove (store, display);
+ gdm_manager_display_removed (gdm_manager_new (), display);
break;
case GDM_DISPLAY_UNMANAGED:
break;
@@ -2127,6 +2130,8 @@ gdm_xdmcp_display_create (GdmXdmcpDisplayFactory *factory,
store = gdm_display_factory_get_display_store (GDM_DISPLAY_FACTORY (factory));
gdm_display_store_add (store, display);
+ gdm_manager_display_added (gdm_manager_new (), display);
+
factory->priv->num_pending_sessions++;
out:
diff --git a/daemon/main.c b/daemon/main.c
index cba7cc2..0255c53 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -38,10 +38,7 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <glib-object.h>
-
-#define DBUS_API_SUBJECT_TO_CHANGE
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
#include "gdm-manager.h"
#include "gdm-log.h"
@@ -54,12 +51,13 @@
#define GDM_DBUS_NAME "org.gnome.DisplayManager"
-static void bus_proxy_destroyed_cb (DBusGProxy *bus_proxy,
- GdmManager **managerp);
+static GDBusConnection *get_system_bus (void);
+static gboolean bus_reconnect (void);
extern char **environ;
static GdmManager *manager = NULL;
+static int name_id = -1;
static GdmSettings *settings = NULL;
static uid_t gdm_uid = -1;
static gid_t gdm_gid = -1;
@@ -71,76 +69,29 @@ timed_exit_cb (GMainLoop *loop)
return FALSE;
}
-static DBusGProxy *
-get_bus_proxy (DBusGConnection *connection)
-{
- DBusGProxy *bus_proxy;
-
- bus_proxy = dbus_g_proxy_new_for_name (connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
- return bus_proxy;
-}
-
-static gboolean
-acquire_name_on_proxy (DBusGProxy *bus_proxy)
+static void
+bus_connection_closed (void)
{
- GError *error;
- guint result;
- gboolean res;
- gboolean ret;
-
- ret = FALSE;
-
- if (bus_proxy == NULL) {
- goto out;
- }
-
- error = NULL;
- res = dbus_g_proxy_call (bus_proxy,
- "RequestName",
- &error,
- G_TYPE_STRING, GDM_DBUS_NAME,
- G_TYPE_UINT, 0,
- G_TYPE_INVALID,
- G_TYPE_UINT, &result,
- G_TYPE_INVALID);
- if (! res) {
- if (error != NULL) {
- g_warning ("Failed to acquire %s: %s", GDM_DBUS_NAME, error->message);
- g_error_free (error);
- } else {
- g_warning ("Failed to acquire %s", GDM_DBUS_NAME);
- }
- goto out;
- }
+ g_debug ("Disconnected from D-Bus");
- if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
- if (error != NULL) {
- g_warning ("Failed to acquire %s: %s", GDM_DBUS_NAME, error->message);
- g_error_free (error);
- } else {
- g_warning ("Failed to acquire %s", GDM_DBUS_NAME);
- }
- goto out;
+ if (manager == NULL) {
+ /* probably shutting down or something */
+ return;
}
- ret = TRUE;
+ g_clear_object (&manager);
- out:
- return ret;
+ g_timeout_add_seconds (3, (GSourceFunc)bus_reconnect, NULL);
}
-static DBusGConnection *
+static GDBusConnection *
get_system_bus (void)
{
GError *error;
- DBusGConnection *bus;
- DBusConnection *connection;
+ GDBusConnection *bus;
error = NULL;
- bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (bus == NULL) {
g_warning ("Couldn't connect to system bus: %s",
error->message);
@@ -148,76 +99,14 @@ get_system_bus (void)
goto out;
}
- connection = dbus_g_connection_get_connection (bus);
- dbus_connection_set_exit_on_disconnect (connection, FALSE);
+ g_signal_connect (bus, "closed",
+ G_CALLBACK (bus_connection_closed), NULL);
+ g_dbus_connection_set_exit_on_close (bus, FALSE);
out:
return bus;
}
-static gboolean
-bus_reconnect (GdmManager *manager)
-{
- DBusGConnection *bus;
- DBusGProxy *bus_proxy;
- gboolean ret;
-
- ret = TRUE;
-
- bus = get_system_bus ();
- if (bus == NULL) {
- goto out;
- }
-
- bus_proxy = get_bus_proxy (bus);
- if (bus_proxy == NULL) {
- g_warning ("Could not construct bus_proxy object; will retry");
- goto out;
- }
-
- if (! acquire_name_on_proxy (bus_proxy) ) {
- g_warning ("Could not acquire name; will retry");
- goto out;
- }
-
- manager = gdm_manager_new ();
- if (manager == NULL) {
- g_warning ("Could not construct manager object");
- exit (1);
- }
-
- g_signal_connect (bus_proxy,
- "destroy",
- G_CALLBACK (bus_proxy_destroyed_cb),
- &manager);
-
- g_debug ("Successfully reconnected to D-Bus");
-
- gdm_manager_start (manager);
-
- ret = FALSE;
-
- out:
- return ret;
-}
-
-static void
-bus_proxy_destroyed_cb (DBusGProxy *bus_proxy,
- GdmManager **managerp)
-{
- g_debug ("Disconnected from D-Bus");
-
- if (managerp == NULL || *managerp == NULL) {
- /* probably shutting down or something */
- return;
- }
-
- g_object_unref (*managerp);
- *managerp = NULL;
-
- g_timeout_add_seconds (3, (GSourceFunc)bus_reconnect, managerp);
-}
-
static void
delete_pid (void)
{
@@ -253,7 +142,7 @@ write_pid (void)
return;
}
- g_atexit (delete_pid);
+ atexit (delete_pid);
}
static void
@@ -527,12 +416,9 @@ main (int argc,
{
GMainLoop *main_loop;
GOptionContext *context;
- DBusGProxy *bus_proxy;
- DBusGConnection *connection;
GError *error;
int ret;
gboolean res;
- gboolean xdmcp_enabled;
GdmSignalHandler *signal_handler;
static gboolean do_timed_exit = FALSE;
static gboolean print_version = FALSE;
@@ -579,22 +465,6 @@ main (int argc,
g_log_set_always_fatal (fatal_mask);
}
- connection = get_system_bus ();
- if (connection == NULL) {
- goto out;
- }
-
- bus_proxy = get_bus_proxy (connection);
- if (bus_proxy == NULL) {
- g_warning ("Could not construct bus_proxy object; bailing out");
- goto out;
- }
-
- if (! acquire_name_on_proxy (bus_proxy) ) {
- g_warning ("Could not acquire name; bailing out");
- goto out;
- }
-
gdm_log_init ();
settings = gdm_settings_new ();
@@ -623,27 +493,15 @@ main (int argc,
exit (-1);
}
+ /* Connect to the bus, own the name and start the manager */
+ bus_reconnect ();
+
/* pid file */
delete_pid ();
write_pid ();
g_chdir (AUTHDIR);
- manager = gdm_manager_new ();
-
- if (manager == NULL) {
- goto out;
- }
-
- xdmcp_enabled = FALSE;
- gdm_settings_direct_get_boolean (GDM_KEY_XDMCP_ENABLE, &xdmcp_enabled);
- gdm_manager_set_xdmcp_enabled (manager, xdmcp_enabled);
-
- g_signal_connect (bus_proxy,
- "destroy",
- G_CALLBACK (bus_proxy_destroyed_cb),
- &manager);
-
main_loop = g_main_loop_new (NULL, FALSE);
signal_handler = gdm_signal_handler_new ();
@@ -661,23 +519,13 @@ main (int argc,
g_timeout_add_seconds (30, (GSourceFunc) timed_exit_cb, main_loop);
}
- gdm_manager_start (manager);
-
g_main_loop_run (main_loop);
g_debug ("GDM finished, cleaning up...");
- if (manager != NULL) {
- g_object_unref (manager);
- }
-
- if (settings != NULL) {
- g_object_unref (settings);
- }
-
- if (signal_handler != NULL) {
- g_object_unref (signal_handler);
- }
+ g_clear_object (&manager);
+ g_clear_object (&settings);
+ g_clear_object (&signal_handler);
gdm_settings_direct_shutdown ();
gdm_log_shutdown ();
@@ -690,3 +538,61 @@ main (int argc,
return ret;
}
+
+static void
+on_name_acquired (GDBusConnection *bus,
+ const char *name,
+ gpointer user_data)
+{
+ gboolean xdmcp_enabled;
+
+ manager = gdm_manager_new ();
+ if (manager == NULL) {
+ g_warning ("Could not construct manager object");
+ exit (1);
+ }
+
+ g_debug ("Successfully connected to D-Bus");
+
+ gdm_manager_start (manager);
+
+ xdmcp_enabled = FALSE;
+ gdm_settings_direct_get_boolean (GDM_KEY_XDMCP_ENABLE, &xdmcp_enabled);
+ gdm_manager_set_xdmcp_enabled (manager, xdmcp_enabled);
+}
+
+static void
+on_name_lost (GDBusConnection *bus,
+ const char *name,
+ gpointer user_data)
+{
+ g_debug ("Lost GDM name on bus");
+
+ bus_connection_closed ();
+}
+
+static gboolean
+bus_reconnect ()
+{
+ GDBusConnection *bus;
+ gboolean ret;
+
+ ret = TRUE;
+
+ bus = get_system_bus ();
+ if (bus == NULL) {
+ goto out;
+ }
+
+ name_id = g_bus_own_name_on_connection (bus,
+ GDM_DBUS_NAME,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ on_name_acquired,
+ on_name_lost,
+ NULL,
+ NULL);
+
+ ret = FALSE;
+ out:
+ return ret;
+}
diff --git a/daemon/test-session.c b/daemon/test-session.c
index 5b838bd..31be1ec 100644
--- a/daemon/test-session.c
+++ b/daemon/test-session.c
@@ -246,8 +246,7 @@ main (int argc,
g_type_init ();
do {
- g_debug ("creating instance of GdmSession object...");
- session = gdm_session_new ("/org/gnome/DisplayManager/Display1",
+ session = gdm_session_new ("/org/gnome/DisplayManager/Displays/1",
":0",
g_get_host_name (),
ttyname (STDIN_FILENO),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]