Merge branch 'p2p'
authorMike Gorse <mgorse@novell.com>
Fri, 3 Dec 2010 20:47:48 +0000 (15:47 -0500)
committerMike Gorse <mgorse@novell.com>
Fri, 3 Dec 2010 20:47:48 +0000 (15:47 -0500)
Conflicts:
atk-adaptor/bridge.c

atk-adaptor/Makefile.include
atk-adaptor/adaptors/Makefile.am
atk-adaptor/adaptors/application-adaptor.c
atk-adaptor/bridge.c
atk-adaptor/bridge.h
atk-adaptor/event.c
atk-adaptor/introspection.c
configure.ac
droute/Makefile.am
droute/droute.c
droute/droute.h

index 3cc3ef3..b5f6bed 100644 (file)
@@ -4,7 +4,7 @@ libatk_bridge_la_CFLAGS = $(DBUS_GLIB_CFLAGS) \
                          $(ATK_CFLAGS)       \
                          -I$(top_srcdir)     \
                          -I$(top_srcdir)/atk-adaptor/adaptors \
-       -DG_DISABLE_DEPRECATED
+       $(P2P_CFLAGS)
 
 libatk_bridge_la_LDFLAGS = -no-undefined  \
                           -module        \
index 460d928..6bba900 100644 (file)
@@ -5,7 +5,7 @@ libatk_bridge_adaptors_la_CFLAGS =\
                          $(ATK_CFLAGS)       \
                          -I$(top_srcdir)     \
                          -I$(top_srcdir)/atk-adaptor \
-       -DG_DISABLE_DEPRECATED
+       $(P2P_CFLAGS)
 
 libatk_bridge_adaptors_la_LIBADD =\
                          $(DBUS_GLIB_LIBS) \
index 71f146b..dd162af 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,30 @@ 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)
+    {
+      const char *retval = (g_getenv ("AT_SPI_CLIENT") ?
+                            "":
+                            spi_global_app_data->app_bus_addr);
+      dbus_message_append_args(reply, DBUS_TYPE_STRING, &retval, 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 35086f4..ce1ea51 100644 (file)
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
+#include<sys/stat.h>
 #include <atk/atk.h>
 
 #include <droute/droute.h>
@@ -175,23 +176,6 @@ set_reply (DBusPendingCall *pending, void *user_data)
     *replyptr = dbus_pending_call_steal_reply (pending);
 }
 
-static DBusMessage *
-send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, DBusError *error)
-{
-    DBusPendingCall *pending;
-    DBusMessage *reply = NULL;
-
-    if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
-    {
-        return NULL;
-    }
-    dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL);
-    while (!reply)
-    {
-      if (!dbus_connection_read_write_dispatch (bus, -1)) return NULL;
-    }
-    return reply;
-}
 /*---------------------------------------------------------------------------*/
 
 static void
@@ -274,7 +258,6 @@ register_reply (DBusPendingCall *pending, void *user_data)
       if (strcmp (dbus_message_get_signature (reply), "(so)") != 0)
         {
           g_warning ("AT-SPI: Could not obtain desktop path or name\n");
-printf("sig: %s\n", dbus_message_get_signature(reply));
         }
       else
         {
@@ -306,6 +289,7 @@ register_application (SpiBridge * app)
   DBusMessageIter iter;
   DBusError error;
   DBusPendingCall *pending;
+  const int max_addr_length = 128; /* should be long enough */
 
   dbus_error_init (&error);
 
@@ -332,6 +316,15 @@ 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/", S_IRWXU);
+app->app_bus_addr = g_malloc(max_addr_length * sizeof(char));
+#ifndef DISABLE_P2P
+sprintf(app->app_bus_addr, "unix:path=/tmp/at-spi2/socket-%d-%d", getpid(),
+rand());
+#endif
+
   return TRUE;
 }
 
@@ -508,6 +501,45 @@ install_plug_hooks ()
   socket_class->embed = socket_embed_hook;
 }
 
+static void
+new_connection_cb (DBusServer *server, DBusConnection *con, void *data)
+{
+  GList *new_list;
+
+  dbus_connection_ref(con);
+  dbus_connection_setup_with_g_main(con, NULL);
+  droute_intercept_dbus (con);
+  droute_context_register (spi_global_app_data->droute, con);
+
+  new_list = g_list_append (spi_global_app_data->direct_connections, con);
+  if (new_list)
+    spi_global_app_data->direct_connections = new_list;
+}
+
+static int
+setup_bus (void)
+{
+#ifndef DISABLE_P2P
+  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);
+
+  spi_global_app_data->server = server;
+#endif
+
+  return 0;
+}
+
+
 gchar *atspi_dbus_name = NULL;
 static gboolean atspi_no_register = FALSE;
 
@@ -622,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.
  *
  */
@@ -688,8 +721,9 @@ adaptor_init (gint * argc, gchar ** argv[])
         }
     }
 
-  dbus_connection_setup_with_g_main (spi_global_app_data->bus,
-                                     g_main_context_default ());
+  spi_global_app_data->main_context = g_main_context_new ();
+
+  dbus_connection_setup_with_g_main (spi_global_app_data->bus, NULL);
 
   /* Hook our plug-and socket functions */
   install_plug_hooks ();
@@ -705,7 +739,7 @@ adaptor_init (gint * argc, gchar ** argv[])
 
   /* Register droute for routing AT-SPI messages */
   spi_global_app_data->droute =
-    droute_new (spi_global_app_data->bus);
+    droute_new ();
 
   treepath = droute_add_one (spi_global_app_data->droute,
                              "/org/a11y/atspi/cache", spi_global_cache);
@@ -743,6 +777,9 @@ adaptor_init (gint * argc, gchar ** argv[])
   spi_initialize_text (accpath);
   spi_initialize_value (accpath);
 
+  droute_context_register (spi_global_app_data->droute,
+                           spi_global_app_data->bus);
+
   /* Register methods to send D-Bus signals on certain ATK events */
   spi_atk_register_event_listeners ();
 
@@ -757,6 +794,8 @@ adaptor_init (gint * argc, gchar ** argv[])
   else
     get_registered_event_listeners (spi_global_app_data);
 
+  setup_bus();
+
   return 0;
 }
 
index 0c8b70d..1a3ebee 100644 (file)
@@ -48,6 +48,9 @@ struct _SpiBridge
 
   DBusConnection *bus;
   DRouteContext  *droute;
+  GMainContext *main_context;
+  DBusServer *server;
+  GList *direct_connections;
 
 /*
   SpiRegister *reg;
@@ -56,6 +59,7 @@ struct _SpiBridge
 */
   gchar *desktop_name;
   gchar *desktop_path;
+char *app_bus_addr;
   GList *events;
   gboolean events_initialized;
 };
index f843f4f..503e454 100644 (file)
@@ -53,11 +53,26 @@ typedef struct _SpiReentrantCallClosure
 } SpiReentrantCallClosure;
 
 static void
+switch_main_context (GMainContext *cnx)
+{
+#ifndef DISABLE_P2P
+/* This code won't work on dbus-glib earlier than 0.9.0 because of FDO#30574 */
+  GList *list;
+
+  dbus_server_setup_with_g_main (spi_global_app_data->server, cnx);
+  dbus_connection_setup_with_g_main (spi_global_app_data->bus, cnx);
+  for (list = spi_global_app_data->direct_connections; list; list = list->next)
+    dbus_connection_setup_with_g_main (list->data, cnx);
+#endif
+}
+
+static void
 set_reply (DBusPendingCall * pending, void *user_data)
 {
   SpiReentrantCallClosure* closure = (SpiReentrantCallClosure *) user_data; 
 
   closure->reply = dbus_pending_call_steal_reply (pending);
+  switch_main_context (NULL);
   g_main_loop_quit (closure->loop);
 }
 
@@ -66,26 +81,20 @@ send_and_allow_reentry (DBusConnection * bus, DBusMessage * message)
 {
   DBusPendingCall *pending;
   SpiReentrantCallClosure closure;
+  GMainContext *main_context;
 
-  if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
-      return NULL;
-  dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
-  closure.loop = g_main_loop_new (NULL, FALSE);
+  main_context = (g_getenv ("AT_SPI_CLIENT") ? NULL :
+                  spi_global_app_data->main_context);
+  closure.loop = g_main_loop_new (main_context, FALSE);
+  switch_main_context (main_context);
 
-  /* TODO: Remove old AT_SPI_CLIENT name */
-  if (getenv ("AT_SPI_CLIENT") || getenv ("AT_SPI_REENTER_G_MAIN_LOOP"))
-    {
-      g_main_loop_run  (closure.loop);
-    }
-  else
+  if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
     {
-      closure.reply = NULL;
-      while (!closure.reply)
-        {
-          if (!dbus_connection_read_write_dispatch (spi_global_app_data->bus, 1000))
-            return NULL;
-        }
+      switch_main_context (NULL);
+      return NULL;
     }
+  dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
+  g_main_loop_run  (closure.loop);
   
   g_main_loop_unref (closure.loop);
   return closure.reply;
index 6a17cf0..22c3115 100644 (file)
@@ -26,10 +26,12 @@ const char *spi_org_a11y_atspi_Accessible =
 "  <method name=\"GetChildAtIndex\">"
 "    <arg direction=\"in\" name=\"index\" type=\"i\" />"
 "    <arg direction=\"out\" type=\"(so)\" />"
+"    "
 "  </method>"
 ""
 "  <method name=\"GetChildren\">"
 "    <arg direction=\"out\" type=\"a(so)\" />"
+"    "
 "  </method>"
 ""
 "  <method name=\"GetIndexInParent\">"
@@ -118,6 +120,10 @@ const char *spi_org_a11y_atspi_Application =
 "    <arg direction=\"out\" type=\"s\" />"
 "  </method>"
 ""
+"  <method name=\"GetApplicationBusAddress\">"
+"    <arg direction=\"out\" type=\"s\" />"
+"  </method>"
+""
 "</interface>"
 "";
 
@@ -321,7 +327,7 @@ const char *spi_org_a11y_atspi_Image =
 const char *spi_org_a11y_atspi_Selection = 
 "<interface name=\"org.a11y.atspi.Selection\" version=\"0.1.7\">"
 ""
-"  <property access=\"read\" name=\"NSelectedChildren\" type=\"i\" />"
+"  <property access=\"read\" name=\"nSelectedChildren\" type=\"i\" />"
 ""
 "  <method name=\"GetSelectedChild\">"
 "    <arg direction=\"in\" name=\"selectedChildIndex\" type=\"i\" />"
@@ -375,9 +381,9 @@ const char *spi_org_a11y_atspi_Table =
 "    "
 "  </property>"
 ""
-"  <property access=\"read\" name=\"NSelectedRows\" type=\"i\" />"
+"  <property access=\"read\" name=\"nSelectedRows\" type=\"i\" />"
 ""
-"  <property access=\"read\" name=\"NSelectedColumns\" type=\"i\" />"
+"  <property access=\"read\" name=\"nSelectedColumns\" type=\"i\" />"
 ""
 "  <method name=\"GetAccessibleAt\">"
 "    <arg direction=\"in\" name=\"row\" type=\"i\" />"
index 88b9864..5f7afb7 100644 (file)
@@ -43,7 +43,10 @@ PKG_CHECK_MODULES(GLIB, [glib-2.0])
 AC_SUBST(GLIB_LIBS)
 AC_SUBST(GLIB_CFLAGS)
 
-PKG_CHECK_MODULES(DBUS_GLIB, [dbus-glib-1 >= 0.7.0])
+PKG_CHECK_MODULES(DBUS_GLIB, dbus-glib-1 >= 0.90, dbus_glib=yes, dbus_glib=no)
+if test "x$dbus_glib" = "xno"; then
+       PKG_CHECK_MODULES(DBUS_GLIB, dbus-glib-1 >= 0.7.0, dbus_glib_old=yes)
+fi
 AC_SUBST(DBUS_GLIB_LIBS)
 AC_SUBST(DBUS_GLIB_CFLAGS)
 
@@ -105,6 +108,12 @@ DBIND_CHECK_ALIGNOF(dbind_pointer)
 DBIND_CHECK_ALIGNOF(dbind_struct)
 CPPFLAGS=$orig_CPPFLAGS 
 
+if test "x$dbus_glib_old" = "xyes"; then
+       P2P_CFLAGS=-DDISABLE_P2P
+       AC_MSG_WARN([found dbus-glib older than 0.9.0; disabling peer-to-peer support])
+fi
+AC_SUBST(P2P_CFLAGS)
+
 AC_CONFIG_FILES([Makefile
                 dbind/dbind-config.h
                 dbind/Makefile
index c8b34b8..94cefaf 100644 (file)
@@ -2,8 +2,7 @@ noinst_LTLIBRARIES = libdroute.la
 
 libdroute_la_CFLAGS = $(DBUS_GLIB_CFLAGS) \
                       -I$(top_builddir)\
-                      -I$(top_srcdir) \
-                      -DG_DISABLE_DEPRECATED
+                      -I$(top_srcdir)
 
 libdroute_la_SOURCES =\
                droute.c\
@@ -20,8 +19,7 @@ check_PROGRAMS = droute-test
 droute_test_SOURCES  = droute-test.c
 droute_test_CFLAGS = $(DBUS_GLIB_CFLAGS) \
                     -I$(top_builddir)\
-                    -I$(top_srcdir) \
-       -DG_DISABLE_DEPRECATED
+                    -I$(top_srcdir)
 
 droute_test_LDFLAGS  = $(top_builddir)/dbind/libdbind.la\
                       libdroute.la\
index a6fe157..321144e 100644 (file)
@@ -39,7 +39,6 @@
 
 struct _DRouteContext
 {
-    DBusConnection       *bus;
     GPtrArray            *registered_paths;
 
     gchar                *introspect_string;
@@ -48,6 +47,8 @@ struct _DRouteContext
 struct _DRoutePath
 {
     DRouteContext        *cnx;
+    gchar *path;
+    gboolean prefix;
     GStringChunk         *chunks;
     GPtrArray            *interfaces;
     GPtrArray            *introspection;
@@ -80,6 +81,8 @@ droute_object_does_not_exist_error (DBusMessage *message);
 
 static DRoutePath *
 path_new (DRouteContext *cnx,
+          const char *path,
+          gboolean prefix,
           void    *user_data,
           DRouteIntrospectChildrenFunction introspect_children_cb,
           void *introspect_children_data,
@@ -89,6 +92,8 @@ path_new (DRouteContext *cnx,
 
     new_path = g_new0 (DRoutePath, 1);
     new_path->cnx = cnx;
+    new_path->path = g_strdup (path);
+    new_path->prefix = prefix;
     new_path->chunks = g_string_chunk_new (CHUNKS_DEFAULT);
     new_path->interfaces = g_ptr_array_new ();
     new_path->introspection = g_ptr_array_new ();
@@ -114,6 +119,7 @@ path_new (DRouteContext *cnx,
 static void
 path_free (DRoutePath *path, gpointer user_data)
 {
+    g_free (path->path);
     g_string_chunk_free  (path->chunks);
     g_ptr_array_free     (path->interfaces, TRUE);
     g_ptr_array_free     (path->introspection, FALSE);
@@ -133,12 +139,11 @@ path_get_datum (DRoutePath *path, const gchar *pathstr)
 /*---------------------------------------------------------------------------*/
 
 DRouteContext *
-droute_new (DBusConnection *bus)
+droute_new ()
 {
     DRouteContext *cnx;
 
     cnx = g_new0 (DRouteContext, 1);
-    cnx->bus = bus;
     cnx->registered_paths = g_ptr_array_new ();
 
     return cnx;
@@ -153,12 +158,6 @@ droute_free (DRouteContext *cnx)
 
 /*---------------------------------------------------------------------------*/
 
-DBusConnection *
-droute_get_bus (DRouteContext *cnx)
-{
-    return cnx->bus;
-}
-
 /*---------------------------------------------------------------------------*/
 
 static DBusObjectPathVTable droute_vtable =
@@ -176,14 +175,7 @@ droute_add_one (DRouteContext *cnx,
     DRoutePath *new_path;
     gboolean registered;
 
-    new_path = path_new (cnx, (void *)data, NULL, NULL, NULL);
-
-    registered = dbus_connection_register_object_path (cnx->bus, path, &droute_vtable, new_path);
-    if (!registered)
-      {
-        path_free (new_path, NULL);
-        return NULL;
-      }
+    new_path = path_new (cnx, path, FALSE, (void *)data, NULL, NULL, NULL);
 
     g_ptr_array_add (cnx->registered_paths, new_path);
     return new_path;
@@ -199,10 +191,9 @@ droute_add_many (DRouteContext *cnx,
 {
     DRoutePath *new_path;
 
-    new_path = path_new (cnx, (void *) data, introspect_children_cb, introspect_children_data, get_datum);
-
-    if (!dbus_connection_register_fallback (cnx->bus, path, &droute_vtable, new_path))
-        oom();
+    new_path = path_new (cnx, path, TRUE, (void *) data,
+                         introspect_children_cb, introspect_children_data,
+                         get_datum);
 
     g_ptr_array_add (cnx->registered_paths, new_path);
     return new_path;
@@ -378,6 +369,32 @@ impl_prop_GetSet (DBusMessage *message,
 }
 
 static DBusHandlerResult
+handle_dbus (DBusConnection *bus,
+                   DBusMessage    *message,
+                   const gchar    *iface,
+                   const gchar    *member,
+                   const gchar    *pathstr)
+{
+  static int id = 1;
+  char *id_str = (char *) g_malloc(40);
+  DBusMessage *reply;
+
+    if (strcmp (iface, DBUS_INTERFACE_DBUS) != 0 ||
+        strcmp (member, "Hello") != 0)
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+    /* TODO: Fix this hack (we don't handle wrap-around, for instance) */
+    sprintf (id_str, ":1.%d", id++);
+    reply = dbus_message_new_method_return (message);
+    dbus_message_append_args (reply, DBUS_TYPE_STRING, &id_str, DBUS_TYPE_INVALID);
+    dbus_connection_send (bus, reply, NULL);
+  dbus_connection_flush (bus);
+    dbus_message_unref (reply);
+  g_free (id_str);
+    return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult
 handle_properties (DBusConnection *bus,
                    DBusMessage    *message,
                    DRoutePath     *path,
@@ -545,7 +562,9 @@ handle_message (DBusConnection *bus, DBusMessage *message, void *user_data)
         iface  == NULL)
         return result;
 
-    if (!strcmp (iface, "org.freedesktop.DBus.Properties"))
+    if (!strcmp (pathstr, DBUS_PATH_DBUS))
+        result = handle_dbus (bus, message, iface, member, pathstr);
+    else if (!strcmp (iface, "org.freedesktop.DBus.Properties"))
         result = handle_properties (bus, message, path, iface, member, pathstr);
     else if (!strcmp (iface, "org.freedesktop.DBus.Introspectable"))
         result = handle_introspection (bus, message, path, iface, member, pathstr);
@@ -636,4 +655,27 @@ droute_invalid_arguments_error (DBusMessage *message)
     return reply;
 }
 
+void
+droute_path_register (DRoutePath *path, DBusConnection *bus)
+{
+    if (path->prefix)
+      dbus_connection_register_fallback (bus, path->path, &droute_vtable, path);
+    else
+      dbus_connection_register_object_path (bus, path->path,
+                                            &droute_vtable, path);
+}
+
+void
+droute_context_register (DRouteContext *cnx, DBusConnection *bus)
+{
+    g_ptr_array_foreach (cnx->registered_paths, (GFunc) droute_path_register,
+                         bus);
+}
+
+void
+droute_intercept_dbus (DBusConnection *bus)
+{
+    dbus_connection_register_object_path (bus, DBUS_PATH_DBUS,
+                                          &droute_vtable, NULL);
+}
 /*END------------------------------------------------------------------------*/
index 3fdfacb..766340e 100644 (file)
@@ -59,7 +59,7 @@ typedef struct _DRoutePath    DRoutePath;
 /*---------------------------------------------------------------------------*/
 
 DRouteContext *
-droute_new      (DBusConnection *bus);
+droute_new      ();
 
 void
 droute_free     (DRouteContext *cnx);
@@ -93,7 +93,12 @@ droute_invalid_arguments_error (DBusMessage *message);
 DBusMessage *
 droute_out_of_memory_error     (DBusMessage *message);
 
-DBusConnection *
-droute_get_bus (DRouteContext *cnx);
+void
+droute_path_register (DRoutePath *path, DBusConnection *bus);
+
+void
+droute_context_register (DRouteContext *cnx, DBusConnection *bus);
 
+void
+droute_intercept_dbus (DBusConnection *connection);
 #endif /* _DROUTE_H */