launch universal-switch, if any of associated vconf flags is set
[platform/upstream/at-spi2-core.git] / bus / at-spi-bus-launcher.c
index b6f7f01..ee4735d 100644 (file)
 #include <X11/Xatom.h>
 #endif
 
+//TODO: move to vconf/vconf-internal-setting-keys.h?
+#define VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH "db/setting/accessibility/universal-switch"
+#define VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SCANNING "db/setting/accessibility/universal-switch/scanning"
+
+#define MAX_NUMBER_OF_KEYS_PER_CLIENT 2
+
 #define APP_CONTROL_OPERATION_SCREEN_READ "http://tizen.org/appcontrol/operation/read_screen"
+#define APP_CONTROL_OPERATION_UNIVERSAL_SWITCH "http://tizen.org/appcontrol/operation/universal_switch"
 #include <appsvc.h>
 #include <vconf.h>
 
@@ -64,6 +71,7 @@ FILE *log_file;
 #define LOGD(arg...) do {if (log_file) {fprintf(log_file, ##arg);fprintf(log_file, "\n"); fflush(log_file);}} while(0)
 #endif
 
+static gboolean _launch_process_repeat_until_success(gpointer user_data);
 
 typedef enum {
   A11Y_BUS_STATE_IDLE = 0,
@@ -73,17 +81,28 @@ typedef enum {
 } A11yBusState;
 
 typedef struct {
+  const char * name;
+  const char * app_control_operation;
+  const char * vconf_key[MAX_NUMBER_OF_KEYS_PER_CLIENT];
+  int number_of_keys;
+  int launch_repeats;
+  int pid;
+} A11yBusClient;
+
+typedef struct {
   GMainLoop *loop;
   gboolean launch_immediately;
   gboolean a11y_enabled;
   gboolean screen_reader_enabled;
+  GHashTable *client_watcher_id;
   GDBusConnection *session_bus;
   GSettings *a11y_schema;
   GSettings *interface_schema;
 
-  int launch_screen_reader_repeats;
-  gboolean screen_reader_needed;
-  int pid;
+  A11yBusClient screen_reader;
+  A11yBusClient universal_switch;
+
+  GDBusProxy *client_proxy;
 
   A11yBusState state;
 
@@ -111,6 +130,144 @@ static const gchar introspection_xml[] =
 static GDBusNodeInfo *introspection_data = NULL;
 
 static void
+respond_to_end_session (GDBusProxy *proxy)
+{
+  GVariant *parameters;
+
+  parameters = g_variant_new ("(bs)", TRUE, "");
+
+  g_dbus_proxy_call (proxy,
+                     "EndSessionResponse", parameters,
+                     G_DBUS_CALL_FLAGS_NONE,
+                     -1, NULL, NULL, NULL);
+}
+
+static void
+g_signal_cb (GDBusProxy *proxy,
+             gchar      *sender_name,
+             gchar      *signal_name,
+             GVariant   *parameters,
+             gpointer    user_data)
+{
+  A11yBusLauncher *app = user_data;
+
+  if (g_strcmp0 (signal_name, "QueryEndSession") == 0)
+    respond_to_end_session (proxy);
+  else if (g_strcmp0 (signal_name, "EndSession") == 0)
+    respond_to_end_session (proxy);
+  else if (g_strcmp0 (signal_name, "Stop") == 0)
+    g_main_loop_quit (app->loop);
+}
+
+static void
+client_proxy_ready_cb (GObject      *source_object,
+                       GAsyncResult *res,
+                       gpointer      user_data)
+{
+  A11yBusLauncher *app = user_data;
+  GError *error = NULL;
+
+  app->client_proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
+
+  if (error != NULL)
+    {
+      g_warning ("Failed to get a client proxy: %s", error->message);
+      g_error_free (error);
+
+      return;
+    }
+
+  g_signal_connect (app->client_proxy, "g-signal",
+                    G_CALLBACK (g_signal_cb), app);
+}
+
+static void
+register_client (A11yBusLauncher *app)
+{
+  GDBusProxyFlags flags;
+  GDBusProxy *sm_proxy;
+  GError *error;
+  const gchar *app_id;
+  const gchar *autostart_id;
+  gchar *client_startup_id;
+  GVariant *parameters;
+  GVariant *variant;
+  gchar *object_path;
+
+  flags = G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+          G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS;
+
+  error = NULL;
+  sm_proxy = g_dbus_proxy_new_sync (app->session_bus, flags, NULL,
+                                    "org.gnome.SessionManager",
+                                    "/org/gnome/SessionManager",
+                                    "org.gnome.SessionManager",
+                                    NULL, &error);
+
+  if (error != NULL)
+    {
+      g_warning ("Failed to get session manager proxy: %s", error->message);
+      g_error_free (error);
+
+      return;
+    }
+
+  app_id = "at-spi-bus-launcher";
+  autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
+
+  if (autostart_id != NULL)
+    {
+      client_startup_id = g_strdup (autostart_id);
+      g_unsetenv ("DESKTOP_AUTOSTART_ID");
+    }
+  else
+    {
+      client_startup_id = g_strdup ("");
+    }
+
+  parameters = g_variant_new ("(ss)", app_id, client_startup_id);
+  g_free (client_startup_id);
+
+  error = NULL;
+  variant = g_dbus_proxy_call_sync (sm_proxy,
+                                    "RegisterClient", parameters,
+                                    G_DBUS_CALL_FLAGS_NONE,
+                                    -1, NULL, &error);
+
+  g_object_unref (sm_proxy);
+
+  if (error != NULL)
+    {
+      g_warning ("Failed to register client: %s", error->message);
+      g_error_free (error);
+
+      return;
+    }
+
+  g_variant_get (variant, "(o)", &object_path);
+  g_variant_unref (variant);
+
+  flags = G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES;
+  g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, flags, NULL,
+                            "org.gnome.SessionManager", object_path,
+                            "org.gnome.SessionManager.ClientPrivate",
+                            NULL, client_proxy_ready_cb, app);
+
+  g_free (object_path);
+}
+
+static void
+name_appeared_handler (GDBusConnection *connection,
+                       const gchar     *name,
+                       const gchar     *name_owner,
+                       gpointer         user_data)
+{
+  A11yBusLauncher *app = user_data;
+
+  register_client (app);
+}
+
+static void
 setup_bus_child (gpointer data)
 {
   A11yBusLauncher *app = data;
@@ -124,7 +281,7 @@ setup_bus_child (gpointer data)
 #ifdef __linux
 #include <sys/prctl.h>
   prctl (PR_SET_PDEATHSIG, 15);
-#endif  
+#endif
 }
 
 /**
@@ -156,7 +313,7 @@ on_bus_exited (GPid     pid,
                gpointer data)
 {
   A11yBusLauncher *app = data;
-  
+
   app->a11y_bus_pid = -1;
   app->state = A11Y_BUS_STATE_ERROR;
   if (app->a11y_launch_error_message == NULL)
@@ -169,7 +326,7 @@ on_bus_exited (GPid     pid,
         app->a11y_launch_error_message = g_strdup_printf ("Bus stopped by signal %d", WSTOPSIG (status));
     }
   g_main_loop_quit (app->loop);
-} 
+}
 
 static gboolean
 ensure_a11y_bus (A11yBusLauncher *app)
@@ -178,15 +335,21 @@ ensure_a11y_bus (A11yBusLauncher *app)
   char *argv[] = { DBUS_DAEMON, NULL, "--nofork", "--print-address", "3", NULL };
   char addr_buf[2048];
   GError *error = NULL;
+  const char *config_path = NULL;
 
   if (app->a11y_bus_pid != 0)
     return FALSE;
-  
-  argv[1] = g_strdup_printf ("--config-file=%s/at-spi2/accessibility.conf", SYSCONFDIR);
+
+  if (g_file_test (SYSCONFDIR"/at-spi2/accessibility.conf", G_FILE_TEST_EXISTS))
+      config_path = "--config-file="SYSCONFDIR"/at-spi2/accessibility.conf";
+  else
+      config_path = "--config-file="DATADIR"/defaults/at-spi2/accessibility.conf";
+
+  argv[1] = (char*)config_path;
 
   if (pipe (app->pipefd) < 0)
     g_error ("Failed to create pipe: %s", strerror (errno));
-  
+
   if (!g_spawn_async (NULL,
                       argv,
                       NULL,
@@ -242,7 +405,7 @@ ensure_a11y_bus (A11yBusLauncher *app)
 #endif
 
   return TRUE;
-  
+
  error:
   close (app->pipefd[0]);
   close (app->pipefd[1]);
@@ -326,6 +489,9 @@ handle_a11y_enabled_change (A11yBusLauncher *app, gboolean enabled,
                                                 &builder,
                                                 &invalidated_builder),
                                  NULL);
+
+  g_variant_builder_clear (&builder);
+  g_variant_builder_clear (&invalidated_builder);
 }
 
 static void
@@ -338,11 +504,6 @@ handle_screen_reader_enabled_change (A11yBusLauncher *app, gboolean enabled,
   if (enabled == app->screen_reader_enabled)
     return;
 
-  /* If the screen reader is being enabled, we should enable accessibility
-   * if it isn't enabled already */
-  if (enabled)
-    handle_a11y_enabled_change (app, enabled, notify_gsettings);
-
   app->screen_reader_enabled = enabled;
 
   if (notify_gsettings && app->a11y_schema)
@@ -364,6 +525,63 @@ handle_screen_reader_enabled_change (A11yBusLauncher *app, gboolean enabled,
                                                 &builder,
                                                 &invalidated_builder),
                                  NULL);
+  g_variant_builder_clear (&builder);
+  g_variant_builder_clear (&invalidated_builder);
+}
+
+static gboolean
+is_client_connected(A11yBusLauncher *app)
+{
+  guint watchers = g_hash_table_size(app->client_watcher_id);
+  LOGD("clients connected: %d", watchers);
+  return watchers > 0;
+}
+
+static void
+remove_client_watch(A11yBusLauncher *app,
+                                  const gchar     *sender)
+{
+  LOGD("Remove client watcher for %s", sender);
+  guint watcher_id = GPOINTER_TO_UINT(g_hash_table_lookup(app->client_watcher_id, sender));
+  if (watcher_id)
+    g_bus_unwatch_name(watcher_id);
+
+  g_hash_table_remove(app->client_watcher_id, sender);
+  if (!is_client_connected(app))
+    handle_a11y_enabled_change (app, FALSE, TRUE);
+}
+
+static void
+on_client_name_vanished (GDBusConnection *connection,
+                                       const gchar     *name,
+                                       gpointer         user_data)
+{
+  A11yBusLauncher *app = user_data;
+  remove_client_watch(app, name);
+}
+
+static void
+add_client_watch(A11yBusLauncher *app,
+                               const gchar     *sender)
+{
+  LOGD("Add client watcher for %s", sender);
+
+  if (g_hash_table_contains(app->client_watcher_id, sender))
+    {
+      LOGI("Watcher for %s already registered", sender);
+      return;
+    }
+
+  guint watcher_id = g_bus_watch_name(G_BUS_TYPE_SESSION,
+                     sender,
+                     G_BUS_NAME_WATCHER_FLAGS_NONE,
+                     NULL,
+                     on_client_name_vanished,
+                     app,
+                     NULL);
+
+  g_hash_table_insert(app->client_watcher_id, g_strdup(sender), GUINT_TO_POINTER(watcher_id));
+  handle_a11y_enabled_change (app, TRUE, TRUE);
 }
 
 static gboolean
@@ -379,7 +597,7 @@ handle_set_property  (GDBusConnection       *connection,
   A11yBusLauncher *app = user_data;
   const gchar *type = g_variant_get_type_string (value);
   gboolean enabled;
-  
+
   if (g_strcmp0 (type, "b") != 0)
     {
       g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
@@ -391,7 +609,10 @@ handle_set_property  (GDBusConnection       *connection,
 
   if (g_strcmp0 (property_name, "IsEnabled") == 0)
     {
-      handle_a11y_enabled_change (app, enabled, TRUE);
+      if (enabled)
+        add_client_watch(app, sender);
+      else
+        remove_client_watch(app, sender);
       return TRUE;
     }
   else if (g_strcmp0 (property_name, "ScreenReaderEnabled") == 0)
@@ -429,7 +650,7 @@ on_bus_acquired (GDBusConnection *connection,
   A11yBusLauncher *app = user_data;
   GError *error;
   guint registration_id;
-  
+
   if (connection == NULL)
     {
       g_main_loop_quit (app->loop);
@@ -488,8 +709,11 @@ on_name_acquired (GDBusConnection *connection,
                   const gchar     *name,
                   gpointer         user_data)
 {
-  A11yBusLauncher *app = user_data;
-  (void) app;
+  g_bus_watch_name (G_BUS_TYPE_SESSION,
+                    "org.gnome.SessionManager",
+                    G_BUS_NAME_WATCHER_FLAGS_NONE,
+                    name_appeared_handler, NULL,
+                    user_data, NULL);
 }
 
 static int sigterm_pipefd[2];
@@ -506,7 +730,7 @@ on_sigterm_pipe (GIOChannel  *channel,
                  gpointer     data)
 {
   A11yBusLauncher *app = data;
-  
+
   g_main_loop_quit (app->loop);
 
   return FALSE;
@@ -544,7 +768,7 @@ already_running ()
   bridge_display = XOpenDisplay (NULL);
   if (!bridge_display)
              return FALSE;
-      
+
   AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False);
   XGetWindowProperty (bridge_display,
                      XDefaultRootWindow (bridge_display),
@@ -592,7 +816,6 @@ static void
 gsettings_key_changed (GSettings *gsettings, const gchar *key, void *user_data)
 {
   gboolean new_val = g_settings_get_boolean (gsettings, key);
-  A11yBusLauncher *app = user_data;
 
   if (!strcmp (key, "toolkit-accessibility"))
     handle_a11y_enabled_change (_global_app, new_val, FALSE);
@@ -600,11 +823,44 @@ gsettings_key_changed (GSettings *gsettings, const gchar *key, void *user_data)
     handle_screen_reader_enabled_change (_global_app, new_val, FALSE);
 }
 
+static int
+_process_dead_tracker (int pid, void *data)
+{
+  A11yBusLauncher *app = data;
+
+  if (app->screen_reader.pid > 0 && pid == app->screen_reader.pid)
+    {
+      LOGE("screen reader is dead, pid: %d, restarting", pid);
+      app->screen_reader.pid = 0;
+      g_timeout_add_seconds (2, _launch_process_repeat_until_success, &app->screen_reader);
+    }
+
+  if (app->universal_switch.pid > 0 && pid == app->universal_switch.pid)
+    {
+      LOGE("universal switch is dead, pid: %d, restarting", pid);
+      app->universal_switch.pid = 0;
+      g_timeout_add_seconds (2, _launch_process_repeat_until_success, &app->universal_switch);
+    }
+  return 0;
+}
+
+static void
+_register_process_dead_tracker ()
+{
+       if(_global_app->screen_reader.pid > 0 || _global_app->universal_switch.pid > 0) {
+               LOGD("registering process dead tracker");
+               aul_listen_app_dead_signal(_process_dead_tracker, _global_app);
+       } else {
+               LOGD("unregistering process dead tracker");
+               aul_listen_app_dead_signal(NULL, NULL);
+       }
+}
+
+
 static gboolean
-_launch_screen_reader(gpointer user_data)
+_launch_client(A11yBusClient *client, gboolean by_vconf_change)
 {
-   A11yBusLauncher *bl = user_data;
-   LOGD("Launching screen reader");
+   LOGD("Launching %s", client->name);
 
    bundle *kb = NULL;
    gboolean ret = FALSE;
@@ -616,101 +872,178 @@ _launch_screen_reader(gpointer user_data)
         LOGD("Can't create bundle");
         return FALSE;
      }
-   int operation_error = appsvc_set_operation(kb, APP_CONTROL_OPERATION_SCREEN_READ);
+
+   if (by_vconf_change)
+     {
+        if (bundle_add_str(kb, "by_vconf_change", "yes") != BUNDLE_ERROR_NONE)
+          {
+             LOGD("Can't add information to bundle");
+          }
+     }
+
+   int operation_error = appsvc_set_operation(kb, client->app_control_operation);
    LOGD("appsvc_set_operation: %i", operation_error);
 
-   bl->pid = appsvc_run_service(kb, 0, NULL, NULL);
+   client->pid = appsvc_run_service(kb, 0, NULL, NULL);
 
-   if (bl->pid > 0)
+   if (client->pid > 0)
      {
-        LOGD("Screen reader launched with pid: %i", bl->pid);
+        LOGD("Process launched with pid: %i", client->pid);
+        _register_process_dead_tracker();
         ret = TRUE;
      }
    else
      {
-        LOGD("Can't start screen-reader - error code: %i", bl->pid);
+        LOGD("Can't start %s - error code: %i", client->name, client->pid);
      }
 
-
    bundle_free(kb);
    return ret;
 }
 
 static gboolean
-_launch_screen_reader_repeat_until_success(gpointer user_data) {
-    A11yBusLauncher *bl = user_data;
+_launch_process_repeat_until_success(gpointer user_data) {
+    A11yBusClient *client = user_data;
 
-    if (bl->launch_screen_reader_repeats > 100 || bl->pid > 0)
+    if (client->launch_repeats > 100 || client->pid > 0)
       {
          //do not try anymore
          return FALSE;
       }
 
-    gboolean ret = _launch_screen_reader(user_data);
+    gboolean ret = _launch_client(client, FALSE);
 
     if (ret)
       {
          //we managed to
-         bl->launch_screen_reader_repeats = 0;
+         client->launch_repeats = 0;
          return FALSE;
       }
+    client->launch_repeats++;
     //try again
     return TRUE;
 }
 
 static gboolean
-_terminate_screen_reader(A11yBusLauncher *bl)
+_terminate_process(int pid)
 {
-   LOGD("Terminating screen reader");
    int ret;
-   if (bl->pid <= 0)
+   int ret_aul;
+   if (pid <= 0)
      return FALSE;
 
-
-   int status = aul_app_get_status_bypid(bl->pid);
+   int status = aul_app_get_status_bypid(pid);
 
    if (status < 0)
      {
-       LOGD("App with pid %d already terminated", bl->pid);
-       bl->pid = 0;
+       LOGD("App with pid %d already terminated", pid);
        return TRUE;
      }
 
-   LOGD("terminate process with pid %d", bl->pid);
-   if (!aul_terminate_pid(bl->pid))
+   LOGD("terminate process with pid %d", pid);
+   ret_aul = aul_terminate_pid(pid);
+   if (ret_aul >= 0)
      {
-        bl->pid = 0;
+        LOGD("Terminating with aul_terminate_pid: return is %d", ret_aul);
         return TRUE;
      }
+   else
+     LOGD("aul_terminate_pid failed: return is %d", ret_aul);
 
    LOGD("Unable to terminate process using aul api. Sending SIGTERM signal");
-   ret = kill(bl->pid, SIGTERM);
+   ret = kill(pid, SIGTERM);
    if (!ret)
      {
-        bl->pid = 0;
         return TRUE;
      }
 
-   LOGD("Unable to terminate process: %d with api or signal.", bl->pid);
+   LOGD("Unable to terminate process: %d with api or signal.", pid);
    return FALSE;
 }
 
-void screen_reader_cb(keynode_t *node, void *user_data)
+static gboolean
+_terminate_client(A11yBusClient *client)
 {
-   A11yBusLauncher *bl = user_data;
-   int ret;
+   LOGD("Terminating %s", client->name);
+   int pid = client->pid;
+   client->pid = 0;
+   _register_process_dead_tracker();
+   gboolean ret = _terminate_process(pid);
+   return ret;
+}
+
+void vconf_client_cb(keynode_t *node, void *user_data)
+{
+   A11yBusClient *client = user_data;
+
+   gboolean client_needed = FALSE;
+   int i;
+   for (i = 0; i < client->number_of_keys; i++) {
+      int status = 0;
+      int ret =vconf_get_bool(client->vconf_key[i], &status);
+      if (ret != 0)
+      {
+        LOGD("Could not read %s key value.\n", client->vconf_key[i]);
+        return;
+      }
+      LOGD("vconf_keynode_get_bool(node): %i", status);
+      if (status < 0)
+        return;
+
+      if (status == 1) {
+        client_needed = TRUE;
+        break;
+      }
+   }
+
+   //check if process really exists (e.g didn't crash)
+   if (client->pid > 0)
+     {
+        int err = kill(client->pid,0);
+        //process doesn't exist
+        if (err == ESRCH)
+          client->pid = 0;
+     }
+
+   LOGD("client_needed: %i, client->pid: %i", client_needed, client->pid);
+   if (!client_needed && (client->pid > 0))
+          _terminate_client(client);
+   else if (client_needed && (client->pid <= 0))
+     _launch_client(client, TRUE);
+}
+
+
+static gboolean register_executable(A11yBusClient *client)
+{
+  gboolean client_needed = FALSE;
+
+  int i;
+  for (i = 0; i < client->number_of_keys; i++) {
+    if (!client->vconf_key[i]) {
+      LOGE("Vconf_key missing for client: %d \n", i);
+      return FALSE;
+    }
 
-   ret = vconf_keynode_get_bool(node);
-   LOGD("vconf_keynode_get_bool(node): %i", ret);
-   if (ret < 0)
-     return;
+    int status = 0;
+    int ret = vconf_get_bool(client->vconf_key[i], &status);
+    if (ret != 0)
+    {
+      LOGD("Could not read %s key value.\n", client->vconf_key[i]);
+      return FALSE;
+    }
+    ret = vconf_notify_key_changed(client->vconf_key[i], vconf_client_cb, client);
+    if (ret != 0)
+    {
+      LOGD("Could not add information level callback\n");
+      return FALSE;
+    }
+    if (status)
+      client_needed = TRUE;
+  }
 
-   bl->screen_reader_needed = ret;
-   LOGD("bl->screen_reader_needed: %i, bl->pid: %i", ret, bl->pid);
-   if (!bl->screen_reader_needed && (bl->pid > 0))
-     _terminate_screen_reader(bl);
-   else if (bl->screen_reader_needed && (bl->pid <= 0))
-     _launch_screen_reader(bl);
+  if (client_needed)
+  g_timeout_add_seconds(2,_launch_process_repeat_until_success, client);
+  return TRUE;
 }
 
 int
@@ -722,10 +1055,6 @@ main (int    argc,
 #endif
 
   LOGD("Starting atspi bus launcher");
-  GError *error = NULL;
-  GMainLoop *loop;
-  GDBusConnection *session_bus;
-  int name_owner_id;
   gboolean a11y_set = FALSE;
   gboolean screen_reader_set = FALSE;
   gint i;
@@ -738,16 +1067,27 @@ main (int    argc,
 
   _global_app = g_slice_new0 (A11yBusLauncher);
   _global_app->loop = g_main_loop_new (NULL, FALSE);
-  _global_app->launch_screen_reader_repeats = 0;
+  _global_app->client_watcher_id = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
+  _global_app->screen_reader.name = "screen-reader";
+  _global_app->screen_reader.app_control_operation = APP_CONTROL_OPERATION_SCREEN_READ;
+  _global_app->screen_reader.vconf_key[0] = VCONFKEY_SETAPPL_ACCESSIBILITY_TTS;
+  _global_app->screen_reader.number_of_keys = 1;
+
+  _global_app->universal_switch.name = "universal-switch";
+  _global_app->universal_switch.app_control_operation = APP_CONTROL_OPERATION_UNIVERSAL_SWITCH;
+  _global_app->universal_switch.vconf_key[0] = VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH;
+  _global_app->universal_switch.vconf_key[1] = VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SCANNING;
+  _global_app->universal_switch.number_of_keys = 2;
 
   for (i = 1; i < argc; i++)
     {
       if (!strcmp (argv[i], "--launch-immediately"))
         _global_app->launch_immediately = TRUE;
-      else if (sscanf (argv[i], "--a11y=%d", &_global_app->a11y_enabled) == 2)
+      else if (sscanf (argv[i], "--a11y=%d", &_global_app->a11y_enabled) == 1)
         a11y_set = TRUE;
       else if (sscanf (argv[i], "--screen-reader=%d",
-                       &_global_app->screen_reader_enabled) == 2)
+                       &_global_app->screen_reader_enabled) == 1)
         screen_reader_set = TRUE;
     else
       g_error ("usage: %s [--launch-immediately] [--a11y=0|1] [--screen-reader=0|1]", argv[0]);
@@ -785,7 +1125,7 @@ main (int    argc,
   introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
   g_assert (introspection_data != NULL);
 
-  name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
+  g_bus_own_name (G_BUS_TYPE_SESSION,
                                   "org.a11y.Bus",
                                   G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
                                   on_bus_acquired,
@@ -794,27 +1134,15 @@ main (int    argc,
                                   _global_app,
                                   NULL);
 
-  int ret = vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &_global_app->screen_reader_needed);
-  if (ret != 0)
-    {
-      LOGD("Could not read VCONFKEY_SETAPPL_ACCESSIBILITY_TTS key value.\n");
-      return FALSE;
-    }
-  ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, screen_reader_cb, _global_app);
-  if(ret != 0)
-    {
-      LOGD("Could not add information level callback\n");
-      return FALSE;
-    }
-  if (_global_app->screen_reader_needed)
-    g_timeout_add_seconds(2,_launch_screen_reader_repeat_until_success, _global_app);
+  register_executable (&_global_app->screen_reader);
+  register_executable (&_global_app->universal_switch);
 
   g_main_loop_run (_global_app->loop);
 
   if (_global_app->a11y_bus_pid > 0)
     kill (_global_app->a11y_bus_pid, SIGTERM);
 
-  /* Clear the X property if our bus is gone; in the case where e.g. 
+  /* Clear the X property if our bus is gone; in the case where e.g.
    * GDM is launching a login on an X server it was using before,
    * we don't want early login processes to pick up the stale address.
    */