dbus_message_set/get_data usage

Brosseau, Vincent vincent.brosseau at bruker.fr
Thu Dec 12 00:07:40 PST 2013

Thank you for your help, Simon.

Now I understand that I can't attach data to the message in this way... But I'm not sure to understand what are dbus_message_set/get_data used for, exactly (your example with Python doesn't help me, sorry)... 

Anyway, I have another question about attaching parameters.
When I use dbus_message_iter_init_append() and then dbus_message_iter_append_basic(), the latter needs a (void *)parameter as the third argument.  If I do this :

void attachParameters( ParameterSet param ) // where ParameterSet is a structure
	DBusMessageIter dbusArg;

	dbus_message_iter_init_append( myMessage, &dbusArg );
	// param contains a field with the number of string values to attach => count
	// and an array of string values => value[MAX_COUNT]
	for( int a = 0; a < param.count; a++ )
		dbus_message_iter_append_basic( &dbusArg, DBUS_TYPE_STRING, &param.value[a] );

This code leads to a "Segmentation fault" : the parameter param.value[a] can't be append.

But if I modify the code in the loop like this :

		const char *arg = param.value[a];
		dbus_message_iter_append_basic( &dbusArg, DBUS_TYPE_STRING, &arg );

It works. Why ?

-----Message d'origine-----
De : dbus-bounces at lists.freedesktop.org [mailto:dbus-bounces at lists.freedesktop.org] De la part de Simon McVittie
Envoyé : mercredi 11 décembre 2013 19:22
À : dbus at lists.freedesktop.org
Objet : Re: dbus_message_set/get_data usage

On 11/12/13 14:37, Brosseau, Vincent wrote:
> Then I can "attach" any type of data to the message (via a pointer), 
> as far as I understand.

This does not attach arbitrary data to the actual D-Bus message, only to the DBusMessage C struct that represents it. For instance, language bindings like dbus-python could use this as a way to link the C DBusMessage to the Python dbus.lowlevel.Message.

When the sender sends a DBusMessage, it serializes it into some bytes and pushes it into the stream. When the recipient receives those bytes, it deserializes it and constructs a new DBusMessage, with its own independent set of data slots. If the recipient was not written using libdbus, it might deserialize the message into some other representation, like a GDBusMessage, instead; the principle is the same but the implementation is different.

If you want to send data in the D-Bus "wire protocol" to be received by the recipient, it has to be represented in the message somehow - for anything not represented in the header, that means "in the message's arguments".

(Think about how/whether your interpretation could possibly work? The pointer is only valid within the sending application's address space; D-Bus doesn't know what your pointer points to, how to serialize it, or whether it can even be serialized.)


dbus mailing list
dbus at lists.freedesktop.org

More information about the dbus mailing list