dbus/dbus dbus-connection.c, 1.114, 1.115 dbus-connection.h, 1.39,
1.40
John Palmieri
johnp at freedesktop.org
Wed Nov 30 12:30:04 PST 2005
Update of /cvs/dbus/dbus/dbus
In directory gabe:/tmp/cvs-serv16415/dbus
Modified Files:
dbus-connection.c dbus-connection.h
Log Message:
* dbus/dbus-connection.c (dbus_connection_read_write): Add new
method for getting messages off the bus in the absence of a
mainloop. This method is much like
dbus_connection_read_write_dispatch except it does not dispatch
the messages to a registered filter function. Instead it
allows a developer to process messages by directly popping
them off the bus.
Index: dbus-connection.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.c,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -d -r1.114 -r1.115
--- dbus-connection.c 30 Nov 2005 19:32:26 -0000 1.114
+++ dbus-connection.c 30 Nov 2005 20:30:02 -0000 1.115
@@ -2847,11 +2847,11 @@
* In this usage you would normally have set up a filter function to look
* at each message as it is dispatched. The loop terminates when the last
* message from the connection (the disconnected signal) is processed.
- *
- * If there are messages to dispatch, this function will
- * dbus_connection_dispatch() once, and return. If there are no
- * messages to dispatch, this function will block until it can read or
- * write, then read or write, then return.
+ *
+ * If there are messages to dispatch and the dispatch flag is set, this
+ * function will dbus_connection_dispatch() once, and return. If there are no
+ * messages to dispatch, this function will block until it can read or write,
+ * then read or write, then return.
*
* The way to think of this function is that it either makes some sort
* of progress, or it blocks.
@@ -2863,11 +2863,13 @@
*
* @param connection the connection
* @param timeout_milliseconds max time to block or -1 for infinite
+ * @param dispatch dispatch new messages or leave them on the incoming queue
* @returns #TRUE if the disconnect message has not been processed
*/
dbus_bool_t
-dbus_connection_read_write_dispatch (DBusConnection *connection,
- int timeout_milliseconds)
+_dbus_connection_read_write_dispatch (DBusConnection *connection,
+ int timeout_milliseconds,
+ dbus_bool_t dispatch)
{
DBusDispatchStatus dstatus;
dbus_bool_t dispatched_disconnected;
@@ -2876,7 +2878,7 @@
_dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1, FALSE);
dstatus = dbus_connection_get_dispatch_status (connection);
- if (dstatus == DBUS_DISPATCH_DATA_REMAINS)
+ if (dispatch && dstatus == DBUS_DISPATCH_DATA_REMAINS)
{
_dbus_verbose ("doing dispatch in %s\n", _DBUS_FUNCTION_NAME);
dbus_connection_dispatch (connection);
@@ -2909,6 +2911,68 @@
return !dispatched_disconnected; /* TRUE if we have not processed disconnected */
}
+
+/**
+ * This function is intended for use with applications that don't want
+ * to write a main loop and deal with #DBusWatch and #DBusTimeout. An
+ * example usage would be:
+ *
+ * @code
+ * while (dbus_connection_read_write_dispatch (connection, -1))
+ * ; // empty loop body
+ * @endcode
+ *
+ * In this usage you would normally have set up a filter function to look
+ * at each message as it is dispatched. The loop terminates when the last
+ * message from the connection (the disconnected signal) is processed.
+ *
+ * If there are messages to dispatch, this function will
+ * dbus_connection_dispatch() once, and return. If there are no
+ * messages to dispatch, this function will block until it can read or
+ * write, then read or write, then return.
+ *
+ * The way to think of this function is that it either makes some sort
+ * of progress, or it blocks.
+ *
+ * The return value indicates whether the disconnect message has been
+ * processed, NOT whether the connection is connected. This is
+ * important because even after disconnecting, you want to process any
+ * messages you received prior to the disconnect.
+ *
+ * @param connection the connection
+ * @param timeout_milliseconds max time to block or -1 for infinite
+ * @returns #TRUE if the disconnect message has not been processed
+ */
+dbus_bool_t
+dbus_connection_read_write_dispatch (DBusConnection *connection,
+ int timeout_milliseconds)
+{
+ return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds, TRUE);
+}
+
+/**
+ * This function is intended for use with applications that don't want to
+ * write a main loop and deal with #DBusWatch and #DBusTimeout.
+ *
+ * If there are no messages to dispatch, this function will block until it can
+ * read or write, then read or write, then return.
+ *
+ * The return value indicates whether the disconnect message has been
+ * processed, NOT whether the connection is connected. This is important
+ * because even after disconnecting, you want to process any messages you
+ * received prior to the disconnect.
+ *
+ * @param connection the connection
+ * @param timeout_milliseconds max time to block or -1 for infinite
+ * @returns #TRUE if the disconnect message has not been processed
+ */
+dbus_bool_t
+dbus_connection_read_write (DBusConnection *connection,
+ int timeout_milliseconds)
+{
+ return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds, FALSE);
+}
+
/**
* Returns the first-received message from the incoming message queue,
* leaving it in the queue. If the queue is empty, returns #NULL.
Index: dbus-connection.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- dbus-connection.h 6 Jun 2005 18:55:22 -0000 1.39
+++ dbus-connection.h 30 Nov 2005 20:30:02 -0000 1.40
@@ -102,6 +102,8 @@
void dbus_connection_flush (DBusConnection *connection);
dbus_bool_t dbus_connection_read_write_dispatch (DBusConnection *connection,
int timeout_milliseconds);
+dbus_bool_t dbus_connection_read_write (DBusConnection *connection,
+ int timeout_milliseconds);
DBusMessage* dbus_connection_borrow_message (DBusConnection *connection);
void dbus_connection_return_message (DBusConnection *connection,
DBusMessage *message);
More information about the dbus-commit
mailing list