DBUS返回值 [英] DBUS Return value

查看:259
本文介绍了DBUS返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DBUS 中,在 XML 文件中,如果我给出以下代码,为什么代理生成具有 void 返回类型的函数?

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;


推荐答案

在DBus中,方法调用的输出通过参数列表,而不是经典的C函数返回机制。此外,如果该方法不是异步的,则仅允许它返回单个true / false布尔结果(以传统的C函数返回样式返回)。在自省中,必须将此方法注释为异步方法,因为它返回多个字符串值。您的代理方法调用将传入两个字符串变量的指针以接收结果。

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.

如果我使用dbus-glib作为示例...

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 
);

请注意,在代理方法中,gboolean结果是是否可以调用D-Bus而不是方法调用的结果。

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.

这篇关于DBUS返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆