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