how can I receive an ARRAY via dbus_message_get_args interface?

Wang, Songyue songyue.wang at intel.com
Wed May 25 21:08:25 PDT 2011


Mike:
Sincerely thanks very much!
But I am still puzzled.
when I changed to 
dbus_message_get_args (message, &dberr,DBUS_TYPE_ARRAY,3,&v_ARRAY, DBUS_TYPE_INVALID);
still not ok!

I want to get the data.
How can I write the code to get the data?

In dbus_send.c:
 dbus_int32_t array[] = { 1, 2, 3 };
 dbus_int32_t *v_ARRAY = array;
dbus_message_append_args (dbmsg, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &v_ARRAY, 3, DBUS_TYPE_INVALID);   

In dbus_get.c:
dbus_int32_t array[] = {0,0,0};
dbus_int32_t *v_ARRAY = array;
dbus_message_get_args (message, &dberr,DBUS_TYPE_ARRAY,DBUS_TYPE_INT32,&v_ARRAY,3, DBUS_TYPE_INVALID);
printf ("wsy Received TestSignal with value of: 'x=%d,y=%d,z=%d'\r\n", array[0],array[1],array[2]);



BRs,
Songyue Wang 王松月
Tel: 86-10-5751-1739
iNet: 8751-1739
Mobile: 15710026726
mailto:songyue.wang at intel.com
DRD Atom/Meego Platform Enabling Team


-----Original Message-----
From: Mike Gorse [mailto:mgorse at novell.com] 
Sent: Thursday, May 26, 2011 11:55 AM
To: Wang, Songyue
Cc: dbus at lists.freedesktop.org
Subject: Re: how can I receive an ARRAY via dbus_message_get_args interface?

Hi Songyue,

On Thu, 26 May 2011, Wang, Songyue wrote:

> In dbus_get.c:
> dbus_int32_t array[] = {0,0,0};
> dbus_int32_t *v_ARRAY = array;
> dbus_message_get_args (message, &dberr,DBUS_TYPE_ARRAY,DBUS_TYPE_INT32,&v_ARRAY,3, DBUS_TYPE_INVALID);

You're misunderstanding the way dbus_message_get_args handles arrays.  It 
does not copy the array into memory that you allocated.  After the call, 
v_array will be modified to point to the array data within the message 
(so, if you need the data after the message goes away, then you'll need to 
copy it, except for string arrays).  The next parameter should point to an 
int where the count of items in the array will be written.  I think your 
code is crashing because you're trying to pass in the number of elements 
you're expecting while libdbus assumes that you've passed a pointer for it 
to store the count.

Hth,
-Mike


More information about the dbus mailing list