mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:17 +00:00
monitor: use class methods for monitor_qapi_event_emit
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-14-berrange@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
committed by
Markus Armbruster
parent
f51c560959
commit
d5b007ae8d
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "block/block.h"
|
||||
#include "qapi/qapi-types-misc.h"
|
||||
#include "qapi/qapi-emit-events.h"
|
||||
#include "qemu/readline.h"
|
||||
#include "exec/hwaddr.h"
|
||||
#include "qom/object.h"
|
||||
|
||||
@@ -111,6 +111,11 @@ struct MonitorClass {
|
||||
*/
|
||||
int (*vprintf)(Monitor *mon, const char *fmt, va_list ap)
|
||||
G_GNUC_PRINTF(2, 0);
|
||||
/*
|
||||
* If non-NULL, the monitor is able to send event
|
||||
* notifications back to the client
|
||||
*/
|
||||
void (*emit_event)(Monitor *mon, QAPIEvent event, QDict *qdict);
|
||||
};
|
||||
|
||||
struct Monitor {
|
||||
|
||||
@@ -348,22 +348,13 @@ static inline QEMUClockType monitor_get_event_clock(void)
|
||||
static void monitor_qapi_event_emit(QAPIEvent event, QDict *qdict)
|
||||
{
|
||||
Monitor *mon;
|
||||
MonitorQMP *qmp_mon;
|
||||
|
||||
trace_monitor_protocol_event_emit(event, qdict);
|
||||
QTAILQ_FOREACH(mon, &mon_list, entry) {
|
||||
if (!monitor_is_qmp(mon)) {
|
||||
continue;
|
||||
MonitorClass *cls = MONITOR_GET_CLASS(mon);
|
||||
if (cls->emit_event) {
|
||||
cls->emit_event(mon, event, qdict);
|
||||
}
|
||||
|
||||
qmp_mon = container_of(mon, MonitorQMP, parent_obj);
|
||||
{
|
||||
QEMU_LOCK_GUARD(&mon->mon_lock);
|
||||
if (qmp_mon->commands == &qmp_cap_negotiation_commands) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
qmp_send_response(qmp_mon, qdict);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,11 +99,17 @@ static void monitor_qmp_set_pretty(Object *obj, bool val, Error **errp)
|
||||
mon->pretty = val;
|
||||
}
|
||||
|
||||
static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *qdict);
|
||||
|
||||
static void monitor_qmp_class_init(ObjectClass *cls, const void *data)
|
||||
{
|
||||
MonitorClass *moncls = MONITOR_CLASS(cls);
|
||||
|
||||
object_class_property_add_bool(cls, "pretty",
|
||||
monitor_qmp_get_pretty,
|
||||
monitor_qmp_set_pretty);
|
||||
|
||||
moncls->emit_event = monitor_qmp_emit_event;
|
||||
}
|
||||
|
||||
static void handle_qmp_command(void *opaque, QObject *req, Error *err);
|
||||
@@ -117,6 +123,20 @@ static void monitor_qmp_init(Object *obj)
|
||||
json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL);
|
||||
}
|
||||
|
||||
static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *qdict)
|
||||
{
|
||||
MonitorQMP *qmp = MONITOR_QMP(mon);
|
||||
|
||||
WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
|
||||
if (qmp->commands == &qmp_cap_negotiation_commands) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
qmp_send_response(qmp, qdict);
|
||||
}
|
||||
|
||||
|
||||
static bool qmp_oob_enabled(MonitorQMP *mon)
|
||||
{
|
||||
return mon->capab[QMP_CAPABILITY_OOB];
|
||||
|
||||
Reference in New Issue
Block a user