我试图注释一个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)
有人可以告诉我我做错了什么。
谢谢。
作为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的例子。