From: Anthony Liguori <anthony@codemonkey.ws>
Cc: Alon Levy <alevy@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
Date: Mon, 07 Feb 2011 09:23:39 -0600 [thread overview]
Message-ID: <4D500E7B.9060006@codemonkey.ws> (raw)
In-Reply-To: <4D500680.3020303@codemonkey.ws>
On 02/07/2011 08:49 AM, Anthony Liguori wrote:
> On 02/07/2011 08:14 AM, Alon Levy wrote:
>> Fair enough, so a patch that added enumeration through QMP would be
>> acceptable?
>> I'm not even sure that makes sense, would you mind outlining how you
>> see this
>> implemented?
>
> Before we write any code, we need to figure out what an enum is, how
> we want to transport it via QMP, and how we will support introspection
> on it.
>
> In terms of the protocol format, I'm inclined to suggest that we
> transmit enums as integers as it maps better to C. That way, we can
> write a first class enumeration type and build our interfaces on top
> of that.
>
> I'm working on a QMP rewrite using a schema located at
> http://repo.or.cz/w/qemu/aliguori.git/shortlog/refs/heads/glib
>
> The schema has the notion of defining types along side with defining
> interfaces. Adding a syntax to define an enum would be pretty
> straight forward. Probably something like:
>
> { 'DriftCompensationPolicy': [{'gradual': 'int'}, {'fast': 'int'},
> {'none': 'int'}] }
http://repo.or.cz/w/qemu/aliguori.git/commit/50375b29f512c18d03cec8b1f9fea47ffdb6b232
Is a start at what I'm talking about here. Adding the qdev type bits
should be pretty straight forward.
Regards,
Anthony Liguori
>
> This would in turn generate:
>
> typedef enum DriftCompensationPolicy {
> DRIFT_COMPENSATION_POLICY_GRADUAL = 0,
> DRIFT_COMPENSATION_POLICY_FAST,
> DRIFT_COMPENSATION_POLICY_NONE
> } DriftCompensationPolicy;
>
> From a QMP side, the value would be marshalled as an integer but the
> schema would contain the type 'DriftCompensationPolicy' as the type.
>
> For -device, this would mean that enums would be treated as integer
> properties, and we'd need some boiler plate code to register the enum
> with symbolic names.
>
> From a qdev perspective, I think it would be easier to generate a
> unique property type for every specific enum type. That means the
> qdev side ends up looking like:
>
> PropertyInfo qdev_prop_drift_compensation_policy = {
> .name = "DriftCompensationPolicy",
> .type = PROP_TYPE_INT32,
> .size = sizeof(DriftCompensationPolicy),
> .parse = parse_drift_compensation_policy,
> .print = print_drift_compensation_policy,
> };
>
> struct MyDevice {
> DriftCompensationPolicy drift_policy;
> };
>
> DEFINE_PROP_DRIFT_COMPENSATION_POLICY("drift_policy", MyDevice,
> drift_policy,
>
> DRIFT_COMPENSATION_POLICY_NONE);
>
> We could autogenerate all of this code from the QMP schema too. It's
> possible to do a one-off forwards compatible enum type for qdev but
> I'd strongly prefer to get the QMP infrastructure in place first.
>
> But the advantage of this approach is pretty significant IMHO. We get
> to work in native C enumeration types both in QEMU and libqmp. That's
> a big win for type safety.
>
> BTW, if we treat QMP introspection as just returning the QMP schema
> that we use for code generation (it's valid JSON afterall), then we
> get enumeration introspection for free.
>
> I think this efficiently gives us what danpb's earlier series was
> going for with his introspection patch set.
>
> Regards,
>
> Anthony Liguori
>
>>> Regards,
>>>
>>> Anthony Liguori
>>>
>>>
>
>
next prev parent reply other threads:[~2011-02-07 15:23 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-03 22:45 [Qemu-devel] [PATCH 00/16] usb-ccid (v18) Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 01/16] qdev: add print_options callback Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 02/16] qdev: add data pointer to Property Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM Alon Levy
2011-02-07 8:53 ` Markus Armbruster
2011-02-07 10:43 ` Alon Levy
2011-02-07 13:15 ` Anthony Liguori
2011-02-07 14:05 ` Markus Armbruster
2011-02-07 14:21 ` Anthony Liguori
2011-02-07 14:14 ` Alon Levy
2011-02-07 14:49 ` Anthony Liguori
2011-02-07 15:23 ` Anthony Liguori [this message]
2011-02-07 14:00 ` Markus Armbruster
2011-02-07 14:27 ` Alon Levy
2011-02-08 15:34 ` Alon Levy
2011-02-08 15:47 ` Markus Armbruster
2011-02-07 13:20 ` Anthony Liguori
2011-02-03 22:45 ` [Qemu-devel] [PATCH 04/16] qdev-properties: parse_enum: don't cast a void* Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 05/16] usb-ccid: add CCID bus Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 06/16] introduce libcacard/vscard_common.h Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 07/16] ccid: add passthru card device Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 08/16] libcacard: initial commit Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 09/16] ccid: add ccid-card-emulated device (v2) Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 10/16] ccid: add docs Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 11/16] ccid: configure: add --enable/disable and nss only disable Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 12/16] ccid: add qdev description strings Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 13/16] smartcard, configure: add --enable-smartcard-nss, report only nss Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 14/16] smartcard,configure: " Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 15/16] ccid-card-emulated: don't link with NSS if --disable-smartcard-nss Alon Levy
2011-02-03 22:45 ` [Qemu-devel] [PATCH 16/16] ccid.h: add copyright, fix define and remove non C89 comments Alon Levy
2011-02-07 11:03 ` [Qemu-devel] [PATCH 00/16] usb-ccid (v18) Alon Levy
2011-02-07 13:12 ` Anthony Liguori
2011-02-07 15:44 ` Alon Levy
2011-02-07 15:56 ` Eric Blake
2011-02-07 18:00 ` Alon Levy
2011-02-07 19:31 ` Anthony Liguori
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=4D500E7B.9060006@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=alevy@redhat.com \
--cc=armbru@redhat.com \
--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).