problem with structure und D-Bus
t_charles at gmx.de
t_charles at gmx.de
Fri Nov 16 01:16:27 PST 2007
Hi,
Iwant to send and receive such a structure " a(is(idd)(idd))" with D-Bus
I proceed as follow:
I have first of all i create the following procedure to help me do what I want.
// append a integer in a GValueArray
static void
_gvalue_array_append_int(GValueArray *g_val_array, gint v_int)
{
GValue val ={0};
g_value_init(&val, G_TYPE_INT);
g_value_set_int(&val, v_int);
g_value_array_append(g_val_array, &val);
g_value_unset(&val);
}
// append a double in a GValueArray
static void
_gvalue_array_append_double(GValueArray *g_val_array, gdouble v_double)
{
GValue val ={0};
g_value_init(&val, G_TYPE_DOUBLE);
g_value_set_double(&val, v_double);
g_value_array_append(g_val_array, &val);
g_value_unset(&val);
}
// append a pointer in a GValueArray
static void
_gvalue_array_append_pointer (GValueArray *g_val_array, gpointer v_pointer)
{
GValue val ={0};
g_value_init(&val, G_TYPE_POINTER);
g_value_set_pointer(&val, v_pointer);
g_value_array_append(g_val_array, &val);
g_value_unset(&val);
}
// append a string in a GValueArray
static void
_gvalue_array_append_string(GValueArray *g_val_array, const gchar *v_string)
{
GValue val ={0};
g_value_init(&val, G_TYPE_STRING);
g_value_set_string(&val, v_string);
g_value_array_append(g_val_array, &val);
g_value_unset(&val);
}
// create the GValueArray structure "(idd)"
void
_gvalue_array_vector (GValueArray *g_val_array, gint v_int, double x, double y)
{
_gvalue_array_append_int (g_val_array, v_int);
_gvalue_array_append_double(g_val_array, x);
_gvalue_array_append_double(g_val_array, y);
}
GPtrArray* gp_plugs; //a(is(idd)(idd))
gp_plugs = g_ptr_array_new();
GValueArray *plug_a, *plug_b; // each contains such a structure "(is(idd)(idd))"
GValueArray *vector_a, *vector_b, *vector_c, *vector_d; // each contains "(idd)"
plug_a = g_value_array_new ();
_gvalue_array_append_int (plug_a, 1);
_gvalue_array_append_string(plug_a, "SKN"); // (is)
vector_a = g_value_array_new ();
_gvalue_array_vector (vector_a, 1, 0.0, 0.0); // (idd)
_gvalue_array_append_pointer(plug_a, vector_a); //(is(idd))
vector_b = g_value_array_new ();
_gvalue_array_vector (vector_b, 2, 0.0, -100.0); // (idd)
_gvalue_array_append_pointer(plug_a, vector_b); // (is(idd)(idd))
g_ptr_array_add(gp_plugs, (gpointer)plug_a); // add the first element
// of the plug structure " a(is(idd)(idd))"
// then a create the second element as follow
plug_b = g_value_array_new ();
_gvalue_array_append_int (plug_b, 2);
_gvalue_array_append_string(plug_b, "AMSK"); // (is)
vector_c = g_value_array_new ();
_gvalue_array_vector (vector_c, 3, 40.0, 0.0); // (idd)
_gvalue_array_append_pointer(plug_b, vector_c); //(is(idd))
vector_d = g_value_array_new (4);
_gvalue_array_vector (vector_d, 4, 40.0, -100.0); // (idd)
_gvalue_array_append_pointer(plug_b, vector_d); // (is(idd)(idd))
g_ptr_array_add(gp_plugs, (gpointer)plug_b); // add the second element
// of the plug structure " a(is(idd)(idd))"
I would like to know if the way I use to build the structure is good, because I proceed like this and i obtain errors that i don't succeed to solve.
Thanks to answer me
Charles
regards,
--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
More information about the dbus
mailing list