2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
29 #include <dbus/dbus.h>
30 #include <dbus/dbus-glib.h>
34 #include "deviceeventcontroller.h"
36 #if !defined ATSPI_INTROSPECTION_PATH
37 #error "No introspection XML directory defined"
40 static GMainLoop *mainloop;
41 static gchar *dbus_name = NULL;
43 static DBusGConnection *bus_connection = NULL;
44 static DBusGProxy *sm_proxy = NULL;
45 static char *client_id = NULL;
46 static DBusGProxy *client_proxy = NULL;
48 static GOptionEntry optentries[] =
50 {"dbus-name", 0, 0, G_OPTION_ARG_STRING, &dbus_name, "Well-known name to register with D-Bus", NULL},
54 #define SM_DBUS_NAME "org.gnome.SessionManager"
55 #define SM_DBUS_PATH "/org/gnome/SessionManager"
56 #define SM_DBUS_INTERFACE "org.gnome.SessionManager"
58 #define SM_CLIENT_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate"
60 static void registry_session_init (const char *previous_client_id, const char *exe);
63 session_manager_connect (void)
66 if (bus_connection == NULL) {
70 bus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
71 if (bus_connection == NULL) {
72 g_message ("Failed to connect to the session bus: %s",
79 sm_proxy = dbus_g_proxy_new_for_name (bus_connection,
83 return (sm_proxy != NULL);
87 stop_cb (gpointer data)
89 g_main_loop_quit (mainloop);
93 end_session_response (gboolean is_okay, const gchar *reason)
98 ret = dbus_g_proxy_call (client_proxy, "EndSessionResponse",
100 G_TYPE_BOOLEAN, is_okay,
101 G_TYPE_STRING, reason,
106 g_warning ("Failed to send session response %s", error->message);
107 g_error_free (error);
114 query_end_session_cb (guint flags, gpointer data)
116 end_session_response (TRUE, NULL);
120 end_session_cb (guint flags, gpointer data)
122 end_session_response (TRUE, NULL);
123 g_main_loop_quit (mainloop);
126 register_client (void)
130 const char *startup_id;
133 startup_id = g_getenv ("DESKTOP_AUTOSTART_ID");
134 app_id = "at-spi-registryd.desktop";
137 res = dbus_g_proxy_call (sm_proxy,
140 G_TYPE_STRING, app_id,
141 G_TYPE_STRING, startup_id,
143 DBUS_TYPE_G_OBJECT_PATH, &client_id,
146 g_warning ("Failed to register client: %s", error->message);
147 g_error_free (error);
151 client_proxy = dbus_g_proxy_new_for_name (bus_connection,
154 SM_CLIENT_DBUS_INTERFACE);
156 dbus_g_proxy_add_signal (client_proxy, "Stop", G_TYPE_INVALID);
157 dbus_g_proxy_connect_signal (client_proxy, "Stop",
158 G_CALLBACK (stop_cb), NULL, NULL);
160 dbus_g_proxy_add_signal (client_proxy, "QueryEndSession", G_TYPE_UINT, G_TYPE_INVALID);
161 dbus_g_proxy_connect_signal (client_proxy, "QueryEndSession",
162 G_CALLBACK (query_end_session_cb), NULL, NULL);
164 dbus_g_proxy_add_signal (client_proxy, "EndSession", G_TYPE_UINT, G_TYPE_INVALID);
165 dbus_g_proxy_connect_signal (client_proxy, "EndSession",
166 G_CALLBACK (end_session_cb), NULL, NULL);
168 g_unsetenv ("DESKTOP_AUTOSTART_ID");
174 main (int argc, char **argv)
176 SpiRegistry *registry;
177 SpiDEController *dec;
178 gchar *introspection_directory;
190 /* We depend on GDK as well as XLib for device event processing */
191 gdk_init(&argc, &argv);
193 /*Parse command options*/
194 opt = g_option_context_new(NULL);
195 g_option_context_add_main_entries(opt, optentries, NULL);
197 if (!g_option_context_parse(opt, &argc, &argv, &err))
198 g_error("Option parsing failed: %s\n", err->message);
200 if (dbus_name == NULL)
201 dbus_name = SPI_DBUS_NAME_REGISTRY;
203 dbus_error_init (&error);
204 bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
207 g_warning("Couldn't connect to dbus: %s\n", error.message);
210 mainloop = g_main_loop_new (NULL, FALSE);
211 dbus_connection_setup_with_g_main(bus, g_main_context_default());
213 ret = dbus_bus_request_name(bus, dbus_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &error);
214 if (ret == DBUS_REQUEST_NAME_REPLY_EXISTS)
216 g_error("Could not obtain D-Bus name - %s\n", dbus_name);
220 g_print ("SpiRegistry daemon is running with well-known name - %s\n", dbus_name);
223 /* Get D-Bus introspection directory */
224 introspection_directory = (char *) g_getenv("ATSPI_INTROSPECTION_PATH");
225 if (introspection_directory == NULL)
226 introspection_directory = ATSPI_INTROSPECTION_PATH;
228 registry = spi_registry_new (bus);
229 dec = spi_registry_dec_new (registry, bus);
231 if (!session_manager_connect ())
233 g_warning ("Unable to connect to session manager");
236 if (!register_client ())
238 g_warning ("Unable to register client with session manager");
241 g_main_loop_run (mainloop);