diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2011-09-02 12:34:48 -0500 |
---|---|---|
committer | Luiz Capitulino <lcapitulino@redhat.com> | 2011-10-04 11:01:30 -0300 |
commit | 48a32bedfed0ea5b30bdbb470c0520acdadc3bf2 (patch) | |
tree | 853831b144edbbbe6edd4b81edb4812ff3a861b1 | |
parent | 303b54b1a2611eda47abb28546869c49b5664f59 (diff) | |
download | qemu-48a32bedfed0ea5b30bdbb470c0520acdadc3bf2.zip qemu-48a32bedfed0ea5b30bdbb470c0520acdadc3bf2.tar.gz qemu-48a32bedfed0ea5b30bdbb470c0520acdadc3bf2.tar.bz2 |
qapi: convert query-name
A simple example conversion 'info name'. This also adds the new files for
QMP and HMP.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
-rw-r--r-- | Makefile.objs | 1 | ||||
-rw-r--r-- | hmp.c | 26 | ||||
-rw-r--r-- | hmp.h | 22 | ||||
-rw-r--r-- | monitor.c | 31 | ||||
-rw-r--r-- | qapi-schema.json | 22 | ||||
-rw-r--r-- | qmp-commands.hx | 6 | ||||
-rw-r--r-- | qmp.c | 28 |
7 files changed, 108 insertions, 28 deletions
diff --git a/Makefile.objs b/Makefile.objs index 587ec36..a669c62 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -407,6 +407,7 @@ qapi-nested-y += qmp-registry.o qmp-dispatch.o qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y)) common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y) +common-obj-y += qmp.o hmp.o ###################################################################### # guest agent @@ -0,0 +1,26 @@ +/* + * Human Monitor Interface + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori <aliguori@us.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#include "hmp.h" +#include "qmp-commands.h" + +void hmp_info_name(Monitor *mon) +{ + NameInfo *info; + + info = qmp_query_name(NULL); + if (info->has_name) { + monitor_printf(mon, "%s\n", info->name); + } + qapi_free_NameInfo(info); +} @@ -0,0 +1,22 @@ +/* + * Human Monitor Interface + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori <aliguori@us.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#ifndef HMP_H +#define HMP_H + +#include "qemu-common.h" +#include "qapi-types.h" + +void hmp_info_name(Monitor *mon); + +#endif @@ -64,6 +64,8 @@ #include "trace/control.h" #include "ui/qemu-spice.h" #include "memory.h" +#include "qmp-commands.h" +#include "hmp.h" //#define DEBUG //#define DEBUG_COMPLETION @@ -760,24 +762,6 @@ static void do_info_version(Monitor *mon, QObject **ret_data) 'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION); } -static void do_info_name_print(Monitor *mon, const QObject *data) -{ - QDict *qdict; - - qdict = qobject_to_qdict(data); - if (qdict_size(qdict) == 0) { - return; - } - - monitor_printf(mon, "%s\n", qdict_get_str(qdict, "name")); -} - -static void do_info_name(Monitor *mon, QObject **ret_data) -{ - *ret_data = qemu_name ? qobject_from_jsonf("{'name': %s }", qemu_name) : - qobject_from_jsonf("{}"); -} - static QObject *get_cmd_dict(const char *name) { const char *p; @@ -3094,8 +3078,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the current VM name", - .user_print = do_info_name_print, - .mhandler.info_new = do_info_name, + .mhandler.info = hmp_info_name, }, { .name = "uuid", @@ -3287,14 +3270,6 @@ static const mon_cmd_t qmp_query_cmds[] = { }, #endif { - .name = "name", - .args_type = "", - .params = "", - .help = "show the current VM name", - .user_print = do_info_name_print, - .mhandler.info_new = do_info_name, - }, - { .name = "uuid", .args_type = "", .params = "", diff --git a/qapi-schema.json b/qapi-schema.json index 7fcefdb..3585324 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1,3 +1,25 @@ # -*- Mode: Python -*- # # QAPI Schema + +## +# @NameInfo: +# +# Guest name information. +# +# @name: #optional The name of the guest +# +# Since 0.14.0 +## +{ 'type': 'NameInfo', 'data': {'*name': 'str'} } + +## +# @query-name: +# +# Return the name information of a guest. +# +# Returns: @NameInfo of the guest +# +# Since 0.14.0 +## +{ 'command': 'query-name', 'returns': 'NameInfo' } diff --git a/qmp-commands.hx b/qmp-commands.hx index d83bce5..7b3839e 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1780,6 +1780,12 @@ Example: EQMP + { + .name = "query-name", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_name, + }, + SQMP query-uuid ---------- @@ -0,0 +1,28 @@ +/* + * QEMU Management Protocol + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori <aliguori@us.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#include "qemu-common.h" +#include "sysemu.h" +#include "qmp-commands.h" + +NameInfo *qmp_query_name(Error **errp) +{ + NameInfo *info = g_malloc0(sizeof(*info)); + + if (qemu_name) { + info->has_name = true; + info->name = g_strdup(qemu_name); + } + + return info; +} |