[D-BUS] How append array of struct

Claudio Takahasi cktakahasi at gmail.com
Wed Aug 3 04:32:29 EST 2005


Hi Havoc,

No error is returned.
At the ending of appending this code, the message signature should be
"yya(ss)(ss)". Is that correct?
However, the function that gets the signature return yya(ss). 

D-Bus message iterators is a new subject for me. I don't know the iterators
pointers works. What happens with the "struct_iter" when I close the container?
At first glance the elements are being overwritten inside the loop, isn't it?


Regarding the restore. When I tryed get the arguments using the code
below, the message "arguments to dbus_message_iter_open_container()
were incorrect, assertion "real->iter_type ==
DBUS_MESSAGE_ITER_TYPE_WRITER" failed" appeared.

dbus_message_iter_init(reply, &iter);
dbus_message_iter_get_basic((&iter, cnf);
dbus_message_iter_next(&iter);
dbus_message_iter_get_basic(&iter, &num_elem);
dbus_message_iter_next(&iter);
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, array_sig,
&array_iter_read);
for ( i = 0; i < num_elem; i++) {
	dbus_message_iter_open_container(&array_iter_read, DBUS_TYPE_STRUCT, NULL
					&struct_iter_read);
	dbus_message_iter_get_basic(&struct_iter_read, &read_name);
	dbus_message_iter_next(&struct_iter_read);
	dbus_message_iter_get_basic(&struct_iter_read, &read_addr);
	if(read_name && read_addr) {
		printf("read :(%s, %s)\n", read_name, read_addr); 
	else {
		printf("read :(NULL, NULL)\n"); 
	}
	dbus_message_iter_close_container(&array_iter_read, &struct_iter_read);
}
dbus_message_iter_close_container(&iter, &array_iter_read);



Claudio.


On 8/2/05, Havoc Pennington <hp at redhat.com> wrote:
> On Tue, 2005-08-02 at 10:36 -0300, Claudio Takahasi wrote:
> > dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE, &cnf);
> > dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE, &dev_num);
> 
> I think cnf and dev_num here should be "unsigned char" rather than "int"
> btw
> 
> > 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);
> 
> When this fails do you get some kind of error message?
> 
> The open_container() for the struct can just have NULL instead of
> struct_sig for the contained type, though in theory the code would
> silently ignore that arg if you specify it.
> 
> Havoc
> 
> 
>


More information about the dbus mailing list