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-product-display.h" |
---|
39 | #include "gdm-product-display-glue.h" |
---|
40 | |
---|
41 | #define GDM_PRODUCT_DISPLAY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_PRODUCT_DISPLAY, GdmProductDisplayPrivate)) |
---|
42 | |
---|
43 | #define DEFAULT_SLAVE_COMMAND LIBEXECDIR"/gdm-product-slave" |
---|
44 | |
---|
45 | struct GdmProductDisplayPrivate |
---|
46 | { |
---|
47 | char *relay_address; |
---|
48 | }; |
---|
49 | |
---|
50 | enum { |
---|
51 | PROP_0, |
---|
52 | PROP_RELAY_ADDRESS, |
---|
53 | }; |
---|
54 | |
---|
55 | static void gdm_product_display_class_init (GdmProductDisplayClass *klass); |
---|
56 | static void gdm_product_display_init (GdmProductDisplay *product_display); |
---|
57 | static void gdm_product_display_finalize (GObject *object); |
---|
58 | |
---|
59 | G_DEFINE_TYPE (GdmProductDisplay, gdm_product_display, GDM_TYPE_DISPLAY) |
---|
60 | |
---|
61 | static gboolean |
---|
62 | gdm_product_display_create_authority (GdmDisplay *display) |
---|
63 | { |
---|
64 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
65 | |
---|
66 | GDM_DISPLAY_CLASS (gdm_product_display_parent_class)->create_authority (display); |
---|
67 | |
---|
68 | return TRUE; |
---|
69 | } |
---|
70 | |
---|
71 | static gboolean |
---|
72 | gdm_product_display_add_user_authorization (GdmDisplay *display, |
---|
73 | const char *username, |
---|
74 | char **filename, |
---|
75 | GError **error) |
---|
76 | { |
---|
77 | return GDM_DISPLAY_CLASS (gdm_product_display_parent_class)->add_user_authorization (display, username, filename, error); |
---|
78 | } |
---|
79 | |
---|
80 | static gboolean |
---|
81 | gdm_product_display_remove_user_authorization (GdmDisplay *display, |
---|
82 | const char *username, |
---|
83 | GError **error) |
---|
84 | { |
---|
85 | return GDM_DISPLAY_CLASS (gdm_product_display_parent_class)->remove_user_authorization (display, username, error); |
---|
86 | } |
---|
87 | |
---|
88 | static gboolean |
---|
89 | gdm_product_display_manage (GdmDisplay *display) |
---|
90 | { |
---|
91 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
92 | |
---|
93 | GDM_DISPLAY_CLASS (gdm_product_display_parent_class)->manage (display); |
---|
94 | |
---|
95 | return TRUE; |
---|
96 | } |
---|
97 | |
---|
98 | static gboolean |
---|
99 | gdm_product_display_finish (GdmDisplay *display) |
---|
100 | { |
---|
101 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
102 | |
---|
103 | GDM_DISPLAY_CLASS (gdm_product_display_parent_class)->finish (display); |
---|
104 | |
---|
105 | /* when a product display is done it is done */ |
---|
106 | gdm_display_unmanage (display); |
---|
107 | |
---|
108 | return TRUE; |
---|
109 | } |
---|
110 | |
---|
111 | static gboolean |
---|
112 | gdm_product_display_unmanage (GdmDisplay *display) |
---|
113 | { |
---|
114 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
115 | |
---|
116 | GDM_DISPLAY_CLASS (gdm_product_display_parent_class)->unmanage (display); |
---|
117 | |
---|
118 | return TRUE; |
---|
119 | } |
---|
120 | |
---|
121 | gboolean |
---|
122 | gdm_product_display_get_relay_address (GdmProductDisplay *display, |
---|
123 | char **address, |
---|
124 | GError **error) |
---|
125 | { |
---|
126 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
127 | |
---|
128 | if (address != NULL) { |
---|
129 | *address = g_strdup (display->priv->relay_address); |
---|
130 | g_debug ("GdmProductDisplay: Returning address: %s", display->priv->relay_address); |
---|
131 | } |
---|
132 | |
---|
133 | return TRUE; |
---|
134 | } |
---|
135 | |
---|
136 | static void |
---|
137 | gdm_product_display_set_relay_address (GdmProductDisplay *display, |
---|
138 | const char *address) |
---|
139 | { |
---|
140 | g_free (display->priv->relay_address); |
---|
141 | display->priv->relay_address = g_strdup (address); |
---|
142 | } |
---|
143 | |
---|
144 | |
---|
145 | static void |
---|
146 | gdm_product_display_set_property (GObject *object, |
---|
147 | guint prop_id, |
---|
148 | const GValue *value, |
---|
149 | GParamSpec *pspec) |
---|
150 | { |
---|
151 | GdmProductDisplay *self; |
---|
152 | |
---|
153 | self = GDM_PRODUCT_DISPLAY (object); |
---|
154 | |
---|
155 | switch (prop_id) { |
---|
156 | case PROP_RELAY_ADDRESS: |
---|
157 | gdm_product_display_set_relay_address (self, g_value_get_string (value)); |
---|
158 | break; |
---|
159 | default: |
---|
160 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
161 | break; |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | static void |
---|
166 | gdm_product_display_get_property (GObject *object, |
---|
167 | guint prop_id, |
---|
168 | GValue *value, |
---|
169 | GParamSpec *pspec) |
---|
170 | { |
---|
171 | GdmProductDisplay *self; |
---|
172 | |
---|
173 | self = GDM_PRODUCT_DISPLAY (object); |
---|
174 | |
---|
175 | switch (prop_id) { |
---|
176 | case PROP_RELAY_ADDRESS: |
---|
177 | g_value_set_string (value, self->priv->relay_address); |
---|
178 | default: |
---|
179 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
180 | break; |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | static GObject * |
---|
185 | gdm_product_display_constructor (GType type, |
---|
186 | guint n_construct_properties, |
---|
187 | GObjectConstructParam *construct_properties) |
---|
188 | { |
---|
189 | GdmProductDisplay *display; |
---|
190 | |
---|
191 | display = GDM_PRODUCT_DISPLAY (G_OBJECT_CLASS (gdm_product_display_parent_class)->constructor (type, |
---|
192 | n_construct_properties, |
---|
193 | construct_properties)); |
---|
194 | return G_OBJECT (display); |
---|
195 | } |
---|
196 | |
---|
197 | static void |
---|
198 | gdm_product_display_class_init (GdmProductDisplayClass *klass) |
---|
199 | { |
---|
200 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
---|
201 | GdmDisplayClass *display_class = GDM_DISPLAY_CLASS (klass); |
---|
202 | |
---|
203 | object_class->get_property = gdm_product_display_get_property; |
---|
204 | object_class->set_property = gdm_product_display_set_property; |
---|
205 | object_class->constructor = gdm_product_display_constructor; |
---|
206 | object_class->finalize = gdm_product_display_finalize; |
---|
207 | |
---|
208 | display_class->create_authority = gdm_product_display_create_authority; |
---|
209 | display_class->add_user_authorization = gdm_product_display_add_user_authorization; |
---|
210 | display_class->remove_user_authorization = gdm_product_display_remove_user_authorization; |
---|
211 | display_class->manage = gdm_product_display_manage; |
---|
212 | display_class->finish = gdm_product_display_finish; |
---|
213 | display_class->unmanage = gdm_product_display_unmanage; |
---|
214 | |
---|
215 | g_type_class_add_private (klass, sizeof (GdmProductDisplayPrivate)); |
---|
216 | |
---|
217 | g_object_class_install_property (object_class, |
---|
218 | PROP_RELAY_ADDRESS, |
---|
219 | g_param_spec_string ("relay-address", |
---|
220 | "relay address", |
---|
221 | "relay address", |
---|
222 | NULL, |
---|
223 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); |
---|
224 | |
---|
225 | dbus_g_object_type_install_info (GDM_TYPE_PRODUCT_DISPLAY, &dbus_glib_gdm_product_display_object_info); |
---|
226 | } |
---|
227 | |
---|
228 | static void |
---|
229 | gdm_product_display_init (GdmProductDisplay *product_display) |
---|
230 | { |
---|
231 | |
---|
232 | product_display->priv = GDM_PRODUCT_DISPLAY_GET_PRIVATE (product_display); |
---|
233 | } |
---|
234 | |
---|
235 | static void |
---|
236 | gdm_product_display_finalize (GObject *object) |
---|
237 | { |
---|
238 | GdmProductDisplay *product_display; |
---|
239 | |
---|
240 | g_return_if_fail (object != NULL); |
---|
241 | g_return_if_fail (GDM_IS_PRODUCT_DISPLAY (object)); |
---|
242 | |
---|
243 | product_display = GDM_PRODUCT_DISPLAY (object); |
---|
244 | |
---|
245 | g_return_if_fail (product_display->priv != NULL); |
---|
246 | |
---|
247 | G_OBJECT_CLASS (gdm_product_display_parent_class)->finalize (object); |
---|
248 | } |
---|
249 | |
---|
250 | GdmDisplay * |
---|
251 | gdm_product_display_new (int display_number, |
---|
252 | const char *relay_address) |
---|
253 | { |
---|
254 | GObject *object; |
---|
255 | char *x11_display; |
---|
256 | |
---|
257 | x11_display = g_strdup_printf (":%d", display_number); |
---|
258 | object = g_object_new (GDM_TYPE_PRODUCT_DISPLAY, |
---|
259 | "slave-command", DEFAULT_SLAVE_COMMAND, |
---|
260 | "x11-display-number", display_number, |
---|
261 | "x11-display-name", x11_display, |
---|
262 | "relay-address", relay_address, |
---|
263 | NULL); |
---|
264 | g_free (x11_display); |
---|
265 | |
---|
266 | return GDM_DISPLAY (object); |
---|
267 | } |
---|