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