2 #include "test-utils.h"
5 static dbus_bool_t already_quit = FALSE;
6 static const char* echo_path = "/org/freedesktop/TestSuite";
19 _dbus_loop_quit (loop);
25 die (const char *message)
27 fprintf (stderr, "*** test-service: %s", message);
31 static DBusHandlerResult
32 handle_echo (DBusConnection *connection,
42 _dbus_verbose ("sending reply to Echo method\n");
44 if (!dbus_connection_get_object_path_data (connection, echo_path, &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",
89 dbus_connection_close (connection);
91 return DBUS_HANDLER_RESULT_HANDLED;
94 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
97 static DBusObjectPathVTable
99 path_unregistered_func,
104 static DBusHandlerResult
105 filter_func (DBusConnection *connection,
106 DBusMessage *message,
109 if (dbus_message_is_signal (message,
110 DBUS_INTERFACE_LOCAL,
113 dbus_connection_close (connection);
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 _dbus_verbose ("*** Test service entering main loop\n");
182 _dbus_loop_run (loop);
184 test_connection_shutdown (loop, connection);
186 dbus_connection_remove_filter (connection, filter_func, NULL);
188 dbus_connection_unref (connection);
190 _dbus_loop_unref (loop);
195 _dbus_verbose ("*** Test service exiting\n");