<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>Hi Simon:<BR>
<BR>> On Tue, 15 Apr 2008 at 12:36:30 +0000, Robert Rawlins wrote:<BR>> > 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?<BR>> <BR>> D-Bus methods (should) always return a success or failure message. The<BR>> success message may contain 0 or more return values; the failure message<BR>> may contain anything, although traditionally it contains a string.<BR>> So, a "void" D-Bus method would be one where the success message<BR>> contains no return values.<BR>> <BR>> In dbus-glib APIs, you often end up with a gboolean and a GError ** - on<BR>> success, the gboolean is TRUE and the GError is undefined, on failure<BR>> the gboolean is FALSE and the GError contains the error - plus an<BR>> argument for each argument of the method, and a by-reference (pointer)<BR>> argument for each return value of the method.<BR>> <BR>> For instance, in a "synchronous" service implementation, you always return a<BR>> gboolean indicating success or failure. If the method returns something<BR>> (say, a string), you'll get a gchar ** argument as well, into which you<BR>> must place the returned string on success.<BR><BR>
Ok, that makes fair sense, I thought that was the case, I now understand that concept.<BR>
<BR>> To return nothing from an asynchronous service implementation (one with<BR>> the org.freedesktop.DBus.GLib.Async annotation),<BR>> successfully, you'd call dbus_g_method_return (context); where context<BR>> is the DBusGMethodInvocation you were given. To return a string you'd<BR>> call dbus_g_method_return (context, my_string);.<BR><BR>
Perfect, this seems like a simple enough implementation, and I use org.freedesktop.<FONT face="">DBus.GLib.Async</FONT> annotation in my current build so that code should drop into place.<BR>
<BR>> The org.freedesktop.DBus.GLib.Const and<BR>> org.freedesktop.DBus.GLib.ReturnVal annotations change these rules even<BR>> more confusingly. I'd recommend avoiding them.<BR>> <BR>> Hope this helps,<BR>> Simon<BR>
<BR>
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.<BR>
<BR>
Cheers Simon, I'll keep you posted.<BR>
<BR>
Robert<BR><br /><hr />News, Sports, Entertainment and Weather on your mobile. <a href='http://mobile.uk.msn.com/pc/msn_content.aspx' target='_new'>Text MSN to 63463 Now.</a></body>
</html>