2007-05-31

Faster ListStore

Your are wondering why ListStore.append() is so slow in your code?
No more turtle-soft: disconnect the view and the store by doing TreeView.set_model(None), edit the ListStore, and then reconnect them.

Tadaaa, this is just thousands of time faster here...

2007-05-11

Returning a array of structs with dbus-glib

I was looking for an example on how to return an array of struct in a D-Bus program, and I found nothing. So here is a fast note for later reference.

This is pseudo code, just to show you how to proceed.

So you want to return a "a(si)", that's it, an array of struct containing each a string and an integer.

in your example.xml: (process with dbus-binding-tool as usual)


<node name="/com/example/Example"></node>
<interface name="com.example.Example"></interface>
<method name="getExampleArray"></method>
<arg type="a(si)" name="array" direction="out"></arg>
</method>
</interface>
</node>


in your example.c:


// you define your structure here by using get_struct
#define DBUS_STRUCT_STRING_INT (dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_INT, G_TYPE_INVALID))

gboolean desktoptracks_get_example_array(DesktopTracks *obj, GPtrArray **stats_data, GError **error)
{
for ( each element you want to return )
{
element_string , element_int = the element you want to return

GValue *value;

value = g_new0 (GValue, 1);
g_value_init (value, DBUS_STRUCT_STRING_INT);
g_value_take_boxed (value, dbus_g_type_specialized_construct (DBUS_STRUCT_STRING_INT));

// field number, value, G_MAXUINT at the end
dbus_g_type_struct_set (value, 0, element_string, 1, element_int, G_MAXUINT);
g_ptr_array_add (array, g_value_get_boxed (value));
g_free (value);
}
}


Easy uh ?