<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> DBusConnection* connection;<br> DBusError error;<br> DBusMessage* msg;<br> DBusMessage* borrow_message;<br> DBusMessage* reply = NULL;<br> dbus_int32_t no =
5;<br> char error_name[40];<br> char error_msg[40];<br> <br> dbus_error_init(&error);<br> <br> connection = dbus_bus_get(DBUS_BUS_SESSION, &error);<br> <br> msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "dbus_connection_borrow_message0");<br> <br> reply = dbus_connection_send_with_reply_and_block(connection, msg, 10000, &error);<br> <br> dbus_message_get_args(reply, &error, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID);<br> <br>
borrow_message = dbus_connection_borrow_message (connection ) ;<br> <br> if(borrow_message)<br> printf("Error\n");<br> <br> return 0;<br>} <br><br>---------- end client code ----<br><br>----- Server code ----<br>#include<stdio.h> <br>#include "test-utils.h"<br>#include<string.h> <br>#include<ctype.h><br>#include<unistd.h> // sleep function is defined in this header file <br>#define TEST_BUS_NAME_TEMP "Test.Method.Call"<br> <br>void called_dbus_connection_borrow_message0(DBusMessage* msg,DBusConnection* connection)<br> {<br> DBusMessage* reply; <br> dbus_int32_t arg;<br> dbus_int32_t return_value =
9090;<br><br> reply = dbus_message_new_method_return(msg);<br> <br> dbus_message_append_args(reply, DBUS_TYPE_INT32, &return_value, DBUS_TYPE_INVALID);<br> dbus_connection_send(connection, reply, NULL);<br> dbus_connection_flush(connection);<br> }<br>void called_dbus_connection_pop_message0(DBusMessage* msg,DBusConnection* connection)<br> {<br> DBusMessage* reply; <br> dbus_int32_t arg;<br> //dbus_int32_t return_value = 9090;<br><br> reply = dbus_message_new_method_return(msg);<br> <br> //dbus_message_append_args(reply, DBUS_TYPE_INT32, &return_value, DBUS_TYPE_INVALID);<br> dbus_connection_send(connection, reply, NULL);<br>
dbus_connection_flush(connection);<br> }<br><br>int main(int argc, char* argv[])<br>{<br> DBusError error;<br> DBusError error1;<br> DBusConnection* connection;<br> DBusMessage* msg;<br> DBusObjectPathVTable vtable;<br> <br> dbus_error_init(&error);<br> dbus_error_init(&error1);<br> fprintf(stdout, "Starting Method");<br>// getchar();<br> <br> connection = dbus_bus_get(DBUS_BUS_SESSION, &error);<br> <br> if(dbus_error_is_set(&error))<br> {<br> fprintf(stdout, "Error Occured :: %s", error.name);<br>// getchar();<br> return
1;<br> }<br> <br><br> <br> if(dbus_connection_register_object_path (connection, "/Test/Method/Object", &vtable, NULL))<br> {<br> fprintf(stdout, "Object Path registered.");<br>// getchar();<br> }<br> else<br> {<br> fprintf(stdout, "Object Path not able to register.");<br>// getchar();<br> return 1;<br> }<br> <br><br><br> if(dbus_bus_request_name (connection, TEST_BUS_NAME_TEMP, DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &error1) == -1)<br> {<br> fprintf(stdout, "Not able to request name.");<br>//
getchar();<br> }<br> else<br> {<br> fprintf(stdout, "Name Request Successful");<br>// getchar();<br> }<br> <br> while(TRUE)<br> { <br> dbus_connection_read_write(connection, 0);<br> <br> msg = dbus_connection_pop_message(connection);<br> <br> if(msg == NULL)<br> {<br> sleep(1);<br> continue;<br> }<br>
<br> fprintf(stdout, "Message Detected");<br> <br> if(DBUS_MESSAGE_TYPE_SIGNAL == dbus_message_get_type(msg))<br> {<br> fprintf(stdout, "Message is Signal.");<br> }<br> <br> if(DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg))<br> {<br> fprintf(stdout, "Message is Method call.");<br> // getchar();<br> }<br> <br>
<br> if(dbus_message_is_method_call(msg, "test.Method.Call", "dbus_connection_borrow_message0"))<br> {<br> <br> called_dbus_connection_borrow_message0(msg, connection);<br> break;<br> }<br> <br> dbus_message_unref(msg);<br> }<br> <br> dbus_connection_unref(connection);<br>// dbus_connection_close(connection);<br>}<br><br>----------- End Server code -------------- <br>
<br><div> </div><p>Regards,</p><p>Sumit</p><p> </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>