target-sparc: make cpu-qom.h not target specific
[qemu/ar7.git] / qapi / qmp-registry.c
blob4332a6818d6acfd238d21ace7deb355a93a3c8f2
1 /*
2 * Core Definitions for QAPI/QMP Dispatch
4 * Copyright IBM, Corp. 2011
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 * Michael Roth <mdroth@us.ibm.com>
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.
15 #include "qemu/osdep.h"
16 #include <glib.h>
17 #include "qapi/qmp/dispatch.h"
19 static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
20 QTAILQ_HEAD_INITIALIZER(qmp_commands);
22 void qmp_register_command(const char *name, QmpCommandFunc *fn,
23 QmpCommandOptions options)
25 QmpCommand *cmd = g_malloc0(sizeof(*cmd));
27 cmd->name = name;
28 cmd->fn = fn;
29 cmd->enabled = true;
30 cmd->options = options;
31 QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
34 QmpCommand *qmp_find_command(const char *name)
36 QmpCommand *cmd;
38 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
39 if (strcmp(cmd->name, name) == 0) {
40 return cmd;
43 return NULL;
46 static void qmp_toggle_command(const char *name, bool enabled)
48 QmpCommand *cmd;
50 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
51 if (strcmp(cmd->name, name) == 0) {
52 cmd->enabled = enabled;
53 return;
58 void qmp_disable_command(const char *name)
60 qmp_toggle_command(name, false);
63 void qmp_enable_command(const char *name)
65 qmp_toggle_command(name, true);
68 bool qmp_command_is_enabled(const QmpCommand *cmd)
70 return cmd->enabled;
73 const char *qmp_command_name(const QmpCommand *cmd)
75 return cmd->name;
78 bool qmp_has_success_response(const QmpCommand *cmd)
80 return !(cmd->options & QCO_NO_SUCCESS_RESP);
83 void qmp_for_each_command(qmp_cmd_callback_fn fn, void *opaque)
85 QmpCommand *cmd;
87 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
88 fn(cmd, opaque);