1 /* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3 * at-spi-bus-launcher: Manage the a11y bus as a child process
5 * Copyright 2011 Red Hat, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
35 #include <X11/Xatom.h>
38 //TODO: move to vconf/vconf-internal-setting-keys.h?
39 #define VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_CONFIGURATION_SERVICE "db/setting/accessibility/universal-switch/configuration-service"
40 #define VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE "db/setting/accessibility/universal-switch/interaction-service"
42 #define MAX_NUMBER_OF_KEYS_PER_CLIENT 2
44 #define APP_CONTROL_OPERATION_SCREEN_READ "http://tizen.org/appcontrol/operation/read_screen"
45 #define APP_CONTROL_OPERATION_UNIVERSAL_SWITCH "http://tizen.org/appcontrol/operation/universal_switch"
49 //uncomment if you want debug
50 //#ifndef TIZEN_ENGINEER_MODE
51 //#define TIZEN_ENGINEER_MODE
57 #define LOG_TAG "ATSPI_BUS_LAUNCHER"
62 //uncomment this if you want log suring startup
63 //seems like dlog is not working at startup time
64 #define ATSPI_BUS_LAUNCHER_LOG_TO_FILE
66 #ifdef ATSPI_BUS_LAUNCHER_LOG_TO_FILE
71 #define LOGD(arg...) do {if (log_file) {fprintf(log_file, ##arg);fprintf(log_file, "\n"); fflush(log_file);}} while(0)
74 static gboolean _launch_process_repeat_until_success(gpointer user_data);
77 A11Y_BUS_STATE_IDLE = 0,
78 A11Y_BUS_STATE_READING_ADDRESS,
79 A11Y_BUS_STATE_RUNNING,
85 const char * app_control_operation;
86 const char * vconf_key[MAX_NUMBER_OF_KEYS_PER_CLIENT];
94 gboolean launch_immediately;
95 gboolean a11y_enabled;
96 gboolean screen_reader_enabled;
97 GHashTable *client_watcher_id;
98 GDBusConnection *session_bus;
99 GSettings *a11y_schema;
100 GSettings *interface_schema;
102 A11yBusClient screen_reader;
103 A11yBusClient universal_switch;
105 GDBusProxy *client_proxy;
109 /* -1 == error, 0 == pending, > 0 == running */
111 char *a11y_bus_address;
113 char *a11y_launch_error_message;
116 static A11yBusLauncher *_global_app = NULL;
118 static const gchar introspection_xml[] =
120 " <interface name='org.a11y.Bus'>"
121 " <method name='GetAddress'>"
122 " <arg type='s' name='address' direction='out'/>"
125 "<interface name='org.a11y.Status'>"
126 "<property name='IsEnabled' type='b' access='readwrite'/>"
127 "<property name='ScreenReaderEnabled' type='b' access='readwrite'/>"
130 static GDBusNodeInfo *introspection_data = NULL;
133 respond_to_end_session (GDBusProxy *proxy)
135 GVariant *parameters;
137 parameters = g_variant_new ("(bs)", TRUE, "");
139 g_dbus_proxy_call (proxy,
140 "EndSessionResponse", parameters,
141 G_DBUS_CALL_FLAGS_NONE,
142 -1, NULL, NULL, NULL);
146 g_signal_cb (GDBusProxy *proxy,
149 GVariant *parameters,
152 A11yBusLauncher *app = user_data;
154 if (g_strcmp0 (signal_name, "QueryEndSession") == 0)
155 respond_to_end_session (proxy);
156 else if (g_strcmp0 (signal_name, "EndSession") == 0)
157 respond_to_end_session (proxy);
158 else if (g_strcmp0 (signal_name, "Stop") == 0)
159 g_main_loop_quit (app->loop);
163 client_proxy_ready_cb (GObject *source_object,
167 A11yBusLauncher *app = user_data;
168 GError *error = NULL;
170 app->client_proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
174 g_warning ("Failed to get a client proxy: %s", error->message);
175 g_error_free (error);
180 g_signal_connect (app->client_proxy, "g-signal",
181 G_CALLBACK (g_signal_cb), app);
185 register_client (A11yBusLauncher *app)
187 GDBusProxyFlags flags;
188 GDBusProxy *sm_proxy;
191 const gchar *autostart_id;
192 gchar *client_startup_id;
193 GVariant *parameters;
197 flags = G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
198 G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS;
201 sm_proxy = g_dbus_proxy_new_sync (app->session_bus, flags, NULL,
202 "org.gnome.SessionManager",
203 "/org/gnome/SessionManager",
204 "org.gnome.SessionManager",
209 g_warning ("Failed to get session manager proxy: %s", error->message);
210 g_error_free (error);
215 app_id = "at-spi-bus-launcher";
216 autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
218 if (autostart_id != NULL)
220 client_startup_id = g_strdup (autostart_id);
221 g_unsetenv ("DESKTOP_AUTOSTART_ID");
225 client_startup_id = g_strdup ("");
228 parameters = g_variant_new ("(ss)", app_id, client_startup_id);
229 g_free (client_startup_id);
232 variant = g_dbus_proxy_call_sync (sm_proxy,
233 "RegisterClient", parameters,
234 G_DBUS_CALL_FLAGS_NONE,
237 g_object_unref (sm_proxy);
241 g_warning ("Failed to register client: %s", error->message);
242 g_error_free (error);
247 g_variant_get (variant, "(o)", &object_path);
248 g_variant_unref (variant);
250 flags = G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES;
251 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, flags, NULL,
252 "org.gnome.SessionManager", object_path,
253 "org.gnome.SessionManager.ClientPrivate",
254 NULL, client_proxy_ready_cb, app);
256 g_free (object_path);
260 name_appeared_handler (GDBusConnection *connection,
262 const gchar *name_owner,
265 A11yBusLauncher *app = user_data;
267 register_client (app);
271 setup_bus_child (gpointer data)
273 A11yBusLauncher *app = data;
276 close (app->pipefd[0]);
277 dup2 (app->pipefd[1], 3);
278 close (app->pipefd[1]);
280 /* On Linux, tell the bus process to exit if this process goes away */
282 #include <sys/prctl.h>
283 prctl (PR_SET_PDEATHSIG, 15);
288 * unix_read_all_fd_to_string:
290 * Read all data from a file descriptor to a C string buffer.
293 unix_read_all_fd_to_string (int fd,
299 while (max_bytes > 1 && (bytes_read = read (fd, buf, MAX (4096, max_bytes - 1))))
304 max_bytes -= bytes_read;
311 on_bus_exited (GPid pid,
315 A11yBusLauncher *app = data;
317 app->a11y_bus_pid = -1;
318 app->state = A11Y_BUS_STATE_ERROR;
319 if (app->a11y_launch_error_message == NULL)
321 if (WIFEXITED (status))
322 app->a11y_launch_error_message = g_strdup_printf ("Bus exited with code %d", WEXITSTATUS (status));
323 else if (WIFSIGNALED (status))
324 app->a11y_launch_error_message = g_strdup_printf ("Bus killed by signal %d", WTERMSIG (status));
325 else if (WIFSTOPPED (status))
326 app->a11y_launch_error_message = g_strdup_printf ("Bus stopped by signal %d", WSTOPSIG (status));
328 g_main_loop_quit (app->loop);
332 ensure_a11y_bus (A11yBusLauncher *app)
335 char *argv[] = { DBUS_DAEMON, NULL, "--nofork", "--print-address", "3", NULL };
337 GError *error = NULL;
338 const char *config_path = NULL;
340 if (app->a11y_bus_pid != 0)
343 if (g_file_test (SYSCONFDIR"/at-spi2/accessibility.conf", G_FILE_TEST_EXISTS))
344 config_path = "--config-file="SYSCONFDIR"/at-spi2/accessibility.conf";
346 config_path = "--config-file="DATADIR"/defaults/at-spi2/accessibility.conf";
348 argv[1] = (char*)config_path;
350 if (pipe (app->pipefd) < 0)
351 g_error ("Failed to create pipe: %s", strerror (errno));
353 if (!g_spawn_async (NULL,
356 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
362 app->a11y_bus_pid = -1;
363 app->a11y_launch_error_message = g_strdup (error->message);
364 g_clear_error (&error);
368 close (app->pipefd[1]);
371 g_child_watch_add (pid, on_bus_exited, app);
373 app->state = A11Y_BUS_STATE_READING_ADDRESS;
374 app->a11y_bus_pid = pid;
375 LOGD("Launched a11y bus, child is %ld", (long) pid);
376 if (!unix_read_all_fd_to_string (app->pipefd[0], addr_buf, sizeof (addr_buf)))
378 app->a11y_launch_error_message = g_strdup_printf ("Failed to read address: %s", strerror (errno));
379 kill (app->a11y_bus_pid, SIGTERM);
382 close (app->pipefd[0]);
384 app->state = A11Y_BUS_STATE_RUNNING;
386 /* Trim the trailing newline */
387 app->a11y_bus_address = g_strchomp (g_strdup (addr_buf));
388 LOGD("a11y bus address: %s", app->a11y_bus_address);
392 Display *display = XOpenDisplay (NULL);
395 Atom bus_address_atom = XInternAtom (display, "AT_SPI_BUS", False);
396 XChangeProperty (display,
397 XDefaultRootWindow (display),
399 XA_STRING, 8, PropModeReplace,
400 (guchar *) app->a11y_bus_address, strlen (app->a11y_bus_address));
402 XCloseDisplay (display);
410 close (app->pipefd[0]);
411 close (app->pipefd[1]);
412 app->state = A11Y_BUS_STATE_ERROR;
418 handle_method_call (GDBusConnection *connection,
420 const gchar *object_path,
421 const gchar *interface_name,
422 const gchar *method_name,
423 GVariant *parameters,
424 GDBusMethodInvocation *invocation,
427 A11yBusLauncher *app = user_data;
429 if (g_strcmp0 (method_name, "GetAddress") == 0)
431 ensure_a11y_bus (app);
432 if (app->a11y_bus_pid > 0)
433 g_dbus_method_invocation_return_value (invocation,
434 g_variant_new ("(s)", app->a11y_bus_address));
436 g_dbus_method_invocation_return_dbus_error (invocation,
437 "org.a11y.Bus.Error",
438 app->a11y_launch_error_message);
443 handle_get_property (GDBusConnection *connection,
445 const gchar *object_path,
446 const gchar *interface_name,
447 const gchar *property_name,
451 A11yBusLauncher *app = user_data;
453 if (g_strcmp0 (property_name, "IsEnabled") == 0)
454 return g_variant_new ("b", app->a11y_enabled);
455 else if (g_strcmp0 (property_name, "ScreenReaderEnabled") == 0)
456 return g_variant_new ("b", app->screen_reader_enabled);
462 handle_a11y_enabled_change (A11yBusLauncher *app, gboolean enabled,
463 gboolean notify_gsettings)
465 GVariantBuilder builder;
466 GVariantBuilder invalidated_builder;
468 if (enabled == app->a11y_enabled)
471 app->a11y_enabled = enabled;
473 if (notify_gsettings && app->interface_schema)
475 g_settings_set_boolean (app->interface_schema, "toolkit-accessibility",
480 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
481 g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));
482 g_variant_builder_add (&builder, "{sv}", "IsEnabled",
483 g_variant_new_boolean (enabled));
485 g_dbus_connection_emit_signal (app->session_bus, NULL, "/org/a11y/bus",
486 "org.freedesktop.DBus.Properties",
488 g_variant_new ("(sa{sv}as)", "org.a11y.Status",
490 &invalidated_builder),
493 g_variant_builder_clear (&builder);
494 g_variant_builder_clear (&invalidated_builder);
498 handle_screen_reader_enabled_change (A11yBusLauncher *app, gboolean enabled,
499 gboolean notify_gsettings)
501 GVariantBuilder builder;
502 GVariantBuilder invalidated_builder;
504 if (enabled == app->screen_reader_enabled)
507 app->screen_reader_enabled = enabled;
509 if (notify_gsettings && app->a11y_schema)
511 g_settings_set_boolean (app->a11y_schema, "screen-reader-enabled",
516 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
517 g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));
518 g_variant_builder_add (&builder, "{sv}", "ScreenReaderEnabled",
519 g_variant_new_boolean (enabled));
521 g_dbus_connection_emit_signal (app->session_bus, NULL, "/org/a11y/bus",
522 "org.freedesktop.DBus.Properties",
524 g_variant_new ("(sa{sv}as)", "org.a11y.Status",
526 &invalidated_builder),
528 g_variant_builder_clear (&builder);
529 g_variant_builder_clear (&invalidated_builder);
533 is_client_connected(A11yBusLauncher *app)
535 guint watchers = g_hash_table_size(app->client_watcher_id);
536 LOGD("clients connected: %d", watchers);
541 remove_client_watch(A11yBusLauncher *app,
544 LOGD("Remove client watcher for %s", sender);
545 guint watcher_id = GPOINTER_TO_UINT(g_hash_table_lookup(app->client_watcher_id, sender));
547 g_bus_unwatch_name(watcher_id);
549 g_hash_table_remove(app->client_watcher_id, sender);
550 if (!is_client_connected(app))
551 handle_a11y_enabled_change (app, FALSE, TRUE);
555 on_client_name_vanished (GDBusConnection *connection,
559 A11yBusLauncher *app = user_data;
560 remove_client_watch(app, name);
564 add_client_watch(A11yBusLauncher *app,
567 LOGD("Add client watcher for %s", sender);
569 if (g_hash_table_contains(app->client_watcher_id, sender))
571 LOGI("Watcher for %s already registered", sender);
575 guint watcher_id = g_bus_watch_name(G_BUS_TYPE_SESSION,
577 G_BUS_NAME_WATCHER_FLAGS_NONE,
579 on_client_name_vanished,
583 g_hash_table_insert(app->client_watcher_id, g_strdup(sender), GUINT_TO_POINTER(watcher_id));
584 handle_a11y_enabled_change (app, TRUE, TRUE);
588 handle_set_property (GDBusConnection *connection,
590 const gchar *object_path,
591 const gchar *interface_name,
592 const gchar *property_name,
597 A11yBusLauncher *app = user_data;
598 const gchar *type = g_variant_get_type_string (value);
601 if (g_strcmp0 (type, "b") != 0)
603 g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
604 "org.a11y.Status.%s expects a boolean but got %s", property_name, type);
608 enabled = g_variant_get_boolean (value);
610 if (g_strcmp0 (property_name, "IsEnabled") == 0)
613 add_client_watch(app, sender);
615 remove_client_watch(app, sender);
618 else if (g_strcmp0 (property_name, "ScreenReaderEnabled") == 0)
620 handle_screen_reader_enabled_change (app, enabled, TRUE);
625 g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
626 "Unknown property '%s'", property_name);
631 static const GDBusInterfaceVTable bus_vtable =
634 NULL, /* handle_get_property, */
635 NULL /* handle_set_property */
638 static const GDBusInterfaceVTable status_vtable =
640 NULL, /* handle_method_call */
646 on_bus_acquired (GDBusConnection *connection,
650 A11yBusLauncher *app = user_data;
652 guint registration_id;
654 if (connection == NULL)
656 g_main_loop_quit (app->loop);
659 app->session_bus = connection;
661 if (app->launch_immediately)
663 ensure_a11y_bus (app);
664 if (app->state == A11Y_BUS_STATE_ERROR)
666 g_main_loop_quit (app->loop);
672 registration_id = g_dbus_connection_register_object (connection,
674 introspection_data->interfaces[0],
679 if (registration_id == 0)
681 g_error ("%s", error->message);
682 g_clear_error (&error);
685 g_dbus_connection_register_object (connection,
687 introspection_data->interfaces[1],
695 on_name_lost (GDBusConnection *connection,
699 A11yBusLauncher *app = user_data;
700 if (app->session_bus == NULL
701 && connection == NULL
702 && app->a11y_launch_error_message == NULL)
703 app->a11y_launch_error_message = g_strdup ("Failed to connect to session bus");
704 g_main_loop_quit (app->loop);
708 on_name_acquired (GDBusConnection *connection,
712 g_bus_watch_name (G_BUS_TYPE_SESSION,
713 "org.gnome.SessionManager",
714 G_BUS_NAME_WATCHER_FLAGS_NONE,
715 name_appeared_handler, NULL,
719 static int sigterm_pipefd[2];
722 sigterm_handler (int signum)
724 write (sigterm_pipefd[1], "X", 1);
728 on_sigterm_pipe (GIOChannel *channel,
729 GIOCondition condition,
732 A11yBusLauncher *app = data;
734 g_main_loop_quit (app->loop);
740 init_sigterm_handling (A11yBusLauncher *app)
742 GIOChannel *sigterm_channel;
744 if (pipe (sigterm_pipefd) < 0)
745 g_error ("Failed to create pipe: %s", strerror (errno));
746 signal (SIGTERM, sigterm_handler);
748 sigterm_channel = g_io_channel_unix_new (sigterm_pipefd[0]);
749 g_io_add_watch (sigterm_channel,
750 G_IO_IN | G_IO_ERR | G_IO_HUP,
761 Display *bridge_display;
763 unsigned char *data = NULL;
764 unsigned long nitems;
765 unsigned long leftover;
766 gboolean result = FALSE;
768 bridge_display = XOpenDisplay (NULL);
772 AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False);
773 XGetWindowProperty (bridge_display,
774 XDefaultRootWindow (bridge_display),
776 (long) BUFSIZ, False,
777 (Atom) 31, &actual_type, &actual_format,
778 &nitems, &leftover, &data);
782 GDBusConnection *bus;
783 bus = g_dbus_connection_new_for_address_sync ((const gchar *)data, 0,
788 g_object_unref (bus);
792 XCloseDisplay (bridge_display);
800 get_schema (const gchar *name)
802 const char * const *schemas = NULL;
805 schemas = g_settings_list_schemas ();
806 for (i = 0; schemas[i]; i++)
808 if (!strcmp (schemas[i], name))
809 return g_settings_new (schemas[i]);
816 gsettings_key_changed (GSettings *gsettings, const gchar *key, void *user_data)
818 gboolean new_val = g_settings_get_boolean (gsettings, key);
820 if (!strcmp (key, "toolkit-accessibility"))
821 handle_a11y_enabled_change (_global_app, new_val, FALSE);
822 else if (!strcmp (key, "screen-reader-enabled"))
823 handle_screen_reader_enabled_change (_global_app, new_val, FALSE);
827 _process_dead_tracker (int pid, void *data)
829 A11yBusLauncher *app = data;
831 if (app->screen_reader.pid > 0 && pid == app->screen_reader.pid)
833 LOGE("screen reader is dead, pid: %d, restarting", pid);
834 app->screen_reader.pid = 0;
835 g_timeout_add_seconds (2, _launch_process_repeat_until_success, &app->screen_reader);
838 if (app->universal_switch.pid > 0 && pid == app->universal_switch.pid)
840 LOGE("universal switch is dead, pid: %d, restarting", pid);
841 app->universal_switch.pid = 0;
842 g_timeout_add_seconds (2, _launch_process_repeat_until_success, &app->universal_switch);
848 _register_process_dead_tracker ()
850 if(_global_app->screen_reader.pid > 0 || _global_app->universal_switch.pid > 0) {
851 LOGD("registering process dead tracker");
852 aul_listen_app_dead_signal(_process_dead_tracker, _global_app);
854 LOGD("unregistering process dead tracker");
855 aul_listen_app_dead_signal(NULL, NULL);
861 _launch_client(A11yBusClient *client, gboolean by_vconf_change)
863 LOGD("Launching %s", client->name);
866 gboolean ret = FALSE;
868 kb = bundle_create();
872 LOGD("Can't create bundle");
878 if (bundle_add_str(kb, "by_vconf_change", "yes") != BUNDLE_ERROR_NONE)
880 LOGD("Can't add information to bundle");
884 int operation_error = appsvc_set_operation(kb, client->app_control_operation);
885 LOGD("appsvc_set_operation: %i", operation_error);
887 client->pid = appsvc_run_service(kb, 0, NULL, NULL);
891 LOGD("Process launched with pid: %i", client->pid);
892 _register_process_dead_tracker();
897 LOGD("Can't start %s - error code: %i", client->name, client->pid);
905 _launch_process_repeat_until_success(gpointer user_data) {
906 A11yBusClient *client = user_data;
908 if (client->launch_repeats > 100 || client->pid > 0)
914 gboolean ret = _launch_client(client, FALSE);
919 client->launch_repeats = 0;
922 client->launch_repeats++;
928 _terminate_process(int pid)
935 int status = aul_app_get_status_bypid(pid);
939 LOGD("App with pid %d already terminated", pid);
943 LOGD("terminate process with pid %d", pid);
944 ret_aul = aul_terminate_pid(pid);
947 LOGD("Terminating with aul_terminate_pid: return is %d", ret_aul);
951 LOGD("aul_terminate_pid failed: return is %d", ret_aul);
953 LOGD("Unable to terminate process using aul api. Sending SIGTERM signal");
954 ret = kill(pid, SIGTERM);
960 LOGD("Unable to terminate process: %d with api or signal.", pid);
965 _terminate_client(A11yBusClient *client)
967 LOGD("Terminating %s", client->name);
968 int pid = client->pid;
970 _register_process_dead_tracker();
971 gboolean ret = _terminate_process(pid);
975 void vconf_client_cb(keynode_t *node, void *user_data)
977 A11yBusClient *client = user_data;
979 gboolean client_needed = FALSE;
981 for (i = 0; i < client->number_of_keys; i++) {
983 int ret =vconf_get_bool(client->vconf_key[i], &status);
986 LOGD("Could not read %s key value.\n", client->vconf_key[i]);
989 LOGD("vconf_keynode_get_bool(node): %i", status);
994 client_needed = TRUE;
999 //check if process really exists (e.g didn't crash)
1000 if (client->pid > 0)
1002 int err = kill(client->pid,0);
1003 //process doesn't exist
1008 LOGD("client_needed: %i, client->pid: %i", client_needed, client->pid);
1009 if (!client_needed && (client->pid > 0))
1010 _terminate_client(client);
1011 else if (client_needed && (client->pid <= 0))
1012 _launch_client(client, TRUE);
1016 static gboolean register_executable(A11yBusClient *client)
1018 gboolean client_needed = FALSE;
1021 for (i = 0; i < client->number_of_keys; i++) {
1022 if (!client->vconf_key[i]) {
1023 LOGE("Vconf_key missing for client: %d \n", i);
1028 int ret = vconf_get_bool(client->vconf_key[i], &status);
1031 LOGD("Could not read %s key value.\n", client->vconf_key[i]);
1034 ret = vconf_notify_key_changed(client->vconf_key[i], vconf_client_cb, client);
1037 LOGD("Could not add information level callback\n");
1041 client_needed = TRUE;
1045 g_timeout_add_seconds(2,_launch_process_repeat_until_success, client);
1053 #ifdef ATSPI_BUS_LAUNCHER_LOG_TO_FILE
1054 log_file = fopen("/tmp/at-spi-bus-launcher.log", "a");
1057 LOGD("Starting atspi bus launcher");
1058 gboolean a11y_set = FALSE;
1059 gboolean screen_reader_set = FALSE;
1062 if (already_running ())
1064 LOGD("atspi bus launcher is already running");
1068 _global_app = g_slice_new0 (A11yBusLauncher);
1069 _global_app->loop = g_main_loop_new (NULL, FALSE);
1070 _global_app->client_watcher_id = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
1072 _global_app->screen_reader.name = "screen-reader";
1073 _global_app->screen_reader.app_control_operation = APP_CONTROL_OPERATION_SCREEN_READ;
1074 _global_app->screen_reader.vconf_key[0] = VCONFKEY_SETAPPL_ACCESSIBILITY_TTS;
1075 _global_app->screen_reader.number_of_keys = 1;
1077 _global_app->universal_switch.name = "universal-switch";
1078 _global_app->universal_switch.app_control_operation = APP_CONTROL_OPERATION_UNIVERSAL_SWITCH;
1079 _global_app->universal_switch.vconf_key[0] = VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_CONFIGURATION_SERVICE;
1080 _global_app->universal_switch.vconf_key[1] = VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE;
1081 _global_app->universal_switch.number_of_keys = 2;
1083 for (i = 1; i < argc; i++)
1085 if (!strcmp (argv[i], "--launch-immediately"))
1086 _global_app->launch_immediately = TRUE;
1087 else if (sscanf (argv[i], "--a11y=%d", &_global_app->a11y_enabled) == 1)
1089 else if (sscanf (argv[i], "--screen-reader=%d",
1090 &_global_app->screen_reader_enabled) == 1)
1091 screen_reader_set = TRUE;
1093 g_error ("usage: %s [--launch-immediately] [--a11y=0|1] [--screen-reader=0|1]", argv[0]);
1096 _global_app->interface_schema = get_schema ("org.gnome.desktop.interface");
1097 _global_app->a11y_schema = get_schema ("org.gnome.desktop.a11y.applications");
1101 _global_app->a11y_enabled = _global_app->interface_schema
1102 ? g_settings_get_boolean (_global_app->interface_schema, "toolkit-accessibility")
1103 : _global_app->launch_immediately;
1106 if (!screen_reader_set)
1108 _global_app->screen_reader_enabled = _global_app->a11y_schema
1109 ? g_settings_get_boolean (_global_app->a11y_schema, "screen-reader-enabled")
1113 if (_global_app->interface_schema)
1114 g_signal_connect (_global_app->interface_schema,
1115 "changed::toolkit-accessibility",
1116 G_CALLBACK (gsettings_key_changed), _global_app);
1118 if (_global_app->a11y_schema)
1119 g_signal_connect (_global_app->a11y_schema,
1120 "changed::screen-reader-enabled",
1121 G_CALLBACK (gsettings_key_changed), _global_app);
1123 init_sigterm_handling (_global_app);
1125 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
1126 g_assert (introspection_data != NULL);
1128 g_bus_own_name (G_BUS_TYPE_SESSION,
1130 G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
1137 register_executable (&_global_app->screen_reader);
1138 register_executable (&_global_app->universal_switch);
1140 g_main_loop_run (_global_app->loop);
1142 if (_global_app->a11y_bus_pid > 0)
1143 kill (_global_app->a11y_bus_pid, SIGTERM);
1145 /* Clear the X property if our bus is gone; in the case where e.g.
1146 * GDM is launching a login on an X server it was using before,
1147 * we don't want early login processes to pick up the stale address.
1151 Display *display = XOpenDisplay (NULL);
1154 Atom bus_address_atom = XInternAtom (display, "AT_SPI_BUS", False);
1155 XDeleteProperty (display,
1156 XDefaultRootWindow (display),
1160 XCloseDisplay (display);
1165 if (_global_app->a11y_launch_error_message)
1167 g_printerr ("Failed to launch bus: %s", _global_app->a11y_launch_error_message);