aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-09-04 13:28:09 +0100
committerPeter Maydell <peter.maydell@linaro.org>2017-09-04 13:28:09 +0100
commit98bfaac788be0ca63d7d010c8d4ba100ff1d8278 (patch)
treea6adc21256f54beb05f428440b0ed0e69bdddc45 /include
parent32f0f68bb77289b75a82925f712bb52e16eac3ba (diff)
parentebf677c8497ee81537f7ce57b165c978511ccde5 (diff)
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2017-09-01-v3' into staging
QAPI patches for 2017-09-01 # gpg: Signature made Mon 04 Sep 2017 12:30:31 BST # gpg: using RSA key 0x3870B400EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2017-09-01-v3: (47 commits) qapi: drop the sentinel in enum array qapi: Change data type of the FOO_lookup generated for enum FOO qapi: Convert indirect uses of FOO_lookup[...] to qapi_enum_lookup() qapi: Mechanically convert FOO_lookup[...] to FOO_str(...) qapi: Generate FOO_str() macro for QAPI enum FOO qapi: Avoid unnecessary use of enum lookup table's sentinel qapi: Use qapi_enum_parse() in input_type_enum() crypto: Use qapi_enum_parse() in qcrypto_block_luks_name_lookup() quorum: Use qapi_enum_parse() in quorum_open() block: Use qemu_enum_parse() in blkdebug_debug_breakpoint() hmp: Use qapi_enum_parse() in hmp_migrate_set_parameter() hmp: Use qapi_enum_parse() in hmp_migrate_set_capability() tpm: Clean up model registration & lookup tpm: Clean up driver registration & lookup qapi: Drop superfluous qapi_enum_parse() parameter max qapi: Update qapi-code-gen.txt examples to match current code qapi-schema: Improve section headings qapi-schema: Move queries from common.json to qapi-schema.json qapi-schema: Make block-core.json self-contained qapi-schema: Fold event.json back into qapi-schema.json ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'include')
-rw-r--r--include/hw/qdev-core.h2
-rw-r--r--include/qapi/qmp/qdict.h4
-rw-r--r--include/qapi/qmp/qlit.h54
-rw-r--r--include/qapi/qmp/qnum.h21
-rw-r--r--include/qapi/util.h10
-rw-r--r--include/qapi/visitor.h2
-rw-r--r--include/qom/object.h4
-rw-r--r--include/sysemu/tpm_backend.h4
8 files changed, 92 insertions, 9 deletions
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index ae317286a4..089146197f 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -249,7 +249,7 @@ struct Property {
struct PropertyInfo {
const char *name;
const char *description;
- const char * const *enum_table;
+ const QEnumLookup *enum_table;
int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
void (*set_default_value)(Object *obj, const Property *prop);
void (*create)(Object *obj, Property *prop, Error **errp);
diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h
index 363e431106..6588c7f0c8 100644
--- a/include/qapi/qmp/qdict.h
+++ b/include/qapi/qmp/qdict.h
@@ -53,13 +53,15 @@ void qdict_destroy_obj(QObject *obj);
#define qdict_put(qdict, key, obj) \
qdict_put_obj(qdict, key, QOBJECT(obj))
-/* Helpers for int, bool, and string */
+/* Helpers for int, bool, null, and string */
#define qdict_put_int(qdict, key, value) \
qdict_put(qdict, key, qnum_from_int(value))
#define qdict_put_bool(qdict, key, value) \
qdict_put(qdict, key, qbool_from_bool(value))
#define qdict_put_str(qdict, key, value) \
qdict_put(qdict, key, qstring_from_str(value))
+#define qdict_put_null(qdict, key) \
+ qdict_put(qdict, key, qnull())
/* High level helpers */
double qdict_get_double(const QDict *qdict, const char *key);
diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h
new file mode 100644
index 0000000000..b18406bce9
--- /dev/null
+++ b/include/qapi/qmp/qlit.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright IBM, Corp. 2009
+ * Copyright (c) 2013, 2015, 2017 Red Hat Inc.
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ * Markus Armbruster <armbru@redhat.com>
+ * Marc-André Lureau <marcandre.lureau@redhat.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.
+ *
+ */
+#ifndef QLIT_H
+#define QLIT_H
+
+#include "qapi-types.h"
+#include "qobject.h"
+
+typedef struct QLitDictEntry QLitDictEntry;
+typedef struct QLitObject QLitObject;
+
+struct QLitObject {
+ int type;
+ union {
+ bool qbool;
+ int64_t qnum;
+ const char *qstr;
+ QLitDictEntry *qdict;
+ QLitObject *qlist;
+ } value;
+};
+
+struct QLitDictEntry {
+ const char *key;
+ QLitObject value;
+};
+
+#define QLIT_QNULL \
+ { .type = QTYPE_QNULL }
+#define QLIT_QBOOL(val) \
+ { .type = QTYPE_QBOOL, .value.qbool = (val) }
+#define QLIT_QNUM(val) \
+ { .type = QTYPE_QNUM, .value.qnum = (val) }
+#define QLIT_QSTR(val) \
+ { .type = QTYPE_QSTRING, .value.qstr = (val) }
+#define QLIT_QDICT(val) \
+ { .type = QTYPE_QDICT, .value.qdict = (val) }
+#define QLIT_QLIST(val) \
+ { .type = QTYPE_QLIST, .value.qlist = (val) }
+
+bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs);
+
+#endif /* QLIT_H */
diff --git a/include/qapi/qmp/qnum.h b/include/qapi/qmp/qnum.h
index 09d745c490..d6b0791139 100644
--- a/include/qapi/qmp/qnum.h
+++ b/include/qapi/qmp/qnum.h
@@ -23,6 +23,27 @@ typedef enum {
QNUM_DOUBLE
} QNumKind;
+/*
+ * QNum encapsulates how our dialect of JSON fills in the blanks left
+ * by the JSON specification (RFC 7159) regarding numbers.
+ *
+ * Conceptually, we treat number as an abstract type with three
+ * concrete subtypes: floating-point, signed integer, unsigned
+ * integer. QNum implements this as a discriminated union of double,
+ * int64_t, uint64_t.
+ *
+ * The JSON parser picks the subtype as follows. If the number has a
+ * decimal point or an exponent, it is floating-point. Else if it
+ * fits into int64_t, it's signed integer. Else if it fits into
+ * uint64_t, it's unsigned integer. Else it's floating-point.
+ *
+ * Any number can serve as double: qnum_get_double() converts under
+ * the hood.
+ *
+ * An integer can serve as signed / unsigned integer as long as it is
+ * in range: qnum_get_try_int() / qnum_get_try_uint() check range and
+ * convert under the hood.
+ */
typedef struct QNum {
QObject base;
QNumKind kind;
diff --git a/include/qapi/util.h b/include/qapi/util.h
index 7436ed815c..a7c3c64148 100644
--- a/include/qapi/util.h
+++ b/include/qapi/util.h
@@ -11,8 +11,14 @@
#ifndef QAPI_UTIL_H
#define QAPI_UTIL_H
-int qapi_enum_parse(const char * const lookup[], const char *buf,
- int max, int def, Error **errp);
+typedef struct QEnumLookup {
+ const char *const *array;
+ int size;
+} QEnumLookup;
+
+const char *qapi_enum_lookup(const QEnumLookup *lookup, int val);
+int qapi_enum_parse(const QEnumLookup *lookup, const char *buf,
+ int def, Error **errp);
int parse_qapi_name(const char *name, bool complete);
diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
index 0f3b8cb459..62a51a54cb 100644
--- a/include/qapi/visitor.h
+++ b/include/qapi/visitor.h
@@ -469,7 +469,7 @@ bool visit_optional(Visitor *v, const char *name, bool *present);
* that visit_type_str() must have no unwelcome side effects.
*/
void visit_type_enum(Visitor *v, const char *name, int *obj,
- const char *const strings[], Error **errp);
+ const QEnumLookup *lookup, Error **errp);
/*
* Check if visitor is an input visitor.
diff --git a/include/qom/object.h b/include/qom/object.h
index 1b828994fa..f3e5cff37a 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1415,14 +1415,14 @@ void object_class_property_add_bool(ObjectClass *klass, const char *name,
*/
void object_property_add_enum(Object *obj, const char *name,
const char *typename,
- const char * const *strings,
+ const QEnumLookup *lookup,
int (*get)(Object *, Error **),
void (*set)(Object *, int, Error **),
Error **errp);
void object_class_property_add_enum(ObjectClass *klass, const char *name,
const char *typename,
- const char * const *strings,
+ const QEnumLookup *lookup,
int (*get)(Object *, Error **),
void (*set)(Object *, int, Error **),
Error **errp);
diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
index b58f52d39f..b0a9731aee 100644
--- a/include/sysemu/tpm_backend.h
+++ b/include/sysemu/tpm_backend.h
@@ -226,7 +226,7 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);
TPMBackend *qemu_find_tpm(const char *id);
const TPMDriverOps *tpm_get_backend_driver(const char *type);
-int tpm_register_model(enum TpmModel model);
-int tpm_register_driver(const TPMDriverOps *tdo);
+void tpm_register_model(enum TpmModel model);
+void tpm_register_driver(const TPMDriverOps *tdo);
#endif