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>
Marc-André Lureau committed
Jun 23, 2026 at 11:44 UTC
6ca4df5e9c9054fcbf094bb94704c973890410fd
2 files changed
+41
include/ui/console.h
+18
@@ -415,6 +415,24 @@ const char *qemu_display_get_vc(DisplayOptions *opts);
415
void qemu_display_cleanup(void);
416
void qemu_display_help(void);
417
418
+/*
419
+ * Console notifications:
420
+ * Handlers must be idempotent, it may notify multiple times.
421
+ */
422
+typedef enum {
423
+ QEMU_CONSOLE_ADDED,
424
+ QEMU_CONSOLE_REMOVED,
425
+} QemuConsoleEventType;
426
+
427
+typedef struct QemuConsoleEvent {
428
+ QemuConsoleEventType type;
429
+ QemuConsole *con;
430
+} QemuConsoleEvent;
431
+
432
+void qemu_console_add_notifier(Notifier *notifier);
433
+void qemu_console_remove_notifier(Notifier *notifier);
434
+void qemu_console_notify(QemuConsoleEventType type, QemuConsole *con);
435
+
436
/* vnc.c */
437
void vnc_display_add_client(const char *id, int csock, bool skipauth);
438
int vnc_display_password(const char *id, const char *password, Error **errp);
ui/console.c
+23
@@ -70,6 +70,7 @@ struct DisplayState {
70
bool refreshing;
71
72
QLIST_HEAD(, DisplayChangeListener) listeners;
73
+ NotifierList console_notifiers;
74
};
75
76
static DisplayState *display_state;
@@ -84,6 +85,16 @@ static bool console_compatible_with(QemuConsole *con,
85
static QemuConsole *qemu_graphic_console_lookup_unused(void);
86
static void dpy_set_ui_info_timer(void *opaque);
87
88
+void qemu_console_notify(QemuConsoleEventType type, QemuConsole *con)
89
+{
90
+ DisplayState *ds = get_alloc_displaystate();
91
+ QemuConsoleEvent event = {
92
+ .type = type,
93
+ .con = con,
94
+ };
95
+ notifier_list_notify(&ds->console_notifiers, &event);
96
+}
97
+
98
static void gui_update(void *opaque)
99
{
100
uint64_t interval = GUI_REFRESH_INTERVAL_IDLE;
@@ -1056,10 +1067,22 @@ static DisplayState *get_alloc_displaystate(void)
1067
{
1068
if (!display_state) {
1069
display_state = g_new0(DisplayState, 1);
1070
+ notifier_list_init(&display_state->console_notifiers);
1071
}
1072
return display_state;
1073
}
1074
1075
+void qemu_console_add_notifier(Notifier *notifier)
1076
+{
1077
+ DisplayState *ds = get_alloc_displaystate();
1078
+ notifier_list_add(&ds->console_notifiers, notifier);
1079
+}
1080
+
1081
+void qemu_console_remove_notifier(Notifier *notifier)
1082
+{
1083
+ notifier_remove(notifier);
1084
+}
1085
+
1086
/*
1087
* Called by main(), after creating QemuConsoles
1088
* and before initializing ui (sdl/vnc/...).