1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include "qemu/osdep.h"
16#include <glib.h>
17#include "qapi/qmp/dispatch.h"
18
19static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
20 QTAILQ_HEAD_INITIALIZER(qmp_commands);
21
22void qmp_register_command(const char *name, QmpCommandFunc *fn,
23 QmpCommandOptions options)
24{
25 QmpCommand *cmd = g_malloc0(sizeof(*cmd));
26
27 cmd->name = name;
28 cmd->fn = fn;
29 cmd->enabled = true;
30 cmd->options = options;
31 QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
32}
33
34QmpCommand *qmp_find_command(const char *name)
35{
36 QmpCommand *cmd;
37
38 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
39 if (strcmp(cmd->name, name) == 0) {
40 return cmd;
41 }
42 }
43 return NULL;
44}
45
46static void qmp_toggle_command(const char *name, bool enabled)
47{
48 QmpCommand *cmd;
49
50 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
51 if (strcmp(cmd->name, name) == 0) {
52 cmd->enabled = enabled;
53 return;
54 }
55 }
56}
57
58void qmp_disable_command(const char *name)
59{
60 qmp_toggle_command(name, false);
61}
62
63void qmp_enable_command(const char *name)
64{
65 qmp_toggle_command(name, true);
66}
67
68bool qmp_command_is_enabled(const QmpCommand *cmd)
69{
70 return cmd->enabled;
71}
72
73const char *qmp_command_name(const QmpCommand *cmd)
74{
75 return cmd->name;
76}
77
78bool qmp_has_success_response(const QmpCommand *cmd)
79{
80 return !(cmd->options & QCO_NO_SUCCESS_RESP);
81}
82
83void qmp_for_each_command(qmp_cmd_callback_fn fn, void *opaque)
84{
85 QmpCommand *cmd;
86
87 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
88 fn(cmd, opaque);
89 }
90}
91