qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <famz@redhat.com>,
	"open list:Block layer core" <qemu-block@nongnu.org>
Subject: [Qemu-devel] [PATCH 11/11] RFC: qemu-img: Use new JSON output formatter
Date: Thu, 10 Dec 2015 16:53:41 -0700	[thread overview]
Message-ID: <1449791621-16185-12-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1449791621-16185-1-git-send-email-eblake@redhat.com>

Now that we can pretty-print straight to JSON from a visitor,
we can eliminate the temporary conversion into QObject inside
qemu-img.

RFC because at least qemu-iotests 043 has changed output, not
included in this version of the patch.  Conflicts with Fam's
qemu-img edits, so one of the two of us will get to rebase on
the other:
https://lists.gnu.org/archive/html/qemu-devel/2015-12/msg01756.html

Signed-off-by: Eric Blake <eblake@redhat.com>
Cc: Fam Zheng <famz@redhat.com>
---
 qemu-img.c | 70 ++++++++++++++++++++++++++------------------------------------
 1 file changed, 29 insertions(+), 41 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index cb961e6..08dca98 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -22,9 +22,9 @@
  * THE SOFTWARE.
  */
 #include "qapi-visit.h"
-#include "qapi/qmp-output-visitor.h"
+#include "qapi/json-output-visitor.h"
 #include "qapi/qmp/qerror.h"
-#include "qapi/qmp/qobject-json.h"
+#include "qapi/qmp/qstring.h"
 #include "qemu-common.h"
 #include "qemu/option.h"
 #include "qemu/error-report.h"
@@ -375,19 +375,15 @@ fail:

 static void dump_json_image_check(ImageCheck *check, bool quiet)
 {
-    Error *local_err = NULL;
-    QString *str;
-    QmpOutputVisitor *ov = qmp_output_visitor_new();
-    QObject *obj;
-    visit_type_ImageCheck(qmp_output_get_visitor(ov),
-                          &check, NULL, &local_err);
-    obj = qmp_output_get_qobject(ov);
-    str = qobject_to_json_pretty(obj);
-    assert(str != NULL);
-    qprintf(quiet, "%s\n", qstring_get_str(str));
-    qobject_decref(obj);
-    qmp_output_visitor_cleanup(ov);
-    QDECREF(str);
+    char *str;
+    JsonOutputVisitor *ov = json_output_visitor_new(true);
+    visit_type_ImageCheck(json_output_get_visitor(ov),
+                          &check, NULL, &error_abort);
+    str = json_output_get_string(ov);
+    assert(str);
+    qprintf(quiet, "%s\n", str);
+    g_free(str);
+    json_output_visitor_cleanup(ov);
 }

 static void dump_human_image_check(ImageCheck *check, bool quiet)
@@ -1926,36 +1922,28 @@ static void dump_snapshots(BlockDriverState *bs)

 static void dump_json_image_info_list(ImageInfoList *list)
 {
-    Error *local_err = NULL;
-    QString *str;
-    QmpOutputVisitor *ov = qmp_output_visitor_new();
-    QObject *obj;
-    visit_type_ImageInfoList(qmp_output_get_visitor(ov),
-                             &list, NULL, &local_err);
-    obj = qmp_output_get_qobject(ov);
-    str = qobject_to_json_pretty(obj);
-    assert(str != NULL);
-    printf("%s\n", qstring_get_str(str));
-    qobject_decref(obj);
-    qmp_output_visitor_cleanup(ov);
-    QDECREF(str);
+    char *str;
+    JsonOutputVisitor *ov = json_output_visitor_new(true);
+    visit_type_ImageInfoList(json_output_get_visitor(ov),
+                             &list, NULL, &error_abort);
+    str = json_output_get_string(ov);
+    assert(str);
+    printf("%s\n", str);
+    json_output_visitor_cleanup(ov);
+    g_free(str);
 }

 static void dump_json_image_info(ImageInfo *info)
 {
-    Error *local_err = NULL;
-    QString *str;
-    QmpOutputVisitor *ov = qmp_output_visitor_new();
-    QObject *obj;
-    visit_type_ImageInfo(qmp_output_get_visitor(ov),
-                         &info, NULL, &local_err);
-    obj = qmp_output_get_qobject(ov);
-    str = qobject_to_json_pretty(obj);
-    assert(str != NULL);
-    printf("%s\n", qstring_get_str(str));
-    qobject_decref(obj);
-    qmp_output_visitor_cleanup(ov);
-    QDECREF(str);
+    char *str;
+    JsonOutputVisitor *ov = json_output_visitor_new(true);
+    visit_type_ImageInfo(json_output_get_visitor(ov),
+                         &info, NULL, &error_abort);
+    str = json_output_get_string(ov);
+    assert(str);
+    printf("%s\n", str);
+    json_output_visitor_cleanup(ov);
+    g_free(str);
 }

 static void dump_human_image_info_list(ImageInfoList *list)
-- 
2.4.3

  parent reply	other threads:[~2015-12-10 23:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-10 23:53 [Qemu-devel] [RFC PATCH 00/11] Add qapi-to-JSON output visitor Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 01/11] qapi: Rename qjson.h to qobject-json.h Eric Blake
2015-12-11 11:00   ` Paolo Bonzini
2015-12-10 23:53 ` [Qemu-devel] [PATCH 02/11] qapi: Improve use of qmp/types.h Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 03/11] qapi: Factor out JSON string escaping Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 04/11] qapi: Factor out JSON number formatting Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 05/11] qapi: Use qstring_append_chr() where appropriate Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 06/11] qapi: Add qstring_append_format() Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 07/11] qapi: add json output visitor Eric Blake
2015-12-11  0:24   ` Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 08/11] qjson: Simplify by using json-output-visitor Eric Blake
2015-12-11 11:10   ` Paolo Bonzini
2015-12-11 13:42     ` Eric Blake
2015-12-11 13:45       ` Paolo Bonzini
2015-12-18 23:06     ` Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 09/11] qapi: Add qobject_to_json_pretty_prefix() Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 10/11] qapi: Support pretty printing in JSON output visitor Eric Blake
2015-12-10 23:53 ` Eric Blake [this message]
2015-12-11  1:36   ` [Qemu-devel] [PATCH 11/11] RFC: qemu-img: Use new JSON output formatter Fam Zheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1449791621-16185-12-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).