<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
Hello,<br>
<br>
Could somebody please analyze the piece of source code below.<br>
<br>
I'd like to send a message containing an array of structures using
low-level API. The sent message shall be received in Qt. <br>
For the test purposes the structure is a two-string structure, the
array contains 10 entries.<br>
<br>
The receiver side (Qt) defines following parameter for the slot
method (Q_DECLARE METATYPE are omitted here):<br>
<br>
<font size="-1" face="Courier New, Courier, monospace">structure <br>
{<br>
QString str1;<br>
QString str2;<br>
} twoString;<br>
<br>
typedef QVector<twoString> structArr;<br>
<br>
void slotMethod( structArr arr );</font> <br>
<br>
Now to the sender. I have to use low-level API :(. <br>
Running the example below I get the following run-time error:<br>
<br>
<font size="-1" face="Courier New, Courier, monospace">-------------------PASSED_0<br>
-------------------PASSED_1<br>
process 6585: Array or variant type requires that type struct be
written, but begin_struct was written<br>
D-Bus not built with -rdynamic so unable to print a backtrace</font><br>
<br>
And now the source code:<br>
<br>
<font size="-1" face="Courier New, Courier, monospace">gboolean
arrayOfStructSignal( MyClass *self )<br>
{<br>
// unique number<br>
dbus_uint32_t serialNr = 0; <br>
<br>
// DBusMessage<br>
DBusMessage *msg;<br>
<br>
// Dbus Message Iterators - main, array, structure<br>
DBusMessageIter iter,<br>
arr,<br>
strct;<br>
<br>
// Connection<br>
DBusConnection *conn;<br>
<br>
gchar buffer[BUFF_SIZE_SMALL];<br>
const char *buff = buffer;<br>
<br>
if( NULL == self )<br>
{<br>
return false;<br>
}<br>
<br>
conn = self->m_conn;<br>
assert( NULL != conn ); <br>
<br>
// create a signal and check for errors <br>
msg = dbus_message_new_signal( "/myObj", <br>
"my.test.Interface", <br>
"arrOfStructSignal" );<br>
if (NULL == msg) <br>
{ <br>
return false; <br>
}<br>
<br>
dbus_message_iter_init_append( msg, &iter );<br>
<br>
// open the array of structures<br>
dbus_message_iter_open_container( &iter, <br>
DBUS_TYPE_ARRAY, <br>
"r",<br>
&arr );<br>
<br>
cout << "-------------------PASSED_0 " << endl; <br>
<br>
// array of 10 structures a(ss) - for test<br>
for( int i = 0; i < 10; i++ )<br>
{<br>
<br>
cout << "-------------------PASSED_1 " << endl; <br>
<br>
// Open the a structure within an array <br>
// Here run-time error !!!!!!!!!!!!!!!!!!!<br>
dbus_message_iter_open_container( &arr, <br>
DBUS_TYPE_STRUCT, <br>
NULL,<br>
&strct );<br>
<br>
cout << "-------------------PASSED_2 " << endl; <br>
<br>
memset( buffer, 0, BUFF_SIZE_SMALL );<br>
sprintf(buffer, "test 0 %d", i );<br>
<br>
// append first string to the structure <br>
if( !dbus_message_iter_append_basic(&strct,
DBUS_TYPE_STRING, &buff) )<br>
{<br>
dbus_message_unref(msg); <br>
return false;<br>
}<br>
<br>
cout << "-------------------PASSED_3 " << endl; <br>
<br>
memset( buffer, 0, BUFF_SIZE_SMALL );<br>
sprintf(buffer, "test 0 %d", i );<br>
<br>
// append second string to the structure <br>
if( !dbus_message_iter_append_basic(&strct,
DBUS_TYPE_STRING, &buff) )<br>
{<br>
dbus_message_unref(msg); <br>
return false;<br>
}<br>
<br>
cout << "-------------------PASSED_4 " << endl; <br>
<br>
// close structure container<br>
dbus_message_iter_close_container( &arr, &strct );<br>
}<br>
<br>
// close struct container<br>
dbus_message_iter_close_container( &iter, &arr );<br>
<br>
// send the message and flush the connection<br>
if( !dbus_connection_send(conn, msg, &serialNr)) <br>
{ <br>
dbus_message_unref(msg); <br>
return false;<br>
}<br>
dbus_connection_flush(conn);<br>
<br>
// free the message <br>
dbus_message_unref(msg);<br>
<br>
return true;<br>
}<br>
<br>
</font>Thanks for your help<br>
<br>
regards,<br>
<br>
Bogdan<br>
<font size="-1" face="Courier New, Courier, monospace"><br>
<br>
<br>
</font><br>
<br>
<br>
<br>
<br>
</body>
</html>