GLib example doesn't work

Emilio Monti emilmont at gmail.com
Mon Jun 4 02:31:06 PDT 2007


On Wed Jul 19 17:02:15 PDT 2006, Hobin Yoon wrote:
> Hi all,
> The glib client / service example doesn't work. Does anybody suffer
> the same result? Here is the result.

> ./example-client
> Failed to complete GetTuple: Message did not receive a reply (timeout
> by message bus)

> ./example-service
> service running
> Hello from example-client.c!

> GLib-GObject-CRITICAL **: g_value_copy: assertion
> `g_value_type_compatible (G_VALUE_TYPE (src_value), G_VALUE_TYPE
> (dest_value))' failed
> aborting...
> Aborted (core dumped)

In the GLib example the following method:
<method name="GetTuple"><arg type="(ss)" direction="out" /></method>

Is implemented in the following way:
gboolean some_object_get_tuple (SomeObject *obj, GValueArray **ret,
GError **error) {
  *ret = g_value_array_new (6);
  g_value_array_prepend (*ret, NULL);
  g_value_init (g_value_array_get_nth (*ret, 0), G_TYPE_STRING);
  g_value_set_string (g_value_array_get_nth (*ret, 0), "hello");
  g_value_array_prepend (*ret, NULL);
  g_value_init (g_value_array_get_nth (*ret, 0), G_TYPE_UINT);
  g_value_set_uint (g_value_array_get_nth (*ret, 0), 42);

  return TRUE;
}

A correct implementation could be:
gboolean some_object_get_tuple (SomeObject *obj, GValueArray **ret,
GError **error) {
  GValue tmp_value = {0};
  *ret = g_value_array_new(2);
  g_value_init(&tmp_value, G_TYPE_STRING);
  g_value_set_string(&tmp_value, "hello");
  g_value_array_append (*ret, &tmp_value);
  g_value_set_string(&tmp_value, "world");
  g_value_array_append (*ret, &tmp_value);
  	
  return TRUE;
}

Otherwise, should be changed the "GetTuple" method prototype.

Emilio


More information about the dbus mailing list