qobject: Make qobject_to_json_pretty() take a pretty argument
Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20201211171152.146877-4-armbru@redhat.com>
This commit is contained in:
parent
20076f4a8c
commit
6589f45991
@ -26,6 +26,6 @@ QDict *qdict_from_jsonf_nofail(const char *string, ...)
|
|||||||
GCC_FMT_ATTR(1, 2);
|
GCC_FMT_ATTR(1, 2);
|
||||||
|
|
||||||
QString *qobject_to_json(const QObject *obj);
|
QString *qobject_to_json(const QObject *obj);
|
||||||
QString *qobject_to_json_pretty(const QObject *obj);
|
QString *qobject_to_json_pretty(const QObject *obj, bool pretty);
|
||||||
|
|
||||||
#endif /* QJSON_H */
|
#endif /* QJSON_H */
|
||||||
|
@ -112,7 +112,7 @@ void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
|
|||||||
const QObject *data = QOBJECT(rsp);
|
const QObject *data = QOBJECT(rsp);
|
||||||
QString *json;
|
QString *json;
|
||||||
|
|
||||||
json = mon->pretty ? qobject_to_json_pretty(data) : qobject_to_json(data);
|
json = qobject_to_json_pretty(data, mon->pretty);
|
||||||
assert(json != NULL);
|
assert(json != NULL);
|
||||||
|
|
||||||
qstring_append_chr(json, '\n');
|
qstring_append_chr(json, '\n');
|
||||||
|
@ -633,7 +633,7 @@ static void dump_json_image_check(ImageCheck *check, bool quiet)
|
|||||||
|
|
||||||
visit_type_ImageCheck(v, NULL, &check, &error_abort);
|
visit_type_ImageCheck(v, NULL, &check, &error_abort);
|
||||||
visit_complete(v, &obj);
|
visit_complete(v, &obj);
|
||||||
str = qobject_to_json_pretty(obj);
|
str = qobject_to_json_pretty(obj, true);
|
||||||
assert(str != NULL);
|
assert(str != NULL);
|
||||||
qprintf(quiet, "%s\n", qstring_get_str(str));
|
qprintf(quiet, "%s\n", qstring_get_str(str));
|
||||||
qobject_unref(obj);
|
qobject_unref(obj);
|
||||||
@ -2795,7 +2795,7 @@ static void dump_json_image_info_list(ImageInfoList *list)
|
|||||||
|
|
||||||
visit_type_ImageInfoList(v, NULL, &list, &error_abort);
|
visit_type_ImageInfoList(v, NULL, &list, &error_abort);
|
||||||
visit_complete(v, &obj);
|
visit_complete(v, &obj);
|
||||||
str = qobject_to_json_pretty(obj);
|
str = qobject_to_json_pretty(obj, true);
|
||||||
assert(str != NULL);
|
assert(str != NULL);
|
||||||
printf("%s\n", qstring_get_str(str));
|
printf("%s\n", qstring_get_str(str));
|
||||||
qobject_unref(obj);
|
qobject_unref(obj);
|
||||||
@ -2811,7 +2811,7 @@ static void dump_json_image_info(ImageInfo *info)
|
|||||||
|
|
||||||
visit_type_ImageInfo(v, NULL, &info, &error_abort);
|
visit_type_ImageInfo(v, NULL, &info, &error_abort);
|
||||||
visit_complete(v, &obj);
|
visit_complete(v, &obj);
|
||||||
str = qobject_to_json_pretty(obj);
|
str = qobject_to_json_pretty(obj, true);
|
||||||
assert(str != NULL);
|
assert(str != NULL);
|
||||||
printf("%s\n", qstring_get_str(str));
|
printf("%s\n", qstring_get_str(str));
|
||||||
qobject_unref(obj);
|
qobject_unref(obj);
|
||||||
@ -5242,7 +5242,7 @@ static void dump_json_block_measure_info(BlockMeasureInfo *info)
|
|||||||
|
|
||||||
visit_type_BlockMeasureInfo(v, NULL, &info, &error_abort);
|
visit_type_BlockMeasureInfo(v, NULL, &info, &error_abort);
|
||||||
visit_complete(v, &obj);
|
visit_complete(v, &obj);
|
||||||
str = qobject_to_json_pretty(obj);
|
str = qobject_to_json_pretty(obj, true);
|
||||||
assert(str != NULL);
|
assert(str != NULL);
|
||||||
printf("%s\n", qstring_get_str(str));
|
printf("%s\n", qstring_get_str(str));
|
||||||
qobject_unref(obj);
|
qobject_unref(obj);
|
||||||
|
@ -149,8 +149,6 @@ QDict *qdict_from_jsonf_nofail(const char *string, ...)
|
|||||||
return qdict;
|
return qdict;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void to_json(const QObject *obj, QString *str, int pretty, int indent);
|
|
||||||
|
|
||||||
static void json_pretty_newline(QString *str, bool pretty, int indent)
|
static void json_pretty_newline(QString *str, bool pretty, int indent)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -163,7 +161,7 @@ static void json_pretty_newline(QString *str, bool pretty, int indent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void to_json(const QObject *obj, QString *str, int pretty, int indent)
|
static void to_json(const QObject *obj, QString *str, bool pretty, int indent)
|
||||||
{
|
{
|
||||||
switch (qobject_type(obj)) {
|
switch (qobject_type(obj)) {
|
||||||
case QTYPE_QNULL:
|
case QTYPE_QNULL:
|
||||||
@ -294,20 +292,16 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString *qobject_to_json_pretty(const QObject *obj, bool pretty)
|
||||||
|
{
|
||||||
|
QString *str = qstring_new();
|
||||||
|
|
||||||
|
to_json(obj, str, pretty, 0);
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
QString *qobject_to_json(const QObject *obj)
|
QString *qobject_to_json(const QObject *obj)
|
||||||
{
|
{
|
||||||
QString *str = qstring_new();
|
return qobject_to_json_pretty(obj, false);
|
||||||
|
|
||||||
to_json(obj, str, 0, 0);
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString *qobject_to_json_pretty(const QObject *obj)
|
|
||||||
{
|
|
||||||
QString *str = qstring_new();
|
|
||||||
|
|
||||||
to_json(obj, str, 1, 0);
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ void hmp_qom_get(Monitor *mon, const QDict *qdict)
|
|||||||
QObject *obj = qmp_qom_get(path, property, &err);
|
QObject *obj = qmp_qom_get(path, property, &err);
|
||||||
|
|
||||||
if (err == NULL) {
|
if (err == NULL) {
|
||||||
QString *str = qobject_to_json_pretty(obj);
|
QString *str = qobject_to_json_pretty(obj, true);
|
||||||
monitor_printf(mon, "%s\n", qstring_get_str(str));
|
monitor_printf(mon, "%s\n", qstring_get_str(str));
|
||||||
qobject_unref(str);
|
qobject_unref(str);
|
||||||
}
|
}
|
||||||
|
@ -1197,7 +1197,7 @@ void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
|
|||||||
|
|
||||||
g_assert(response);
|
g_assert(response);
|
||||||
if (!qdict_haskey(response, "return")) {
|
if (!qdict_haskey(response, "return")) {
|
||||||
QString *s = qobject_to_json_pretty(QOBJECT(response));
|
QString *s = qobject_to_json_pretty(QOBJECT(response), true);
|
||||||
g_test_message("%s", qstring_get_str(s));
|
g_test_message("%s", qstring_get_str(s));
|
||||||
qobject_unref(s);
|
qobject_unref(s);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user