} CData;
-dbus_bool_t
-test_connection_dispatch_one_message (DBusConnection *connection)
-{
- DBusDispatchStatus status;
-
- while ((status = dbus_connection_dispatch (connection)) == DBUS_DISPATCH_NEED_MEMORY)
- _dbus_wait_for_memory ();
-
- return status == DBUS_DISPATCH_DATA_REMAINS;
-}
-
-void
-test_connection_dispatch_all_messages (DBusConnection *connection)
-{
- while (test_connection_dispatch_one_message (connection))
- ;
-}
-
static dbus_bool_t
connection_watch_callback (DBusWatch *watch,
unsigned int condition,
void *data)
{
- CData *cd = data;
- dbus_bool_t retval;
-
- dbus_connection_ref (cd->connection);
-
- retval = dbus_connection_handle_watch (cd->connection, watch, condition);
-
- test_connection_dispatch_all_messages (cd->connection);
-
- dbus_connection_unref (cd->connection);
-
- return retval;
+ return dbus_watch_handle (watch, condition);
}
static dbus_bool_t
{
CData *cd = data;
- dbus_connection_ref (cd->connection);
-
/* Can return FALSE on OOM but we just let it fire again later */
dbus_timeout_handle (timeout);
-
- test_connection_dispatch_all_messages (cd->connection);
-
- dbus_connection_unref (cd->connection);
}
static dbus_bool_t
}
static void
+dispatch_status_function (DBusConnection *connection,
+ DBusDispatchStatus new_status,
+ void *data)
+{
+ DBusLoop *loop = data;
+
+ if (new_status != DBUS_DISPATCH_COMPLETE)
+ {
+ while (!_dbus_loop_queue_dispatch (loop, connection))
+ _dbus_wait_for_memory ();
+ }
+}
+
+static void
cdata_free (void *data)
{
CData *cd = data;
{
CData *cd;
+ cd = NULL;
+
+ dbus_connection_set_dispatch_status_function (connection, dispatch_status_function,
+ loop, NULL);
+
cd = cdata_new (loop, connection);
if (cd == NULL)
goto nomem;
remove_timeout,
NULL,
cd, cdata_free))
+ goto nomem;
+
+ if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
{
- dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL);
- goto nomem;
+ if (!_dbus_loop_queue_dispatch (loop, connection))
+ goto nomem;
}
-
+
return TRUE;
nomem:
if (cd)
cdata_free (cd);
+
+ dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
+ dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL);
+ dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
+
return FALSE;
}
+
+void
+test_connection_shutdown (DBusLoop *loop,
+ DBusConnection *connection)
+{
+ if (!dbus_connection_set_watch_functions (connection,
+ NULL,
+ NULL,
+ NULL,
+ NULL, NULL))
+ _dbus_assert_not_reached ("setting watch functions to NULL failed");
+
+ if (!dbus_connection_set_timeout_functions (connection,
+ NULL,
+ NULL,
+ NULL,
+ NULL, NULL))
+ _dbus_assert_not_reached ("setting timeout functions to NULL failed");
+
+ dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
+}