2011-07-19 23:50:36 +04:00
|
|
|
/*
|
|
|
|
* Core Definitions for QAPI/QMP Dispatch
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2011
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
* Michael Roth <mdroth@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
|
|
|
* See the COPYING.LIB file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qapi/qmp-core.h"
|
|
|
|
|
2011-12-07 08:03:42 +04:00
|
|
|
static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
|
2011-07-19 23:50:36 +04:00
|
|
|
QTAILQ_HEAD_INITIALIZER(qmp_commands);
|
|
|
|
|
|
|
|
void qmp_register_command(const char *name, QmpCommandFunc *fn)
|
|
|
|
{
|
2011-08-21 07:09:37 +04:00
|
|
|
QmpCommand *cmd = g_malloc0(sizeof(*cmd));
|
2011-07-19 23:50:36 +04:00
|
|
|
|
|
|
|
cmd->name = name;
|
|
|
|
cmd->type = QCT_NORMAL;
|
|
|
|
cmd->fn = fn;
|
2011-12-07 08:03:42 +04:00
|
|
|
cmd->enabled = true;
|
2011-07-19 23:50:36 +04:00
|
|
|
QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
QmpCommand *qmp_find_command(const char *name)
|
|
|
|
{
|
2011-12-07 08:03:42 +04:00
|
|
|
QmpCommand *cmd;
|
2011-07-19 23:50:36 +04:00
|
|
|
|
2011-12-07 08:03:42 +04:00
|
|
|
QTAILQ_FOREACH(cmd, &qmp_commands, node) {
|
|
|
|
if (strcmp(cmd->name, name) == 0) {
|
|
|
|
return cmd;
|
2011-07-19 23:50:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-12-07 08:03:42 +04:00
|
|
|
|
|
|
|
void qmp_disable_command(const char *name)
|
|
|
|
{
|
|
|
|
QmpCommand *cmd;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(cmd, &qmp_commands, node) {
|
|
|
|
if (strcmp(cmd->name, name) == 0) {
|
|
|
|
cmd->enabled = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-07 08:03:43 +04:00
|
|
|
bool qmp_command_is_enabled(const char *name)
|
|
|
|
{
|
|
|
|
QmpCommand *cmd;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(cmd, &qmp_commands, node) {
|
|
|
|
if (strcmp(cmd->name, name) == 0) {
|
|
|
|
return cmd->enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-07 08:03:42 +04:00
|
|
|
char **qmp_get_command_list(void)
|
|
|
|
{
|
|
|
|
QmpCommand *cmd;
|
|
|
|
int count = 1;
|
|
|
|
char **list_head, **list;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(cmd, &qmp_commands, node) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_head = list = g_malloc0(count * sizeof(char *));
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(cmd, &qmp_commands, node) {
|
|
|
|
*list = strdup(cmd->name);
|
|
|
|
list++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return list_head;
|
|
|
|
}
|