1 #include "../test-utils.h"
4 die (const char *message, ...)
7 va_start (args, message);
8 vfprintf (stderr, message, args);
13 typedef struct TestServiceData TestServiceData;
15 struct TestServiceData
22 new_connection_callback (DBusServer *server,
23 DBusConnection *new_connection,
26 TestServiceData *testdata = data;
28 if (!test_connection_setup (testdata->loop, new_connection))
29 dbus_connection_close (new_connection);
32 static DBusHandlerResult
33 filter_session_message (DBusConnection *connection,
37 TestServiceData *testdata = user_data;
39 if (dbus_message_is_method_call (message,
40 "org.freedesktop.DBus.TestSuite.TestServer",
44 reply = dbus_message_new_method_return (message);
45 dbus_message_append_args (reply, DBUS_TYPE_STRING,
46 &(testdata->private_addr), DBUS_TYPE_INVALID);
47 dbus_connection_send (connection, reply, NULL);
48 dbus_message_unref (reply);
49 return DBUS_HANDLER_RESULT_HANDLED;
51 else if (dbus_message_is_method_call (message,
52 "org.freedesktop.DBus.TestSuite.TestServer",
55 fprintf (stderr, "server exiting loop\n");
56 _dbus_loop_quit (testdata->loop);
57 return DBUS_HANDLER_RESULT_HANDLED;
59 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
63 main (int argc, char *argv[])
68 DBusConnection *session;
69 TestServiceData *testdata;
71 dbus_error_init (&error);
73 loop = _dbus_loop_new ();
75 testdata = dbus_new (TestServiceData, 1);
76 testdata->loop = loop;
78 session = dbus_bus_get (DBUS_BUS_SESSION, &error);
80 die ("couldn't access session bus");
82 test_connection_setup (loop, session);
84 dbus_bus_request_name (session, "org.freedesktop.DBus.TestSuite.TestServer", 0, &error);
85 if (dbus_error_is_set (&error))
86 die ("couldn't request name: %s", error.message);
88 if (!dbus_connection_add_filter (session, filter_session_message, testdata, NULL))
89 die ("couldn't add filter");
91 server = dbus_server_listen ("unix:tmpdir=/tmp", &error);
94 testdata->private_addr = dbus_server_get_address (server);
95 printf ("test server listening on %s\n", testdata->private_addr);
97 dbus_server_set_new_connection_function (server, new_connection_callback,
100 if (!test_server_setup (loop, server))
101 die ("server setup failed");
103 fprintf (stderr, "server running mainloop\n");
104 _dbus_loop_run (loop);
105 fprintf (stderr, "server mainloop quit\n");
107 test_server_shutdown (loop, server);
109 test_connection_shutdown (loop, session);
111 dbus_connection_unref (session);
113 _dbus_loop_unref (loop);
115 dbus_free (testdata);