qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 07/27] qom: add property get/set wrappers for C types
Date: Mon, 06 Feb 2012 08:17:44 -0600	[thread overview]
Message-ID: <4F2FE108.1070904@codemonkey.ws> (raw)
In-Reply-To: <1328342577-25732-8-git-send-email-pbonzini@redhat.com>

On 02/04/2012 02:02 AM, Paolo Bonzini wrote:
> Add wrappers that let you get/set properties using normal C data types.
>
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>   include/qemu/object.h |   70 +++++++++++++++++++++++++++++
>   qom/object.c          |  119 +++++++++++++++++++++++++++++++++++++++++++++----
>   2 files changed, 180 insertions(+), 9 deletions(-)
>
> diff --git a/include/qemu/object.h b/include/qemu/object.h
> index ad7d32d..b27f80e 100644
> --- a/include/qemu/object.h
> +++ b/include/qemu/object.h
> @@ -622,6 +622,76 @@ void object_property_get(Object *obj, struct Visitor *v, const char *name,
>                            struct Error **errp);
>
>   /**
> + * object_property_set_str:
> + * @value: the value to be written to the property
> + * @name: the name of the property
> + * @errp: returns an error if this function fails
> + *
> + * Writes a string value to a property.
> + */
> +void object_property_set_str(Object *obj, const char *value,
> +                             const char *name, struct Error **errp);
> +
> +/**
> + * object_property_get_str:
> + * @obj: the object
> + * @name: the name of the property
> + * @errp: returns an error if this function fails
> + *
> + * Returns: the value of the property, converted to a C string, or NULL if
> + * an error occurs (including when the property value is not a string).
> + * The caller should free the string.
> + */
> +char *object_property_get_str(Object *obj, const char *name,
> +                              struct Error **errp);
> +
> +/**
> + * object_property_set_bool:
> + * @value: the value to be written to the property
> + * @name: the name of the property
> + * @errp: returns an error if this function fails
> + *
> + * Writes a bool value to a property.
> + */
> +void object_property_set_bool(Object *obj, bool value,
> +                              const char *name, struct Error **errp);
> +
> +/**
> + * object_property_get_bool:
> + * @obj: the object
> + * @name: the name of the property
> + * @errp: returns an error if this function fails
> + *
> + * Returns: the value of the property, converted to a boolean, or NULL if
> + * an error occurs (including when the property value is not a bool).
> + */
> +bool object_property_get_bool(Object *obj, const char *name,
> +                              struct Error **errp);
> +
> +/**
> + * object_property_set_int:
> + * @value: the value to be written to the property
> + * @name: the name of the property
> + * @errp: returns an error if this function fails
> + *
> + * Writes an integer value to a property.
> + */
> +void object_property_set_int(Object *obj, int64_t value,
> +                             const char *name, struct Error **errp);
> +
> +/**
> + * object_property_get_int:
> + * @obj: the object
> + * @name: the name of the property
> + * @errp: returns an error if this function fails
> + *
> + * Returns: the value of the property, converted to an integer, or NULL if
> + * an error occurs (including when the property value is not an integer).
> + */
> +int64_t object_property_get_int(Object *obj, const char *name,
> +                                struct Error **errp);
> +
> +/**
>    * object_property_set:
>    * @obj: the object
>    * @v: the visitor that will be used to write the property value.  This should
> diff --git a/qom/object.c b/qom/object.c
> index c0f6d54..d3a443f 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -14,6 +14,14 @@
>   #include "qemu-common.h"
>   #include "qapi/qapi-visit-core.h"
>
> +/* TODO: replace QObject with a simpler visitor to avoid a dependency
> + * of the QOM core on QObject?  */
> +#include "qemu/qom-qobject.h"
> +#include "qobject.h"
> +#include "qbool.h"
> +#include "qint.h"
> +#include "qstring.h"
> +
>   #define MAX_INTERFACES 32
>
>   typedef struct InterfaceImpl InterfaceImpl;
> @@ -646,6 +654,99 @@ void object_property_set(Object *obj, Visitor *v, const char *name,
>       }
>   }
>
> +void object_property_set_str(Object *obj, const char *value,
> +                             const char *name, Error **errp)
> +{
> +    QString *qstr = qstring_from_str(value);
> +    object_property_set_qobject(obj, QOBJECT(qstr), name, errp);
> +
> +    QDECREF(qstr);
> +}
> +
> +char *object_property_get_str(Object *obj, const char *name,
> +                              Error **errp)
> +{
> +    QObject *ret = object_property_get_qobject(obj, name, errp);
> +    QString *qstring;
> +    char *retval;
> +
> +    if (!ret) {
> +        return NULL;
> +    }
> +    qstring = qobject_to_qstring(ret);
> +    if (!qstring) {
> +        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, "string");
> +        retval = NULL;
> +    } else {
> +        retval = g_strdup(qstring_get_str(qstring));
> +    }
> +
> +    QDECREF(qstring);
> +    return retval;
> +}
> +
> +void object_property_set_bool(Object *obj, bool value,
> +                              const char *name, Error **errp)
> +{
> +    QBool *qbool = qbool_from_int(value);
> +    object_property_set_qobject(obj, QOBJECT(qbool), name, errp);
> +
> +    QDECREF(qbool);
> +}
> +
> +bool object_property_get_bool(Object *obj, const char *name,
> +                              Error **errp)
> +{
> +    QObject *ret = object_property_get_qobject(obj, name, errp);
> +    QBool *qbool;
> +    bool retval;
> +
> +    if (!ret) {
> +        return false;
> +    }
> +    qbool = qobject_to_qbool(ret);
> +    if (!qbool) {
> +        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, "boolean");
> +        retval = false;
> +    } else {
> +        retval = qbool_get_int(qbool);
> +    }
> +
> +    QDECREF(qbool);
> +    return retval;
> +}
> +
> +void object_property_set_int(Object *obj, int64_t value,
> +                             const char *name, Error **errp)
> +{
> +    QInt *qint = qint_from_int(value);
> +    object_property_set_qobject(obj, QOBJECT(qint), name, errp);
> +
> +    QDECREF(qint);
> +}
> +
> +int64_t object_property_get_int(Object *obj, const char *name,
> +                                Error **errp)
> +{
> +    QObject *ret = object_property_get_qobject(obj, name, errp);
> +    QInt *qint;
> +    int64_t retval;
> +
> +    if (!ret) {
> +        return -1;
> +    }
> +    qint = qobject_to_qint(ret);
> +    if (!qint) {
> +        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, "int");
> +        retval = -1;
> +    } else {
> +        retval = qint_get_int(qint);
> +    }
> +
> +    QDECREF(qint);
> +    return retval;
> +}
> +
>   const char *object_property_get_type(Object *obj, const char *name, Error **errp)
>   {
>       ObjectProperty *prop = object_property_find(obj, name);
> @@ -927,8 +1028,8 @@ typedef struct StringProperty
>       void (*set)(Object *, const char *, Error **);
>   } StringProperty;
>
> -static void object_property_get_str(Object *obj, Visitor *v, void *opaque,
> -                                    const char *name, Error **errp)
> +static void property_get_str(Object *obj, Visitor *v, void *opaque,
> +                             const char *name, Error **errp)
>   {
>       StringProperty *prop = opaque;
>       char *value;
> @@ -940,8 +1041,8 @@ static void object_property_get_str(Object *obj, Visitor *v, void *opaque,
>       }
>   }
>
> -static void object_property_set_str(Object *obj, Visitor *v, void *opaque,
> -                                  const char *name, Error **errp)
> +static void property_set_str(Object *obj, Visitor *v, void *opaque,
> +                             const char *name, Error **errp)
>   {
>       StringProperty *prop = opaque;
>       char *value;
> @@ -957,8 +1058,8 @@ static void object_property_set_str(Object *obj, Visitor *v, void *opaque,
>       g_free(value);
>   }
>
> -static void object_property_release_str(Object *obj, const char *name,
> -                                      void *opaque)
> +static void property_release_str(Object *obj, const char *name,
> +                                 void *opaque)
>   {
>       StringProperty *prop = opaque;
>       g_free(prop);
> @@ -975,8 +1076,8 @@ void object_property_add_str(Object *obj, const char *name,
>       prop->set = set;
>
>       object_property_add(obj, name, "string",
> -                        get ? object_property_get_str : NULL,
> -                        set ? object_property_set_str : NULL,
> -                        object_property_release_str,
> +                        get ? property_get_str : NULL,
> +                        set ? property_set_str : NULL,
> +                        property_release_str,
>                           prop, errp);
>   }

  reply	other threads:[~2012-02-06 14:17 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-04  8:02 [Qemu-devel] [PATCH v2 00/27] next steps for qdev & QOM Paolo Bonzini
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 01/27] qom: clean up cast macros Paolo Bonzini
2012-02-06 14:03   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 02/27] qom: more documentation on subclassing Paolo Bonzini
2012-02-06 14:04   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 03/27] qom: clean up/optimize object_dynamic_cast Paolo Bonzini
2012-02-06 14:10   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 04/27] qom: avoid useless conversions from string to type Paolo Bonzini
2012-02-06 14:14   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 05/27] qom: do not include qdev header file Paolo Bonzini
2012-02-06 14:15   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 06/27] qom: add QObject-based property get/set wrappers Paolo Bonzini
2012-02-06 14:16   ` Anthony Liguori
2012-02-07  9:12     ` Paolo Bonzini
2012-02-08 12:29       ` Luiz Capitulino
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 07/27] qom: add property get/set wrappers for C types Paolo Bonzini
2012-02-06 14:17   ` Anthony Liguori [this message]
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 08/27] qom: fix off-by-one Paolo Bonzini
2012-02-06 14:19   ` Anthony Liguori
2012-02-07  9:13     ` Paolo Bonzini
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 09/27] qom: add object_resolve_path_type Paolo Bonzini
2012-02-06 14:21   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 10/27] qom: use object_resolve_path_type for links Paolo Bonzini
2012-02-06 14:24   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 11/27] qom: fix canonical paths vs. interfaces Paolo Bonzini
2012-02-06 14:24   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 12/27] qom: add property get/set wrappers for links Paolo Bonzini
2012-02-06 14:27   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 13/27] qdev: remove direct calls to print/parse Paolo Bonzini
2012-02-06 14:30   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 14/27] qdev: allow reusing get/set for legacy property Paolo Bonzini
2012-02-06 14:31   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 15/27] qdev: remove parse method for string properties Paolo Bonzini
2012-02-06 14:31   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 16/27] qdev: remove print/parse methods from LostTickPolicy properties Paolo Bonzini
2012-02-06 14:32   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 17/27] qdev: remove parse/print methods for mac properties Paolo Bonzini
2012-02-06 14:32   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 18/27] qdev: make the non-legacy pci address property accept an integer Paolo Bonzini
2012-02-06 14:33   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 19/27] qdev: remove parse/print methods for pointer properties Paolo Bonzini
2012-02-06 14:34   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 20/27] qdev: let QOM free properties Paolo Bonzini
2012-02-06 14:35   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 21/27] qdev: fix off-by-one Paolo Bonzini
2012-02-06 14:35   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 22/27] qdev: access properties via QOM Paolo Bonzini
2012-02-06 14:36   ` Anthony Liguori
2012-02-11 15:46   ` Blue Swirl
2012-02-13  7:53     ` Paolo Bonzini
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 23/27] qdev: inline qdev_prop_set into qdev_prop_set_ptr Paolo Bonzini
2012-02-06 14:37   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 24/27] qdev: initialize properties via QOM Paolo Bonzini
2012-02-06 14:38   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 25/27] qdev: remove unused fields from PropertyInfo Paolo Bonzini
2012-02-06 14:39   ` Anthony Liguori
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 26/27] omap_clk: convert to QOM Paolo Bonzini
2012-02-06 14:42   ` Anthony Liguori
2012-02-06 16:32   ` Peter Maydell
2012-02-04  8:02 ` [Qemu-devel] [PATCH v2 27/27] omap: remove PROP_PTR properties Paolo Bonzini
2012-02-06 14:43   ` Anthony Liguori
2012-02-07 13:20 ` [Qemu-devel] [PATCH v2 00/27] next steps for qdev & QOM Paolo Bonzini

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=4F2FE108.1070904@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=pbonzini@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).