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 <kraxel@redhat.com>
Reviewed-by: Jose R. Ziviani <jziviani@suse.de>
Message-Id: <20210624103836.2382472-31-kraxel@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Gerd Hoffmann 2021-06-24 12:38:32 +02:00 committed by Paolo Bonzini
parent dae0ec159f
commit f0e48cbd79
3 changed files with 26 additions and 0 deletions

View file

@ -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();