dbus_connection_send_with_reply_and_block error

Sumit Kumar Jain sumitskj_20 at yahoo.com
Mon Feb 25 23:07:44 PST 2008


Hi,
I have a test code that calls dbus_connection_send_with_reply_and_block(). The API documentation says that the message is removed of the incoming queue and hence if we call dbus_connection_borrow_message(), it should return NULL. However thats not the case. 

Any help. Have I misinterpreted the documentation by any chance.

The below test code demonstrates  the issue.

---- client code ---
int main()
{
        DBusConnection* connection;
        DBusError error;
        DBusMessage* msg;
        DBusMessage* borrow_message;
        DBusMessage* reply = NULL;
        dbus_int32_t no = 5;
        char error_name[40];
        char error_msg[40];
        
        dbus_error_init(&error);
        
        connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
    
        msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "dbus_connection_borrow_message0");
        
        reply = dbus_connection_send_with_reply_and_block(connection, msg, 10000, &error);
        
        dbus_message_get_args(reply, &error, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID);
        
        borrow_message =  dbus_connection_borrow_message (connection )   ;
    
        if(borrow_message)
            printf("Error\n");
    
         return 0;
}    

---------- end client code ----

----- Server code ----
#include<stdio.h>  
#include "test-utils.h"
#include<string.h> 
#include<ctype.h>
#include<unistd.h>  // sleep function is defined in this header file 
#define TEST_BUS_NAME_TEMP "Test.Method.Call"
     
void called_dbus_connection_borrow_message0(DBusMessage* msg,DBusConnection* connection)
    {
    DBusMessage* reply;    
    dbus_int32_t arg;
    dbus_int32_t return_value = 9090;

    reply = dbus_message_new_method_return(msg);
    
    dbus_message_append_args(reply, DBUS_TYPE_INT32, &return_value, DBUS_TYPE_INVALID);
    dbus_connection_send(connection, reply, NULL);
    dbus_connection_flush(connection);
    }
void called_dbus_connection_pop_message0(DBusMessage* msg,DBusConnection* connection)
    {
    DBusMessage* reply;    
    dbus_int32_t arg;
    //dbus_int32_t return_value = 9090;

    reply = dbus_message_new_method_return(msg);
    
    //dbus_message_append_args(reply, DBUS_TYPE_INT32, &return_value, DBUS_TYPE_INVALID);
    dbus_connection_send(connection, reply, NULL);
    dbus_connection_flush(connection);
    }

int main(int argc, char* argv[])
{
    DBusError error;
    DBusError error1;
    DBusConnection* connection;
    DBusMessage* msg;
    DBusObjectPathVTable vtable;
     
    dbus_error_init(&error);
    dbus_error_init(&error1);
    fprintf(stdout, "Starting Method");
//    getchar();
    
    connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
    
    if(dbus_error_is_set(&error))
    {
        fprintf(stdout, "Error Occured :: %s", error.name);
//        getchar();
        return 1;
    }
    

    
    if(dbus_connection_register_object_path (connection, "/Test/Method/Object", &vtable, NULL))
    {
        fprintf(stdout, "Object Path registered.");
//        getchar();
    }
    else
    {
        fprintf(stdout, "Object Path not able to register.");
//        getchar();
        return 1;
    }
 


    if(dbus_bus_request_name (connection, TEST_BUS_NAME_TEMP, DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &error1) == -1)
    {
        fprintf(stdout, "Not able to request name.");
//        getchar();
    }
    else
    {
        fprintf(stdout, "Name Request Successful");
//        getchar();
    }
    
    while(TRUE)
    {    
        dbus_connection_read_write(connection, 0);
        
        msg = dbus_connection_pop_message(connection);
            
        if(msg == NULL)
        {
            sleep(1);
            continue;
        }
             
        fprintf(stdout, "Message Detected");
        
        if(DBUS_MESSAGE_TYPE_SIGNAL == dbus_message_get_type(msg))
        {
            fprintf(stdout, "Message is Signal.");
        }
        
        if(DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg))
        {
            fprintf(stdout, "Message is Method call.");
    //        getchar();
        }
        
                
        if(dbus_message_is_method_call(msg, "test.Method.Call", "dbus_connection_borrow_message0"))
            {
            
            called_dbus_connection_borrow_message0(msg, connection);
            break;
            }
        
        dbus_message_unref(msg);
    }
    
    dbus_connection_unref(connection);
//    dbus_connection_close(connection);
}

-----------  End Server code --------------        
        
 
Regards,
Sumit
 
Sumit Kumar Jain
Call me: +91-9880472974





      Share files, take polls, and discuss your passions - all under one roof. Go to http://in.promos.yahoo.com/groups
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20080225/1105fcf1/attachment.html 


More information about the dbus mailing list