Methods need always return values?
robert_rawlins at hotmail.com
Tue Apr 15 06:09:36 PDT 2008
> 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.
Ok, that makes fair sense, I thought that was the case, I now understand that concept.
> 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);.
Perfect, this seems like a simple enough implementation, and I use org.freedesktop.DBus.GLib.Async annotation in my current build so that code should drop into place.
> 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
I removed my return lines from a method which I no longer wanted to return a value and couldn't figure out why it broke the application but I'm pretty sure that what you've explain here is the reason. I'll try dropping in the dbus_g_method_return (context) snippet into my method a little later and see what effect it has.
Cheers Simon, I'll keep you posted.
Win 100’s of Virgin Experience days with BigSnapSearch.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the dbus