我正在尝试注释一个xml文件,以便dbus-codegen生成一个使用GVariant *而不是像gchar这样的本机类型的方法。
下面是我正在使用的xml代码。
<node>
<interface name="org.bluez.GattCharacteristic1">
<method name="WriteValue">
<arg name="value" type="ay" direction="in"/>
</method>
</interface>
</node>我已经阅读了下面的stackoverflow帖子:
Sending a byte array (type ay) over D-Bus using GDBus
在读完那篇文章后,我尝试了以下几点:
1)编辑xml文件以包含注释
<node>
<interface name="org.bluez.GattCharacteristic1">
<method name="WriteValue">
<annotation name="org.gtk.GDBus.C.ForceGVariant" value="true">
<arg name="value" type="ay" direction="in"/>
</annotation>
</method>
</interface>
</node>然后执行以下操作:
gdbus-codegen --interface-prefix org.bluez --c-generate-object-manager --generate-c-code generated-code org.bluez.xml这并没有产生我想要的结果。
2)在gdbus-codegen上使用--annotate开关:
gdbus-codegen --annotate "org.bluez.GattCharacteristic1.WriteValue()" org.gtk.GDBus.C.ForceGVariant true --interface-prefix org.bluez --c-generate-object-manager --generate-c-code generated-code org.bluez.xml这并没有产生我想要的结果。
我成功的唯一方法是将以下代码中的"ay“更改为”a(Y)“:
<annotation name="org.gtk.GDBus.C.ForceGVariant" value="true">
<arg name="value" type="a(y)" direction="in"/>
</annotation>'然而,这会导致其他问题。
那么,如何使用以下声明获取WriteValue方法:
gboolean gatt_characteristic1_call_write_value_sync
(GattCharacteristic1 *proxy,
GVariant *arg_value,
GCancellable *cancellable,
GError **error)而不是:
gboolean gatt_characteristic1_call_write_value_sync (
GattCharacteristic1 *proxy,
const gchar *arg_value,
GCancellable *cancellable,
GError **error)能告诉我我哪里做错了吗?
谢谢。
发布于 2019-04-29 02:49:58
作为documented in the D-Bus specification’s section on the introspection data format,您需要使用<annotation>作为自关闭元素,而不是将<arg>元素包围起来。
所以你想要:
<node>
<interface name="org.bluez.GattCharacteristic1">
<method name="WriteValue">
<arg name="value" type="ay" direction="in">
<annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
</arg>
</method>
</interface>
</node>您还可以查看此in the GLib source code的示例。
https://stackoverflow.com/questions/55875308
复制相似问题