[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> 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>
_______________________________________________
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