Prasath
Prasath

Reputation: 49

DBUS Return value

In DBUS, in the XML file if I give the below code why is proxy generating a function with void return type ?

    <method name="getLocalTime">
        <arg type="s" name="timeString" direction="out" />
        <arg type="s" name="dateString" direction="out" />
    </method>


virtual void getMyTime(std::string& time, std::string& date) = 0;

Upvotes: 1

Views: 2612

Answers (1)

K Scott Piel
K Scott Piel

Reputation: 4380

In DBus, output from method calls is passed via the argument list, not the classical C function return mechanism. Furthermore, if the method is not asynchronous, then it is only allowed to return a single true/false Boolean result (which is returned in the classical C function return style). In your introspection, you must annotate this method as asynchronous because it returns multiple string values. Your proxy method call will pass in pointers to two string variables to receive the result in.

If I'm using dbus-glib as the example...

<method name="getLocalTime">
    <arg type="s" name="timeString" direction="out" />
    <arg type="s" name="dateString" direction="out" />
    <annotate name="org.freedesktop.DBus.GLib.Async" />
</method>

Then in my implementation of that method...

void 
dbus_service_get_local_time( 
    MyGObject* self, 
    DBusGMethodInvocation* context 
)
{
    char* timeString;
    char* dateString;

    // do stuff to create your two strings...

    dbus_g_method_return( context, timeString, dateString );

    // clean up allocated memory, etc...
}

and from a caller's perspective, the proxy method call would look something like this...

gboolean 
dbus_supplicant_get_local_time( 
    DBusProxy* proxy, 
    char* OUT_timeString, 
    char* OUT_dateString, 
    GError** error 
);

Note that in the proxy method, the gboolean result is whether or not the D-Bus call could be made, not the result of the method called.

Upvotes: 2

Related Questions