2 * Core Definitions for QAPI/QMP Dispatch
4 * Copyright IBM, Corp. 2011
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 "qapi/qmp-core.h"
17 static QTAILQ_HEAD(QmpCommandList
, QmpCommand
) qmp_commands
=
18 QTAILQ_HEAD_INITIALIZER(qmp_commands
);
20 void qmp_register_command(const char *name
, QmpCommandFunc
*fn
)
22 QmpCommand
*cmd
= g_malloc0(sizeof(*cmd
));
25 cmd
->type
= QCT_NORMAL
;
28 QTAILQ_INSERT_TAIL(&qmp_commands
, cmd
, node
);
31 QmpCommand
*qmp_find_command(const char *name
)
35 QTAILQ_FOREACH(cmd
, &qmp_commands
, node
) {
36 if (strcmp(cmd
->name
, name
) == 0) {
43 static void qmp_toggle_command(const char *name
, bool enabled
)
47 QTAILQ_FOREACH(cmd
, &qmp_commands
, node
) {
48 if (strcmp(cmd
->name
, name
) == 0) {
49 cmd
->enabled
= enabled
;
55 void qmp_disable_command(const char *name
)
57 qmp_toggle_command(name
, false);
60 void qmp_enable_command(const char *name
)
62 qmp_toggle_command(name
, true);
65 bool qmp_command_is_enabled(const char *name
)
69 QTAILQ_FOREACH(cmd
, &qmp_commands
, node
) {
70 if (strcmp(cmd
->name
, name
) == 0) {
78 char **qmp_get_command_list(void)
82 char **list_head
, **list
;
84 QTAILQ_FOREACH(cmd
, &qmp_commands
, node
) {
88 list_head
= list
= g_malloc0(count
* sizeof(char *));
90 QTAILQ_FOREACH(cmd
, &qmp_commands
, node
) {
91 *list
= strdup(cmd
->name
);