monitor: add monitor_cur_hmp() helper
This will help to simplify the code in the following changes. Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260828-qemu-no-hmp-v5-33-9227de146347@redhat.com>
Marc-André Lureau committed
Aug 28, 2026 at 16:04 UTC
7204d4c2c0bc2b23b77776775dd5ea0785fca43c
4 files changed
+22
include/monitor/hmp.h
+2
@@ -36,6 +36,8 @@ struct MonitorDef {
36
void monitor_new_hmp(const char *id, const char *chardev_id,
37
bool use_readline, Error **errp);
38
39
+MonitorHMP *monitor_cur_hmp(void);
40
+
41
int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
42
G_GNUC_PRINTF(2, 0);
43
int monitor_printf(Monitor *mon, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
monitor/hmp.c
+10
@@ -47,6 +47,16 @@
47
48
OBJECT_DEFINE_TYPE(MonitorHMP, monitor_hmp, MONITOR_HMP, MONITOR);
49
50
+MonitorHMP *monitor_cur_hmp(void)
51
+{
52
+ Monitor *mon = monitor_cur();
53
+ if (mon) {
54
+ return (MonitorHMP *)object_dynamic_cast(OBJECT(mon),
55
+ TYPE_MONITOR_HMP);
56
+ }
57
+ return NULL;
58
+}
59
+
60
static void monitor_hmp_finalize(Object *obj)
61
{
62
MonitorHMP *hmp = MONITOR_HMP(obj);
stubs/meson.build
+1
@@ -7,6 +7,7 @@ stub_ss.add(files('fdset.c'))
7
stub_ss.add(files('iothread-lock.c'))
8
stub_ss.add(files('is-daemonized.c'))
9
stub_ss.add(files('monitor-core.c'))
10
+stub_ss.add(files('monitor-hmp.c'))
11
stub_ss.add(files('replay-mode.c'))
12
stub_ss.add(files('trace-control.c'))
13
stubs/monitor-hmp.c
new
+9
@@ -0,0 +1,9 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
2
+
3
+#include "qemu/osdep.h"
4
+#include "monitor/hmp.h"
5
+
6
+MonitorHMP *monitor_cur_hmp(void)
7
+{
8
+ return NULL;
9
+}