diff options
| author | John (J5) Palmieri <johnp@redhat.com> | 2005-11-30 20:30:02 +0000 | 
|---|---|---|
| committer | John (J5) Palmieri <johnp@redhat.com> | 2005-11-30 20:30:02 +0000 | 
| commit | 263d1dfdd40b87f62648c4c5c50e8a6472fd5322 (patch) | |
| tree | d11ab5f717ed29e3cf96efaf528d8e0e5f5ae12d | |
| parent | 982592992055de23aa7fee61a72d7c71228c1469 (diff) | |
* 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.
| -rw-r--r-- | ChangeLog | 10 | ||||
| -rw-r--r-- | dbus/dbus-connection.c | 80 | ||||
| -rw-r--r-- | dbus/dbus-connection.h | 2 | 
3 files changed, 84 insertions, 8 deletions
| @@ -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 diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 3c8c765d..0c9fe28d 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -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. diff --git a/dbus/dbus-connection.h b/dbus/dbus-connection.h index 70369d3f..9784f260 100644 --- a/dbus/dbus-connection.h +++ b/dbus/dbus-connection.h @@ -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); | 
