Methods need always return values?

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Apr 15 05:55:01 PDT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, 15 Apr 2008 at 12:36:30 +0000, Robert Rawlins wrote:
> After reading through the tutorial documentation found here http://dbus.freedesktop.org/doc/dbus-tutorial.html it seems that when calling a method which is published as a dbus service that method must _always_ return a value. Is that correct? What if the method which is called doesn't return a value? can I return a VOID value to save upsetting dbus?

D-Bus methods (should) always return a success or failure message. The
success message may contain 0 or more return values; the failure message
may contain anything, although traditionally it contains a string.
So, a "void" D-Bus method would be one where the success message
contains no return values.

In dbus-glib APIs, you often end up with a gboolean and a GError ** - on
success, the gboolean is TRUE and the GError is undefined, on failure
the gboolean is FALSE and the GError contains the error - plus an
argument for each argument of the method, and a by-reference (pointer)
argument for each return value of the method.

For instance, in a "synchronous" service implementation, you always return a
gboolean indicating success or failure. If the method returns something
(say, a string), you'll get a gchar ** argument as well, into which you
must place the returned string on success.

To return nothing from an asynchronous service implementation (one with
the org.freedesktop.DBus.GLib.Async annotation),
successfully, you'd call dbus_g_method_return (context); where context
is the DBusGMethodInvocation you were given. To return a string you'd
call dbus_g_method_return (context, my_string);.

The org.freedesktop.DBus.GLib.Const and
org.freedesktop.DBus.GLib.ReturnVal annotations change these rules even
more confusingly. I'd recommend avoiding them.

Hope this helps,
    Simon
-----BEGIN PGP SIGNATURE-----

iD8DBQFIBKWlWSc8zVUw7HYRAufRAKDx6+99KAvpietx/lA+UyO3ySwnegCgpmtD
njrVgnOZWQKHmmxJa7ELhkw=
=36xO
-----END PGP SIGNATURE-----


More information about the dbus mailing list