west suhanic
west suhanic

Reputation: 41

How to annotate an xml file with org.gtk.GDBus.C.ForceGVariant using gdbus-codegen

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.

Upvotes: 1

Views: 925

Answers (2)

Fabian
Fabian

Reputation: 847

When using the --annotate option of gdbus-codegen, then you need to specify the parameter using square brackets. So in your case, use the following.

gdbus-codegen --annotate "org.bluez.GattCharacteristic1.WriteValue()[value]" org.gtk.GDBus.C.ForceGVariant true --interface-prefix org.bluez --c-generate-object-manager --generate-c-code generated-code org.bluez.xml

Upvotes: 0

Philip Withnall
Philip Withnall

Reputation: 5733

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.

Upvotes: 3

Related Questions