[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-trivial] [PATCH v6] qdev: Add support for property type bool
From: |
Jan Kiszka |
Subject: |
Re: [Qemu-trivial] [PATCH v6] qdev: Add support for property type bool |
Date: |
Tue, 24 Jan 2012 18:29:08 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 |
On 2012-01-24 18:17, Andreas Färber wrote:
> From: Andreas Färber <address@hidden>
>
> VMState supports the type bool but qdev instead supports bit, backed by
> uint32_t. Therefore let's add DEFINE_PROP_BOOL() and qdev_prop_set_bool().
>
> bool by definition is either true or false. Should the need arise to
> parse yes/no, on/off, 1/0 or whatever as well, we can still add that at
> a later point in time.
To make it a real replacement for PROP_TYPE_BIT, let's use on/off, also
for printing. Not only programmers may use this interface. ;)
>
> Signed-off-by: Andreas Färber <address@hidden>
> Cc: Juan Quintela <address@hidden>
> Cc: Markus Armbruster <address@hidden>
> Cc: Jan Kiszka <address@hidden>
> Cc: Vasilis Liaskovitis <address@hidden>
> ---
> v5 -> v6:
> * Rebased onto QOM properties.
> * Parse and print true/false for bool, leave bit untouched.
> Please review, v6 untested.
>
> v4 -> v5 (40P):
> * Parse on/off in addition to yes/no for both bit and bool, print yes/no for
> bool.
>
> v4 (ISA):
> * Introduced.
>
> hw/qdev-properties.c | 62
> ++++++++++++++++++++++++++++++++++++++++++++++++++
> hw/qdev.h | 4 +++
> 2 files changed, 66 insertions(+), 0 deletions(-)
>
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index 02f0dae..612f2ea 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -96,6 +96,68 @@ PropertyInfo qdev_prop_bit = {
> .set = set_bit,
> };
>
> +/* --- bool --- */
> +
> +static int parse_bool(DeviceState *dev, Property *prop, const char *str)
> +{
> + bool *ptr = qdev_get_prop_ptr(dev, prop);
> + if (strcmp(str, "true") == 0) {
> + *ptr = true;
> + } else if (strcmp(str, "false") == 0) {
> + *ptr = false;
> + } else {
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> +static int print_bool(DeviceState *dev, Property *prop, char *dest, size_t
> len)
> +{
> + bool *ptr = qdev_get_prop_ptr(dev, prop);
> + return snprintf(dest, len, *ptr ? "true" : "false");
> +}
> +
> +static void get_bool(DeviceState *dev, Visitor *v, void *opaque,
> + const char *name, Error **errp)
> +{
> + Property *prop = opaque;
> + bool *ptr = qdev_get_prop_ptr(dev, prop);
> +
> + visit_type_bool(v, ptr, name, errp);
> +}
> +
> +static void set_bool(DeviceState *dev, Visitor *v, void *opaque,
> + const char *name, Error **errp)
> +{
> + Property *prop = opaque;
> + bool *ptr = qdev_get_prop_ptr(dev, prop);
> + Error *local_err = NULL;
> + bool value;
> +
> + if (dev->state != DEV_STATE_CREATED) {
> + error_set(errp, QERR_PERMISSION_DENIED);
> + return;
> + }
> +
> + visit_type_bool(v, &value, name, &local_err);
> + if (local_err) {
> + error_propagate(errp, local_err);
> + return;
> + }
> + *ptr = value;
> +}
> +
> +PropertyInfo qdev_prop_bool = {
> + .name = "bool",
Now we have "bool" and "boolean". Can we rename the latter to bit?
Jan
--
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux