Received: from eggs.gnu.org ([2001:4830:134:3::10]:33719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePm4V-0004w8-Kj for qemu-devel@nongnu.org; Fri, 15 Dec 2017 04:14:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePm4R-00010Q-KP for qemu-devel@nongnu.org; Fri, 15 Dec 2017 04:14:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33560) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ePm4R-0000zs-Bi for qemu-devel@nongnu.org; Fri, 15 Dec 2017 04:14:19 -0500 Date: Fri, 15 Dec 2017 17:14:03 +0800 From: Peter Xu Message-ID: <20171215091403.GQ7780@xz-mi> References: <20171205055200.16305-1-peterx@redhat.com> <20171205055200.16305-12-peterx@redhat.com> <20171213165651.GB8317@stefanha-x1.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20171213165651.GB8317@stefanha-x1.localdomain> Subject: Re: [Qemu-devel] [RFC v5 11/26] qmp: introduce QMPCapability List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, Stefan Hajnoczi , "Daniel P . Berrange" , Paolo Bonzini , Fam Zheng , Juan Quintela , mdroth@linux.vnet.ibm.com, Eric Blake , Laurent Vivier , Markus Armbruster , marcandre.lureau@redhat.com, "Dr . David Alan Gilbert" On Wed, Dec 13, 2017 at 04:56:51PM +0000, Stefan Hajnoczi wrote: > On Tue, Dec 05, 2017 at 01:51:45PM +0800, Peter Xu wrote: > > There was no QMP capabilities defined. Define the first "oob" as > > capability to allow out-of-band messages. > > > > Also, touch up qmp-test.c to test the new bits. > > > > Signed-off-by: Peter Xu > > --- > > monitor.c | 15 +++++++++++++-- > > qapi-schema.json | 13 +++++++++++++ > > tests/qmp-test.c | 10 +++++++++- > > 3 files changed, 35 insertions(+), 3 deletions(-) > > > > diff --git a/monitor.c b/monitor.c > > index e8f5a586e4..bad6ee8dd1 100644 > > --- a/monitor.c > > +++ b/monitor.c > > @@ -3944,12 +3944,23 @@ void monitor_resume(Monitor *mon) > > > > static QObject *get_qmp_greeting(void) > > { > > + QDict *result = qdict_new(), *qmp = qdict_new(); > > + QList *cap_list = qlist_new(); > > QObject *ver = NULL; > > + QMPCapability cap; > > + > > + qdict_put(result, "QMP", qmp); > > > > qmp_marshal_query_version(NULL, &ver, NULL); > > + qdict_put_obj(qmp, "version", ver); > > + > > + for (cap = 0; cap < QMP_CAPABILITY__MAX; cap++) { > > + qlist_append(cap_list, qstring_from_str( > > + QMPCapability_str(cap))); > > + } > > + qdict_put(qmp, "capabilities", cap_list); > > > > - return qobject_from_jsonf("{'QMP': {'version': %p, 'capabilities': []}}", > > - ver); > > + return QOBJECT(result); > > } > > Why did you replace qobject_from_jsonf() with manual qdict_*() calls? > > I was expecting this (it's shorter and easier to read): > > static QObject *get_qmp_greeting(void) > { > QList *cap_list = qlist_new(); > QObject *ver = NULL; > QMPCapability cap; > > qmp_marshal_query_version(NULL, &ver, NULL); > > for (cap = 0; cap < QMP_CAPABILITY__MAX; cap++) { > qlist_append(cap_list, qstring_from_str( > QMPCapability_str(cap))); > } > > return qobject_from_jsonf("{'QMP': {'version': %p, 'capabilities': %p}}", > ver, cap); (I believe you mean s/cap/cap_list/ here?) > } Oh I just didn't notice that "%p" magic at all... :( I think for me it's fine in either way. Frankly speaking creating the objects explicitly would be even easier to understand for me instead of using a mixture of two ways... But just let me know if you want me to do it your way. I can switch. Thanks, -- Peter Xu