2 #include "../test-utils.h"
5 die (const char *message, ...)
8 va_start (args, message);
9 vfprintf (stderr, message, args);
14 typedef struct TestServiceData TestServiceData;
16 struct TestServiceData
23 new_connection_callback (DBusServer *server,
24 DBusConnection *new_connection,
27 TestServiceData *testdata = data;
29 if (!test_connection_setup (testdata->loop, new_connection))
30 dbus_connection_close (new_connection);
33 static DBusHandlerResult
34 filter_session_message (DBusConnection *connection,
38 TestServiceData *testdata = user_data;
40 if (dbus_message_is_method_call (message,
41 "org.freedesktop.DBus.TestSuite.PrivServer",
45 reply = dbus_message_new_method_return (message);
46 dbus_message_append_args (reply, DBUS_TYPE_STRING,
47 &(testdata->private_addr), DBUS_TYPE_INVALID);
48 dbus_connection_send (connection, reply, NULL);
49 dbus_message_unref (reply);
50 return DBUS_HANDLER_RESULT_HANDLED;
52 else if (dbus_message_is_method_call (message,
53 "org.freedesktop.DBus.TestSuite.PrivServer",
56 fprintf (stderr, "server exiting loop\n");
57 _dbus_loop_quit (testdata->loop);
58 return DBUS_HANDLER_RESULT_HANDLED;
60 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
64 main (int argc, char *argv[])
69 DBusConnection *session;
70 TestServiceData *testdata;
72 dbus_error_init (&error);
74 loop = _dbus_loop_new ();
76 testdata = dbus_new (TestServiceData, 1);
77 testdata->loop = loop;
79 session = dbus_bus_get (DBUS_BUS_SESSION, &error);
81 die ("couldn't access session bus");
83 test_connection_setup (loop, session);
85 dbus_bus_request_name (session, "org.freedesktop.DBus.TestSuite.PrivServer", 0, &error);
86 if (dbus_error_is_set (&error))
87 die ("couldn't request name: %s", error.message);
89 if (!dbus_connection_add_filter (session, filter_session_message, testdata, NULL))
90 die ("couldn't add filter");
92 server = dbus_server_listen ("unix:tmpdir=/tmp", &error);
95 testdata->private_addr = dbus_server_get_address (server);
96 printf ("test server listening on %s\n", testdata->private_addr);
98 dbus_server_set_new_connection_function (server, new_connection_callback,
101 if (!test_server_setup (loop, server))
102 die ("server setup failed");
104 fprintf (stderr, "server running mainloop\n");
105 _dbus_loop_run (loop);
106 fprintf (stderr, "server mainloop quit\n");
108 test_server_shutdown (loop, server);
110 test_connection_shutdown (loop, session);
112 dbus_connection_unref (session);
114 _dbus_loop_unref (loop);
116 dbus_free (testdata);