1

I am attempting to annotate an xml file so that dbus-codegen generates a method that uses GVariant * instead of a native type like gchar.

Here is the xml code I am working with.

<node>
  <interface name="org.bluez.GattCharacteristic1">
    <method name="WriteValue">

        <arg name="value" type="ay" direction="in"/>

    </method>
  </interface>
</node>

I have read the following stackoverflow post:

Sending a byte array (type `ay`) over D-Bus using GDBus

After reading that post I have tried the following:

1)Edit the xml file to include annotations

<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>

then do:

gdbus-codegen --interface-prefix org.bluez --c-generate-object-manager --generate-c-code generated-code org.bluez.xml

This did not generate what I wanted.

2)Use the --annotate switch on gdbus-codegen:

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

This did not generate what I wanted.

The only way I have been successful is to change the "ay" in the following code to "a(y):

    <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true">
    <arg name="value" type="a(y)" direction="in"/>
    </annotation>'

However this causes other problems.

So how do I get a WriteValue method with the following declaration:

    gboolean gatt_characteristic1_call_write_value_sync
    (GattCharacteristic1 *proxy,
    GVariant *arg_value,
    GCancellable *cancellable,
    GError **error)

instead of:

    gboolean gatt_characteristic1_call_write_value_sync (
    GattCharacteristic1 *proxy,
    const gchar *arg_value,
    GCancellable *cancellable,
    GError **error)

Can some please tell me what I am doing wrong.

thank you.

west suhanic
  • 41
  • 1
  • 4

1 Answers1

3

As documented in the D-Bus specification’s section on the introspection data format, you need to use <annotation> as a self-closing element, rather than surrounding the <arg> element.

So you want:

<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>

You can also see examples of this in the GLib source code.

Philip Withnall
  • 5,293
  • 14
  • 28