Sound Juicer "They Keep Hiding The Truth And Rights" 2.10.1

Sound Juicer "They Keep Hiding The Truth And Rights" 2.10.1 is out as usual, fixing a couple of crashers and adding more translations.

Translations by Adam Weinberger (en_CA), Ahmad Riza H Nst (id), Canonical Ltd (xh), Jyotsna Shrestha (ne), Mugurel Tudor (ro), Raphael Higino (pt_BR), and Steve Murphy (rw).

18:27 Monday, 04 Apr 2005 [#] [computers/sound-juicer] (0 comments)

GObject/DBus Magic

I am Colin Walters's fanboy. That is all.

I suppose I should elaborate on that. I've just build a shiny new DBus release (from CVS, but for all intents and purposes it is 0.32), and had a quick experiment with the new GLib bindings. In the good old days the GLib bindings provided mainloop integration and not much else, but not any more... I started by creating a simple GObject which has an echo method, this is pretty standard stuff but the echo prototype is:

gboolean echo_echo (Echo *echo, const char in_s, char **out_s, GError **error);

It's nice and simple, out_s is set to a reversed copy of in_s. I then wrote an XML file which describes the object. In the future I believe this will be generated by parsing the C code just as gtk-doc does now, but I can handle writing it manually for now:

<?xml version="1.0"?>
<node name="/com/openedhand/DBus/Tests/Echo">
  <interface name="com.openedhand.DBus.Tests.Echo">
    <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="echo"/>
    <method name="Echo">
      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="echo_echo"/>
      <arg type="s" name="string" direction="in"/>
      <arg type="s" name="echo_string" direction="out"/>
    </method>
  </interface>
</node>

This file defines the names of the interfaces, objects, and methods in the DBus world, and also how they map to the real GObject. This file is then used to generate two header files: server-side glue for the GObject to the bus, and client-side wrappers around the bus. Ignoring the boring connecting to the bus and error checking, connecting this GObject to the bus is pretty simple:

#include "EchoObjectGlue.h" /* Defines dbus_glib_echo_object_info */

  ...
  obj = g_object_new (ECHO_TYPE, NULL);
  dbus_g_object_class_install_info (G_OBJECT_GET_CLASS (obj), &dbus_glib_echo_object_info);
  dbus_g_connection_register_g_object (connection,
                                       "/com/openedhand/DBus/Tests/Echo",
                                       obj);
    

No more manual argument parsing on the server, which is excellent. Even more exciting is what happens on the client (without error handling but nothing else removed):

#include <dbus/dbus-glib-bindings.h>
#include "EchoObjectBindings.h"
  ...
  DBusGConnection *connection;
  DBusGProxy *proxy;
  char *s_out = NULL;
  
  connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
  proxy = dbus_g_proxy_new_for_name_owner (connection,
                                           "com.openedhand.DBus.Tests.Echo",
                                           "/com/openedhand/DBus/Tests/Echo",
                                           "com.openedhand.DBus.Tests.Echo",
                                           NULL);
  com_openedhand_DBus_Tests_Echo_echo (proxy, "Hello, World", &s_out, NULL); /* Defined in EchoObjectBindings.h */  
  printf("Got '%s'\n", s_out);

The tedious create message-add arguments-send message-wait for reply is gone, and wrapped up inside auto-generated code and introspection frameworks. I believe this is going to make a massive difference to the rate of DBus adoption in GNOME, as until now the prospect of putting complicated structures and methods on the bus wasn't very appealing. Now it's simple and doesn't result in massive code bloat from duplicated code to manipulate the bus messages.

Update: I've put a tarball of the source online. I've also been informed by Colin that Havoc wrote half of the code, so I'm now fanboying both Havoc and Colin.

NP: Babylon Rewound, Thievery Corporation

14:14 Monday, 04 Apr 2005 [#] [computers] (4 comments)