Hi,

In my application, i am getting a message over dbus which has to be 
parsed(extracted) using gvariant functions.
The format string is "((yu)ya(ysb((sss)(sss))))" which is a bit complex one.
Have writen a sample fn to try out the extraction, which is not currently 
working.



//------------------------------------------------------------------------------
#include <glib.h>
#include <glib/gstdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>

int ParseVariant (GVariant *value);
{
        GVariantBuilder *devicelist;
        GVariant *list;
        GVariant *list_1;
        gchar ch1,ch2,ch3;
        gchar *str1,*str2,*str3,*str4,*str5,*str6,*str7 ;
        gboolean bool1;
        gint x,y,z;
        GVariantIter *iter;
 g_print ("Inside Parse");
// g_print ("g_variant_get_size:%s",g_variant_get_size (&value));

// GVariantIter *iter;

g_variant_get (value, "((yu)ya(ysb((sss)(sss))))", &ch1, &x, &ch2, &iter);
 g_variant_get_type_string (iter);
while (g_variant_iter_loop (iter, "ysb((sss)(sss))", &ch3,str1, &bool1, str2, 
str3, str4, str5, str6, str7))
    g_print ("%s\n", str1);
  g_variant_iter_free (iter);
}

int main()
{

GVariantBuilder *builder;
GVariant *value;


builder = g_variant_builder_new (G_VARIANT_TYPE ("a(ysb((sss)(sss)))"));
g_variant_builder_add (builder, "(ysb((sss)(sss)))", 'J', "Test1", TRUE, "Hn", 
"di", "hedfs", "dd", "dr", "hdf");
g_variant_builder_add (builder, "(ysb((sss)(sss)))", 'J', "Test2", TRUE, "Hn", 
"di", "hedfs", "dd", "dr", "hdf");
//g_variant_builder_add (builder, "(ysb((sss)(sss)))", 'J', "Test3", TRUE, 
"Hn", "di", "hedfs", "dd", "dr", "hdf");


GVariant *result = g_variant_new ("((yu)ya(ysb((sss)(sss))))", 'R', 23, 'E', 
builder);

g_variant_builder_unref (builder);
ParseVariant (result);
}
//------------------------------------------------------------------------------

Can anyone help in correcting the parser function (ParseVariant (result)) using 
which I can extract each element of the variant result.

Thanks in advance.

Regards,
Dhanesh


_______________________________________________
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list

Reply via email to