[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freedesktop-dbus
Subject:    dbus_connection_send_with_reply_and_block error
From:       Sumit Kumar Jain <sumitskj_20 () yahoo ! com>
Date:       2008-02-26 7:07:44
Message-ID: 472656.22253.qm () web31008 ! mail ! mud ! yahoo ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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


[Attachment #5 (text/html)]

<html><head><style type="text/css"><!-- DIV {margin:0px;} \
--></style></head><body><div \
style="font-family:arial,helvetica,sans-serif;font-size:12pt">Hi,<br>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. \
<br><br>Any help. Have I misinterpreted the documentation by any chance.<br><br>The \
below test code demonstrates  the issue.<br><br>---- client code ---<br>int \
main()<br>{<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DBusConnection* \
connection;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DBusError \
error;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DBusMessage* \
msg;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DBusMessage* \
borrow_message;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DBusMessage* reply = \
NULL;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dbus_int32_t no =  \
5;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char \
error_name[40];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char \
error_msg[40];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; dbus_error_init(&amp;error);<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; connection = \
dbus_bus_get(DBUS_BUS_SESSION, &amp;error);<br>&nbsp;&nbsp;&nbsp; \
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; msg = \
dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", \
"test.Method.Call", "dbus_connection_borrow_message0");<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;  <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; reply = \
dbus_connection_send_with_reply_and_block(connection, msg, 10000, \
&amp;error);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;  <br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; dbus_message_get_args(reply, &amp;error, DBUS_TYPE_INT32, &amp;no, \
DBUS_TYPE_INVALID);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;  <br>&nbsp;&nbsp;&nbsp;  \
&nbsp;&nbsp;&nbsp; borrow_message =&nbsp; dbus_connection_borrow_message (connection \
)&nbsp;&nbsp; ;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;  \
if(borrow_message)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;  &nbsp;&nbsp;  \
printf("Error\n");<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  \
return 0;<br>}&nbsp;&nbsp;  <br><br>---------- end client code ----<br><br>----- \
Server code ----<br>#include&lt;stdio.h&gt;&nbsp; <br>#include \
"test-utils.h"<br>#include&lt;string.h&gt; \
<br>#include&lt;ctype.h&gt;<br>#include&lt;unistd.h&gt;&nbsp; // sleep function is \
defined in this header file <br>#define TEST_BUS_NAME_TEMP \
"Test.Method.Call"<br>&nbsp;&nbsp;&nbsp;  <br>void \
called_dbus_connection_borrow_message0(DBusMessage* msg,DBusConnection* \
connection)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; DBusMessage* \
reply;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; dbus_int32_t \
arg;<br>&nbsp;&nbsp;&nbsp; dbus_int32_t return_value =  \
9090;<br><br>&nbsp;&nbsp;&nbsp; reply = \
dbus_message_new_method_return(msg);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; \
dbus_message_append_args(reply, DBUS_TYPE_INT32, &amp;return_value, \
DBUS_TYPE_INVALID);<br>&nbsp;&nbsp;&nbsp; dbus_connection_send(connection, reply, \
NULL);<br>&nbsp;&nbsp;&nbsp; dbus_connection_flush(connection);<br>&nbsp;&nbsp;&nbsp; \
}<br>void called_dbus_connection_pop_message0(DBusMessage* msg,DBusConnection* \
connection)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; DBusMessage* \
reply;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; dbus_int32_t \
arg;<br>&nbsp;&nbsp;&nbsp; //dbus_int32_t return_value = \
9090;<br><br>&nbsp;&nbsp;&nbsp; reply = \
dbus_message_new_method_return(msg);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; \
//dbus_message_append_args(reply, DBUS_TYPE_INT32, &amp;return_value, \
DBUS_TYPE_INVALID);<br>&nbsp;&nbsp;&nbsp; dbus_connection_send(connection, reply, \
NULL);<br>&nbsp;&nbsp;&nbsp;  \
dbus_connection_flush(connection);<br>&nbsp;&nbsp;&nbsp; }<br><br>int main(int argc, \
char* argv[])<br>{<br>&nbsp;&nbsp;&nbsp; DBusError error;<br>&nbsp;&nbsp;&nbsp; \
DBusError error1;<br>&nbsp;&nbsp;&nbsp; DBusConnection* \
connection;<br>&nbsp;&nbsp;&nbsp; DBusMessage* msg;<br>&nbsp;&nbsp;&nbsp; \
DBusObjectPathVTable vtable;<br>&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; \
dbus_error_init(&amp;error);<br>&nbsp;&nbsp;&nbsp; \
dbus_error_init(&amp;error1);<br>&nbsp;&nbsp;&nbsp; fprintf(stdout, "Starting \
Method");<br>//&nbsp;&nbsp;&nbsp; getchar();<br>&nbsp;&nbsp;&nbsp; \
<br>&nbsp;&nbsp;&nbsp; connection = dbus_bus_get(DBUS_BUS_SESSION, \
&amp;error);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; \
if(dbus_error_is_set(&amp;error))<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; fprintf(stdout, "Error Occured :: %s", \
error.name);<br>//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
getchar();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return  1;<br>&nbsp;&nbsp;&nbsp; \
}<br>&nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; \
if(dbus_connection_register_object_path (connection, "/Test/Method/Object", \
&amp;vtable, NULL))<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
fprintf(stdout, "Object Path registered.");<br>//&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; getchar();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; \
else<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stdout, \
"Object Path not able to register.");<br>//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
getchar();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return 1;<br>&nbsp;&nbsp;&nbsp; \
}<br>&nbsp;<br><br><br>&nbsp;&nbsp;&nbsp; if(dbus_bus_request_name (connection, \
TEST_BUS_NAME_TEMP, DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &amp;error1) == \
-1)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stdout, \
"Not able to request name.");<br>//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  \
getchar();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; \
{<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stdout, "Name Request \
Successful");<br>//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
getchar();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; \
while(TRUE)<br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; dbus_connection_read_write(connection, 0);<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; msg = \
dbus_connection_pop_message(connection);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(msg == \
NULL)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sleep(1);<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; continue;<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  \
&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stdout, \
"Message Detected");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; if(DBUS_MESSAGE_TYPE_SIGNAL == \
dbus_message_get_type(msg))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
{<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stdout, \
"Message is Signal.");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
if(DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg))<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
fprintf(stdout, "Message is Method call.");<br>&nbsp;&nbsp;&nbsp; \
//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; getchar();<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  <br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; if(dbus_message_is_method_call(msg, "test.Method.Call", \
"dbus_connection_borrow_message0"))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
called_dbus_connection_borrow_message0(msg, connection);<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; dbus_message_unref(msg);<br>&nbsp;&nbsp;&nbsp; \
}<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; \
dbus_connection_unref(connection);<br>//&nbsp;&nbsp;&nbsp; \
dbus_connection_close(connection);<br>}<br><br>-----------&nbsp; End Server code \
-------------- &nbsp;&nbsp; &nbsp;&nbsp;  <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  \
<br><div>&nbsp;</div><p>Regards,</p><p>Sumit</p><p>&nbsp;</p><p>Sumit Kumar \
Jain</p><p>Call me: +91-9880472974</p><div><br></div></div><br>


      <!--10--><hr size=1></hr> Chat on a cool, new interface. No download required. \
<a href="http://in.rd.yahoo.com/tagline_webmessenger_10/*http://in.messenger.yahoo.com/webmessengerpromo.php">Click \
here.</a></body></html>



_______________________________________________
dbus mailing list
dbus@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dbus


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic