RE: gvariant parsing for a complex format



Something like this:

#include <glib.h>

#include <glib/gstdio.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <gio/gio.h>

int ParseVariant (GVariant *value)

{

    GVariant * list;

    gchar ch1,ch2,ch3;

    gchar *str1,*str2,*str3,*str4,*str5,*str6,*str7;

    gboolean bool1;

    gint x;

    GVariantIter iter;

 

    g_print ("Inside Parse\n");

    

    g_variant_get (value, "((yu)y a(ysb((sss)(sss))))", &ch1, &x, &ch2, &list);

    g_variant_iter_init (&iter, list);

    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_unref(list);

}

int main()

{

    GVariantBuilder * 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");

    

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

    

    g_variant_builder_unref (builder);

    ParseVariant (result);

}

 

 

From: gtk-list [mailto:gtk-list-bounces gnome org] On Behalf Of Dhanesh Sudhakaran Nair (RBEI/ECS1)
Sent: 3. april 2015 05:06
To: gtk-list gnome org
Subject: gvariant parsing for a complex format

 

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

 

 

This message is subject to the following terms and conditions: MAIL DISCLAIMER


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]