* dbus/dbus-connection.c (dbus_connection_read_write): Add new
authorJohn (J5) Palmieri <johnp@redhat.com>
Wed, 30 Nov 2005 20:30:02 +0000 (20:30 +0000)
committerJohn (J5) Palmieri <johnp@redhat.com>
Wed, 30 Nov 2005 20:30:02 +0000 (20:30 +0000)
  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.

ChangeLog
dbus/dbus-connection.c
dbus/dbus-connection.h

index 8b5b184..a9c39e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2005-11-30  John (J5) Palmieri  <johnp@redhat.com>
 
+       * 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.
+
+2005-11-30  John (J5) Palmieri  <johnp@redhat.com>
+
        * bus/desktop-file.c (parse_key_value): Ignore locales allowing 
        the parser to continue instead of returning error
        (bus_desktop_file_load): Do not free parser data when
index 3c8c765..0c9fe28 100644 (file)
@@ -2847,11 +2847,11 @@ dbus_connection_flush (DBusConnection *connection)
  * 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 @@ dbus_connection_flush (DBusConnection *connection)
  *
  * @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_connection_read_write_dispatch (DBusConnection *connection,
   _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 @@ dbus_connection_read_write_dispatch (DBusConnection *connection,
   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 70369d3..9784f26 100644 (file)
@@ -102,6 +102,8 @@ void               dbus_connection_set_exit_on_disconnect       (DBusConnection
 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);