osdep: poison {HOST,TARGET}_WORDS_BIGENDIAN
[qemu.git] / qapi / qmp-registry.c
blob485bc5e6fc713ebd0d44888c2be4fc31a00d988c
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,
20 unsigned special_features)
22 QmpCommand *cmd = g_malloc0(sizeof(*cmd));
24 /* QCO_COROUTINE and QCO_ALLOW_OOB are incompatible for now */
25 assert(!((options & QCO_COROUTINE) && (options & QCO_ALLOW_OOB)));
27 cmd->name = name;
28 cmd->fn = fn;
29 cmd->enabled = true;
30 cmd->options = options;
31 cmd->special_features = special_features;
32 QTAILQ_INSERT_TAIL(cmds, cmd, node);
35 const QmpCommand *qmp_find_command(const QmpCommandList *cmds, const char *name)
37 QmpCommand *cmd;
39 QTAILQ_FOREACH(cmd, cmds, node) {
40 if (strcmp(cmd->name, name) == 0) {
41 return cmd;
44 return NULL;
47 static void qmp_toggle_command(QmpCommandList *cmds, const char *name,
48 bool enabled, const char *disable_reason)
50 QmpCommand *cmd;
52 QTAILQ_FOREACH(cmd, cmds, node) {
53 if (strcmp(cmd->name, name) == 0) {
54 cmd->enabled = enabled;
55 cmd->disable_reason = disable_reason;
56 return;
61 void qmp_disable_command(QmpCommandList *cmds, const char *name,
62 const char *disable_reason)
64 qmp_toggle_command(cmds, name, false, disable_reason);
67 void qmp_enable_command(QmpCommandList *cmds, const char *name)
69 qmp_toggle_command(cmds, name, true, NULL);
72 bool qmp_command_is_enabled(const QmpCommand *cmd)
74 return cmd->enabled;
77 const char *qmp_command_name(const QmpCommand *cmd)
79 return cmd->name;
82 bool qmp_has_success_response(const QmpCommand *cmd)
84 return !(cmd->options & QCO_NO_SUCCESS_RESP);
87 void qmp_for_each_command(const QmpCommandList *cmds, qmp_cmd_callback_fn fn,
88 void *opaque)
90 const QmpCommand *cmd;
92 QTAILQ_FOREACH(cmd, cmds, node) {
93 fn(cmd, opaque);