【问题标题】:How to annotate an xml file with org.gtk.GDBus.C.ForceGVariant using gdbus-codegen如何使用 gdbus-codegen 使用 org.gtk.GDBus.C.ForceGVariant 注释 xml 文件
【发布时间】:2019-09-16 10:07:59
【问题描述】:

我正在尝试注释一个 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)

谁能告诉我我做错了什么。

谢谢。

【问题讨论】:

    标签: c++ dbus bluez


    【解决方案1】:

    作为documented in the D-Bus specification’s section on the introspection data format,你需要使用&lt;annotation&gt;作为自闭合元素,而不是包围&lt;arg&gt;元素。

    所以你想要:

    <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 的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-29
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      • 2011-06-15
      • 1970-01-01
      • 2015-01-11
      相关资源
      最近更新 更多