]> git.proxmox.com Git - qemu.git/blame - qapi/qmp-registry.c
prep: Initialize PC speaker
[qemu.git] / qapi / qmp-registry.c
CommitLineData
43c20a43
MR
1/*
2 * Core Definitions for QAPI/QMP Dispatch
3 *
4 * Copyright IBM, Corp. 2011
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 * Michael Roth <mdroth@us.ibm.com>
9 *
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.
12 *
13 */
14
15#include "qapi/qmp-core.h"
16
abd6cf6d 17static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
43c20a43
MR
18 QTAILQ_HEAD_INITIALIZER(qmp_commands);
19
20void qmp_register_command(const char *name, QmpCommandFunc *fn)
21{
7267c094 22 QmpCommand *cmd = g_malloc0(sizeof(*cmd));
43c20a43
MR
23
24 cmd->name = name;
25 cmd->type = QCT_NORMAL;
26 cmd->fn = fn;
abd6cf6d 27 cmd->enabled = true;
43c20a43
MR
28 QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
29}
30
31QmpCommand *qmp_find_command(const char *name)
32{
abd6cf6d 33 QmpCommand *cmd;
43c20a43 34
abd6cf6d
MR
35 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
36 if (strcmp(cmd->name, name) == 0) {
37 return cmd;
43c20a43
MR
38 }
39 }
40 return NULL;
41}
abd6cf6d
MR
42
43void qmp_disable_command(const char *name)
44{
45 QmpCommand *cmd;
46
47 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
48 if (strcmp(cmd->name, name) == 0) {
49 cmd->enabled = false;
50 return;
51 }
52 }
53}
54
bf95c0d5
MR
55bool qmp_command_is_enabled(const char *name)
56{
57 QmpCommand *cmd;
58
59 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
60 if (strcmp(cmd->name, name) == 0) {
61 return cmd->enabled;
62 }
63 }
64
65 return false;
66}
67
abd6cf6d
MR
68char **qmp_get_command_list(void)
69{
70 QmpCommand *cmd;
71 int count = 1;
72 char **list_head, **list;
73
74 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
75 count++;
76 }
77
78 list_head = list = g_malloc0(count * sizeof(char *));
79
80 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
81 *list = strdup(cmd->name);
82 list++;
83 }
84
85 return list_head;
86}