summaryrefslogtreecommitdiff
path: root/monitor
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2026-07-06 14:58:02 +0100
committerMarkus Armbruster <armbru@redhat.com>2026-07-07 11:16:24 +0200
commitda85de2934e0600328d2f68e3fb56c634d4e4298 (patch)
tree395c63e7d65c5ce0b2fca781d9779e27fcb03c8b /monitor
parentd5b007ae8d4e5707eda863ff9bd7bc90e26bebf2 (diff)
downloadqemu-da85de2934e0600328d2f68e3fb56c634d4e4298.tar.gz
qemu-da85de2934e0600328d2f68e3fb56c634d4e4298.zip
monitor: use class methods for monitor_accept_input
This removes the need for using monitor_is_qmp() to check the subclass type, which is an anti-pattern. Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Tested-by: Peter Krempa <pkrempa@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20260706135824.2623960-15-berrange@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'monitor')
-rw-r--r--monitor/hmp.c16
-rw-r--r--monitor/monitor-internal.h5
-rw-r--r--monitor/monitor.c12
3 files changed, 24 insertions, 9 deletions
diff --git a/monitor/hmp.c b/monitor/hmp.c
index f9252387c4..4636165d0b 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -70,6 +70,7 @@ static void monitor_hmp_set_readline(Object *obj, bool val, Error **errp)
int monitor_hmp_vprintf(Monitor *mon, const char *fmt, va_list ap)
G_GNUC_PRINTF(2, 0);
+static void monitor_hmp_accept_input(Monitor *mon);
static void monitor_hmp_class_init(ObjectClass *cls, const void *data)
{
@@ -80,6 +81,7 @@ static void monitor_hmp_class_init(ObjectClass *cls, const void *data)
monitor_hmp_set_readline);
moncls->vprintf = monitor_hmp_vprintf;
+ moncls->accept_input = monitor_hmp_accept_input;
}
static void monitor_hmp_init(Object *obj)
@@ -100,6 +102,20 @@ int monitor_hmp_vprintf(Monitor *mon, const char *fmt, va_list ap)
return monitor_puts(mon, buf);
}
+static void monitor_hmp_accept_input(Monitor *mon)
+{
+ qemu_mutex_lock(&mon->mon_lock);
+ if (mon->reset_seen) {
+ MonitorHMP *hmp = MONITOR_HMP(mon);
+ assert(hmp->rs);
+ readline_restart(hmp->rs);
+ qemu_mutex_unlock(&mon->mon_lock);
+ readline_show_prompt(hmp->rs);
+ } else {
+ qemu_mutex_unlock(&mon->mon_lock);
+ }
+}
+
static void monitor_command_cb(void *opaque, const char *cmdline,
void *readline_opaque)
{
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index 763b5c9625..592f146331 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -116,6 +116,11 @@ struct MonitorClass {
* notifications back to the client
*/
void (*emit_event)(Monitor *mon, QAPIEvent event, QDict *qdict);
+ /*
+ * If non-NULL, perform any actions needed to prepare
+ * the monitor to accept further client input
+ */
+ void (*accept_input)(Monitor *mon);
};
struct Monitor {
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 90cfb59c66..6e63e7a5c7 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -578,16 +578,10 @@ int monitor_suspend(Monitor *mon)
static void monitor_accept_input(void *opaque)
{
Monitor *mon = opaque;
+ MonitorClass *cls = MONITOR_GET_CLASS(mon);
- qemu_mutex_lock(&mon->mon_lock);
- if (!monitor_is_qmp(mon) && mon->reset_seen) {
- MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, parent_obj);
- assert(hmp_mon->rs);
- readline_restart(hmp_mon->rs);
- qemu_mutex_unlock(&mon->mon_lock);
- readline_show_prompt(hmp_mon->rs);
- } else {
- qemu_mutex_unlock(&mon->mon_lock);
+ if (cls->accept_input) {
+ cls->accept_input(mon);
}
qemu_chr_fe_accept_input(&mon->chr);