ui/dbus: do not limit to one listener per connection / bus name

This is an arbitrary limitation that doesn't concern QEMU directly and
may make some use cases unnecessarily more complicated.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-ID: <20241008125028.1177932-11-marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2024-10-08 16:50:19 +04:00
parent 1bfb726112
commit 2448ff392c

View File

@ -41,7 +41,7 @@ struct _DBusDisplayConsole {
DisplayChangeListener dcl; DisplayChangeListener dcl;
DBusDisplay *display; DBusDisplay *display;
GHashTable *listeners; GPtrArray *listeners;
QemuDBusDisplay1Console *iface; QemuDBusDisplay1Console *iface;
QemuDBusDisplay1Keyboard *iface_kbd; QemuDBusDisplay1Keyboard *iface_kbd;
@ -142,8 +142,7 @@ dbus_display_console_init(DBusDisplayConsole *object)
{ {
DBusDisplayConsole *ddc = DBUS_DISPLAY_CONSOLE(object); DBusDisplayConsole *ddc = DBUS_DISPLAY_CONSOLE(object);
ddc->listeners = g_hash_table_new_full(g_str_hash, g_str_equal, ddc->listeners = g_ptr_array_new_with_free_func(g_object_unref);
NULL, g_object_unref);
ddc->dcl.ops = &dbus_console_dcl_ops; ddc->dcl.ops = &dbus_console_dcl_ops;
} }
@ -157,7 +156,7 @@ dbus_display_console_dispose(GObject *object)
g_clear_object(&ddc->iface_mouse); g_clear_object(&ddc->iface_mouse);
g_clear_object(&ddc->iface_kbd); g_clear_object(&ddc->iface_kbd);
g_clear_object(&ddc->iface); g_clear_object(&ddc->iface);
g_clear_pointer(&ddc->listeners, g_hash_table_unref); g_clear_pointer(&ddc->listeners, g_ptr_array_unref);
g_clear_pointer(&ddc->kbd, qkbd_state_free); g_clear_pointer(&ddc->kbd, qkbd_state_free);
G_OBJECT_CLASS(dbus_display_console_parent_class)->dispose(object); G_OBJECT_CLASS(dbus_display_console_parent_class)->dispose(object);
@ -179,7 +178,7 @@ listener_vanished_cb(DBusDisplayListener *listener)
trace_dbus_listener_vanished(name); trace_dbus_listener_vanished(name);
g_hash_table_remove(ddc->listeners, name); g_ptr_array_remove_fast(ddc->listeners, listener);
qkbd_state_lift_all_keys(ddc->kbd); qkbd_state_lift_all_keys(ddc->kbd);
} }
@ -267,16 +266,6 @@ dbus_console_register_listener(DBusDisplayConsole *ddc,
DBusDisplayListener *listener; DBusDisplayListener *listener;
int fd; int fd;
if (sender && g_hash_table_contains(ddc->listeners, sender)) {
g_dbus_method_invocation_return_error(
invocation,
DBUS_DISPLAY_ERROR,
DBUS_DISPLAY_ERROR_INVALID,
"`%s` is already registered!",
sender);
return DBUS_METHOD_INVOCATION_HANDLED;
}
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
if (!dbus_win32_import_socket(invocation, arg_listener, &fd)) { if (!dbus_win32_import_socket(invocation, arg_listener, &fd)) {
return DBUS_METHOD_INVOCATION_HANDLED; return DBUS_METHOD_INVOCATION_HANDLED;
@ -331,9 +320,7 @@ dbus_console_register_listener(DBusDisplayConsole *ddc,
return DBUS_METHOD_INVOCATION_HANDLED; return DBUS_METHOD_INVOCATION_HANDLED;
} }
g_hash_table_insert(ddc->listeners, g_ptr_array_add(ddc->listeners, listener);
(gpointer)dbus_display_listener_get_bus_name(listener),
listener);
g_object_connect(listener_conn, g_object_connect(listener_conn,
"swapped-signal::closed", listener_vanished_cb, listener, "swapped-signal::closed", listener_vanished_cb, listener,
NULL); NULL);