qapi: rename QmpInputVisitor to QObjectInputVisitor

The QmpInputVisitor has no direct dependency on QMP. It is
valid to use it anywhere that one has a QObject. Rename it
to better reflect its functionality as a generic QObject
to QAPI converter.

The previous commit renamed the files, this one renames C identifiers.

Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1475246744-29302-5-git-send-email-berrange@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Straightforwardly rebased, split into file and identifier rename]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
Daniel P. Berrange 2016-09-30 15:45:27 +01:00 committed by Markus Armbruster
parent b3db211f3c
commit 09e68369a8
12 changed files with 97 additions and 95 deletions

View File

@ -1024,7 +1024,7 @@ Example:
Visitor *v;
UserDefOneList *arg1 = NULL;
v = qmp_input_visitor_new(QOBJECT(args), true);
v = qobject_input_visitor_new(QOBJECT(args), true);
visit_start_struct(v, NULL, NULL, 0, &err);
if (err) {
goto out;

View File

@ -17,7 +17,7 @@
#include "qapi/visitor.h"
#include "qapi/qmp/qobject.h"
typedef struct QmpInputVisitor QmpInputVisitor;
typedef struct QObjectInputVisitor QObjectInputVisitor;
/*
* Return a new input visitor that converts a QObject to a QAPI object.
@ -25,6 +25,6 @@ typedef struct QmpInputVisitor QmpInputVisitor;
* Set @strict to reject a parse that doesn't consume all keys of a
* dictionary; otherwise excess input is ignored.
*/
Visitor *qmp_input_visitor_new(QObject *obj, bool strict);
Visitor *qobject_input_visitor_new(QObject *obj, bool strict);
#endif

View File

@ -34,7 +34,7 @@ typedef struct StackObject
QSLIST_ENTRY(StackObject) node;
} StackObject;
struct QmpInputVisitor
struct QObjectInputVisitor
{
Visitor visitor;
@ -49,12 +49,12 @@ struct QmpInputVisitor
bool strict;
};
static QmpInputVisitor *to_qiv(Visitor *v)
static QObjectInputVisitor *to_qiv(Visitor *v)
{
return container_of(v, QmpInputVisitor, visitor);
return container_of(v, QObjectInputVisitor, visitor);
}
static QObject *qmp_input_get_object(QmpInputVisitor *qiv,
static QObject *qobject_input_get_object(QObjectInputVisitor *qiv,
const char *name,
bool consume, Error **errp)
{
@ -102,8 +102,9 @@ static void qdict_add_key(const char *key, QObject *obj, void *opaque)
g_hash_table_insert(h, (gpointer) key, NULL);
}
static const QListEntry *qmp_input_push(QmpInputVisitor *qiv, QObject *obj,
void *qapi, Error **errp)
static const QListEntry *qobject_input_push(QObjectInputVisitor *qiv,
QObject *obj, void *qapi,
Error **errp)
{
GHashTable *h;
StackObject *tos = g_new0(StackObject, 1);
@ -125,9 +126,9 @@ static const QListEntry *qmp_input_push(QmpInputVisitor *qiv, QObject *obj,
}
static void qmp_input_check_struct(Visitor *v, Error **errp)
static void qobject_input_check_struct(Visitor *v, Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObjectInputVisitor *qiv = to_qiv(v);
StackObject *tos = QSLIST_FIRST(&qiv->stack);
assert(tos && !tos->entry);
@ -145,7 +146,7 @@ static void qmp_input_check_struct(Visitor *v, Error **errp)
}
}
static void qmp_input_stack_object_free(StackObject *tos)
static void qobject_input_stack_object_free(StackObject *tos)
{
if (tos->h) {
g_hash_table_unref(tos->h);
@ -154,21 +155,21 @@ static void qmp_input_stack_object_free(StackObject *tos)
g_free(tos);
}
static void qmp_input_pop(Visitor *v, void **obj)
static void qobject_input_pop(Visitor *v, void **obj)
{
QmpInputVisitor *qiv = to_qiv(v);
QObjectInputVisitor *qiv = to_qiv(v);
StackObject *tos = QSLIST_FIRST(&qiv->stack);
assert(tos && tos->qapi == obj);
QSLIST_REMOVE_HEAD(&qiv->stack, node);
qmp_input_stack_object_free(tos);
qobject_input_stack_object_free(tos);
}
static void qmp_input_start_struct(Visitor *v, const char *name, void **obj,
static void qobject_input_start_struct(Visitor *v, const char *name, void **obj,
size_t size, Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
Error *err = NULL;
if (obj) {
@ -183,7 +184,7 @@ static void qmp_input_start_struct(Visitor *v, const char *name, void **obj,
return;
}
qmp_input_push(qiv, qobj, obj, &err);
qobject_input_push(qiv, qobj, obj, &err);
if (err) {
error_propagate(errp, err);
return;
@ -195,11 +196,12 @@ static void qmp_input_start_struct(Visitor *v, const char *name, void **obj,
}
static void qmp_input_start_list(Visitor *v, const char *name,
GenericList **list, size_t size, Error **errp)
static void qobject_input_start_list(Visitor *v, const char *name,
GenericList **list, size_t size,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
const QListEntry *entry;
if (!qobj) {
@ -214,7 +216,7 @@ static void qmp_input_start_list(Visitor *v, const char *name,
return;
}
entry = qmp_input_push(qiv, qobj, list, errp);
entry = qobject_input_push(qiv, qobj, list, errp);
if (list) {
if (entry) {
*list = g_malloc0(size);
@ -224,10 +226,10 @@ static void qmp_input_start_list(Visitor *v, const char *name,
}
}
static GenericList *qmp_input_next_list(Visitor *v, GenericList *tail,
static GenericList *qobject_input_next_list(Visitor *v, GenericList *tail,
size_t size)
{
QmpInputVisitor *qiv = to_qiv(v);
QObjectInputVisitor *qiv = to_qiv(v);
StackObject *so = QSLIST_FIRST(&qiv->stack);
if (!so->entry) {
@ -238,12 +240,12 @@ static GenericList *qmp_input_next_list(Visitor *v, GenericList *tail,
}
static void qmp_input_start_alternate(Visitor *v, const char *name,
static void qobject_input_start_alternate(Visitor *v, const char *name,
GenericAlternate **obj, size_t size,
bool promote_int, Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, false, errp);
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, false, errp);
if (!qobj) {
*obj = NULL;
@ -256,11 +258,11 @@ static void qmp_input_start_alternate(Visitor *v, const char *name,
}
}
static void qmp_input_type_int64(Visitor *v, const char *name, int64_t *obj,
static void qobject_input_type_int64(Visitor *v, const char *name, int64_t *obj,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
QInt *qint;
if (!qobj) {
@ -276,12 +278,12 @@ static void qmp_input_type_int64(Visitor *v, const char *name, int64_t *obj,
*obj = qint_get_int(qint);
}
static void qmp_input_type_uint64(Visitor *v, const char *name, uint64_t *obj,
Error **errp)
static void qobject_input_type_uint64(Visitor *v, const char *name,
uint64_t *obj, Error **errp)
{
/* FIXME: qobject_to_qint mishandles values over INT64_MAX */
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
QInt *qint;
if (!qobj) {
@ -297,11 +299,11 @@ static void qmp_input_type_uint64(Visitor *v, const char *name, uint64_t *obj,
*obj = qint_get_int(qint);
}
static void qmp_input_type_bool(Visitor *v, const char *name, bool *obj,
static void qobject_input_type_bool(Visitor *v, const char *name, bool *obj,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
QBool *qbool;
if (!qobj) {
@ -317,11 +319,11 @@ static void qmp_input_type_bool(Visitor *v, const char *name, bool *obj,
*obj = qbool_get_bool(qbool);
}
static void qmp_input_type_str(Visitor *v, const char *name, char **obj,
static void qobject_input_type_str(Visitor *v, const char *name, char **obj,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
QString *qstr;
*obj = NULL;
@ -338,11 +340,11 @@ static void qmp_input_type_str(Visitor *v, const char *name, char **obj,
*obj = g_strdup(qstring_get_str(qstr));
}
static void qmp_input_type_number(Visitor *v, const char *name, double *obj,
static void qobject_input_type_number(Visitor *v, const char *name, double *obj,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
QInt *qint;
QFloat *qfloat;
@ -365,11 +367,11 @@ static void qmp_input_type_number(Visitor *v, const char *name, double *obj,
"number");
}
static void qmp_input_type_any(Visitor *v, const char *name, QObject **obj,
static void qobject_input_type_any(Visitor *v, const char *name, QObject **obj,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
*obj = NULL;
if (!qobj) {
@ -380,10 +382,10 @@ static void qmp_input_type_any(Visitor *v, const char *name, QObject **obj,
*obj = qobj;
}
static void qmp_input_type_null(Visitor *v, const char *name, Error **errp)
static void qobject_input_type_null(Visitor *v, const char *name, Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
if (!qobj) {
return;
@ -395,10 +397,10 @@ static void qmp_input_type_null(Visitor *v, const char *name, Error **errp)
}
}
static void qmp_input_optional(Visitor *v, const char *name, bool *present)
static void qobject_input_optional(Visitor *v, const char *name, bool *present)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, false, NULL);
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, false, NULL);
if (!qobj) {
*present = false;
@ -408,44 +410,44 @@ static void qmp_input_optional(Visitor *v, const char *name, bool *present)
*present = true;
}
static void qmp_input_free(Visitor *v)
static void qobject_input_free(Visitor *v)
{
QmpInputVisitor *qiv = to_qiv(v);
QObjectInputVisitor *qiv = to_qiv(v);
while (!QSLIST_EMPTY(&qiv->stack)) {
StackObject *tos = QSLIST_FIRST(&qiv->stack);
QSLIST_REMOVE_HEAD(&qiv->stack, node);
qmp_input_stack_object_free(tos);
qobject_input_stack_object_free(tos);
}
qobject_decref(qiv->root);
g_free(qiv);
}
Visitor *qmp_input_visitor_new(QObject *obj, bool strict)
Visitor *qobject_input_visitor_new(QObject *obj, bool strict)
{
QmpInputVisitor *v;
QObjectInputVisitor *v;
assert(obj);
v = g_malloc0(sizeof(*v));
v->visitor.type = VISITOR_INPUT;
v->visitor.start_struct = qmp_input_start_struct;
v->visitor.check_struct = qmp_input_check_struct;
v->visitor.end_struct = qmp_input_pop;
v->visitor.start_list = qmp_input_start_list;
v->visitor.next_list = qmp_input_next_list;
v->visitor.end_list = qmp_input_pop;
v->visitor.start_alternate = qmp_input_start_alternate;
v->visitor.type_int64 = qmp_input_type_int64;
v->visitor.type_uint64 = qmp_input_type_uint64;
v->visitor.type_bool = qmp_input_type_bool;
v->visitor.type_str = qmp_input_type_str;
v->visitor.type_number = qmp_input_type_number;
v->visitor.type_any = qmp_input_type_any;
v->visitor.type_null = qmp_input_type_null;
v->visitor.optional = qmp_input_optional;
v->visitor.free = qmp_input_free;
v->visitor.start_struct = qobject_input_start_struct;
v->visitor.check_struct = qobject_input_check_struct;
v->visitor.end_struct = qobject_input_pop;
v->visitor.start_list = qobject_input_start_list;
v->visitor.next_list = qobject_input_next_list;
v->visitor.end_list = qobject_input_pop;
v->visitor.start_alternate = qobject_input_start_alternate;
v->visitor.type_int64 = qobject_input_type_int64;
v->visitor.type_uint64 = qobject_input_type_uint64;
v->visitor.type_bool = qobject_input_type_bool;
v->visitor.type_str = qobject_input_type_str;
v->visitor.type_number = qobject_input_type_number;
v->visitor.type_any = qobject_input_type_any;
v->visitor.type_null = qobject_input_type_null;
v->visitor.optional = qobject_input_optional;
v->visitor.free = qobject_input_free;
v->strict = strict;
v->root = obj;

2
qmp.c
View File

@ -675,7 +675,7 @@ void qmp_object_add(const char *type, const char *id,
pdict = qdict_new();
}
v = qmp_input_visitor_new(QOBJECT(pdict), true);
v = qobject_input_visitor_new(QOBJECT(pdict), true);
obj = user_creatable_add_type(type, id, pdict, v, errp);
visit_free(v);
if (obj) {

View File

@ -23,7 +23,7 @@ void object_property_set_qobject(Object *obj, QObject *value,
{
Visitor *v;
/* TODO: Should we reject, rather than ignore, excess input? */
v = qmp_input_visitor_new(value, false);
v = qobject_input_visitor_new(value, false);
object_property_set(obj, v, name, errp);
visit_free(v);
}

View File

@ -130,7 +130,7 @@ def gen_marshal(name, arg_type, boxed, ret_type):
push_indent()
ret += mcgen('''
v = qmp_input_visitor_new(QOBJECT(args), true);
v = qobject_input_visitor_new(QOBJECT(args), true);
visit_start_struct(v, NULL, NULL, 0, &err);
if (err) {
goto out;

View File

@ -345,7 +345,7 @@ static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info,
}
if (qdict) {
visitor = qmp_input_visitor_new(info->props, true);
visitor = qobject_input_visitor_new(info->props, true);
visit_start_struct(visitor, NULL, NULL, 0, errp);
if (*errp) {
object_unref(obj);

View File

@ -47,7 +47,7 @@ static void qnull_visit_test(void)
g_assert(qnull_.refcnt == 1);
obj = qnull();
v = qmp_input_visitor_new(obj, true);
v = qobject_input_visitor_new(obj, true);
qobject_decref(obj);
visit_type_null(v, NULL, &error_abort);
visit_free(v);

View File

@ -244,7 +244,7 @@ static void test_dealloc_partial(void)
ud2_dict = qdict_new();
qdict_put_obj(ud2_dict, "string0", QOBJECT(qstring_from_str(text)));
v = qmp_input_visitor_new(QOBJECT(ud2_dict), true);
v = qobject_input_visitor_new(QOBJECT(ud2_dict), true);
visit_type_UserDefTwo(v, NULL, &ud2, &err);
visit_free(v);
QDECREF(ud2_dict);

View File

@ -53,7 +53,7 @@ static Visitor *validate_test_init_internal(TestInputVisitorData *data,
data->obj = qobject_from_jsonv(json_string, ap);
g_assert(data->obj);
data->qiv = qmp_input_visitor_new(data->obj, true);
data->qiv = qobject_input_visitor_new(data->obj, true);
g_assert(data->qiv);
return data->qiv;
}

View File

@ -49,7 +49,7 @@ static Visitor *visitor_input_test_init_internal(TestInputVisitorData *data,
data->obj = qobject_from_jsonv(json_string, ap);
g_assert(data->obj);
data->qiv = qmp_input_visitor_new(data->obj, false);
data->qiv = qobject_input_visitor_new(data->obj, false);
g_assert(data->qiv);
return data->qiv;
}

View File

@ -1040,7 +1040,7 @@ static void qmp_deserialize(void **native_out, void *datap,
obj = qobject_from_json(qstring_get_str(output_json));
QDECREF(output_json);
d->qiv = qmp_input_visitor_new(obj, true);
d->qiv = qobject_input_visitor_new(obj, true);
qobject_decref(obj_orig);
qobject_decref(obj);
visit(d->qiv, native_out, errp);