Problem emitting signal with GVariant constructed from unit tuple
Alban Crequy
alban.crequy at collabora.co.uk
Wed Jul 9 06:07:36 PDT 2014
On Wed, 09 Jul 2014 13:23:27 +0200
Bogdan Lotko <boguslaw.lotko at chello.at> wrote:
> Hello,
>
> I have a problem with emitting of the following signal:
>
> <signal name="mySignal">
> <arg type="s" name="paramName" direction="out"/>
> <arg type="s" name="group" direction="out"/>
> <arg type="v" name="paramDetails" direction="out"/>
> </signal>
>
> the code (myInterface_if_emit_my_signal) has been generated with
> gdbus-codegen ( glib-2.32.0 )
>
> I am working on SLES 11.
>
> Following source code illustrates the problem
>
> ...
> GVariant *arr[GVARIANT_GEN_SIZE];
> int cnt = 0;
>
> if( *condition*)
> {
> arr[cnt++] = g_variant_new_boolean( aBoolValue );
> ....
> arr[cnt++] = g_variant_new_xxx( xxxValue );
> }
>
> GVariant *gv = g_variant_new_variant( g_variant_new_tuple(arr, cnt) );
>
> myInterface_if_emit_my_signal( "string1", "string2", gv );
> ....
>
> As long as the *condition* is true, everything works perfectly.
>
> In case that the *condition* is false, the unit tuple shall be
> constructed (cnt == 0) - the g-variant-new-tuple description states:
> "If /|n_children|/ is 0 then the unit tuple is constructed"
>
> Emitting the signal with such a unit tuple causes the application
> crash.
>
> Is this a "feature", bug or my mistake? How to resolve this?
The D-Bus specification says: "Empty structures are not allowed":
http://dbus.freedesktop.org/doc/dbus-specification.html
So a GVariant containing an empty tuple cannot be sent in a D-Bus
message.
D-Bus does not have "maybe" type yet:
https://bugs.freedesktop.org/show_bug.cgi?id=27857
So it cannot be worked around with a maybe-variant paramDetails.
But you could send a dummy byte set to zero, or an empty a{sv}...
Best regards,
Alban
More information about the dbus
mailing list