1 #include "test-utils.h"
6 DBusConnection *connection;
11 connection_watch_callback (DBusWatch *watch,
12 unsigned int condition,
15 return dbus_watch_handle (watch, condition);
19 add_watch (DBusWatch *watch,
24 return _dbus_loop_add_watch (cd->loop,
26 connection_watch_callback,
31 remove_watch (DBusWatch *watch,
36 _dbus_loop_remove_watch (cd->loop,
37 watch, connection_watch_callback, cd);
41 connection_timeout_callback (DBusTimeout *timeout,
46 /* Can return FALSE on OOM but we just let it fire again later */
47 dbus_timeout_handle (timeout);
51 add_timeout (DBusTimeout *timeout,
56 return _dbus_loop_add_timeout (cd->loop,
57 timeout, connection_timeout_callback, cd, NULL);
61 remove_timeout (DBusTimeout *timeout,
66 _dbus_loop_remove_timeout (cd->loop,
67 timeout, connection_timeout_callback, cd);
71 dispatch_status_function (DBusConnection *connection,
72 DBusDispatchStatus new_status,
75 DBusLoop *loop = data;
77 if (new_status != DBUS_DISPATCH_COMPLETE)
79 while (!_dbus_loop_queue_dispatch (loop, connection))
80 _dbus_wait_for_memory ();
85 cdata_free (void *data)
89 dbus_connection_unref (cd->connection);
90 _dbus_loop_unref (cd->loop);
96 cdata_new (DBusLoop *loop,
97 DBusConnection *connection)
101 cd = dbus_new0 (CData, 1);
106 cd->connection = connection;
108 dbus_connection_ref (cd->connection);
109 _dbus_loop_ref (cd->loop);
115 test_connection_setup (DBusLoop *loop,
116 DBusConnection *connection)
122 dbus_connection_set_dispatch_status_function (connection, dispatch_status_function,
125 cd = cdata_new (loop, connection);
129 /* Because dbus-mainloop.c checks dbus_timeout_get_enabled(),
130 * dbus_watch_get_enabled() directly, we don't have to provide
131 * "toggled" callbacks.
134 if (!dbus_connection_set_watch_functions (connection,
142 cd = cdata_new (loop, connection);
146 if (!dbus_connection_set_timeout_functions (connection,
153 if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
155 if (!_dbus_loop_queue_dispatch (loop, connection))
165 dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
166 dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL);
167 dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
173 test_connection_shutdown (DBusLoop *loop,
174 DBusConnection *connection)
176 if (!dbus_connection_set_watch_functions (connection,
181 _dbus_assert_not_reached ("setting watch functions to NULL failed");
183 if (!dbus_connection_set_timeout_functions (connection,
188 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
190 dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);