]>
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 <[email protected]> | |
8 | * Michael Roth <[email protected]> | |
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 | 18 | static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands = |
43c20a43 MR |
19 | QTAILQ_HEAD_INITIALIZER(qmp_commands); |
20 | ||
d34b867d LC |
21 | void 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 | ||
60b03e4e MA |
33 | void qmp_unregister_command(const char *name) |
34 | { | |
35 | QmpCommand *cmd = qmp_find_command(name); | |
36 | ||
37 | QTAILQ_REMOVE(&qmp_commands, cmd, node); | |
38 | g_free(cmd); | |
39 | } | |
40 | ||
43c20a43 MR |
41 | QmpCommand *qmp_find_command(const char *name) |
42 | { | |
abd6cf6d | 43 | QmpCommand *cmd; |
43c20a43 | 44 | |
abd6cf6d MR |
45 | QTAILQ_FOREACH(cmd, &qmp_commands, node) { |
46 | if (strcmp(cmd->name, name) == 0) { | |
47 | return cmd; | |
43c20a43 MR |
48 | } |
49 | } | |
50 | return NULL; | |
51 | } | |
abd6cf6d | 52 | |
f22d85e9 | 53 | static void qmp_toggle_command(const char *name, bool enabled) |
abd6cf6d MR |
54 | { |
55 | QmpCommand *cmd; | |
56 | ||
57 | QTAILQ_FOREACH(cmd, &qmp_commands, node) { | |
58 | if (strcmp(cmd->name, name) == 0) { | |
f22d85e9 | 59 | cmd->enabled = enabled; |
abd6cf6d MR |
60 | return; |
61 | } | |
62 | } | |
63 | } | |
64 | ||
f22d85e9 MR |
65 | void qmp_disable_command(const char *name) |
66 | { | |
67 | qmp_toggle_command(name, false); | |
68 | } | |
69 | ||
70 | void qmp_enable_command(const char *name) | |
71 | { | |
72 | qmp_toggle_command(name, true); | |
73 | } | |
74 | ||
8dc4d915 | 75 | bool qmp_command_is_enabled(const QmpCommand *cmd) |
bf95c0d5 | 76 | { |
8dc4d915 MW |
77 | return cmd->enabled; |
78 | } | |
bf95c0d5 | 79 | |
8dc4d915 MW |
80 | const char *qmp_command_name(const QmpCommand *cmd) |
81 | { | |
82 | return cmd->name; | |
bf95c0d5 MR |
83 | } |
84 | ||
0106dc4f MW |
85 | bool qmp_has_success_response(const QmpCommand *cmd) |
86 | { | |
87 | return !(cmd->options & QCO_NO_SUCCESS_RESP); | |
88 | } | |
89 | ||
8dc4d915 | 90 | void qmp_for_each_command(qmp_cmd_callback_fn fn, void *opaque) |
abd6cf6d MR |
91 | { |
92 | QmpCommand *cmd; | |
abd6cf6d MR |
93 | |
94 | QTAILQ_FOREACH(cmd, &qmp_commands, node) { | |
8dc4d915 | 95 | fn(cmd, opaque); |
abd6cf6d | 96 | } |
abd6cf6d | 97 | } |