1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include "qemu/osdep.h"
16#include "qapi/qmp/dispatch.h"
17
18void qmp_register_command(QmpCommandList *cmds, const char *name,
19 QmpCommandFunc *fn, QmpCommandOptions options)
20{
21 QmpCommand *cmd = g_malloc0(sizeof(*cmd));
22
23
24 assert(!((options & QCO_COROUTINE) && (options & QCO_ALLOW_OOB)));
25
26 cmd->name = name;
27 cmd->fn = fn;
28 cmd->enabled = true;
29 cmd->options = options;
30 QTAILQ_INSERT_TAIL(cmds, cmd, node);
31}
32
33const QmpCommand *qmp_find_command(const QmpCommandList *cmds, const char *name)
34{
35 QmpCommand *cmd;
36
37 QTAILQ_FOREACH(cmd, cmds, node) {
38 if (strcmp(cmd->name, name) == 0) {
39 return cmd;
40 }
41 }
42 return NULL;
43}
44
45static void qmp_toggle_command(QmpCommandList *cmds, const char *name,
46 bool enabled)
47{
48 QmpCommand *cmd;
49
50 QTAILQ_FOREACH(cmd, cmds, node) {
51 if (strcmp(cmd->name, name) == 0) {
52 cmd->enabled = enabled;
53 return;
54 }
55 }
56}
57
58void qmp_disable_command(QmpCommandList *cmds, const char *name)
59{
60 qmp_toggle_command(cmds, name, false);
61}
62
63void qmp_enable_command(QmpCommandList *cmds, const char *name)
64{
65 qmp_toggle_command(cmds, 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(const QmpCommandList *cmds, qmp_cmd_callback_fn fn,
84 void *opaque)
85{
86 const QmpCommand *cmd;
87
88 QTAILQ_FOREACH(cmd, cmds, node) {
89 fn(cmd, opaque);
90 }
91}
92