]>
Commit | Line | Data |
---|---|---|
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 | 18 | void qmp_register_command(QmpCommandList *cmds, const char *name, |
6604e475 MA |
19 | QmpCommandFunc *fn, QmpCommandOptions options, |
20 | unsigned special_features) | |
43c20a43 | 21 | { |
7267c094 | 22 | QmpCommand *cmd = g_malloc0(sizeof(*cmd)); |
43c20a43 | 23 | |
9ce44e2c KW |
24 | /* QCO_COROUTINE and QCO_ALLOW_OOB are incompatible for now */ |
25 | assert(!((options & QCO_COROUTINE) && (options & QCO_ALLOW_OOB))); | |
26 | ||
43c20a43 | 27 | cmd->name = name; |
43c20a43 | 28 | cmd->fn = fn; |
abd6cf6d | 29 | cmd->enabled = true; |
d34b867d | 30 | cmd->options = options; |
6604e475 | 31 | cmd->special_features = special_features; |
1527badb | 32 | QTAILQ_INSERT_TAIL(cmds, cmd, node); |
43c20a43 MR |
33 | } |
34 | ||
f0ccc00b | 35 | const QmpCommand *qmp_find_command(const QmpCommandList *cmds, const char *name) |
43c20a43 | 36 | { |
abd6cf6d | 37 | QmpCommand *cmd; |
43c20a43 | 38 | |
1527badb | 39 | QTAILQ_FOREACH(cmd, cmds, node) { |
abd6cf6d MR |
40 | if (strcmp(cmd->name, name) == 0) { |
41 | return cmd; | |
43c20a43 MR |
42 | } |
43 | } | |
44 | return NULL; | |
45 | } | |
abd6cf6d | 46 | |
1527badb | 47 | static void qmp_toggle_command(QmpCommandList *cmds, const char *name, |
c98939da | 48 | bool enabled, const char *disable_reason) |
abd6cf6d MR |
49 | { |
50 | QmpCommand *cmd; | |
51 | ||
1527badb | 52 | QTAILQ_FOREACH(cmd, cmds, node) { |
abd6cf6d | 53 | if (strcmp(cmd->name, name) == 0) { |
f22d85e9 | 54 | cmd->enabled = enabled; |
c98939da | 55 | cmd->disable_reason = disable_reason; |
abd6cf6d MR |
56 | return; |
57 | } | |
58 | } | |
59 | } | |
60 | ||
c98939da MAL |
61 | void qmp_disable_command(QmpCommandList *cmds, const char *name, |
62 | const char *disable_reason) | |
f22d85e9 | 63 | { |
c98939da | 64 | qmp_toggle_command(cmds, name, false, disable_reason); |
f22d85e9 MR |
65 | } |
66 | ||
1527badb | 67 | void qmp_enable_command(QmpCommandList *cmds, const char *name) |
f22d85e9 | 68 | { |
c98939da | 69 | qmp_toggle_command(cmds, name, true, NULL); |
f22d85e9 MR |
70 | } |
71 | ||
8dc4d915 | 72 | bool qmp_command_is_enabled(const QmpCommand *cmd) |
bf95c0d5 | 73 | { |
8dc4d915 MW |
74 | return cmd->enabled; |
75 | } | |
bf95c0d5 | 76 | |
8dc4d915 MW |
77 | const char *qmp_command_name(const QmpCommand *cmd) |
78 | { | |
79 | return cmd->name; | |
bf95c0d5 MR |
80 | } |
81 | ||
0106dc4f MW |
82 | bool qmp_has_success_response(const QmpCommand *cmd) |
83 | { | |
84 | return !(cmd->options & QCO_NO_SUCCESS_RESP); | |
85 | } | |
86 | ||
f0ccc00b | 87 | void qmp_for_each_command(const QmpCommandList *cmds, qmp_cmd_callback_fn fn, |
1527badb | 88 | void *opaque) |
abd6cf6d | 89 | { |
f0ccc00b | 90 | const QmpCommand *cmd; |
abd6cf6d | 91 | |
1527badb | 92 | QTAILQ_FOREACH(cmd, cmds, node) { |
8dc4d915 | 93 | fn(cmd, opaque); |
abd6cf6d | 94 | } |
abd6cf6d | 95 | } |