From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uouvh-0008WJ-4C for qemu-devel@nongnu.org; Tue, 18 Jun 2013 08:22:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uouvc-0006JH-0J for qemu-devel@nongnu.org; Tue, 18 Jun 2013 08:22:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44484) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uouvb-0006Iu-P8 for qemu-devel@nongnu.org; Tue, 18 Jun 2013 08:22:27 -0400 Date: Tue, 18 Jun 2013 20:21:12 +0800 From: Amos Kong Message-ID: <20130618122030.GA25925@amosk.info> References: <20130522134007.GA2051@t430s.nay.redhat.com> <20130607101230.GA32546@t430s.nay.redhat.com> <20130607101726.GB32546@t430s.nay.redhat.com> <20130614095244.GA24720@t430s.nay.redhat.com> <51BAF9ED.4000206@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <51BAF9ED.4000206@redhat.com> Subject: Re: [Qemu-devel] RFC: Full introspection support for QMP (with draft patch) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, Markus Armbruster , qemu-devel , qiaonuohan@cn.fujitsu.com, Ronen Hod , lcapitulino@redhat.com On Fri, Jun 14, 2013 at 12:09:33PM +0100, Eric Blake wrote: > On 06/14/2013 10:52 AM, Amos Kong wrote: > > +const char *type; > > +const char *name; > > +const char *data; > > +const char *returns; > > +} qmp_schema_table[] = { > > +""" > > + > > +for i in exprs_all[1]: > > + print i > > + > > + data = returns = "" > > + type = i.keys()[0] > > + name = i[type] > > + for k in i.keys(): > > + if isinstance(i[k], OrderedDict): > > + ret = {} > > + for key in i[k]: > > + ret[key] = i[k][key] > > + i[k] = ret > > + > > + if i.has_key('data'): > > + data = i['data'] > > I think this is where you'd need to do more processing of data to spit > it out in a more structured format, but my python is too weak to > actually write that conversion. I found a solution :-) Generate a string array in C head file to record the raw json string; Convert each json string to QObject, and convert the QObject to QDict for traversal by recursion; Define a new type and uion [1] to describe dynamical date for QMP. and allocate & connect nested members in recursion function. Finally, we can provide dynamical data with metadate according the definition in json file. I will send a v1 patch later. ---- [1] ---- { 'union': 'DataValue', 'data': { 'string': 'str', 'obj': 'DataObj' } } { 'type': 'DataObj', 'data': { '*key': 'str', 'value': 'DataValue' } } { 'type': 'SchemaData', 'data': { 'type': 'str', 'name': 'str', '*data': ['DataObj'], '*returns': ['DataObj'] } } -- Amos.