Retrieving the Array of strings

Kaustubh Atrawalkar kaustubh.atrawalkar at celunite.com
Wed Jan 10 22:31:15 PST 2007


Hi !!

I m appending an array of string to send over dbus. On the other end i m 
retrieving the structure. But i m getting garbage values. If i change 
the DBUS_TYPE_STRING to DBUS_TYPE_UINT32 i get the perfect results.I m 
attaching the part of the code. Where i m going wrong ? I think its 
marshaling problem.

------------- Sending part ---------------

        DBusMessage *reply;
        DBusMessage *mesg;

        DBusMessageIter iter, array_iter, struct_iter;

        guint dev_num =2, i;
        char name0[] = "MP3";
        char title0[] = "Playing..";
        char name1[] = "CALL";
        char title1[] = "On Hold..";
        char *ptr_name = name0;
        char *ptr_title = title0;

        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;

        mesg =  dbus_g_message_get_message(context->message);
        reply = dbus_message_new_method_return(mesg);

        dbus_message_iter_init_append(reply, &iter);
        dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &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, NULL, &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_title);
                printf("\n%s %s\n", ptr_name, ptr_title);
                dbus_message_iter_close_container(&array_iter, 
&struct_iter);
                ptr_name = name1;
                ptr_title = title1;
        }
        dbus_message_iter_close_container(&iter, &array_iter);
        if (!dbus_connection_send(bus_conn, reply, 0))
        {
                g_warning("Out Of Memory!");
                CLP_APPMGR_EXIT_FUNCTION();
                return FALSE;
        }

        dbus_message_unref(reply);
        dbus_message_unref(mesg);


------------ Receiving part -----------------

        DBusMessageIter iter, array_iter_read, struct_iter_read;

        dbus_message_iter_init(msg, &iter);
        dbus_message_iter_get_basic(&iter, &num_elem);
        printf("\n\nNumber of apps:%d\n",num_elem);
        dbus_message_iter_next(&iter);

        printf("\n%s\n",dbus_message_iter_get_signature(&iter));

        dbus_message_iter_recurse(&iter, &array_iter_read);

        for (i = 0; i < num_elem; i++) {
                dbus_message_iter_recurse(&array_iter_read, 
&struct_iter_read);
                dbus_message_iter_get_basic(&struct_iter_read, &appname);
                dbus_message_iter_next(&struct_iter_read);
                dbus_message_iter_get_basic(&struct_iter_read, &apptitle);
                printf("read :(%s, %s)\n", appname, apptitle);
                dbus_message_iter_next(&array_iter_read);
        }




More information about the dbus mailing list