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.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
include/ui/console.h | 18 ++++++++++++++++++
ui/console.c | 23 +++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/include/ui/console.h b/include/ui/console.h
index 1c7f7e62c1a..44ebc578651 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -442,6 +442,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);
diff --git a/ui/console.c b/ui/console.c
index 1fe3e3a3a6c..76851bc129d 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -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/...).
--
2.54.0