mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:10 +00:00
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>
This commit is contained in:
committed by
Markus Armbruster
parent
d5b007ae8d
commit
da85de2934
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user