Support GDBus in UI server as well as dbus-glib
authorSam Thursfield <samthursfield@codethink.co.uk>
Tue, 29 Nov 2011 12:39:36 +0000 (12:39 +0000)
committerSam Thursfield <samthursfield@codethink.co.uk>
Tue, 29 Nov 2011 12:40:59 +0000 (12:40 +0000)
Vala 0.13 and newer have dropped support for dbus-glib. We continue supporting this so that
moonshot-ui can build on Debian Squeeze but we now use GDBus instead of GIO >= 2.26 is
avaiable.

libmoonshot still uses dbus-glib, because this is written in C so there is no reason to
maintain two versions.

Makefile.am
configure.ac
src/moonshot-window.vala

index ead78f4..7b03494 100644 (file)
@@ -133,13 +133,21 @@ dbusservice_DATA = $(dbusservice_in_files:.service.in=.service)
 $(dbusservice_DATA): $(dbusservice_in_files) Makefile
        @sed -e "s|\@bindir\@|$(bindir)|" $< > $@
 
-AM_VALAFLAGS += \
-       --pkg dbus-glib-1 \
-       --define=IPC_DBUS
-
 libmoonshot_libmoonshot_la_SOURCES += libmoonshot/libmoonshot-dbus.c
 
 CLEANFILES = $(dbusservice_DATA)
+
+if IPC_DBUS_GLIB
+AM_VALAFLAGS += \
+       --pkg dbus-glib-1 \
+       --define=IPC_DBUS_GLIB \
+       --define=IPC_DBUS
+else
+AM_VALAFLAGS += \
+       --pkg gio-2.0 \
+       --define=IPC_GDBUS \
+       --define=IPC_DBUS
+endif
 endif
 
 EXTRA_DIST = webprovisioning/moonshot.xml $(dbusservice_in_files) \
index 6ab18d0..ab3e55e 100644 (file)
@@ -16,7 +16,11 @@ AM_MAINTAINER_MODE([enable])
 LT_PREREQ([2.2])
 LT_INIT([win32-dll])
 
+# Checks for programs.
 PKG_PROG_PKG_CONFIG([0.23])
+AC_PROG_CC
+AM_PROG_CC_C_O
+AM_PROG_VALAC([0.9])
 
 # Platform checks
 AC_CANONICAL_HOST
@@ -29,20 +33,44 @@ case "$host" in
     ;;
   *)
     win32=no
-    SERVER_IPC_MODULE="dbus-glib-1"
+
+    # We require dbus-glib for the client library even if we are using GDBus
+    # in the server. The reason we can't always use dbus-glib in the server is
+    # because Vala drops support for it, but as it ships with DBus there is very
+    # little danger of it being dropped by distros any time soon.
     CLIENT_IPC_MODULE="dbus-glib-1"
+    PKG_CHECK_MODULES([GDBUS],
+            [gio-2.0 >= 2.26],
+            [SERVER_IPC_MODULE="gio-2.0"],
+            [SERVER_IPC_MODULE="dbus-glib-1"]
+    )
+
     ;;
 esac
 
 AM_CONDITIONAL([OS_LINUX], [test "$win32" != "yes"])
 AM_CONDITIONAL([OS_WIN32], [test "$win32" = "yes"])
-AM_CONDITIONAL([IPC_MSRPC], [test "$SERVER_IPC_MODULE" = "msrpc-glib2-1.0"])
-AM_CONDITIONAL([IPC_DBUS], [test "$SERVER_IPC_MODULE" = "dbus-glib-1"])
 
-# Checks for programs.
-AC_PROG_CC
-AM_PROG_CC_C_O
-AM_PROG_VALAC([0.9])
+AM_CONDITIONAL([IPC_MSRPC], [test "$SERVER_IPC_MODULE" = "msrpc-glib2-1.0"])
+AM_CONDITIONAL([IPC_DBUS], [test "$SERVER_IPC_MODULE" != "msrpc-glib2-1.0"])
+AM_CONDITIONAL([IPC_DBUS_GLIB], [test "$SERVER_IPC_MODULE" = "dbus-glib-1"])
+AM_CONDITIONAL([IPC_GDBUS], [test "$SERVER_IPC_MODULE" = "gio-2.0"])
+
+if test "$SERVER_IPC_MODULE" = "dbus-glib-1"; then
+  AC_MSG_CHECKING([$VALAC is no greater than 0.12.1])
+  vala_version=`$VALAC --version | sed 's/Vala  *//'`
+  AS_VERSION_COMPARE([0.12.1], ["$vala_version"],
+    [vala_supports_dbus_glib="no"],
+    [vala_supports_dbus_glib="no"],
+    [vala_supports_dbus_glib="yes"])
+
+  AC_MSG_RESULT([$vala_supports_dbus_glib])
+  if test "$vala_supports_dbus_glib" = "no"; then
+    AC_MSG_ERROR([
+*** Vala 0.12.1 or earlier is required for dbus-glib support. Newer versions
+*** require that you have GLib 2.26 or newer (for GDBus support).])
+  fi
+fi
 
 if test "$SERVER_IPC_MODULE" = "msrpc-glib2-1.0"; then
   # MS RPC utilities
index 0b9a5d2..f1be90a 100644 (file)
@@ -949,15 +949,18 @@ SUCH DAMAGE.
         this.destroy.connect (Gtk.main_quit);
     }
 
+#if IPC_MSRPC
     private void init_ipc_server ()
     {
-#if IPC_MSRPC
         /* Errors will currently be sent via g_log - ie. to an
          * obtrusive message box, on Windows
          */
         this.ipc_server = MoonshotServer.get_instance ();
         MoonshotServer.start (this);
-#else
+    }
+#elif IPC_DBUS_GLIB
+    private void init_ipc_server ()
+    {
         try {
             var conn = DBus.Bus.get (DBus.BusType.SESSION);
             dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus",
@@ -970,14 +973,37 @@ SUCH DAMAGE.
 
             this.ipc_server = new MoonshotServer (this);
             conn.register_object ("/org/janet/moonshot", ipc_server);
-
         }
         catch (DBus.Error e)
         {
             stderr.printf ("%s\n", e.message);
         }
-#endif
     }
+#else
+    private void bus_acquired_cb (DBusConnection conn)
+    {
+        try {
+            conn.register_object ("/org/janet/moonshot", ipc_server);
+        }
+        catch (Error e)
+        {
+            stderr.printf ("%s\n", e.message);
+        }
+    }
+
+    private void init_ipc_server ()
+    {
+        this.ipc_server = new MoonshotServer (this);
+        GLib.Bus.own_name (GLib.BusType.SESSION,
+                           "org.janet.Moonshot",
+                           GLib.BusNameOwnerFlags.NONE,
+                           bus_acquired_cb,
+                           (conn, name) => {},
+                           (conn, name) => {
+                               error ("Couldn't own name %s on DBus.", name);
+                           });
+    }
+#endif
 
     public static int main(string[] args)
     {