qapi: Update qapi-code-gen.txt example to match current code
Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
16a9189921
commit
6e2bb3ec70
|
@ -258,11 +258,23 @@ Example:
|
||||||
mdroth@illuin:~/w/qemu2.git$ python scripts/qapi-types.py \
|
mdroth@illuin:~/w/qemu2.git$ python scripts/qapi-types.py \
|
||||||
--output-dir="qapi-generated" --prefix="example-" --input-file=example-schema.json
|
--output-dir="qapi-generated" --prefix="example-" --input-file=example-schema.json
|
||||||
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qapi-types.c
|
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qapi-types.c
|
||||||
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
[Uninteresting stuff omitted...]
|
||||||
|
|
||||||
|
void qapi_free_UserDefOneList(UserDefOneList * obj)
|
||||||
|
{
|
||||||
|
QapiDeallocVisitor *md;
|
||||||
|
Visitor *v;
|
||||||
|
|
||||||
|
if (!obj) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
md = qapi_dealloc_visitor_new();
|
||||||
|
v = qapi_dealloc_get_visitor(md);
|
||||||
|
visit_type_UserDefOneList(v, &obj, NULL, NULL);
|
||||||
|
qapi_dealloc_visitor_cleanup(md);
|
||||||
|
}
|
||||||
|
|
||||||
#include "qapi/qapi-dealloc-visitor.h"
|
|
||||||
#include "example-qapi-types.h"
|
|
||||||
#include "example-qapi-visit.h"
|
|
||||||
|
|
||||||
void qapi_free_UserDefOne(UserDefOne * obj)
|
void qapi_free_UserDefOne(UserDefOne * obj)
|
||||||
{
|
{
|
||||||
|
@ -280,31 +292,37 @@ Example:
|
||||||
}
|
}
|
||||||
|
|
||||||
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qapi-types.h
|
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qapi-types.h
|
||||||
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
[Uninteresting stuff omitted...]
|
||||||
#ifndef QAPI_GENERATED_EXAMPLE_QAPI_TYPES
|
|
||||||
#define QAPI_GENERATED_EXAMPLE_QAPI_TYPES
|
|
||||||
|
|
||||||
#include "qapi/qapi-types-core.h"
|
#ifndef EXAMPLE_QAPI_TYPES_H
|
||||||
|
#define EXAMPLE_QAPI_TYPES_H
|
||||||
|
|
||||||
|
[Builtin types omitted...]
|
||||||
|
|
||||||
typedef struct UserDefOne UserDefOne;
|
typedef struct UserDefOne UserDefOne;
|
||||||
|
|
||||||
typedef struct UserDefOneList
|
typedef struct UserDefOneList
|
||||||
{
|
{
|
||||||
UserDefOne *value;
|
union {
|
||||||
|
UserDefOne *value;
|
||||||
|
uint64_t padding;
|
||||||
|
};
|
||||||
struct UserDefOneList *next;
|
struct UserDefOneList *next;
|
||||||
} UserDefOneList;
|
} UserDefOneList;
|
||||||
|
|
||||||
|
[Functions on builtin types omitted...]
|
||||||
|
|
||||||
struct UserDefOne
|
struct UserDefOne
|
||||||
{
|
{
|
||||||
int64_t integer;
|
int64_t integer;
|
||||||
char * string;
|
char * string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void qapi_free_UserDefOneList(UserDefOneList * obj);
|
||||||
void qapi_free_UserDefOne(UserDefOne * obj);
|
void qapi_free_UserDefOne(UserDefOne * obj);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
=== scripts/qapi-visit.py ===
|
=== scripts/qapi-visit.py ===
|
||||||
|
|
||||||
Used to generate the visitor functions used to walk through and convert
|
Used to generate the visitor functions used to walk through and convert
|
||||||
|
@ -328,39 +346,63 @@ Example:
|
||||||
mdroth@illuin:~/w/qemu2.git$ python scripts/qapi-visit.py \
|
mdroth@illuin:~/w/qemu2.git$ python scripts/qapi-visit.py \
|
||||||
--output-dir="qapi-generated" --prefix="example-" --input-file=example-schema.json
|
--output-dir="qapi-generated" --prefix="example-" --input-file=example-schema.json
|
||||||
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qapi-visit.c
|
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qapi-visit.c
|
||||||
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
[Uninteresting stuff omitted...]
|
||||||
|
|
||||||
#include "example-qapi-visit.h"
|
static void visit_type_UserDefOne_fields(Visitor *m, UserDefOne ** obj, Error **errp)
|
||||||
|
{
|
||||||
|
Error *err = NULL;
|
||||||
|
visit_type_int(m, &(*obj)->integer, "integer", &err);
|
||||||
|
visit_type_str(m, &(*obj)->string, "string", &err);
|
||||||
|
|
||||||
|
error_propagate(errp, err);
|
||||||
|
}
|
||||||
|
|
||||||
void visit_type_UserDefOne(Visitor *m, UserDefOne ** obj, const char *name, Error **errp)
|
void visit_type_UserDefOne(Visitor *m, UserDefOne ** obj, const char *name, Error **errp)
|
||||||
{
|
{
|
||||||
visit_start_struct(m, (void **)obj, "UserDefOne", name, sizeof(UserDefOne), errp);
|
if (!error_is_set(errp)) {
|
||||||
visit_type_int(m, (obj && *obj) ? &(*obj)->integer : NULL, "integer", errp);
|
Error *err = NULL;
|
||||||
visit_type_str(m, (obj && *obj) ? &(*obj)->string : NULL, "string", errp);
|
visit_start_struct(m, (void **)obj, "UserDefOne", name, sizeof(UserDefOne), &err);
|
||||||
visit_end_struct(m, errp);
|
if (!err) {
|
||||||
|
if (*obj) {
|
||||||
|
visit_type_UserDefOne_fields(m, obj, &err);
|
||||||
|
error_propagate(errp, err);
|
||||||
|
err = NULL;
|
||||||
|
}
|
||||||
|
/* Always call end_struct if start_struct succeeded. */
|
||||||
|
visit_end_struct(m, &err);
|
||||||
|
}
|
||||||
|
error_propagate(errp, err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void visit_type_UserDefOneList(Visitor *m, UserDefOneList ** obj, const char *name, Error **errp)
|
void visit_type_UserDefOneList(Visitor *m, UserDefOneList ** obj, const char *name, Error **errp)
|
||||||
{
|
{
|
||||||
GenericList *i, **prev = (GenericList **)obj;
|
GenericList *i, **prev = (GenericList **)obj;
|
||||||
|
Error *err = NULL;
|
||||||
|
|
||||||
visit_start_list(m, name, errp);
|
if (!error_is_set(errp)) {
|
||||||
|
visit_start_list(m, name, &err);
|
||||||
|
if (!err) {
|
||||||
|
for (; (i = visit_next_list(m, prev, &err)) != NULL; prev = &i) {
|
||||||
|
UserDefOneList *native_i = (UserDefOneList *)i;
|
||||||
|
visit_type_UserDefOne(m, &native_i->value, NULL, &err);
|
||||||
|
}
|
||||||
|
error_propagate(errp, err);
|
||||||
|
err = NULL;
|
||||||
|
|
||||||
for (; (i = visit_next_list(m, prev, errp)) != NULL; prev = &i) {
|
/* Always call end_list if start_list succeeded. */
|
||||||
UserDefOneList *native_i = (UserDefOneList *)i;
|
visit_end_list(m, &err);
|
||||||
visit_type_UserDefOne(m, &native_i->value, NULL, errp);
|
}
|
||||||
|
error_propagate(errp, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
visit_end_list(m, errp);
|
|
||||||
}
|
}
|
||||||
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qapi-visit.h
|
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qapi-visit.h
|
||||||
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
[Uninteresting stuff omitted...]
|
||||||
|
|
||||||
#ifndef QAPI_GENERATED_EXAMPLE_QAPI_VISIT
|
#ifndef EXAMPLE_QAPI_VISIT_H
|
||||||
#define QAPI_GENERATED_EXAMPLE_QAPI_VISIT
|
#define EXAMPLE_QAPI_VISIT_H
|
||||||
|
|
||||||
#include "qapi/qapi-visit-core.h"
|
[Visitors for builtin types omitted...]
|
||||||
#include "example-qapi-types.h"
|
|
||||||
|
|
||||||
void visit_type_UserDefOne(Visitor *m, UserDefOne ** obj, const char *name, Error **errp);
|
void visit_type_UserDefOne(Visitor *m, UserDefOne ** obj, const char *name, Error **errp);
|
||||||
void visit_type_UserDefOneList(Visitor *m, UserDefOneList ** obj, const char *name, Error **errp);
|
void visit_type_UserDefOneList(Visitor *m, UserDefOneList ** obj, const char *name, Error **errp);
|
||||||
|
@ -368,9 +410,6 @@ Example:
|
||||||
#endif
|
#endif
|
||||||
mdroth@illuin:~/w/qemu2.git$
|
mdroth@illuin:~/w/qemu2.git$
|
||||||
|
|
||||||
(The actual structure of the visit_type_* functions is a bit more complex
|
|
||||||
in order to propagate errors correctly and avoid leaking memory).
|
|
||||||
|
|
||||||
=== scripts/qapi-commands.py ===
|
=== scripts/qapi-commands.py ===
|
||||||
|
|
||||||
Used to generate the marshaling/dispatch functions for the commands defined
|
Used to generate the marshaling/dispatch functions for the commands defined
|
||||||
|
@ -391,18 +430,8 @@ $(prefix)qmp-commands.h: Function prototypes for the QMP commands
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qmp-marshal.c
|
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qmp-marshal.c
|
||||||
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
[Uninteresting stuff omitted...]
|
||||||
|
|
||||||
#include "qemu-objects.h"
|
|
||||||
#include "qapi/qmp-core.h"
|
|
||||||
#include "qapi/qapi-visit-core.h"
|
|
||||||
#include "qapi/qmp-output-visitor.h"
|
|
||||||
#include "qapi/qmp-input-visitor.h"
|
|
||||||
#include "qapi/qapi-dealloc-visitor.h"
|
|
||||||
#include "example-qapi-types.h"
|
|
||||||
#include "example-qapi-visit.h"
|
|
||||||
|
|
||||||
#include "example-qmp-commands.h"
|
|
||||||
static void qmp_marshal_output_my_command(UserDefOne * ret_in, QObject **ret_out, Error **errp)
|
static void qmp_marshal_output_my_command(UserDefOne * ret_in, QObject **ret_out, Error **errp)
|
||||||
{
|
{
|
||||||
QapiDeallocVisitor *md = qapi_dealloc_visitor_new();
|
QapiDeallocVisitor *md = qapi_dealloc_visitor_new();
|
||||||
|
@ -411,15 +440,16 @@ Example:
|
||||||
|
|
||||||
v = qmp_output_get_visitor(mo);
|
v = qmp_output_get_visitor(mo);
|
||||||
visit_type_UserDefOne(v, &ret_in, "unused", errp);
|
visit_type_UserDefOne(v, &ret_in, "unused", errp);
|
||||||
|
if (!error_is_set(errp)) {
|
||||||
|
*ret_out = qmp_output_get_qobject(mo);
|
||||||
|
}
|
||||||
|
qmp_output_visitor_cleanup(mo);
|
||||||
v = qapi_dealloc_get_visitor(md);
|
v = qapi_dealloc_get_visitor(md);
|
||||||
visit_type_UserDefOne(v, &ret_in, "unused", errp);
|
visit_type_UserDefOne(v, &ret_in, "unused", NULL);
|
||||||
qapi_dealloc_visitor_cleanup(md);
|
qapi_dealloc_visitor_cleanup(md);
|
||||||
|
|
||||||
|
|
||||||
*ret_out = qmp_output_get_qobject(mo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qmp_marshal_input_my_command(QmpState *qmp__sess, QDict *args, QObject **ret, Error **errp)
|
static void qmp_marshal_input_my_command(QDict *args, QObject **ret, Error **errp)
|
||||||
{
|
{
|
||||||
UserDefOne * retval = NULL;
|
UserDefOne * retval = NULL;
|
||||||
QmpInputVisitor *mi;
|
QmpInputVisitor *mi;
|
||||||
|
@ -427,38 +457,42 @@ Example:
|
||||||
Visitor *v;
|
Visitor *v;
|
||||||
UserDefOne * arg1 = NULL;
|
UserDefOne * arg1 = NULL;
|
||||||
|
|
||||||
mi = qmp_input_visitor_new(QOBJECT(args));
|
mi = qmp_input_visitor_new_strict(QOBJECT(args));
|
||||||
v = qmp_input_get_visitor(mi);
|
v = qmp_input_get_visitor(mi);
|
||||||
visit_type_UserDefOne(v, &arg1, "arg1", errp);
|
visit_type_UserDefOne(v, &arg1, "arg1", errp);
|
||||||
|
qmp_input_visitor_cleanup(mi);
|
||||||
|
|
||||||
if (error_is_set(errp)) {
|
if (error_is_set(errp)) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
retval = qmp_my_command(arg1, errp);
|
retval = qmp_my_command(arg1, errp);
|
||||||
qmp_marshal_output_my_command(retval, ret, errp);
|
if (!error_is_set(errp)) {
|
||||||
|
qmp_marshal_output_my_command(retval, ret, errp);
|
||||||
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
md = qapi_dealloc_visitor_new();
|
md = qapi_dealloc_visitor_new();
|
||||||
v = qapi_dealloc_get_visitor(md);
|
v = qapi_dealloc_get_visitor(md);
|
||||||
visit_type_UserDefOne(v, &arg1, "arg1", errp);
|
visit_type_UserDefOne(v, &arg1, "arg1", NULL);
|
||||||
qapi_dealloc_visitor_cleanup(md);
|
qapi_dealloc_visitor_cleanup(md);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qmp_init_marshal(void)
|
static void qmp_init_marshal(void)
|
||||||
{
|
{
|
||||||
qmp_register_command("my-command", qmp_marshal_input_my_command);
|
qmp_register_command("my-command", qmp_marshal_input_my_command, QCO_NO_OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
qapi_init(qmp_init_marshal);
|
qapi_init(qmp_init_marshal);
|
||||||
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qmp-commands.h
|
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qmp-commands.h
|
||||||
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
[Uninteresting stuff omitted...]
|
||||||
|
|
||||||
#ifndef QAPI_GENERATED_EXAMPLE_QMP_COMMANDS
|
#ifndef EXAMPLE_QMP_COMMANDS_H
|
||||||
#define QAPI_GENERATED_EXAMPLE_QMP_COMMANDS
|
#define EXAMPLE_QMP_COMMANDS_H
|
||||||
|
|
||||||
#include "example-qapi-types.h"
|
#include "example-qapi-types.h"
|
||||||
#include "error.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
|
|
||||||
UserDefOne * qmp_my_command(UserDefOne * arg1, Error **errp);
|
UserDefOne * qmp_my_command(UserDefOne * arg1, Error **errp);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue