[D-BUS] How append array of struct

Claudio Takahasi cktakahasi at gmail.com
Tue Aug 2 23:36:30 EST 2005


Hi Havoc,

I started change my code in order to follow your suggestion. I want
send a message with the following  content:
byte - operation result
byte - number of elements in the array
array of struct, where each struct contains 2 strings 
signature: yya(ss)(ss)

The code below contains only 2 structs for demonstration, in the final
code the number of elements will be variable.


What is wrong with the code below?
I am not able to append the second struct. The final signature is yya(ss)
Probably, there is a problem in the logic/commands of my code related
to the struct iterator or I am not specifying the array signature
correctly.

Thanks in advance,
Claudio.



const char array_sig[] = \
			DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
			DBUS_TYPE_STRING_AS_STRING\
			DBUS_TYPE_STRING_AS_STRING\
			DBUS_STRUCT_END_CHAR_AS_STRING;
	
const char struct_sig[] = \
			DBUS_TYPE_STRING_AS_STRING\
			DBUS_TYPE_STRING_AS_STRING;

int dev_num = 2;

const char name0[] = "name0"; 
const char name1[] = "name1"; 
const char addr0[] = "address0"; 
const char addr1[] = "address1"; 
char *ptr_name = name0;
char *ptr_addr = addr0;

....

dbus_message_iter_init_append(&iter);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE, &cnf);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE, &dev_num);
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, array_sig,
&array_iter);
for ( i = 0; i < dev_num; i++) {
	dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, struct_sig,
			&struct_iter);
	dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &ptr_name);
	dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &ptr_addr);
	dbus_message_iter_close_container(&array_iter, &struct_iter);
	ptr_name = name1;
	ptr_addr = addr1;
}
dbus_message_iter_close_container(&iter, &array_iter);


On 7/28/05, Havoc Pennington <hp at redhat.com> wrote:
> On Thu, 2005-07-28 at 16:26 -0300, Claudio Takahasi wrote:
> > Hi folks,
> >
> > Is it possible append array of struct?
> >
> > When I tried, the following message appeared:
> > "arrays of struct can't be appended with
> > dbus_message_append_args_valist for now"
> >
> > Is there a workaround for it?
> >
> 
> You have to do a separate function call for each level of recursion.
> 
> So, open_container(array of struct), open_container(struct),
> append(string),append(string),append(byte), close_container(struct),
> open_container(struct) ...
> 
> append_args_valist is just a convenience function.
> 
> > I want to create a message like this: ya(ssy)(ssy)...
> 
> Havoc
> 
> 
>


More information about the dbus mailing list