Suggestion: dbus_connection_set_suspended to temporarily suspend DBUS-Input

Friedemann Kleint (Fa. metis) kleint at bifab.de
Mon Sep 27 12:22:40 UTC 2004


Hi,

I would like to suggest the following patch:

- API extension: 

    dbus_connection_set_suspended(DBusConnection *connection,
                                  dbus_bool_t suspended)
    
    Suspends dispatching of DBUS-Messages.

- Aim:

    There are  situations    (mainly in GUI-applications) in which
    one does not want IPC-messages   to interfer with normal event
    processing for a limited amount of time.   
    
    For example,    the application  may   perform   some  lenghty
    operation in a background  thread and does mainloop-iterations
    while waiting for the thread  to   terminate.   In  this case,
    only expose-events should be processed.
    
    There should be a function to suspend DBUS-input. On resuming,
    all pending messages should be delivered.
    
    So far, the Qt/Glib  bindings offer no such function;  one
    would have to re-do the mainloop integration.

- Solution: 

   Havoc suggested setting the receive   size  to a low value, but
   this causes messages to be lost.
   
   I added  a   "suspended" flag the  connection-structure   which
   causes  _dbus_connection_get_dispatch_status_unlocked()      to
   return  DISPATCH_COMPLETE    if set. There might a more elegant
   way to do this?  

-Friedemann Kleint

    
--------------- Patch (applicable to dbus-0.22)-------------
--- dbus-0.22/dbus/dbus-connection.c.orig	2004-09-27 11:16:41.010029000 +0200
+++ dbus-0.22/dbus/dbus-connection.c	2004-09-27 13:29:45.340001000 +0200
@@ -203,6 +203,7 @@
   DBusDispatchStatusFunction dispatch_status_function; /**< Function on dispatch status changes  */
   void *dispatch_status_data; /**< Application data for dispatch_status_function */
   DBusFreeFunction free_dispatch_status_data; /**< free dispatch_status_data */
+  dbus_bool_t suspended; /**< Message dispatching suspended */
 
   DBusDispatchStatus last_dispatch_status; /**< The last dispatch status we reported to the application. */
 
@@ -905,6 +906,7 @@
   connection->pending_replies = pending_replies;
   connection->outgoing_counter = outgoing_counter;
   connection->filter_list = NULL;
+  connection->suspended =  FALSE;
   connection->last_dispatch_status = DBUS_DISPATCH_COMPLETE; /* so we're notified first time there's data */
   connection->objects = objects;
   connection->exit_on_disconnect = FALSE;
@@ -2340,6 +2342,8 @@
 static DBusDispatchStatus
 _dbus_connection_get_dispatch_status_unlocked (DBusConnection *connection)
 {
+  if (connection->suspended)
+    return DBUS_DISPATCH_COMPLETE;
   if (connection->n_incoming > 0)
     return DBUS_DISPATCH_DATA_REMAINS;
   else if (!_dbus_transport_queue_messages (connection->transport))
@@ -2408,6 +2412,27 @@
 }
 
 /**
+ * Suspend dispatching of messages.
+ *
+ * @param connection the connection.
+ * @param suspended flag indicating state.
+ */
+
+void
+dbus_connection_set_suspended(DBusConnection *connection,
+                              dbus_bool_t suspended)
+{
+    _dbus_return_if_fail (connection != NULL);
+
+    CONNECTION_LOCK (connection);
+
+    connection->suspended = suspended;
+
+    CONNECTION_UNLOCK (connection);
+}
+
+
+/**
  * Gets the current state (what we would currently return
  * from dbus_connection_dispatch()) but doesn't actually
  * dispatch any messages.
--- dbus-0.22/dbus/dbus-connection.h.orig	2004-09-27 11:16:50.980001000 +0200
+++ dbus-0.22/dbus/dbus-connection.h	2004-09-27 13:25:03.390000000 +0200
@@ -104,6 +104,8 @@
                                                                  DBusMessage                *message);
 DBusMessage*       dbus_connection_pop_message                  (DBusConnection             *connection);
 DBusDispatchStatus dbus_connection_get_dispatch_status          (DBusConnection             *connection);
+void               dbus_connection_set_suspended                (DBusConnection *connection,
+                                                                 dbus_bool_t suspended);
 DBusDispatchStatus dbus_connection_dispatch                     (DBusConnection             *connection);
 dbus_bool_t        dbus_connection_send                         (DBusConnection             *connection,


More information about the dbus mailing list