]> git.proxmox.com Git - mirror_qemu.git/blame - qapi/qmp-registry.c
virtio: decrement vq->inuse in virtqueue_discard()
[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
abd6cf6d 18static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
43c20a43
MR
19 QTAILQ_HEAD_INITIALIZER(qmp_commands);
20
d34b867d
LC
21void qmp_register_command(const char *name, QmpCommandFunc *fn,
22 QmpCommandOptions options)
43c20a43 23{
7267c094 24 QmpCommand *cmd = g_malloc0(sizeof(*cmd));
43c20a43
MR
25
26 cmd->name = name;
43c20a43 27 cmd->fn = fn;
abd6cf6d 28 cmd->enabled = true;
d34b867d 29 cmd->options = options;
43c20a43
MR
30 QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
31}
32
33QmpCommand *qmp_find_command(const char *name)
34{
abd6cf6d 35 QmpCommand *cmd;
43c20a43 36
abd6cf6d
MR
37 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
38 if (strcmp(cmd->name, name) == 0) {
39 return cmd;
43c20a43
MR
40 }
41 }
42 return NULL;
43}
abd6cf6d 44
f22d85e9 45static void qmp_toggle_command(const char *name, bool enabled)
abd6cf6d
MR
46{
47 QmpCommand *cmd;
48
49 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
50 if (strcmp(cmd->name, name) == 0) {
f22d85e9 51 cmd->enabled = enabled;
abd6cf6d
MR
52 return;
53 }
54 }
55}
56
f22d85e9
MR
57void qmp_disable_command(const char *name)
58{
59 qmp_toggle_command(name, false);
60}
61
62void qmp_enable_command(const char *name)
63{
64 qmp_toggle_command(name, true);
65}
66
8dc4d915 67bool qmp_command_is_enabled(const QmpCommand *cmd)
bf95c0d5 68{
8dc4d915
MW
69 return cmd->enabled;
70}
bf95c0d5 71
8dc4d915
MW
72const char *qmp_command_name(const QmpCommand *cmd)
73{
74 return cmd->name;
bf95c0d5
MR
75}
76
0106dc4f
MW
77bool qmp_has_success_response(const QmpCommand *cmd)
78{
79 return !(cmd->options & QCO_NO_SUCCESS_RESP);
80}
81
8dc4d915 82void qmp_for_each_command(qmp_cmd_callback_fn fn, void *opaque)
abd6cf6d
MR
83{
84 QmpCommand *cmd;
abd6cf6d
MR
85
86 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
8dc4d915 87 fn(cmd, opaque);
abd6cf6d 88 }
abd6cf6d 89}