[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 54/59] qom: introduce object_property_help()
From: |
Paolo Bonzini |
Subject: |
[PULL 54/59] qom: introduce object_property_help() |
Date: |
Thu, 23 Jan 2020 14:50:44 +0100 |
From: Marc-André Lureau <address@hidden>
Let's factor out the code to format a help string for a property. We
are going to reuse it in qdev next, which will bring some consistency.
Signed-off-by: Marc-André Lureau <address@hidden>
Message-Id: <address@hidden>
[Adjust for removal of object_property_get_default, move default
after description. - Paolo]
Signed-off-by: Paolo Bonzini <address@hidden>
---
include/qom/object.h | 13 +++++++++++++
qom/object_interfaces.c | 45 ++++++++++++++++++++++++++++-----------------
2 files changed, 41 insertions(+), 17 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index 18660fd..2954649 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1837,6 +1837,19 @@ Object *container_get(Object *root, const char *path);
*/
size_t object_type_get_instance_size(const char *typename);
+/**
+ * object_property_help:
+ * @name: the name of the property
+ * @type: the type of the property
+ * @defval: the default value
+ * @description: description of the property
+ *
+ * Returns: a user-friendly formatted string describing the property
+ * for help purposes.
+ */
+char *object_property_help(const char *name, const char *type,
+ QObject *defval, const char *description);
+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(Object, object_unref)
#endif
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index edb4cc4..72cb9e3 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -4,6 +4,8 @@
#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
+#include "qapi/qmp/qjson.h"
+#include "qapi/qmp/qstring.h"
#include "qom/object_interfaces.h"
#include "qemu/help_option.h"
#include "qemu/module.h"
@@ -158,6 +160,29 @@ int user_creatable_add_opts_foreach(void *opaque, QemuOpts
*opts, Error **errp)
return 0;
}
+char *object_property_help(const char *name, const char *type,
+ QObject *defval, const char *description)
+{
+ GString *str = g_string_new(NULL);
+
+ g_string_append_printf(str, " %s=<%s>", name, type);
+ if (description || defval) {
+ if (str->len < 24) {
+ g_string_append_printf(str, "%*s", 24 - (int)str->len, "");
+ }
+ g_string_append(str, " - ");
+ }
+ if (description) {
+ g_string_append(str, description);
+ }
+ if (defval) {
+ g_autofree char *def_json = qstring_free(qobject_to_json(defval),
TRUE);
+ g_string_append_printf(str, " (default: %s)", def_json);
+ }
+
+ return g_string_free(str, false);
+}
+
bool user_creatable_print_help(const char *type, QemuOpts *opts)
{
ObjectClass *klass;
@@ -184,27 +209,13 @@ bool user_creatable_print_help(const char *type, QemuOpts
*opts)
object_class_property_iter_init(&iter, klass);
while ((prop = object_property_iter_next(&iter))) {
- GString *str;
- char *defval;
-
if (!prop->set) {
continue;
}
- str = g_string_new(NULL);
- g_string_append_printf(str, " %s=<%s>", prop->name, prop->type);
- defval = object_property_get_default(prop);
- if (defval) {
- g_string_append_printf(str, " (default: %s)", defval);
- g_free(defval);
- }
- if (prop->description) {
- if (str->len < 24) {
- g_string_append_printf(str, "%*s", 24 - (int)str->len, "");
- }
- g_string_append_printf(str, " - %s", prop->description);
- }
- g_ptr_array_add(array, g_string_free(str, false));
+ g_ptr_array_add(array,
+ object_property_help(prop->name, prop->type,
+ prop->defval,
prop->description));
}
g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0);
if (array->len > 0) {
--
1.8.3.1
- [PULL 43/59] object: add direct link flag, (continued)
- [PULL 43/59] object: add direct link flag, Paolo Bonzini, 2020/01/23
- [PULL 44/59] object: express const link with link property, Paolo Bonzini, 2020/01/23
- [PULL 45/59] object: add object_class_property_add_link(), Paolo Bonzini, 2020/01/23
- [PULL 46/59] object: release all props, Paolo Bonzini, 2020/01/23
- [PULL 47/59] object: return self in object_ref(), Paolo Bonzini, 2020/01/23
- [PULL 49/59] qdev: rename DeviceClass.props, Paolo Bonzini, 2020/01/23
- [PULL 50/59] qdev: move instance properties to class properties, Paolo Bonzini, 2020/01/23
- [PULL 52/59] vl: print default value in object help, Paolo Bonzini, 2020/01/23
- [PULL 51/59] qdev: register properties as class properties, Paolo Bonzini, 2020/01/23
- [PULL 53/59] qom: simplify qmp_device_list_properties(), Paolo Bonzini, 2020/01/23
- [PULL 54/59] qom: introduce object_property_help(),
Paolo Bonzini <=
- [PULL 55/59] qapi/qmp: add ObjectPropertyInfo.default-value, Paolo Bonzini, 2020/01/23
- [PULL 56/59] qdev: use object_property_help(), Paolo Bonzini, 2020/01/23
- [PULL 57/59] target/i386: Add the 'model-id' for Skylake -v3 CPU models, Paolo Bonzini, 2020/01/23
- [PULL 59/59] tests: fix test-qga on macosx, Paolo Bonzini, 2020/01/23
- [PULL 58/59] build-sys: clean up flags included in the linker command line, Paolo Bonzini, 2020/01/23
- [PULL 48/59] qdev: set properties with device_class_set_props(), Paolo Bonzini, 2020/01/23
- Re: [PULL v2 00/59] Misc (x86 and QOM) patches for 2020-01-23, Peter Maydell, 2020/01/23