2011-07-19 19:50:36 +00: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-10-23 23:35:44 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <string.h>
|
2012-12-17 17:19:43 +00:00
|
|
|
#include "qapi/qmp/dispatch.h"
|
2011-07-19 19:50:36 +00:00
|
|
|
|
2011-12-07 04:03:42 +00:00
|
|
|
static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
|
2011-07-19 19:50:36 +00:00
|
|
|
QTAILQ_HEAD_INITIALIZER(qmp_commands);
|
|
|
|
|
2012-05-08 17:24:44 +00:00
|
|
|
void qmp_register_command(const char *name, QmpCommandFunc *fn,
|
|
|
|
QmpCommandOptions options)
|
2011-07-19 19:50:36 +00:00
|
|
|
{
|
2011-08-21 03:09:37 +00:00
|
|
|
QmpCommand *cmd = g_malloc0(sizeof(*cmd));
|
2011-07-19 19:50:36 +00:00
|
|
|
|
|
|
|
cmd->name = name;
|
|
|
|
cmd->type = QCT_NORMAL;
|
|
|
|
cmd->fn = fn;
|
2011-12-07 04:03:42 +00:00
|
|
|
cmd->enabled = true;
|
2012-05-08 17:24:44 +00:00
|
|
|
cmd->options = options;
|
2011-07-19 19:50:36 +00:00
|
|
|
QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
QmpCommand *qmp_find_command(const char *name)
|
|
|
|
{
|
2011-12-07 04:03:42 +00:00
|
|
|
QmpCommand *cmd;
|
2011-07-19 19:50:36 +00:00
|
|
|
|
2011-12-07 04:03:42 +00:00
|
|
|
QTAILQ_FOREACH(cmd, &qmp_commands, node) {
|
|
|
|
if (strcmp(cmd->name, name) == 0) {
|
|
|
|
return cmd;
|
2011-07-19 19:50:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-12-07 04:03:42 +00:00
|
|
|
|
2012-04-18 00:01:45 +00:00
|
|
|
static void qmp_toggle_command(const char *name, bool enabled)
|
2011-12-07 04:03:42 +00:00
|
|
|
{
|
|
|
|
QmpCommand *cmd;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(cmd, &qmp_commands, node) {
|
|
|
|
if (strcmp(cmd->name, name) == 0) {
|
2012-04-18 00:01:45 +00:00
|
|
|
cmd->enabled = enabled;
|
2011-12-07 04:03:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-18 00:01:45 +00:00
|
|
|
void qmp_disable_command(const char *name)
|
|
|
|
{
|
|
|
|
qmp_toggle_command(name, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qmp_enable_command(const char *name)
|
|
|
|
{
|
|
|
|
qmp_toggle_command(name, true);
|
|
|
|
}
|
|
|
|
|
2013-10-09 03:25:07 +00:00
|
|
|
bool qmp_command_is_enabled(const QmpCommand *cmd)
|
2011-12-07 04:03:43 +00:00
|
|
|
{
|
2013-10-09 03:25:07 +00:00
|
|
|
return cmd->enabled;
|
|
|
|
}
|
2011-12-07 04:03:43 +00:00
|
|
|
|
2013-10-09 03:25:07 +00:00
|
|
|
const char *qmp_command_name(const QmpCommand *cmd)
|
|
|
|
{
|
|
|
|
return cmd->name;
|
2011-12-07 04:03:43 +00:00
|
|
|
}
|
|
|
|
|
2013-10-09 02:37:26 +00:00
|
|
|
bool qmp_has_success_response(const QmpCommand *cmd)
|
|
|
|
{
|
|
|
|
return !(cmd->options & QCO_NO_SUCCESS_RESP);
|
|
|
|
}
|
|
|
|
|
2013-10-09 03:25:07 +00:00
|
|
|
void qmp_for_each_command(qmp_cmd_callback_fn fn, void *opaque)
|
2011-12-07 04:03:42 +00:00
|
|
|
{
|
|
|
|
QmpCommand *cmd;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(cmd, &qmp_commands, node) {
|
2013-10-09 03:25:07 +00:00
|
|
|
fn(cmd, opaque);
|
2011-12-07 04:03:42 +00:00
|
|
|
}
|
|
|
|
}
|