enable peer to peer comunication for at-spi2
authorTrevor Saunders <trev.saunders@gmail.com>
Sat, 31 Jul 2010 05:08:37 +0000 (01:08 -0400)
committerMike Gorse <mgorse@novell.com>
Tue, 31 Aug 2010 01:10:12 +0000 (21:10 -0400)
Each application will setup a dbus server listening on a unix socket in
/tmp/at-spi2/xxxxxx.  A getApplicationBusAddress method is added to
atk-adaptors/adaptors/application-adaptor.c so that clients of at-spi2
can get the address of the socket on which to contact the application
server.  This method returns a string which is a dbus address so it can
be passed directly to dbus_connection_open.

atk-adaptor/adaptors/application-adaptor.c
atk-adaptor/bridge.c
atk-adaptor/bridge.h

index 71f146b..bc8c431 100644 (file)
@@ -28,6 +28,9 @@
 #include "common/spi-dbus.h"
 #include "introspection.h"
 
+/* for spi_global_app_data  is there a better way? */
+#include "../bridge.h"
+
 static dbus_bool_t
 impl_get_ToolkitName (DBusMessageIter * iter, void *user_data)
 {
@@ -87,12 +90,24 @@ impl_GetLocale (DBusConnection * bus, DBusMessage * message, void *user_data)
   return NULL;
 }
 
+static DBusMessage *
+impl_get_app_bus(DBusConnection *bus, DBusMessage *msg, void *data)
+{
+DBusMessage *reply;
+
+reply = dbus_message_new_method_return(msg);
+if(reply) dbus_message_append_args(reply, DBUS_TYPE_STRING, &(spi_global_app_data->app_bus_addr), DBUS_TYPE_INVALID);
+
+return reply;
+}
+
 static DRouteMethod methods[] = {
   {impl_registerToolkitEventListener, "registerToolkitEventListener"},
   {impl_registerObjectEventListener, "registerObjectEventListener"},
   {impl_pause, "pause"},
   {impl_resume, "resume"},
   {impl_GetLocale, "GetLocale"},
+  {impl_get_app_bus, "getApplicationBusAddress"},
   {NULL, NULL}
 };
 
index f7c3fa8..356b5fc 100644 (file)
@@ -330,6 +330,16 @@ register_application (SpiBridge * app)
   if (message)
     dbus_message_unref (message);
 
+/* could this be better, we accept some amount of race in getting the temp name*/
+/* make sure the directory exists */
+mkdir("/tmp/at-spi2/", 0);
+app->app_bus_addr = mktmp("/tmp/at-spi2/app-socket-xxxxxx");
+    }
+  else
+    {
+      g_warning ("AT-SPI: Could not embed inside desktop: %s\n", error.message);
+      return FALSE;
+    }
   return TRUE;
 }
 
@@ -506,6 +516,30 @@ install_plug_hooks ()
   socket_class->embed = socket_embed_hook;
 }
 
+static void new_connection_cb(DBusServer *server, DBusConnection *con, void *data)
+{
+dbus_connection_ref(con);
+dbus_connection_setup_with_g_main(con, NULL);
+}
+
+static int setup_bus(void)
+{
+DBusServer *server;
+DBusError err;
+
+dbus_error_init(&err);
+       server = dbus_server_listen(spi_global_app_data->app_bus_addr, &err);
+
+/* is there a better way to handle this */
+if(server == NULL) return -1;
+
+dbus_server_setup_with_g_main(server, NULL);
+dbus_server_set_new_connection_function(server, new_connection_cb, NULL, NULL);
+
+return 0;
+}
+
+
 gchar *atspi_dbus_name = NULL;
 static gboolean atspi_no_register = FALSE;
 
@@ -620,6 +654,7 @@ signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
  *
  * - DRoute for routing message to their accessible objects.
  * - Event handlers for emmitting signals on specific ATK events.
+ * - setup the bus for p2p communication
  * - Application registration with the AT-SPI registry.
  *
  */
@@ -755,6 +790,8 @@ adaptor_init (gint * argc, gchar ** argv[])
   else
     get_registered_event_listeners (spi_global_app_data);
 
+  setup_bus();
+
   g_atexit (exit_func);
 
   return 0;
index 05fa56a..7410235 100644 (file)
@@ -56,6 +56,7 @@ struct _SpiBridge
 */
   gchar *desktop_name;
   gchar *desktop_path;
+char *app_bus_addr;
   GList *events;
 };