From f0e48cbd791e88728fcea65366dbb6d9a63a16e5 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 24 Jun 2021 12:38:32 +0200 Subject: monitor: allow register hmp commands Allow commands having a NULL cmd pointer, add a function to set the pointer later. Use case: allow modules implement hmp commands. Signed-off-by: Gerd Hoffmann Reviewed-by: Jose R. Ziviani Message-Id: <20210624103836.2382472-31-kraxel@redhat.com> Signed-off-by: Paolo Bonzini --- monitor/misc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'monitor/misc.c') diff --git a/monitor/misc.c b/monitor/misc.c index 1539e18557..ad476c6e51 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -1974,6 +1974,22 @@ static void sortcmdlist(void) compare_mon_cmd); } +void monitor_register_hmp(const char *name, bool info, + void (*cmd)(Monitor *mon, const QDict *qdict)) +{ + HMPCommand *table = info ? hmp_info_cmds : hmp_cmds; + + while (table->name != NULL) { + if (strcmp(table->name, name) == 0) { + g_assert(table->cmd == NULL); + table->cmd = cmd; + return; + } + table++; + } + g_assert_not_reached(); +} + void monitor_init_globals(void) { monitor_init_globals_core(); -- cgit 1.4.1