]> git.proxmox.com Git - mirror_qemu.git/blame - qapi/qmp-registry.c
Merge remote-tracking branch 'remotes/kraxel/tags/audio-20210316-pull-request' into...
[mirror_qemu.git] / qapi / qmp-registry.c
CommitLineData
43c20a43
MR
1/*
2 * Core Definitions for QAPI/QMP Dispatch
3 *
4 * Copyright IBM, Corp. 2011
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 * Michael Roth <mdroth@us.ibm.com>
9 *
10 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
11 * See the COPYING.LIB file in the top-level directory.
12 *
13 */
14
cbf21151 15#include "qemu/osdep.h"
7b1b5d19 16#include "qapi/qmp/dispatch.h"
43c20a43 17
1527badb
MA
18void qmp_register_command(QmpCommandList *cmds, const char *name,
19 QmpCommandFunc *fn, QmpCommandOptions options)
43c20a43 20{
7267c094 21 QmpCommand *cmd = g_malloc0(sizeof(*cmd));
43c20a43 22
9ce44e2c
KW
23 /* QCO_COROUTINE and QCO_ALLOW_OOB are incompatible for now */
24 assert(!((options & QCO_COROUTINE) && (options & QCO_ALLOW_OOB)));
25
43c20a43 26 cmd->name = name;
43c20a43 27 cmd->fn = fn;
abd6cf6d 28 cmd->enabled = true;
d34b867d 29 cmd->options = options;
1527badb 30 QTAILQ_INSERT_TAIL(cmds, cmd, node);
43c20a43
MR
31}
32
f0ccc00b 33const QmpCommand *qmp_find_command(const QmpCommandList *cmds, const char *name)
43c20a43 34{
abd6cf6d 35 QmpCommand *cmd;
43c20a43 36
1527badb 37 QTAILQ_FOREACH(cmd, cmds, node) {
abd6cf6d
MR
38 if (strcmp(cmd->name, name) == 0) {
39 return cmd;
43c20a43
MR
40 }
41 }
42 return NULL;
43}
abd6cf6d 44
1527badb
MA
45static void qmp_toggle_command(QmpCommandList *cmds, const char *name,
46 bool enabled)
abd6cf6d
MR
47{
48 QmpCommand *cmd;
49
1527badb 50 QTAILQ_FOREACH(cmd, cmds, node) {
abd6cf6d 51 if (strcmp(cmd->name, name) == 0) {
f22d85e9 52 cmd->enabled = enabled;
abd6cf6d
MR
53 return;
54 }
55 }
56}
57
1527badb 58void qmp_disable_command(QmpCommandList *cmds, const char *name)
f22d85e9 59{
1527badb 60 qmp_toggle_command(cmds, name, false);
f22d85e9
MR
61}
62
1527badb 63void qmp_enable_command(QmpCommandList *cmds, const char *name)
f22d85e9 64{
1527badb 65 qmp_toggle_command(cmds, name, true);
f22d85e9
MR
66}
67
8dc4d915 68bool qmp_command_is_enabled(const QmpCommand *cmd)
bf95c0d5 69{
8dc4d915
MW
70 return cmd->enabled;
71}
bf95c0d5 72
8dc4d915
MW
73const char *qmp_command_name(const QmpCommand *cmd)
74{
75 return cmd->name;
bf95c0d5
MR
76}
77
0106dc4f
MW
78bool qmp_has_success_response(const QmpCommand *cmd)
79{
80 return !(cmd->options & QCO_NO_SUCCESS_RESP);
81}
82
f0ccc00b 83void qmp_for_each_command(const QmpCommandList *cmds, qmp_cmd_callback_fn fn,
1527badb 84 void *opaque)
abd6cf6d 85{
f0ccc00b 86 const QmpCommand *cmd;
abd6cf6d 87
1527badb 88 QTAILQ_FOREACH(cmd, cmds, node) {
8dc4d915 89 fn(cmd, opaque);
abd6cf6d 90 }
abd6cf6d 91}