Hi All,<br><br>I'm considering DBUS (version-1.6.2/ linux platform) as option to signal different modules within event driven system. Eg. Module-A sends signal to Module-B, Module-B process signal and replies module-A with response signal. <br>
<br>So I wanted to send some extra information with signal across different module. I tried sending extra information in Byte array. Following is code to do so:<br><br>struct MyExample {<br>
char cchar[30];<br>
int iint;<br>
double ddouble;<br>
char c;<br>
}; <br>
<br>/--------------- Send Signal Code -------------------/<br> // Extra Information with signal is in MyExample Object<br> struct MyExample obj;<br> strcpy(obj.cchar,"String");<br> obj.iint = 9209;<br>
obj.ddouble = 10.12;<br> obj.c = 'A';<br> char tBuff[100];<br> memcpy(tBuff, &obj,sizeof(obj)); // Serialising obj into buffer<br> int len = sizeof(obj); <br> unsigned char *val = (unsigned char *)tBuff; <br>
if (!dbus_message_append_args (signal,<br> DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &val, len,<br> DBUS_TYPE_INVALID))<br> die ("No memory"); <br> if (!dbus_connection_send (connection, signal, NULL))<br>
die ("No memory\n");<br>/------------------ End Code ----------------/<br><br>On receiver side, ideally I should get correct 'extra information' after type casting the byte array I would be getting by dbus_message_iter_get_fixed_array API. But when I type cast the buffer, I'm seeing some weird data. Following is the code to read the byte array:<br>
/---------------- Processing Signal --------------/<br> DBusMessageIter iter;<br> dbus_message_iter_init (message,& iter);<br> int argType, eleType;<br> argType = dbus_message_iter_get_arg_type(&iter);<br>
if (argType == DBUS_TYPE_ARRAY) {<br> if (dbus_message_iter_get_element_type(&iter) == DBUS_TYPE_BYTE) {<br> DBusMessageIter arrayIter;<br> dbus_message_iter_recurse(&iter,&arrayIter);<br>
unsigned char buff[50];<br> int length;<br> dbus_message_iter_get_fixed_array(&arrayIter,&buff,&length);<br> struct MyExample *obj = (struct MyExample*) buff;<br>
printf ("\nLength: %d Name: %s, Int: %d, Double:%f, Char: %c\n",length, obj->cchar, obj->iint,obj->ddouble,obj->c); <br> }<br> }<br>/---------------- End Processing -----------------/<br clear="all">
<br>I got the correct information when I used 'dbus_message_iter_get_basic' API iterating over byte array. But I dont want to use this method as its execution is expensive.<br><br>1. Basic question is, is Byte Array is good choice to use for information forwarding in DBUS?<br>
2. What am I missing cause of which I'm not getting correct data on receiver side?<br><br>In case if I have posted on wrong forum, please guide me to correct forum. I'm newbie in DBUS. <br><br>Thanks in advance.<br>
<br>-- <br>Regards,<br>Rajnikant Jachak.<br><br><br>