3 #include "test-utils.h"
6 static dbus_bool_t already_quit = FALSE;
7 static const char* echo_path = "/org/freedesktop/TestSuite";
20 _dbus_loop_quit (loop);
26 die (const char *message)
28 fprintf (stderr, "*** test-service: %s", message);
32 static DBusHandlerResult
33 handle_echo (DBusConnection *connection,
42 _dbus_verbose ("sending reply to Echo method\n");
44 if (!dbus_connection_get_object_path_data (connection, echo_path, (void **)&d))
48 dbus_error_init (&error);
50 reply = dbus_message_new_method_return (message);
54 dbus_message_iter_init_append (reply, &iter);
55 for (i = 0; i < d->argc; ++i)
56 if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &(d->argv[i])))
59 if (!dbus_connection_send (connection, reply, NULL))
62 fprintf (stderr, "Shell echo service echoed the command line\n");
64 dbus_message_unref (reply);
66 return DBUS_HANDLER_RESULT_HANDLED;
70 path_unregistered_func (DBusConnection *connection,
73 /* connection was finalized */
76 static DBusHandlerResult
77 path_message_func (DBusConnection *connection,
81 if (dbus_message_is_method_call (message,
82 "org.freedesktop.TestSuite",
84 return handle_echo (connection, message);
85 else if (dbus_message_is_method_call (message,
86 "org.freedesktop.TestSuite",
90 return DBUS_HANDLER_RESULT_HANDLED;
93 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
96 static DBusObjectPathVTable
98 path_unregistered_func,
103 static DBusHandlerResult
104 filter_func (DBusConnection *connection,
105 DBusMessage *message,
108 if (dbus_message_is_signal (message,
109 DBUS_INTERFACE_LOCAL,
113 return DBUS_HANDLER_RESULT_HANDLED;
117 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
125 DBusConnection *connection;
130 echo_data.argc = argc;
131 echo_data.argv = argv;
133 dbus_error_init (&error);
134 connection = dbus_bus_get (DBUS_BUS_STARTER, &error);
135 if (connection == NULL)
137 fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n",
139 dbus_error_free (&error);
143 loop = _dbus_loop_new ();
147 if (!test_connection_setup (loop, connection))
150 if (!dbus_connection_add_filter (connection,
151 filter_func, NULL, NULL))
154 if (!dbus_connection_register_object_path (connection,
162 if (!dbus_connection_get_object_path_data (connection, echo_path, &d))
164 if (d != (void*) &echo_data)
165 die ("dbus_connection_get_object_path_data() doesn't seem to work right\n");
168 result = dbus_bus_request_name (connection, "org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess",
170 if (dbus_error_is_set (&error))
172 fprintf (stderr, "Error %s\n", error.message);
173 _dbus_verbose ("*** Failed to acquire service: %s\n",
175 dbus_error_free (&error);
179 if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
181 fprintf (stderr, "Unable to acquire service: code %d\n", result);
182 _dbus_verbose ("*** Failed to acquire service: %d\n", result);
186 _dbus_verbose ("*** Test service entering main loop\n");
187 _dbus_loop_run (loop);
189 test_connection_shutdown (loop, connection);
191 dbus_connection_remove_filter (connection, filter_func, NULL);
193 dbus_connection_unref (connection);
195 _dbus_loop_unref (loop);
200 _dbus_verbose ("*** Test service exiting\n");