DBUS as IPC medium for communicating signals/events

rajnikant jachak rajnikantjachak at gmail.com
Wed Aug 1 04:56:09 PDT 2012


Hi All,

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.

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:

struct MyExample {
    char cchar[30];
    int iint;
    double ddouble;
    char c;
};

/--------------- Send Signal Code -------------------/
    // Extra Information with signal is in MyExample Object
    struct MyExample obj;
    strcpy(obj.cchar,"String");
    obj.iint = 9209;
    obj.ddouble = 10.12;
    obj.c = 'A';
    char tBuff[100];
    memcpy(tBuff, &obj,sizeof(obj));  // Serialising obj into buffer
    int len = sizeof(obj);
    unsigned char *val = (unsigned char *)tBuff;
    if (!dbus_message_append_args (signal,
                DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &val, len,
                DBUS_TYPE_INVALID))
        die ("No memory");
    if (!dbus_connection_send (connection, signal, NULL))
        die ("No memory\n");
/------------------ End Code ----------------/

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:
/---------------- Processing Signal --------------/
            DBusMessageIter iter;
            dbus_message_iter_init (message,& iter);
            int argType, eleType;
            argType = dbus_message_iter_get_arg_type(&iter);
            if (argType == DBUS_TYPE_ARRAY) {
                if (dbus_message_iter_get_element_type(&iter) ==
DBUS_TYPE_BYTE) {
                    DBusMessageIter arrayIter;
                    dbus_message_iter_recurse(&iter,&arrayIter);
                    unsigned char buff[50];
                    int length;

dbus_message_iter_get_fixed_array(&arrayIter,&buff,&length);
                    struct MyExample *obj = (struct MyExample*) buff;
                     printf ("\nLength: %d Name: %s, Int: %d, Double:%f,
Char: %c\n",length, obj->cchar, obj->iint,obj->ddouble,obj->c);
                 }
             }
/---------------- End Processing -----------------/

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.

1. Basic question is, is Byte Array is good choice to use for information
forwarding in DBUS?
2. What am I missing cause of which I'm not getting correct data on
receiver side?

In case if I have posted on wrong forum, please guide me to correct forum.
I'm newbie in DBUS.

Thanks in advance.

-- 
Regards,
Rajnikant Jachak.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20120801/adbfe61a/attachment.html>


More information about the dbus mailing list