From: Fam Zheng <famz@redhat.com>
To: Markus Armbruster <armbru@redhat.com>, eblake@redhat.com
Cc: Kevin Wolf <kwolf@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
Michael Roth <mdroth@linux.vnet.ibm.com>,
qemu-devel@nongnu.org, Luiz Capitulino <lcapitulino@redhat.com>,
akong@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 2/2] qapi: Allow setting default values for optional parameters
Date: Tue, 6 May 2014 09:30:11 +0800 [thread overview]
Message-ID: <20140506013011.GA1574@T430.nay.redhat.com> (raw)
In-Reply-To: <8761lktrg3.fsf@blackfin.pond.sub.org>
On Mon, 05/05 13:06, Markus Armbruster wrote:
> Fam Zheng <famz@redhat.com> writes:
> > An example command is:
> >
> > { 'command': 'my-command',
> > - 'data': { 'arg1': 'str', '*arg2': 'str' },
> > + 'data': { 'arg1': 'str', '*arg2': 'str', '*arg3': 'int' },
> > + 'defaults': { 'arg2': 'default value for arg2', 'arg3': 12345 },
> > 'returns': 'str' }
> >
> >
>
> I'm only reviewing schema design here.
Thanks! That's very constructive.
>
> So far, a command parameter has three propagated: name, type, and
> whether it's optional. Undocumented hack: a type '**' means "who
> knows", and suppresses marshalling function generation for the command.
>
> The three properties are encoded in a single member of 'data': name
> becomes the member name, and type becomes the value, except optional is
> shoehorned into the name as well[*].
>
> Your patch adds have a fourth property, namely the default value. It is
> only valid for optional parameters. You put it into a separate member
> 'defaults', next to 'data. This spreads parameter properties over two
> separate objects. I don't like that. What if we come up with a fifth
> one? Then it'll get even worse.
>
> Can we keep a parameter's properties together? Perhaps like this:
>
> NAME: { 'type': TYPE, 'default': DEFAULT }
>
> where
>
> NAME: { 'type': TYPE }
>
> can be abbreviated to
>
> NAME: TYPE
>
> and
>
> NAME: { 'type': TYPE, 'default': null }
Good idea. We have a problem to solve though.
In data definition, we allow inline sub-structure:
{ 'type': 'VersionInfo',
'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
'package': 'str'} }
If we allow properties as a dict, we need to disambiguate properly from the
above case. Proposing:
MAGIC: { 'name': NAME, 'type: TYPE, 'default': DEFAULT }
Where MAGIC should NOT be something that is a valid NAME from current schema.
Some ideas:
- Special string, that has invalid chars as a identifier, like '*', '%', '&',
etc, or simply an empty str ''.
Of course we need to enforce the checking and distinguishing in
scripts/qapi-types.py.
- Non-string: current NAME must be a string, any type non-string could be
distinguished from NAME, like number, bool, null, []. But its meaning could
be confusing to reviewer.
- Special symbol: we can define a dedicate symbol for this, like the literal
TYPE, in the schema. But this way we deviate more from JSON.
Personally, I think empty str '' makes more sense for me. What do you think?
Anyway we only add things, so we will keep the '*name' suger.
Thanks,
Fam
next prev parent reply other threads:[~2014-05-06 2:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1398764656-27534-1-git-send-email-famz@redhat.com>
[not found] ` <1398764656-27534-2-git-send-email-famz@redhat.com>
[not found] ` <535F9E40.8010407@redhat.com>
2014-05-05 8:33 ` [Qemu-devel] [PATCH v2 1/2] qapi: Allow decimal values Markus Armbruster
[not found] ` <1398764656-27534-3-git-send-email-famz@redhat.com>
[not found] ` <20140429112436.GE4835@noname.str.redhat.com>
[not found] ` <535FA06F.2060603@redhat.com>
2014-05-04 3:14 ` [Qemu-devel] [PATCH v2 2/2] qapi: Allow setting default values for optional parameters Fam Zheng
2014-05-05 9:51 ` Markus Armbruster
2014-05-05 15:13 ` Eric Blake
2014-05-05 11:06 ` Markus Armbruster
2014-05-05 15:18 ` Eric Blake
2014-05-05 17:34 ` Markus Armbruster
2014-05-05 23:03 ` Eric Blake
2014-05-06 9:55 ` Markus Armbruster
2014-05-06 12:35 ` Eric Blake
2014-05-06 15:09 ` Markus Armbruster
2014-05-06 1:30 ` Fam Zheng [this message]
2014-05-06 3:09 ` Eric Blake
2014-05-06 5:11 ` Fam Zheng
2014-05-06 11:57 ` Markus Armbruster
2014-05-06 11:53 ` Markus Armbruster
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=20140506013011.GA1574@T430.nay.redhat.com \
--to=famz@redhat.com \
--cc=akong@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=peter.maydell@linaro.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).