I'm trying to send a two dimendional array of strings over dbus.( I'm using the gdbus api, with gdbus-codegen).
I have defined the dbus interface as follows.
<method name="foo">
<arg name="count" direction="out" type="i" />
<arg name="array" direction="out" type="a(ia(s))" />
</method>
I'm trying to create the GVariant in the following manner:
GVariantBuilder *builder;
GVariant *variant;
builder = g_variant_builder_new(G_VARIANT_TYPE("a(ia(s))"));
for (int i = 0; i < count; i++)
{
g_variant_builder_add(builder, "(ia(s))",
options[i].num_supported,
pack_string_array(options[i].num_supported, options[i].supported_values));
}
variant = g_variant_new("a(a(s))", builder);
my_interface_complete_foo(interface, invocation, count, variant);
where pack_string_array packs an array of c style strings into a gvariant.
GVariant* pack_string_array(int num_val, char **val)
{
GVariantBuilder *builder;
GVariant *values;
builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
for (int i = 0; i < num_val; i++)
{
g_message("%s", val[i]);
g_variant_builder_add(builder, "(s)", val[i]);
}
if (num_val == 0)
g_variant_builder_add(builder, "(s)", "NA");
values = g_variant_new("a(s)", builder);
return values;
}
However when I test it,the program crashes with the following errors:
GLib-CRITICAL **: g_variant_builder_end: assertion 'ensure_valid_builder (builder)' failed
g_variant_get_type: assertion 'value != NULL' failed
How can I send a array of string arrays over the dbus?