diff options
author | William Jon McCann <mccann@jhu.edu> | 2007-08-02 23:20:41 +0000 |
---|---|---|
committer | William Jon McCann <mccann@src.gnome.org> | 2007-08-02 23:20:41 +0000 |
commit | 15b71907d0691b2cb69dacdf0c6e11ab4d8cad23 (patch) | |
tree | c98b3878dc1877033b48c4b2806c05b948918bec | |
parent | ac5eabb7b5c661c23d5f2192e397f91b669075ae (diff) | |
download | gdm-15b71907d0691b2cb69dacdf0c6e11ab4d8cad23.tar.gz |
Add new object that will monitor HAL and act as a factory for displays.
2007-08-02 William Jon McCann <mccann@jhu.edu>
* daemon/Makefile.am:
* daemon/gdm-local-display-factory.c:
(gdm_local_display_factory_error_quark), (get_pci_seat_devices),
(gdm_local_display_factory_start),
(gdm_local_display_factory_stop),
(gdm_local_display_factory_set_display_store),
(gdm_local_display_factory_set_property),
(gdm_local_display_factory_get_property),
(gdm_local_display_factory_class_init), (connect_to_hal),
(disconnect_from_hal), (gdm_local_display_factory_init),
(gdm_local_display_factory_finalize),
(gdm_local_display_factory_new):
* daemon/gdm-local-display-factory.h:
* daemon/gdm-manager.c: (gdm_manager_start),
(gdm_manager_set_wait_for_go), (gdm_manager_constructor):
Add new object that will monitor HAL and act as a factory
for displays.
svn path=/branches/mccann-gobject/; revision=5125
-rw-r--r-- | ChangeLog | 20 | ||||
-rw-r--r-- | daemon/Makefile.am | 2 | ||||
-rw-r--r-- | daemon/gdm-local-display-factory.c | 334 | ||||
-rw-r--r-- | daemon/gdm-local-display-factory.h | 70 | ||||
-rw-r--r-- | daemon/gdm-manager.c | 111 |
5 files changed, 442 insertions, 95 deletions
@@ -1,3 +1,23 @@ +2007-08-02 William Jon McCann <mccann@jhu.edu> + + * daemon/Makefile.am: + * daemon/gdm-local-display-factory.c: + (gdm_local_display_factory_error_quark), (get_pci_seat_devices), + (gdm_local_display_factory_start), + (gdm_local_display_factory_stop), + (gdm_local_display_factory_set_display_store), + (gdm_local_display_factory_set_property), + (gdm_local_display_factory_get_property), + (gdm_local_display_factory_class_init), (connect_to_hal), + (disconnect_from_hal), (gdm_local_display_factory_init), + (gdm_local_display_factory_finalize), + (gdm_local_display_factory_new): + * daemon/gdm-local-display-factory.h: + * daemon/gdm-manager.c: (gdm_manager_start), + (gdm_manager_set_wait_for_go), (gdm_manager_constructor): + Add new object that will monitor HAL and act as a factory + for displays. + 2007-08-01 William Jon McCann <mccann@jhu.edu> * daemon/gdm-session-worker.c: (open_idle), (free_open_data), diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 40f38bb8..ef52991d 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -234,6 +234,8 @@ gdm_binary_SOURCES = \ main.c \ gdm-display-store.c \ gdm-display-store.h \ + gdm-local-display-factory.c \ + gdm-local-display-factory.h \ gdm-display.c \ gdm-display.h \ gdm-xdmcp-display.c \ diff --git a/daemon/gdm-local-display-factory.c b/daemon/gdm-local-display-factory.c new file mode 100644 index 00000000..2c9febe6 --- /dev/null +++ b/daemon/gdm-local-display-factory.c @@ -0,0 +1,334 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include <stdlib.h> +#include <stdio.h> + +#include <glib.h> +#include <glib/gi18n.h> +#include <glib-object.h> + +#include "gdm-local-display-factory.h" +#include "gdm-display-store.h" +#include "gdm-static-display.h" +#include "gdm-static-factory-display.h" + +#define GDM_LOCAL_DISPLAY_FACTORY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_LOCAL_DISPLAY_FACTORY, GdmLocalDisplayFactoryPrivate)) + +#define HAL_DBUS_NAME "org.freedesktop.Hal" +#define HAL_DBUS_MANAGER_PATH "/org/freedesktop/Hal/Manager" +#define HAL_DBUS_MANAGER_INTERFACE "org.freedesktop.Hal.Manager" +#define HAL_DBUS_DEVICE_INTERFACE "org.freedesktop.Hal.Device" +#define SEAT_PCI_DEVICE_CLASS 3 + +struct GdmLocalDisplayFactoryPrivate +{ + GdmDisplayStore *display_store; + + DBusGConnection *connection; + DBusGProxy *proxy; + +}; + +enum { + DISPLAY_ADDED, + DISPLAY_REMOVED, + LAST_SIGNAL +}; + +enum { + PROP_0, + PROP_DISPLAY_STORE, +}; + +static guint signals [LAST_SIGNAL] = { 0, }; + +static void gdm_local_display_factory_class_init (GdmLocalDisplayFactoryClass *klass); +static void gdm_local_display_factory_init (GdmLocalDisplayFactory *factory); +static void gdm_local_display_factory_finalize (GObject *object); + +static gpointer local_display_factory_object = NULL; + +G_DEFINE_TYPE (GdmLocalDisplayFactory, gdm_local_display_factory, G_TYPE_OBJECT) + +GQuark +gdm_local_display_factory_error_quark (void) +{ + static GQuark ret = 0; + if (ret == 0) { + ret = g_quark_from_static_string ("gdm_local_display_factory_error"); + } + + return ret; +} + +static void +get_pci_seat_devices (GdmLocalDisplayFactory *factory, + GList *seats) +{ + char **devices; + const char *key; + const char *value; + GError *error; + gboolean res; + int i; + + g_debug ("Getting PCI seat devices"); + + key = "info.bus"; + value = "pci"; + + devices = NULL; + error = NULL; + res = dbus_g_proxy_call (factory->priv->proxy, + "FindDeviceStringMatch", + &error, + G_TYPE_STRING, key, + G_TYPE_STRING, value, + G_TYPE_INVALID, + G_TYPE_STRV, &devices, + G_TYPE_INVALID); + if (! res) { + g_warning ("Unable to query HAL: %s", error->message); + g_error_free (error); + } + + /* now look for pci class 3 */ + key = "pci.device_class"; + for (i = 0; devices [i] != NULL; i++) { + DBusGProxy *device_proxy; + int class_val; + + device_proxy = dbus_g_proxy_new_for_name (factory->priv->connection, + HAL_DBUS_NAME, + devices [i], + HAL_DBUS_DEVICE_INTERFACE); + if (device_proxy == NULL) { + continue; + } + + res = dbus_g_proxy_call (device_proxy, + "GetPropertyInteger", + &error, + G_TYPE_STRING, key, + G_TYPE_INVALID, + G_TYPE_INT, &class_val, + G_TYPE_INVALID); + if (class_val == SEAT_PCI_DEVICE_CLASS) { + g_debug ("Found device: %s", devices [i]); + seats = g_list_prepend (seats, devices [i]); + } + + g_object_unref (device_proxy); + } + + g_strfreev (devices); +} + +gboolean +gdm_local_display_factory_start (GdmLocalDisplayFactory *factory, + GError **error) +{ + gboolean ret; + GdmDisplay *display; + + g_return_val_if_fail (GDM_IS_LOCAL_DISPLAY_FACTORY (factory), FALSE); + + ret = TRUE; + + /* FIXME: */ + + display = gdm_static_display_new (0); + if (display == NULL) { + g_warning ("Unable to create display: %d", 0); + return FALSE; + } + + gdm_display_store_add (factory->priv->display_store, display); + /* let store own the ref */ + g_object_unref (display); + + if (! gdm_display_manage (display)) { + gdm_display_unmanage (display); + } + + return ret; +} + +gboolean +gdm_local_display_factory_stop (GdmLocalDisplayFactory *factory, + GError **error) +{ + g_return_val_if_fail (GDM_IS_LOCAL_DISPLAY_FACTORY (factory), FALSE); + + return TRUE; +} + +static void +gdm_local_display_factory_set_display_store (GdmLocalDisplayFactory *factory, + GdmDisplayStore *display_store) +{ + if (factory->priv->display_store != NULL) { + g_object_unref (factory->priv->display_store); + factory->priv->display_store = NULL; + } + + if (display_store != NULL) { + factory->priv->display_store = g_object_ref (display_store); + } +} + +static void +gdm_local_display_factory_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GdmLocalDisplayFactory *self; + + self = GDM_LOCAL_DISPLAY_FACTORY (object); + + switch (prop_id) { + case PROP_DISPLAY_STORE: + gdm_local_display_factory_set_display_store (self, g_value_get_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gdm_local_display_factory_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GdmLocalDisplayFactory *self; + + self = GDM_LOCAL_DISPLAY_FACTORY (object); + + switch (prop_id) { + case PROP_DISPLAY_STORE: + g_value_set_object (value, self->priv->display_store); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gdm_local_display_factory_class_init (GdmLocalDisplayFactoryClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = gdm_local_display_factory_get_property; + object_class->set_property = gdm_local_display_factory_set_property; + object_class->finalize = gdm_local_display_factory_finalize; + + g_object_class_install_property (object_class, + PROP_DISPLAY_STORE, + g_param_spec_object ("display-store", + "display store", + "display store", + GDM_TYPE_DISPLAY_STORE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_type_class_add_private (klass, sizeof (GdmLocalDisplayFactoryPrivate)); +} + +static gboolean +connect_to_hal (GdmLocalDisplayFactory *factory) +{ + GError *error; + + error = NULL; + factory->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); + if (factory->priv->connection == NULL) { + g_critical ("Couldn't connect to system bus: %s", + error->message); + g_error_free (error); + + return FALSE; + } + + factory->priv->proxy = dbus_g_proxy_new_for_name (factory->priv->connection, + HAL_DBUS_NAME, + HAL_DBUS_MANAGER_PATH, + HAL_DBUS_MANAGER_INTERFACE); + if (factory->priv->proxy == NULL) { + g_warning ("Couldn't create proxy for HAL Manager"); + return FALSE; + } + + return TRUE; +} + +static void +disconnect_from_hal (GdmLocalDisplayFactory *factory) +{ + if (factory->priv->proxy == NULL) { + g_object_unref (factory->priv->proxy); + } +} + +static void +gdm_local_display_factory_init (GdmLocalDisplayFactory *factory) +{ + factory->priv = GDM_LOCAL_DISPLAY_FACTORY_GET_PRIVATE (factory); + + connect_to_hal (factory); +} + +static void +gdm_local_display_factory_finalize (GObject *object) +{ + GdmLocalDisplayFactory *factory; + + g_return_if_fail (object != NULL); + g_return_if_fail (GDM_IS_LOCAL_DISPLAY_FACTORY (object)); + + factory = GDM_LOCAL_DISPLAY_FACTORY (object); + + g_return_if_fail (factory->priv != NULL); + + disconnect_from_hal (factory); + + G_OBJECT_CLASS (gdm_local_display_factory_parent_class)->finalize (object); +} + +GdmLocalDisplayFactory * +gdm_local_display_factory_new (GdmDisplayStore *store) +{ + if (local_display_factory_object != NULL) { + g_object_ref (local_display_factory_object); + } else { + local_display_factory_object = g_object_new (GDM_TYPE_LOCAL_DISPLAY_FACTORY, + "display-store", store, + NULL); + g_object_add_weak_pointer (local_display_factory_object, + (gpointer *) &local_display_factory_object); + } + + return GDM_LOCAL_DISPLAY_FACTORY (local_display_factory_object); +} diff --git a/daemon/gdm-local-display-factory.h b/daemon/gdm-local-display-factory.h new file mode 100644 index 00000000..a8d89f72 --- /dev/null +++ b/daemon/gdm-local-display-factory.h @@ -0,0 +1,70 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#ifndef __GDM_LOCAL_DISPLAY_FACTORY_H +#define __GDM_LOCAL_DISPLAY_FACTORY_H + +#include <glib-object.h> + +#include "gdm-display-store.h" + +G_BEGIN_DECLS + +#define GDM_TYPE_LOCAL_DISPLAY_FACTORY (gdm_local_display_factory_get_type ()) +#define GDM_LOCAL_DISPLAY_FACTORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDM_TYPE_LOCAL_DISPLAY_FACTORY, GdmLocalDisplayFactory)) +#define GDM_LOCAL_DISPLAY_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GDM_TYPE_LOCAL_DISPLAY_FACTORY, GdmLocalDisplayFactoryClass)) +#define GDM_IS_LOCAL_DISPLAY_FACTORY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDM_TYPE_LOCAL_DISPLAY_FACTORY)) +#define GDM_IS_LOCAL_DISPLAY_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GDM_TYPE_LOCAL_DISPLAY_FACTORY)) +#define GDM_LOCAL_DISPLAY_FACTORY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDM_TYPE_LOCAL_DISPLAY_FACTORY, GdmLocalDisplayFactoryClass)) + +typedef struct GdmLocalDisplayFactoryPrivate GdmLocalDisplayFactoryPrivate; + +typedef struct +{ + GObject parent; + GdmLocalDisplayFactoryPrivate *priv; +} GdmLocalDisplayFactory; + +typedef struct +{ + GObjectClass parent_class; +} GdmLocalDisplayFactoryClass; + +typedef enum +{ + GDM_LOCAL_DISPLAY_FACTORY_ERROR_GENERAL +} GdmLocalDisplayFactoryError; + +#define GDM_LOCAL_DISPLAY_FACTORY_ERROR gdm_local_display_factory_error_quark () + +GQuark gdm_local_display_factory_error_quark (void); +GType gdm_local_display_factory_get_type (void); + +GdmLocalDisplayFactory * gdm_local_display_factory_new (GdmDisplayStore *display_store); + +gboolean gdm_local_display_factory_start (GdmLocalDisplayFactory *manager, + GError **error); +gboolean gdm_local_display_factory_stop (GdmLocalDisplayFactory *manager, + GError **error); + +G_END_DECLS + +#endif /* __GDM_LOCAL_DISPLAY_FACTORY_H */ diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c index 71ae7e94..cf62776a 100644 --- a/daemon/gdm-manager.c +++ b/daemon/gdm-manager.c @@ -39,12 +39,10 @@ #include "gdm-manager.h" #include "gdm-manager-glue.h" #include "gdm-display-store.h" +#include "gdm-local-display-factory.h" #include "gdm-xdmcp-manager.h" #include "gdm-common.h" -#include "gdm-static-display.h" -#include "gdm-static-factory-display.h" - #define GDM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_MANAGER, GdmManagerPrivate)) #define GDM_DBUS_PATH "/org/gnome/DisplayManager" @@ -53,17 +51,18 @@ struct GdmManagerPrivate { - GdmDisplayStore *display_store; - GdmXdmcpManager *xdmcp_manager; + GdmDisplayStore *display_store; + GdmLocalDisplayFactory *local_factory; + GdmXdmcpManager *xdmcp_manager; - gboolean xdmcp_enabled; + gboolean xdmcp_enabled; - GString *global_cookie; - gboolean wait_for_go; - gboolean no_console; + GString *global_cookie; + gboolean wait_for_go; + gboolean no_console; - DBusGProxy *bus_proxy; - DBusGConnection *connection; + DBusGProxy *bus_proxy; + DBusGConnection *connection; }; enum { @@ -135,38 +134,6 @@ gdm_manager_get_displays (GdmManager *manager, return TRUE; } -static gboolean -start_local_display (const char *id, - GdmDisplay *d, - GdmManager *manager) -{ - gboolean ret; - - ret = TRUE; - - g_assert (d != NULL); - - if ((GDM_IS_STATIC_FACTORY_DISPLAY (d) || - GDM_IS_STATIC_DISPLAY (d)) && - gdm_display_get_status (d) == GDM_DISPLAY_UNMANAGED) { - if (! gdm_display_manage (d)) { - gdm_display_unmanage (d); - } else { - ret = FALSE; - } - } - - return ret; -} - -static void -start_unborn_local_displays (GdmManager *manager) -{ - gdm_display_store_foreach (manager->priv->display_store, - (GdmDisplayStoreFunc)start_local_display, - manager); -} - static void make_global_cookie (GdmManager *manager) { @@ -199,63 +166,14 @@ make_global_cookie (GdmManager *manager) g_free (file); } -static void -load_static_displays_from_file (GdmManager *manager) -{ -#if 0 - - for (l = xservers; l != NULL; l = l->next) { - GdmDisplay *display; - - g_debug ("Loading display for '%d' %s", xserver->number, xserver->id); - - display = gdm_static_display_new (xserver->number); - - if (display == NULL) { - g_warning ("Unable to create display: %d %s", xserver->number, xserver->id); - continue; - } - - gdm_display_store_add (manager->priv->display_store, display); - - /* let store own the ref */ - g_object_unref (display); - } -#else - GdmDisplay *display; - - /* just load one for now */ - /*display = gdm_static_factory_display_new (0, manager->priv->display_store);*/ - display = gdm_static_display_new (0); - - if (display == NULL) { - g_warning ("Unable to create display: %d", 0); - return; - } - - gdm_display_store_add (manager->priv->display_store, display); - - /* let store own the ref */ - g_object_unref (display); -#endif -} - -static void -load_static_servers (GdmManager *manager) -{ - - load_static_displays_from_file (manager); -} - void gdm_manager_start (GdmManager *manager) { g_debug ("GDM starting to manage"); - load_static_servers (manager); - - /* Start static X servers */ - start_unborn_local_displays (manager); + if (! manager->priv->wait_for_go) { + gdm_local_display_factory_start (manager->priv->local_factory, NULL); + } /* Accept remote connections */ if (manager->priv->xdmcp_enabled && ! manager->priv->wait_for_go) { @@ -276,6 +194,7 @@ gdm_manager_set_wait_for_go (GdmManager *manager, if (! wait_for_go) { /* we got a go */ + gdm_local_display_factory_start (manager->priv->local_factory, NULL); if (manager->priv->xdmcp_enabled && manager->priv->xdmcp_manager != NULL) { g_debug ("Accepting XDMCP connections..."); @@ -439,6 +358,8 @@ gdm_manager_constructor (GType type, n_construct_properties, construct_properties)); + manager->priv->local_factory = gdm_local_display_factory_new (manager->priv->display_store); + if (manager->priv->xdmcp_enabled) { manager->priv->xdmcp_manager = gdm_xdmcp_manager_new (manager->priv->display_store); } |