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>
---
monitor/hmp.c | 16 ++++++++++++++++
monitor/monitor-internal.h | 5 +++++
monitor/monitor.c | 12 +++---------
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);
--
2.55.0