ui/console: add console event notifier infrastructure

Add a NotifierList to DisplayState so display backends can be notified
when consoles are added or removed at runtime.

No events are fired yet, that follows in the next commits.

Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260623-b4-ui-v4-23-4656aec3398d@redhat.com>
This commit is contained in:
Marc-André Lureau
2026-06-23 11:44:38 +04:00
parent b09e45f77a
commit 6ca4df5e9c
2 changed files with 41 additions and 0 deletions

View File

@@ -415,6 +415,24 @@ const char *qemu_display_get_vc(DisplayOptions *opts);
void qemu_display_cleanup(void);
void qemu_display_help(void);
/*
* Console notifications:
* Handlers must be idempotent, it may notify multiple times.
*/
typedef enum {
QEMU_CONSOLE_ADDED,
QEMU_CONSOLE_REMOVED,
} QemuConsoleEventType;
typedef struct QemuConsoleEvent {
QemuConsoleEventType type;
QemuConsole *con;
} QemuConsoleEvent;
void qemu_console_add_notifier(Notifier *notifier);
void qemu_console_remove_notifier(Notifier *notifier);
void qemu_console_notify(QemuConsoleEventType type, QemuConsole *con);
/* vnc.c */
void vnc_display_add_client(const char *id, int csock, bool skipauth);
int vnc_display_password(const char *id, const char *password, Error **errp);

View File

@@ -70,6 +70,7 @@ struct DisplayState {
bool refreshing;
QLIST_HEAD(, DisplayChangeListener) listeners;
NotifierList console_notifiers;
};
static DisplayState *display_state;
@@ -84,6 +85,16 @@ static bool console_compatible_with(QemuConsole *con,
static QemuConsole *qemu_graphic_console_lookup_unused(void);
static void dpy_set_ui_info_timer(void *opaque);
void qemu_console_notify(QemuConsoleEventType type, QemuConsole *con)
{
DisplayState *ds = get_alloc_displaystate();
QemuConsoleEvent event = {
.type = type,
.con = con,
};
notifier_list_notify(&ds->console_notifiers, &event);
}
static void gui_update(void *opaque)
{
uint64_t interval = GUI_REFRESH_INTERVAL_IDLE;
@@ -1056,10 +1067,22 @@ static DisplayState *get_alloc_displaystate(void)
{
if (!display_state) {
display_state = g_new0(DisplayState, 1);
notifier_list_init(&display_state->console_notifiers);
}
return display_state;
}
void qemu_console_add_notifier(Notifier *notifier)
{
DisplayState *ds = get_alloc_displaystate();
notifier_list_add(&ds->console_notifiers, notifier);
}
void qemu_console_remove_notifier(Notifier *notifier)
{
notifier_remove(notifier);
}
/*
* Called by main(), after creating QemuConsoles
* and before initializing ui (sdl/vnc/...).