aboutsummaryrefslogtreecommitdiff
path: root/include/qapi
diff options
context:
space:
mode:
Diffstat (limited to 'include/qapi')
-rw-r--r--include/qapi/clone-visitor.h14
-rw-r--r--include/qapi/qmp/qdict.h8
-rw-r--r--include/qapi/qmp/qlist.h8
-rw-r--r--include/qapi/visitor.h6
4 files changed, 34 insertions, 2 deletions
diff --git a/include/qapi/clone-visitor.h b/include/qapi/clone-visitor.h
index b16177e1ee..a4915c7d57 100644
--- a/include/qapi/clone-visitor.h
+++ b/include/qapi/clone-visitor.h
@@ -24,6 +24,9 @@ typedef struct QapiCloneVisitor QapiCloneVisitor;
void *qapi_clone(const void *src, void (*visit_type)(Visitor *, const char *,
void **, Error **));
+void qapi_clone_members(void *dst, const void *src, size_t sz,
+ void (*visit_type_members)(Visitor *, void *,
+ Error **));
/*
* Deep-clone QAPI object @src of the given @type, and return the result.
@@ -36,4 +39,15 @@ void *qapi_clone(const void *src, void (*visit_type)(Visitor *, const char *,
(void (*)(Visitor *, const char *, void**, \
Error **))visit_type_ ## type))
+/*
+ * Copy deep clones of @type members from @src to @dst.
+ *
+ * Not usable on QAPI scalars (integers, strings, enums), nor on a
+ * QAPI object that references the 'any' type.
+ */
+#define QAPI_CLONE_MEMBERS(type, dst, src) \
+ qapi_clone_members(dst, src, sizeof(type), \
+ (void (*)(Visitor *, void *, \
+ Error **))visit_type_ ## type ## _members)
+
#endif
diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h
index fe9a4c5c60..188440a6a8 100644
--- a/include/qapi/qmp/qdict.h
+++ b/include/qapi/qmp/qdict.h
@@ -52,6 +52,14 @@ 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 */
+#define qdict_put_int(qdict, key, value) \
+ qdict_put(qdict, key, qint_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))
+
/* High level helpers */
double qdict_get_double(const QDict *qdict, const char *key);
int64_t qdict_get_int(const QDict *qdict, const char *key);
diff --git a/include/qapi/qmp/qlist.h b/include/qapi/qmp/qlist.h
index a84117ecb1..5dc4ed9616 100644
--- a/include/qapi/qmp/qlist.h
+++ b/include/qapi/qmp/qlist.h
@@ -29,6 +29,14 @@ typedef struct QList {
#define qlist_append(qlist, obj) \
qlist_append_obj(qlist, QOBJECT(obj))
+/* Helpers for int, bool, and string */
+#define qlist_append_int(qlist, value) \
+ qlist_append(qlist, qint_from_int(value))
+#define qlist_append_bool(qlist, value) \
+ qlist_append(qlist, qbool_from_bool(value))
+#define qlist_append_str(qlist, value) \
+ qlist_append(qlist, qstring_from_str(value))
+
#define QLIST_FOREACH_ENTRY(qlist, var) \
for ((var) = ((qlist)->head.tqh_first); \
(var); \
diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
index 1a1b62012b..b0e233df76 100644
--- a/include/qapi/visitor.h
+++ b/include/qapi/visitor.h
@@ -63,8 +63,10 @@
* The @name parameter of visit_type_FOO() describes the relation
* between this QAPI value and its parent container. When visiting
* the root of a tree, @name is ignored; when visiting a member of an
- * object, @name is the key associated with the value; and when
- * visiting a member of a list, @name is NULL.
+ * object, @name is the key associated with the value; when visiting a
+ * member of a list, @name is NULL; and when visiting the member of an
+ * alternate, @name should equal the name used for visiting the
+ * alternate.
*
* The visit_type_FOO() functions expect a non-null @obj argument;
* they allocate *@obj during input visits, leave it unchanged on