openpic: IRQ_check: search the queue a word at a time
[qemu/ar7.git] / qapi / qmp-registry.c
blob70cdbca470ef584fda11e8c76a243a2d52ac4030
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 <glib.h>
16 #include <string.h>
17 #include "qapi/qmp/dispatch.h"
19 static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
20 QTAILQ_HEAD_INITIALIZER(qmp_commands);
22 void qmp_register_command(const char *name, QmpCommandFunc *fn,
23 QmpCommandOptions options)
25 QmpCommand *cmd = g_malloc0(sizeof(*cmd));
27 cmd->name = name;
28 cmd->type = QCT_NORMAL;
29 cmd->fn = fn;
30 cmd->enabled = true;
31 cmd->options = options;
32 QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
35 QmpCommand *qmp_find_command(const char *name)
37 QmpCommand *cmd;
39 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
40 if (strcmp(cmd->name, name) == 0) {
41 return cmd;
44 return NULL;
47 static void qmp_toggle_command(const char *name, bool enabled)
49 QmpCommand *cmd;
51 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
52 if (strcmp(cmd->name, name) == 0) {
53 cmd->enabled = enabled;
54 return;
59 void qmp_disable_command(const char *name)
61 qmp_toggle_command(name, false);
64 void qmp_enable_command(const char *name)
66 qmp_toggle_command(name, true);
69 bool qmp_command_is_enabled(const char *name)
71 QmpCommand *cmd;
73 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
74 if (strcmp(cmd->name, name) == 0) {
75 return cmd->enabled;
79 return false;
82 char **qmp_get_command_list(void)
84 QmpCommand *cmd;
85 int count = 1;
86 char **list_head, **list;
88 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
89 count++;
92 list_head = list = g_malloc0(count * sizeof(char *));
94 QTAILQ_FOREACH(cmd, &qmp_commands, node) {
95 *list = strdup(cmd->name);
96 list++;
99 return list_head;