DBUS返回值

编程入门 行业动态 更新时间:2024-10-28 01:19:35
本文介绍了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返回值

本文发布于:2023-10-26 14:42:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530445.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:返回值   DBUS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!