1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
---|
2 | * |
---|
3 | * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> |
---|
4 | * |
---|
5 | * This program is free software; you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU General Public License as published by |
---|
7 | * the Free Software Foundation; either version 2 of the License, or |
---|
8 | * (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public License |
---|
16 | * along with this program; if not, write to the Free Software |
---|
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
18 | * |
---|
19 | */ |
---|
20 | |
---|
21 | #include "config.h" |
---|
22 | |
---|
23 | #include <stdlib.h> |
---|
24 | #include <stdio.h> |
---|
25 | #include <fcntl.h> |
---|
26 | #include <unistd.h> |
---|
27 | #include <string.h> |
---|
28 | #include <signal.h> |
---|
29 | #include <sys/stat.h> |
---|
30 | #include <sys/types.h> |
---|
31 | #include <sys/socket.h> |
---|
32 | |
---|
33 | #include <glib.h> |
---|
34 | #include <glib/gi18n.h> |
---|
35 | #include <glib-object.h> |
---|
36 | |
---|
37 | #include "gdm-display.h" |
---|
38 | #include "gdm-static-factory-display.h" |
---|
39 | #include "gdm-static-factory-display-glue.h" |
---|
40 | |
---|
41 | #define GDM_STATIC_FACTORY_DISPLAY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_STATIC_FACTORY_DISPLAY, GdmStaticFactoryDisplayPrivate)) |
---|
42 | |
---|
43 | #define DEFAULT_SLAVE_COMMAND LIBEXECDIR"/gdm-factory-slave" |
---|
44 | |
---|
45 | struct GdmStaticFactoryDisplayPrivate |
---|
46 | { |
---|
47 | gpointer dummy; |
---|
48 | }; |
---|
49 | |
---|
50 | enum { |
---|
51 | PROP_0, |
---|
52 | }; |
---|
53 | |
---|
54 | static void gdm_static_factory_display_class_init (GdmStaticFactoryDisplayClass *klass); |
---|
55 | static void gdm_static_factory_display_init (GdmStaticFactoryDisplay *static_factory_display); |
---|
56 | static void gdm_static_factory_display_finalize (GObject *object); |
---|
57 | |
---|
58 | G_DEFINE_TYPE (GdmStaticFactoryDisplay, gdm_static_factory_display, GDM_TYPE_DISPLAY) |
---|
59 | |
---|
60 | static gboolean |
---|
61 | gdm_static_factory_display_add_user_authorization (GdmDisplay *display, |
---|
62 | const char *username, |
---|
63 | char **filename, |
---|
64 | GError **error) |
---|
65 | { |
---|
66 | return GDM_DISPLAY_CLASS (gdm_static_factory_display_parent_class)->add_user_authorization (display, username, filename, error); |
---|
67 | } |
---|
68 | |
---|
69 | static gboolean |
---|
70 | gdm_static_factory_display_remove_user_authorization (GdmDisplay *display, |
---|
71 | const char *username, |
---|
72 | GError **error) |
---|
73 | { |
---|
74 | return GDM_DISPLAY_CLASS (gdm_static_factory_display_parent_class)->remove_user_authorization (display, username, error); |
---|
75 | } |
---|
76 | |
---|
77 | static gboolean |
---|
78 | gdm_static_factory_display_create_authority (GdmDisplay *display) |
---|
79 | { |
---|
80 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
81 | |
---|
82 | GDM_DISPLAY_CLASS (gdm_static_factory_display_parent_class)->create_authority (display); |
---|
83 | |
---|
84 | return TRUE; |
---|
85 | } |
---|
86 | |
---|
87 | static gboolean |
---|
88 | gdm_static_factory_display_manage (GdmDisplay *display) |
---|
89 | { |
---|
90 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
91 | |
---|
92 | GDM_DISPLAY_CLASS (gdm_static_factory_display_parent_class)->manage (display); |
---|
93 | |
---|
94 | return TRUE; |
---|
95 | } |
---|
96 | |
---|
97 | static gboolean |
---|
98 | gdm_static_factory_display_finish (GdmDisplay *display) |
---|
99 | { |
---|
100 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
101 | |
---|
102 | GDM_DISPLAY_CLASS (gdm_static_factory_display_parent_class)->finish (display); |
---|
103 | |
---|
104 | /* restart static displays */ |
---|
105 | gdm_display_unmanage (display); |
---|
106 | gdm_display_manage (display); |
---|
107 | |
---|
108 | return TRUE; |
---|
109 | } |
---|
110 | |
---|
111 | static gboolean |
---|
112 | gdm_static_factory_display_unmanage (GdmDisplay *display) |
---|
113 | { |
---|
114 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
115 | |
---|
116 | GDM_DISPLAY_CLASS (gdm_static_factory_display_parent_class)->unmanage (display); |
---|
117 | |
---|
118 | return TRUE; |
---|
119 | } |
---|
120 | |
---|
121 | static void |
---|
122 | gdm_static_factory_display_set_property (GObject *object, |
---|
123 | guint prop_id, |
---|
124 | const GValue *value, |
---|
125 | GParamSpec *pspec) |
---|
126 | { |
---|
127 | switch (prop_id) { |
---|
128 | default: |
---|
129 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
130 | break; |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | static void |
---|
135 | gdm_static_factory_display_get_property (GObject *object, |
---|
136 | guint prop_id, |
---|
137 | GValue *value, |
---|
138 | GParamSpec *pspec) |
---|
139 | { |
---|
140 | switch (prop_id) { |
---|
141 | default: |
---|
142 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
143 | break; |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | static GObject * |
---|
148 | gdm_static_factory_display_constructor (GType type, |
---|
149 | guint n_construct_properties, |
---|
150 | GObjectConstructParam *construct_properties) |
---|
151 | { |
---|
152 | GdmStaticFactoryDisplay *display; |
---|
153 | |
---|
154 | display = GDM_STATIC_FACTORY_DISPLAY (G_OBJECT_CLASS (gdm_static_factory_display_parent_class)->constructor (type, |
---|
155 | n_construct_properties, |
---|
156 | construct_properties)); |
---|
157 | |
---|
158 | return G_OBJECT (display); |
---|
159 | } |
---|
160 | |
---|
161 | static void |
---|
162 | gdm_static_factory_display_class_init (GdmStaticFactoryDisplayClass *klass) |
---|
163 | { |
---|
164 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
---|
165 | GdmDisplayClass *display_class = GDM_DISPLAY_CLASS (klass); |
---|
166 | |
---|
167 | object_class->get_property = gdm_static_factory_display_get_property; |
---|
168 | object_class->set_property = gdm_static_factory_display_set_property; |
---|
169 | object_class->constructor = gdm_static_factory_display_constructor; |
---|
170 | object_class->finalize = gdm_static_factory_display_finalize; |
---|
171 | |
---|
172 | display_class->create_authority = gdm_static_factory_display_create_authority; |
---|
173 | display_class->add_user_authorization = gdm_static_factory_display_add_user_authorization; |
---|
174 | display_class->remove_user_authorization = gdm_static_factory_display_remove_user_authorization; |
---|
175 | display_class->manage = gdm_static_factory_display_manage; |
---|
176 | display_class->finish = gdm_static_factory_display_finish; |
---|
177 | display_class->unmanage = gdm_static_factory_display_unmanage; |
---|
178 | |
---|
179 | g_type_class_add_private (klass, sizeof (GdmStaticFactoryDisplayPrivate)); |
---|
180 | |
---|
181 | dbus_g_object_type_install_info (GDM_TYPE_STATIC_FACTORY_DISPLAY, &dbus_glib_gdm_static_factory_display_object_info); |
---|
182 | } |
---|
183 | |
---|
184 | static void |
---|
185 | gdm_static_factory_display_init (GdmStaticFactoryDisplay *static_factory_display) |
---|
186 | { |
---|
187 | |
---|
188 | static_factory_display->priv = GDM_STATIC_FACTORY_DISPLAY_GET_PRIVATE (static_factory_display); |
---|
189 | } |
---|
190 | |
---|
191 | static void |
---|
192 | gdm_static_factory_display_finalize (GObject *object) |
---|
193 | { |
---|
194 | GdmStaticFactoryDisplay *static_factory_display; |
---|
195 | |
---|
196 | g_return_if_fail (object != NULL); |
---|
197 | g_return_if_fail (GDM_IS_STATIC_FACTORY_DISPLAY (object)); |
---|
198 | |
---|
199 | static_factory_display = GDM_STATIC_FACTORY_DISPLAY (object); |
---|
200 | |
---|
201 | g_return_if_fail (static_factory_display->priv != NULL); |
---|
202 | |
---|
203 | G_OBJECT_CLASS (gdm_static_factory_display_parent_class)->finalize (object); |
---|
204 | } |
---|
205 | |
---|
206 | GdmDisplay * |
---|
207 | gdm_static_factory_display_new (int display_number) |
---|
208 | { |
---|
209 | GObject *object; |
---|
210 | char *x11_display; |
---|
211 | |
---|
212 | x11_display = g_strdup_printf (":%d", display_number); |
---|
213 | object = g_object_new (GDM_TYPE_STATIC_FACTORY_DISPLAY, |
---|
214 | "slave-command", DEFAULT_SLAVE_COMMAND, |
---|
215 | "x11-display-number", display_number, |
---|
216 | "x11-display-name", x11_display, |
---|
217 | NULL); |
---|
218 | g_free (x11_display); |
---|
219 | |
---|
220 | return GDM_DISPLAY (object); |
---|
221 | } |
---|