2 #include "test-utils.h"
7 DBusConnection *connection;
12 add_watch (DBusWatch *watch,
17 return _dbus_loop_add_watch (cd->loop, watch);
21 remove_watch (DBusWatch *watch,
26 _dbus_loop_remove_watch (cd->loop, watch);
30 toggle_watch (DBusWatch *watch,
35 _dbus_loop_toggle_watch (cd->loop, watch);
39 add_timeout (DBusTimeout *timeout,
44 return _dbus_loop_add_timeout (cd->loop, timeout);
48 remove_timeout (DBusTimeout *timeout,
53 _dbus_loop_remove_timeout (cd->loop, timeout);
57 dispatch_status_function (DBusConnection *connection,
58 DBusDispatchStatus new_status,
61 DBusLoop *loop = data;
63 if (new_status != DBUS_DISPATCH_COMPLETE)
65 while (!_dbus_loop_queue_dispatch (loop, connection))
66 _dbus_wait_for_memory ();
71 cdata_free (void *data)
75 dbus_connection_unref (cd->connection);
76 _dbus_loop_unref (cd->loop);
82 cdata_new (DBusLoop *loop,
83 DBusConnection *connection)
87 cd = dbus_new0 (CData, 1);
92 cd->connection = connection;
94 dbus_connection_ref (cd->connection);
95 _dbus_loop_ref (cd->loop);
101 test_connection_setup (DBusLoop *loop,
102 DBusConnection *connection)
108 dbus_connection_set_dispatch_status_function (connection, dispatch_status_function,
111 cd = cdata_new (loop, connection);
115 if (!dbus_connection_set_watch_functions (connection,
123 cd = cdata_new (loop, connection);
127 if (!dbus_connection_set_timeout_functions (connection,
134 if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
136 if (!_dbus_loop_queue_dispatch (loop, connection))
146 dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
147 dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL);
148 dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
154 test_connection_shutdown (DBusLoop *loop,
155 DBusConnection *connection)
157 if (!dbus_connection_set_watch_functions (connection,
162 _dbus_assert_not_reached ("setting watch functions to NULL failed");
164 if (!dbus_connection_set_timeout_functions (connection,
169 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
171 dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
181 serverdata_free (void *data)
183 ServerData *sd = data;
185 dbus_server_unref (sd->server);
186 _dbus_loop_unref (sd->loop);
192 serverdata_new (DBusLoop *loop,
197 sd = dbus_new0 (ServerData, 1);
204 dbus_server_ref (sd->server);
205 _dbus_loop_ref (sd->loop);
211 add_server_watch (DBusWatch *watch,
214 ServerData *context = data;
216 return _dbus_loop_add_watch (context->loop, watch);
220 toggle_server_watch (DBusWatch *watch,
223 ServerData *context = data;
225 _dbus_loop_toggle_watch (context->loop, watch);
229 remove_server_watch (DBusWatch *watch,
232 ServerData *context = data;
234 _dbus_loop_remove_watch (context->loop, watch);
238 add_server_timeout (DBusTimeout *timeout,
241 ServerData *context = data;
243 return _dbus_loop_add_timeout (context->loop, timeout);
247 remove_server_timeout (DBusTimeout *timeout,
250 ServerData *context = data;
252 _dbus_loop_remove_timeout (context->loop, timeout);
256 test_server_setup (DBusLoop *loop,
261 sd = serverdata_new (loop, server);
265 if (!dbus_server_set_watch_functions (server,
275 sd = serverdata_new (loop, server);
279 if (!dbus_server_set_timeout_functions (server,
281 remove_server_timeout,
283 sd, serverdata_free))
291 serverdata_free (sd);
293 test_server_shutdown (loop, server);
299 test_server_shutdown (DBusLoop *loop,
302 dbus_server_disconnect (server);
304 if (!dbus_server_set_watch_functions (server,
308 _dbus_assert_not_reached ("setting watch functions to NULL failed");
310 if (!dbus_server_set_timeout_functions (server,
314 _dbus_assert_not_reached ("setting timeout functions to NULL failed");