How create a reply without dbus_message_new_method_return?

Claudio Takahasi cktakahasi at gmail.com
Tue Oct 25 07:26:12 PDT 2005


Hi folks,

I am trying create a reply message without use the function
"dbus_message_new_method_return".

I know that I can create the reply message when I receive the msg and
add the arguments
after. But this approach is a little bit "ugly". I want extract the
values required to create
the reply and create it after using the "dbus_message_new" function.

My client is receiving a timeout error. I don't know what is problem.
Could someone help me? The client and the server code are below.


Regards,
Claudio.
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT


/********** Client request code **********/
message = dbus_message_new_method_call(BLUEZ_BUS_NAME, path,
                                                MANAGER_INTERFACE,
HCI_AUTHENTICATE);

dbus_message_iter_init_append(message, &iter);
        dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING ,&bdaddr);

        dbus_error_init (&error);

        reply = dbus_connection_send_with_reply_and_block(conn,
message, 30000, &error);

        if (dbus_error_is_set (&error)){
                printf("[DBUS] reply error:(%s,%s)\n", error.name,
error.message);
                dbus_error_free(&error);
                goto failed;
        }
...

/********** Server reply code **********/

...
    /* storing the sender info to reply later */
    sender = dbus_message_get_sender(msg);

    if (sender) {
        snprintf(sender, MAX_SENDER_LEN, "%s", sender);
    } else {
        memset(sender, 0, MAX_SENDER_LEN);
    }
    serial = dbus_message_get_serial(msg);

...

///ANOTHER CALLBACK FUNCTION TO AVOID BLOCKING
....

    reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
    if (reply == NULL) {
        syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
            goto failed;
    }

    dbus_message_set_no_reply (reply, TRUE);

    if (!dbus_message_set_sender(reply, sender)) {
        syslog(LOG_INFO, "Set sender failed");
        goto failed;
    }

    if(!dbus_message_set_reply_serial(reply, serial)) {
        syslog(LOG_INFO, "Set serial failed");
        goto failed;
    }

    if (dbus_connection_send(connection, reply, NULL) == FALSE) {
        syslog(LOG_ERR, "Can't send D-BUS remote name message");
        goto failed;
    }

    dbus_connection_flush(connection);

failed:
        if (reply)
                dbus_message_unref(reply);
....


More information about the dbus mailing list