[at-spi2-core] Move atspi_get_a11y_bus back into libatspi and publicly export



commit 7a1f33497791b9dc04ee5d181fbe353a9064d8d7
Author: Mike Gorse <mgorse novell com>
Date:   Sun Mar 20 19:15:47 2011 -0700

    Move atspi_get_a11y_bus back into libatspi and publicly export

 atspi/Makefile.am                 |    1 -
 atspi/atspi-misc.c                |  111 +++++++++++++++++++++++-
 atspi/atspi-misc.h                |    2 +
 registryd/Makefile.am             |   11 +--
 registryd/libregistry-internals.c |  176 -------------------------------------
 registryd/libregistry-internals.h |   35 -------
 registryd/registry-main.c         |    4 +-
 7 files changed, 114 insertions(+), 226 deletions(-)
---
diff --git a/atspi/Makefile.am b/atspi/Makefile.am
index 1a50538..c4b267a 100644
--- a/atspi/Makefile.am
+++ b/atspi/Makefile.am
@@ -9,7 +9,6 @@ libatspi_la_CFLAGS = $(DBUS_GLIB_CFLAGS) \
 
 libatspi_la_LIBADD = $(DBUS_GLIB_LIBS) \
 	$(X_LIBS) \
-	$(top_builddir)/registryd/libregistry-internals.la \
 	$(top_builddir)/dbind/libdbind.la
 
 libatspiincludedir = $(includedir)/at-spi-2.0/atspi
diff --git a/atspi/atspi-misc.c b/atspi/atspi-misc.c
index a635272..248f0d9 100644
--- a/atspi/atspi-misc.c
+++ b/atspi/atspi-misc.c
@@ -29,7 +29,6 @@
  */
 
 #include "atspi-private.h"
-#include "libregistry-internals.h"
 #include "X11/Xlib.h"
 #include "dbus/dbus-glib.h"
 #include <stdio.h>
@@ -831,7 +830,7 @@ atspi_init (void)
   get_live_refs();
 
   dbus_error_init (&error);
-  bus = _libregistry_get_a11y_bus ();
+  bus = atspi_get_a11y_bus ();
   if (!bus)
     return 2;
   dbus_bus_register (bus, &error);
@@ -1251,3 +1250,111 @@ atspi_error_quark (void)
   return g_quark_from_static_string ("atspi_error");
 }
 
+/*
+ * Gets the IOR from the XDisplay.
+ */
+static char *
+get_accessibility_bus_address_x11 (void)
+{
+  Atom AT_SPI_BUS;
+  Atom actual_type;
+  Display *bridge_display;
+  int actual_format;
+  unsigned char *data = NULL;
+  unsigned long nitems;
+  unsigned long leftover;
+
+  bridge_display = XOpenDisplay (spi_display_name ());
+  if (!bridge_display)
+    {
+      g_warning ("Could not open X display");
+      return NULL;
+    }
+      
+  AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False);
+  XGetWindowProperty (bridge_display,
+		      XDefaultRootWindow (bridge_display),
+		      AT_SPI_BUS, 0L,
+		      (long) BUFSIZ, False,
+		      (Atom) 31, &actual_type, &actual_format,
+		      &nitems, &leftover, &data);
+  XCloseDisplay (bridge_display);
+
+  return g_strdup (data);
+}
+
+static char *
+get_accessibility_bus_address_dbus (void)
+{
+  DBusConnection *session_bus = NULL;
+  DBusMessage *message;
+  DBusMessage *reply;
+  char *address = NULL;
+
+  session_bus = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+  if (!session_bus)
+    return NULL;
+
+  message = dbus_message_new_method_call ("org.a11y.Bus",
+					  "/org/a11y/bus",
+					  "org.a11y.Bus",
+					  "GetAddress");
+
+  reply = dbus_connection_send_with_reply_and_block (session_bus,
+						     message,
+						     -1,
+						     NULL);
+  dbus_message_unref (message);
+
+  if (!reply)
+    return NULL;
+  
+  {
+    const char *tmp_address;
+    if (!dbus_message_get_args (reply,
+				NULL,
+				DBUS_TYPE_STRING,
+				&tmp_address,
+				DBUS_TYPE_INVALID))
+      {
+	dbus_message_unref (reply);
+	return NULL;
+      }
+    address = g_strdup (tmp_address);
+    dbus_message_unref (reply);
+  }
+  
+  return address;
+}
+
+DBusConnection *
+atspi_get_a11y_bus (void)
+{
+  DBusConnection *bus = NULL;
+  DBusError error;
+  char *address;
+
+  address = get_accessibility_bus_address_x11 ();
+  if (!address)
+    address = get_accessibility_bus_address_dbus ();
+  if (!address)
+    return NULL;
+
+  dbus_error_init (&error);
+  bus = dbus_connection_open (address, &error);
+  if (!bus)
+    {
+      g_warning ("Couldn't connect to accessibility bus: %s", error.message);
+      return NULL;
+    }
+  else
+    {
+      if (!dbus_bus_register (bus, &error))
+	{
+	  g_warning ("Couldn't register with accessibility bus: %s", error.message);
+	  return NULL;
+	}
+    }
+  
+  return bus;
+}
diff --git a/atspi/atspi-misc.h b/atspi/atspi-misc.h
index a9c160e..0d84ad6 100644
--- a/atspi/atspi-misc.h
+++ b/atspi/atspi-misc.h
@@ -34,4 +34,6 @@ void atspi_event_quit ();
 
 int atspi_exit ();
 
+DBusConnection *
+atspi_get_a11y_bus ();
 #endif	/* _ATSPI_MISC_H_ */
diff --git a/registryd/Makefile.am b/registryd/Makefile.am
index 0adbd9b..b36fc18 100644
--- a/registryd/Makefile.am
+++ b/registryd/Makefile.am
@@ -1,5 +1,4 @@
 libexec_PROGRAMS = at-spi2-registryd
-noinst_LTLIBRARIES = libregistry-internals.la
 
 at_spi2_registryd_CFLAGS =	\
 	$(GLIB_CFLAGS)		\
@@ -10,16 +9,8 @@ at_spi2_registryd_CFLAGS =	\
 	-I$(top_srcdir)		\
 	-DATSPI_INTROSPECTION_PATH=\"$(pkgdatadir)/$(DEFAULT_ATSPI_INTROSPECTION_PATH)\"
 
-libregistry_internals_la_SOURCES = \
-	libregistry-internals.h \
-	libregistry-internals.c
-
-libregistry_internals_la_CFLAGS = $(DBUS_GLIB_CFLAGS)
-libregistry_internals_la_LIBADD = $(DBUS_GLIB_LIBS) $(X_LIBS)
-
-
 at_spi2_registryd_LDADD =	\
-	libregistry-internals.la \
+	../atspi/libatspi.la \
 	$(GLIB_LIBS)		\
 	$(GIO_LIBS)		\
 	$(DBUS_GLIB_LIBS)	\
diff --git a/registryd/registry-main.c b/registryd/registry-main.c
index f08a6b9..1c86485 100644
--- a/registryd/registry-main.c
+++ b/registryd/registry-main.c
@@ -35,7 +35,7 @@
 #include "paths.h"
 #include "registry.h"
 #include "deviceeventcontroller.h"
-#include "libregistry-internals.h"
+#include "atspi/atspi-misc.h"
 
 #define CORBA_GCONF_KEY  "/desktop/gnome/interface/at-spi-corba"
 
@@ -221,7 +221,7 @@ main (int argc, char **argv)
       dbus_name = SPI_DBUS_NAME_REGISTRY;
 
   dbus_error_init (&error);
-  bus = _libregistry_get_a11y_bus ();
+  bus = atspi_get_a11y_bus ();
   if (!bus)
   {
     return 0;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]