accel/tcg: Create io_recompile_replay_branch hook
[qemu/kevin.git] / qapi / qmp-registry.c
blob58c65b5052e54ea797aff868ead18088ae1e85e1
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 "qapi/qmp/dispatch.h"
18 void qmp_register_command(QmpCommandList *cmds, const char *name,
19 QmpCommandFunc *fn, QmpCommandOptions options)
21 QmpCommand *cmd = g_malloc0(sizeof(*cmd));
23 /* QCO_COROUTINE and QCO_ALLOW_OOB are incompatible for now */
24 assert(!((options & QCO_COROUTINE) && (options & QCO_ALLOW_OOB)));
26 cmd->name = name;
27 cmd->fn = fn;
28 cmd->enabled = true;
29 cmd->options = options;
30 QTAILQ_INSERT_TAIL(cmds, cmd, node);
33 const QmpCommand *qmp_find_command(const QmpCommandList *cmds, const char *name)
35 QmpCommand *cmd;
37 QTAILQ_FOREACH(cmd, cmds, node) {
38 if (strcmp(cmd->name, name) == 0) {
39 return cmd;
42 return NULL;
45 static void qmp_toggle_command(QmpCommandList *cmds, const char *name,
46 bool enabled)
48 QmpCommand *cmd;
50 QTAILQ_FOREACH(cmd, cmds, node) {
51 if (strcmp(cmd->name, name) == 0) {
52 cmd->enabled = enabled;
53 return;
58 void qmp_disable_command(QmpCommandList *cmds, const char *name)
60 qmp_toggle_command(cmds, name, false);
63 void qmp_enable_command(QmpCommandList *cmds, const char *name)
65 qmp_toggle_command(cmds, 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(const QmpCommandList *cmds, qmp_cmd_callback_fn fn,
84 void *opaque)
86 const QmpCommand *cmd;
88 QTAILQ_FOREACH(cmd, cmds, node) {
89 fn(cmd, opaque);