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,
41 _dbus_verbose ("sending reply to Echo method\n");
43 if (!dbus_connection_get_object_path_data (connection, echo_path, (void **)&d))
47 dbus_error_init (&error);
49 reply = dbus_message_new_method_return (message);
53 dbus_message_iter_init_append (reply, &iter);
54 for (i = 0; i < d->argc; ++i)
55 if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &(d->argv[i])))
58 if (!dbus_connection_send (connection, reply, NULL))
61 fprintf (stderr, "Shell echo service echoed the command line\n");
63 dbus_message_unref (reply);
65 return DBUS_HANDLER_RESULT_HANDLED;
69 path_unregistered_func (DBusConnection *connection,
72 /* connection was finalized */
75 static DBusHandlerResult
76 path_message_func (DBusConnection *connection,
80 if (dbus_message_is_method_call (message,
81 "org.freedesktop.TestSuite",
83 return handle_echo (connection, message);
84 else if (dbus_message_is_method_call (message,
85 "org.freedesktop.TestSuite",
89 return DBUS_HANDLER_RESULT_HANDLED;
92 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
95 static DBusObjectPathVTable
97 path_unregistered_func,
102 static DBusHandlerResult
103 filter_func (DBusConnection *connection,
104 DBusMessage *message,
107 if (dbus_message_is_signal (message,
108 DBUS_INTERFACE_LOCAL,
112 return DBUS_HANDLER_RESULT_HANDLED;
116 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
124 DBusConnection *connection;
129 echo_data.argc = argc;
130 echo_data.argv = argv;
132 dbus_error_init (&error);
133 connection = dbus_bus_get (DBUS_BUS_STARTER, &error);
134 if (connection == NULL)
136 fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n",
138 dbus_error_free (&error);
142 loop = _dbus_loop_new ();
146 if (!test_connection_setup (loop, connection))
149 if (!dbus_connection_add_filter (connection,
150 filter_func, NULL, NULL))
153 if (!dbus_connection_register_object_path (connection,
161 if (!dbus_connection_get_object_path_data (connection, echo_path, &d))
163 if (d != (void*) &echo_data)
164 die ("dbus_connection_get_object_path_data() doesn't seem to work right\n");
167 result = dbus_bus_request_name (connection, "org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess",
169 if (dbus_error_is_set (&error))
171 fprintf (stderr, "Error %s\n", error.message);
172 _dbus_verbose ("*** Failed to acquire service: %s\n",
174 dbus_error_free (&error);
178 _dbus_verbose ("*** Test service entering main loop\n");
179 _dbus_loop_run (loop);
181 test_connection_shutdown (loop, connection);
183 dbus_connection_remove_filter (connection, filter_func, NULL);
185 dbus_connection_unref (connection);
187 _dbus_loop_unref (loop);
192 _dbus_verbose ("*** Test service exiting\n");