root / qapi / qmp-registry.c @ dc1c13d9
History | View | Annotate | Download (2 kB)
1 | 43c20a43 | Michael Roth | /*
|
---|---|---|---|
2 | 43c20a43 | Michael Roth | * Core Definitions for QAPI/QMP Dispatch
|
3 | 43c20a43 | Michael Roth | *
|
4 | 43c20a43 | Michael Roth | * Copyright IBM, Corp. 2011
|
5 | 43c20a43 | Michael Roth | *
|
6 | 43c20a43 | Michael Roth | * Authors:
|
7 | 43c20a43 | Michael Roth | * Anthony Liguori <aliguori@us.ibm.com>
|
8 | 43c20a43 | Michael Roth | * Michael Roth <mdroth@us.ibm.com>
|
9 | 43c20a43 | Michael Roth | *
|
10 | 43c20a43 | Michael Roth | * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
11 | 43c20a43 | Michael Roth | * See the COPYING.LIB file in the top-level directory.
|
12 | 43c20a43 | Michael Roth | *
|
13 | 43c20a43 | Michael Roth | */
|
14 | 43c20a43 | Michael Roth | |
15 | 43c20a43 | Michael Roth | #include "qapi/qmp-core.h" |
16 | 43c20a43 | Michael Roth | |
17 | abd6cf6d | Michael Roth | static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
|
18 | 43c20a43 | Michael Roth | QTAILQ_HEAD_INITIALIZER(qmp_commands); |
19 | 43c20a43 | Michael Roth | |
20 | d34b867d | Luiz Capitulino | void qmp_register_command(const char *name, QmpCommandFunc *fn, |
21 | d34b867d | Luiz Capitulino | QmpCommandOptions options) |
22 | 43c20a43 | Michael Roth | { |
23 | 7267c094 | Anthony Liguori | QmpCommand *cmd = g_malloc0(sizeof(*cmd));
|
24 | 43c20a43 | Michael Roth | |
25 | 43c20a43 | Michael Roth | cmd->name = name; |
26 | 43c20a43 | Michael Roth | cmd->type = QCT_NORMAL; |
27 | 43c20a43 | Michael Roth | cmd->fn = fn; |
28 | abd6cf6d | Michael Roth | cmd->enabled = true;
|
29 | d34b867d | Luiz Capitulino | cmd->options = options; |
30 | 43c20a43 | Michael Roth | QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node); |
31 | 43c20a43 | Michael Roth | } |
32 | 43c20a43 | Michael Roth | |
33 | 43c20a43 | Michael Roth | QmpCommand *qmp_find_command(const char *name) |
34 | 43c20a43 | Michael Roth | { |
35 | abd6cf6d | Michael Roth | QmpCommand *cmd; |
36 | 43c20a43 | Michael Roth | |
37 | abd6cf6d | Michael Roth | QTAILQ_FOREACH(cmd, &qmp_commands, node) { |
38 | abd6cf6d | Michael Roth | if (strcmp(cmd->name, name) == 0) { |
39 | abd6cf6d | Michael Roth | return cmd;
|
40 | 43c20a43 | Michael Roth | } |
41 | 43c20a43 | Michael Roth | } |
42 | 43c20a43 | Michael Roth | return NULL; |
43 | 43c20a43 | Michael Roth | } |
44 | abd6cf6d | Michael Roth | |
45 | f22d85e9 | Michael Roth | static void qmp_toggle_command(const char *name, bool enabled) |
46 | abd6cf6d | Michael Roth | { |
47 | abd6cf6d | Michael Roth | QmpCommand *cmd; |
48 | abd6cf6d | Michael Roth | |
49 | abd6cf6d | Michael Roth | QTAILQ_FOREACH(cmd, &qmp_commands, node) { |
50 | abd6cf6d | Michael Roth | if (strcmp(cmd->name, name) == 0) { |
51 | f22d85e9 | Michael Roth | cmd->enabled = enabled; |
52 | abd6cf6d | Michael Roth | return;
|
53 | abd6cf6d | Michael Roth | } |
54 | abd6cf6d | Michael Roth | } |
55 | abd6cf6d | Michael Roth | } |
56 | abd6cf6d | Michael Roth | |
57 | f22d85e9 | Michael Roth | void qmp_disable_command(const char *name) |
58 | f22d85e9 | Michael Roth | { |
59 | f22d85e9 | Michael Roth | qmp_toggle_command(name, false);
|
60 | f22d85e9 | Michael Roth | } |
61 | f22d85e9 | Michael Roth | |
62 | f22d85e9 | Michael Roth | void qmp_enable_command(const char *name) |
63 | f22d85e9 | Michael Roth | { |
64 | f22d85e9 | Michael Roth | qmp_toggle_command(name, true);
|
65 | f22d85e9 | Michael Roth | } |
66 | f22d85e9 | Michael Roth | |
67 | bf95c0d5 | Michael Roth | bool qmp_command_is_enabled(const char *name) |
68 | bf95c0d5 | Michael Roth | { |
69 | bf95c0d5 | Michael Roth | QmpCommand *cmd; |
70 | bf95c0d5 | Michael Roth | |
71 | bf95c0d5 | Michael Roth | QTAILQ_FOREACH(cmd, &qmp_commands, node) { |
72 | bf95c0d5 | Michael Roth | if (strcmp(cmd->name, name) == 0) { |
73 | bf95c0d5 | Michael Roth | return cmd->enabled;
|
74 | bf95c0d5 | Michael Roth | } |
75 | bf95c0d5 | Michael Roth | } |
76 | bf95c0d5 | Michael Roth | |
77 | bf95c0d5 | Michael Roth | return false; |
78 | bf95c0d5 | Michael Roth | } |
79 | bf95c0d5 | Michael Roth | |
80 | abd6cf6d | Michael Roth | char **qmp_get_command_list(void) |
81 | abd6cf6d | Michael Roth | { |
82 | abd6cf6d | Michael Roth | QmpCommand *cmd; |
83 | abd6cf6d | Michael Roth | int count = 1; |
84 | abd6cf6d | Michael Roth | char **list_head, **list;
|
85 | abd6cf6d | Michael Roth | |
86 | abd6cf6d | Michael Roth | QTAILQ_FOREACH(cmd, &qmp_commands, node) { |
87 | abd6cf6d | Michael Roth | count++; |
88 | abd6cf6d | Michael Roth | } |
89 | abd6cf6d | Michael Roth | |
90 | abd6cf6d | Michael Roth | list_head = list = g_malloc0(count * sizeof(char *)); |
91 | abd6cf6d | Michael Roth | |
92 | abd6cf6d | Michael Roth | QTAILQ_FOREACH(cmd, &qmp_commands, node) { |
93 | abd6cf6d | Michael Roth | *list = strdup(cmd->name); |
94 | abd6cf6d | Michael Roth | list++; |
95 | abd6cf6d | Michael Roth | } |
96 | abd6cf6d | Michael Roth | |
97 | abd6cf6d | Michael Roth | return list_head;
|
98 | abd6cf6d | Michael Roth | } |