target-ppc: add stxsi[bh]x instruction
[qemu/ar7.git] / qapi / qmp-registry.c
blobe8053686f3f3ae7fa4ef5173075a574b765a48e5
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 static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
19 QTAILQ_HEAD_INITIALIZER(qmp_commands);
21 void qmp_register_command(const char *name, QmpCommandFunc *fn,
22 QmpCommandOptions options)
24 QmpCommand *cmd = g_malloc0(sizeof(*cmd));
26 cmd->name = name;
27 cmd->fn = fn;
28 cmd->enabled = true;
29 cmd->options = options;
30 QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
33 void qmp_unregister_command(const char *name)
35 QmpCommand *cmd = qmp_find_command(name);
37 QTAILQ_REMOVE(&qmp_commands, cmd, node);
38 g_free(cmd);
41 QmpCommand *qmp_find_command(const char *name)
43 QmpCommand *cmd;
45 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
46 if (strcmp(cmd->name, name) == 0) {
47 return cmd;
50 return NULL;
53 static void qmp_toggle_command(const char *name, bool enabled)
55 QmpCommand *cmd;
57 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
58 if (strcmp(cmd->name, name) == 0) {
59 cmd->enabled = enabled;
60 return;
65 void qmp_disable_command(const char *name)
67 qmp_toggle_command(name, false);
70 void qmp_enable_command(const char *name)
72 qmp_toggle_command(name, true);
75 bool qmp_command_is_enabled(const QmpCommand *cmd)
77 return cmd->enabled;
80 const char *qmp_command_name(const QmpCommand *cmd)
82 return cmd->name;
85 bool qmp_has_success_response(const QmpCommand *cmd)
87 return !(cmd->options & QCO_NO_SUCCESS_RESP);
90 void qmp_for_each_command(qmp_cmd_callback_fn fn, void *opaque)
92 QmpCommand *cmd;
94 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
95 fn(cmd, opaque);