The function g_variant_get_type_string() can be used to get the formatting string for the GVariant.
So for sanity, I first tried this on org.freedesktop.DBus.Properties method called “Set”.
Set(in s interface,
in s name,
in v value);
This results in g_variant_get_type_string() on its parameter returns:
(ssv)
This function is working correctly.
For my org.bluez.GattCharacteristic1 method “WriteValue”, g_variant_get_type_string() returns:
(aya{sv})
The gdbus introspect returns:
interface org.bluez.GattCharacteristic1 {
methods:
ReadValue(in a{sv} options,
out ay value);
WriteValue(in ay value,
in a{sv} options);
The error I see is:
Error message: Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist
Code:
GVariantBuilder *builder;
GVariant *v1=g_variant_new("(q)", 0);
GVariant *options;
GVariant *parameters;
const gchar *typestring;
builder = g_variant_builder_new( G_VARIANT_TYPE("a{sv}") );
g_variant_builder_add(builder, "{sv}", "offset", v1);
options = g_variant_new ("a{sv}", builder);
g_variant_builder_unref (builder);
GBytes *bytes = g_bytes_new(RSU2_PASSWORD, strlen(RSU2_PASSWORD)+1);
GVariant *pwd = g_variant_new_from_bytes(G_VARIANT_TYPE_BYTESTRING, bytes, TRUE);
GVariant *args = g_variant_new("(@ay@a{sv})",pwd,options);
typestring = g_variant_get_type_string(args);
g_print("%p: %s: typestring for WriteValue: %s\n",g_thread_self(),__func__,typestring);
gatt_objects = g_dbus_connection_call_sync(con,
"org.bluez",
charp,
"org.bluez.GattCharacteristic1",
"WriteValue",
args,
NULL,
G_DBUS_CALL_FLAGS_NONE, // Flags
10000, // 10 second timeout
NULL, // Cancellable
&errorO // error
); // User data for callback