Commit bb90b1a3 authored by Ralf Habacker's avatar Ralf Habacker

Add dbus bus method org.freedesktop.DBus.EmbeddedTests.Shutdown

This method is used by test-autolaunch to shutdown dbus daemon and
is enabled only when DBUS_ENABLED_EMBEDDED_TESTS is set.
parent fd36c2b6
......@@ -132,8 +132,8 @@ static dbus_bool_t expire_incomplete_timeout (void *data);
#define BUS_CONNECTION_DATA(connection) (dbus_connection_get_data ((connection), connection_data_slot))
static DBusLoop*
connection_get_loop (DBusConnection *connection)
DBusLoop*
bus_connection_get_loop (DBusConnection *connection)
{
BusConnectionData *d;
......@@ -360,7 +360,7 @@ add_connection_watch (DBusWatch *watch,
{
DBusConnection *connection = data;
return _dbus_loop_add_watch (connection_get_loop (connection), watch);
return _dbus_loop_add_watch (bus_connection_get_loop (connection), watch);
}
static void
......@@ -369,7 +369,7 @@ remove_connection_watch (DBusWatch *watch,
{
DBusConnection *connection = data;
_dbus_loop_remove_watch (connection_get_loop (connection), watch);
_dbus_loop_remove_watch (bus_connection_get_loop (connection), watch);
}
static void
......@@ -378,7 +378,7 @@ toggle_connection_watch (DBusWatch *watch,
{
DBusConnection *connection = data;
_dbus_loop_toggle_watch (connection_get_loop (connection), watch);
_dbus_loop_toggle_watch (bus_connection_get_loop (connection), watch);
}
static dbus_bool_t
......@@ -387,7 +387,7 @@ add_connection_timeout (DBusTimeout *timeout,
{
DBusConnection *connection = data;
return _dbus_loop_add_timeout (connection_get_loop (connection), timeout);
return _dbus_loop_add_timeout (bus_connection_get_loop (connection), timeout);
}
static void
......@@ -396,7 +396,7 @@ remove_connection_timeout (DBusTimeout *timeout,
{
DBusConnection *connection = data;
_dbus_loop_remove_timeout (connection_get_loop (connection), timeout);
_dbus_loop_remove_timeout (bus_connection_get_loop (connection), timeout);
}
static void
......
......@@ -127,6 +127,8 @@ dbus_bool_t bus_connection_be_monitor (DBusConnection *connection,
DBusList **rules,
DBusError *error);
DBusLoop* bus_connection_get_loop (DBusConnection *connection);
/* transaction API so we can send or not send a block of messages as a whole */
typedef void (* BusTransactionCancelFunction) (void *data);
......
......@@ -2219,6 +2219,43 @@ bus_driver_handle_disable_verbose (DBusConnection *connection,
}
#endif
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static dbus_bool_t
bus_driver_handle_shutdown (DBusConnection *connection,
BusTransaction *transaction,
DBusMessage *message,
DBusError *error)
{
DBusLoop *loop = NULL;
DBusMessage *reply = NULL;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
reply = dbus_message_new_method_return (message);
if (reply == NULL)
goto oom;
if (! bus_transaction_send_from_driver (transaction, connection, reply))
goto oom;
loop = bus_connection_get_loop (connection);
_dbus_loop_quit (loop);
_dbus_verbose ("Got shutdown request - quit event loop\n");
dbus_message_unref (reply);
return TRUE;
oom:
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
BUS_SET_OOM (error);
if (reply)
dbus_message_unref (reply);
return FALSE;
}
#endif
static dbus_bool_t
bus_driver_handle_get_id (DBusConnection *connection,
BusTransaction *transaction,
......@@ -2671,6 +2708,14 @@ static const MessageHandler verbose_message_handlers[] = {
};
#endif
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static const MessageHandler verbose_embedded_tests_handlers[] = {
{ "Shutdown", "", "", bus_driver_handle_shutdown,
METHOD_FLAG_PRIVILEGED },
{ NULL, NULL, NULL, NULL }
};
#endif
#ifdef DBUS_ENABLE_STATS
static const MessageHandler stats_message_handlers[] = {
{ "GetStats", "", "a{sv}", bus_stats_handle_get_stats,
......@@ -2755,6 +2800,10 @@ static InterfaceHandler interface_handlers[] = {
{ DBUS_INTERFACE_VERBOSE, verbose_message_handlers, NULL,
INTERFACE_FLAG_NONE },
#endif
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
{ DBUS_INTERFACE_EMBEDDED_TESTS, verbose_embedded_tests_handlers, NULL,
INTERFACE_FLAG_NONE },
#endif
#ifdef DBUS_ENABLE_STATS
{ BUS_INTERFACE_STATS, stats_message_handlers, NULL,
INTERFACE_FLAG_NONE },
......
......@@ -93,6 +93,8 @@ typedef enum
/** The verbose interface exported by the dbus-daemon */
#define DBUS_INTERFACE_VERBOSE "org.freedesktop.DBus.Verbose"
/** The embedded tests interface exported by the dbus-daemon */
#define DBUS_INTERFACE_EMBEDDED_TESTS "org.freedesktop.DBus.EmbeddedTests"
/** The interface supported by introspectable objects */
#define DBUS_INTERFACE_INTROSPECTABLE "org.freedesktop.DBus.Introspectable"
/** The interface supported by objects with properties */
......
......@@ -1791,6 +1791,7 @@ check_interfaces (DBusMessageIter *var_iter)
gboolean have_monitoring = FALSE;
gboolean have_stats = FALSE;
gboolean have_verbose = FALSE;
gboolean have_embedded_tests = FALSE;
g_assert_cmpint (dbus_message_iter_get_arg_type (var_iter), ==,
DBUS_TYPE_ARRAY);
......@@ -1818,7 +1819,10 @@ check_interfaces (DBusMessageIter *var_iter)
have_stats = TRUE;
else if (g_strcmp0 (iface, DBUS_INTERFACE_VERBOSE) == 0)
have_verbose = TRUE;
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
else if (g_strcmp0 (iface, DBUS_INTERFACE_EMBEDDED_TESTS) == 0)
have_embedded_tests = TRUE;
#endif
dbus_message_iter_next (&arr_iter);
}
......@@ -1835,6 +1839,12 @@ check_interfaces (DBusMessageIter *var_iter)
#else
g_assert_false (have_verbose);
#endif
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
g_assert_true (have_embedded_tests);
#else
g_assert_false (have_embedded_tests);
#endif
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment