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);
25 static void die (const char *message) _DBUS_GNUC_NORETURN;
28 die (const char *message)
30 fprintf (stderr, "*** test-service: %s", message);
34 static DBusHandlerResult
35 handle_echo (DBusConnection *connection,
44 _dbus_verbose ("sending reply to Echo method\n");
46 if (!dbus_connection_get_object_path_data (connection, echo_path, (void **)&d))
50 dbus_error_init (&error);
52 reply = dbus_message_new_method_return (message);
56 dbus_message_iter_init_append (reply, &iter);
57 for (i = 0; i < d->argc; ++i)
58 if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &(d->argv[i])))
61 if (!dbus_connection_send (connection, reply, NULL))
64 fprintf (stderr, "Shell echo service echoed the command line\n");
66 dbus_message_unref (reply);
68 return DBUS_HANDLER_RESULT_HANDLED;
72 path_unregistered_func (DBusConnection *connection,
75 /* connection was finalized */
78 static DBusHandlerResult
79 path_message_func (DBusConnection *connection,
83 if (dbus_message_is_method_call (message,
84 "org.freedesktop.TestSuite",
86 return handle_echo (connection, message);
87 else if (dbus_message_is_method_call (message,
88 "org.freedesktop.TestSuite",
92 return DBUS_HANDLER_RESULT_HANDLED;
95 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
98 static DBusObjectPathVTable
100 path_unregistered_func,
105 static DBusHandlerResult
106 filter_func (DBusConnection *connection,
107 DBusMessage *message,
110 if (dbus_message_is_signal (message,
111 DBUS_INTERFACE_LOCAL,
115 return DBUS_HANDLER_RESULT_HANDLED;
119 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
127 DBusConnection *connection;
132 echo_data.argc = argc;
133 echo_data.argv = argv;
135 dbus_error_init (&error);
136 connection = dbus_bus_get (DBUS_BUS_STARTER, &error);
137 if (connection == NULL)
139 fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n",
141 dbus_error_free (&error);
145 loop = _dbus_loop_new ();
149 if (!test_connection_setup (loop, connection))
152 if (!dbus_connection_add_filter (connection,
153 filter_func, NULL, NULL))
156 if (!dbus_connection_register_object_path (connection,
164 if (!dbus_connection_get_object_path_data (connection, echo_path, &d))
166 if (d != (void*) &echo_data)
167 die ("dbus_connection_get_object_path_data() doesn't seem to work right\n");
170 result = dbus_bus_request_name (connection, "org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess",
172 if (dbus_error_is_set (&error))
174 fprintf (stderr, "Error %s\n", error.message);
175 _dbus_verbose ("*** Failed to acquire service: %s\n",
177 dbus_error_free (&error);
181 if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
183 fprintf (stderr, "Unable to acquire service: code %d\n", result);
184 _dbus_verbose ("*** Failed to acquire service: %d\n", result);
188 _dbus_verbose ("*** Test service entering main loop\n");
189 _dbus_loop_run (loop);
191 test_connection_shutdown (loop, connection);
193 dbus_connection_remove_filter (connection, filter_func, NULL);
195 dbus_connection_unref (connection);
197 _dbus_loop_unref (loop);
202 _dbus_verbose ("*** Test service exiting\n");