首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用gdbus-codegen用org.gtk.GDBus.C.ForceGVariant标注xml文件

如何使用gdbus-codegen用org.gtk.GDBus.C.ForceGVariant标注xml文件
EN

Stack Overflow用户
提问于 2019-04-27 05:49:03
回答 1查看 411关注 0票数 1

我正在尝试注释一个xml文件,以便dbus-codegen生成一个使用GVariant *而不是像gchar这样的本机类型的方法。

下面是我正在使用的xml代码。

代码语言:javascript
复制
<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文件以包含注释

代码语言:javascript
复制
<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>

然后执行以下操作:

代码语言:javascript
复制
gdbus-codegen --interface-prefix org.bluez --c-generate-object-manager --generate-c-code generated-code org.bluez.xml

这并没有产生我想要的结果。

2)在gdbus-codegen上使用--annotate开关:

代码语言:javascript
复制
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)“:

代码语言:javascript
复制
    <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true">
    <arg name="value" type="a(y)" direction="in"/>
    </annotation>'

然而,这会导致其他问题。

那么,如何使用以下声明获取WriteValue方法:

代码语言:javascript
复制
    gboolean gatt_characteristic1_call_write_value_sync
    (GattCharacteristic1 *proxy,
    GVariant *arg_value,
    GCancellable *cancellable,
    GError **error)

而不是:

代码语言:javascript
复制
    gboolean gatt_characteristic1_call_write_value_sync (
    GattCharacteristic1 *proxy,
    const gchar *arg_value,
    GCancellable *cancellable,
    GError **error)

能告诉我我哪里做错了吗?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-04-29 02:49:58

作为documented in the D-Bus specification’s section on the introspection data format,您需要使用<annotation>作为自关闭元素,而不是将<arg>元素包围起来。

所以你想要:

代码语言:javascript
复制
<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的示例。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55875308

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档