GVariantBuilder build a(ii) or a(vv)

653 views Asked by At

I have this array of 2 int's I want to sent over dbus. It always complains that value is not of type tuple or null depending on the attempt. Hwow does it need to look like?

    GVariantBuilder builder;
    g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ii)"));
    g_variant_builder_add(&builder, "(ii)", 99, 99);
    g_variant_builder_add(&builder, "(ii)", 98, 98);
    GVariant *value = g_variant_new("a(ii)", &builder);
    g_dbus_method_invocation_return_value(invocation, value));

    //g_dbus_method_invocation_return_value(invocation, &value)); - also tried

     //Previous attempts
    //GVariantBuilder *builder; 
    // builder = g_variant_builder_new(G_VARIANT_TYPE("a(ii)"));
    //g_variant_builder_add(&builder, "(ii)", 99, 99);
    //g_variant_builder_add(&builder, "(ii)", 98, 98);
    //and
    //g_variant_builder_add(builder, "(ii)", 99, 99);
   //g_variant_builder_add(builder, "(ii)", 98, 98);
1

There are 1 answers

0
ebassi On

GVariantBuilder is not meant to be used as the payload for a GVariant: it's a builder pattern object, which will construct the GVariant from its contents:

GVariantBuilder builder;

// Initialize the GVariantBuilder with the final type
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ii)"));

// Add the contents of the variant
g_variant_builder_add (&builder, "(ii)", 99, 99);
g_variant_builder_add (&builder, "(ii)", 98, 98);

// Construct the variant from the builder
GVariant *v = g_variant_builder_end (&builder);

You should see the documentation for g_variant_builder_init() and g_variant_builder_end() for more information.