qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Aurelien Jarno" <aurelien@aurel32.net>
Subject: [PATCH 1/4] qom: object*_property_add_bool_ptr() functions
Date: Thu, 22 Oct 2020 18:31:37 -0400	[thread overview]
Message-ID: <20201022223140.2083123-2-ehabkost@redhat.com> (raw)
In-Reply-To: <20201022223140.2083123-1-ehabkost@redhat.com>

Provide helpers for registering boolean properties that simply
read/write a struct field, to reduce the need to manually write
property getters and setters.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
 include/qom/object.h | 23 +++++++++++++++++++++++
 qom/object.c         | 31 +++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index a124cf897d..954a26c567 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1815,6 +1815,29 @@ ObjectProperty *object_class_property_add_uint64_ptr(ObjectClass *klass,
                                           ptrdiff_t offset,
                                           ObjectPropertyFlags flags);
 
+/**
+ * object_property_add_bool_ptr:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @v: pointer to value
+ * @flags: bitwise-or'd ObjectPropertyFlags
+ *
+ * Add an bool property in memory.  This function will add a
+ * property of type 'bool'.
+ *
+ * Returns: The newly added property on success, or %NULL on failure.
+ */
+ObjectProperty *
+object_property_add_bool_ptr(Object *obj, const char *name,
+                             bool *v,
+                             ObjectPropertyFlags flags);
+
+ObjectProperty *
+object_class_property_add_bool_ptr(ObjectClass *klass,
+                                   const char *name,
+                                   ptrdiff_t offset,
+                                   ObjectPropertyFlags flags);
+
 /**
  * object_property_add_alias:
  * @obj: the object to add a property to
diff --git a/qom/object.c b/qom/object.c
index 73f27b8b7e..2abc2bda33 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2713,6 +2713,37 @@ object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
                                               flags, offset);
 }
 
+static void property_visit_bool_ptr(Object *obj, Visitor *v, const char *name,
+                                    void *opaque, Error **errp)
+{
+    PointerProperty *prop = opaque;
+    bool *field = pointer_property_get_ptr(obj, prop);
+    visit_type_bool(v, name, field, errp);
+}
+
+ObjectProperty *
+object_property_add_bool_ptr(Object *obj, const char *name,
+                             bool *v,
+                             ObjectPropertyFlags flags)
+{
+    return object_property_add_uint_ptr(obj, name, "bool",
+                                        property_visit_bool_ptr,
+                                        property_visit_bool_ptr,
+                                        flags,
+                                        (void *)v);
+}
+
+ObjectProperty *
+object_class_property_add_bool_ptr(ObjectClass *klass, const char *name,
+                                   ptrdiff_t offset,
+                                   ObjectPropertyFlags flags)
+{
+    return object_class_property_add_uint_ptr(klass, name, "bool",
+                                              property_visit_bool_ptr,
+                                              property_visit_bool_ptr,
+                                              flags, offset);
+}
+
 typedef struct {
     Object *target_obj;
     char *target_name;
-- 
2.28.0



  reply	other threads:[~2020-10-22 22:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-22 22:31 [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions Eduardo Habkost
2020-10-22 22:31 ` Eduardo Habkost [this message]
2020-10-22 22:31 ` [PATCH 2/4] autz/listfile: Use object_class_property_add_bool_ptr() Eduardo Habkost
2020-10-22 22:31 ` [PATCH 3/4] machine: Use object_class_property_add_bool_ptr() when possible Eduardo Habkost
2020-10-22 22:31 ` [PATCH 4/4] pc: Use object_class_property_add_bool_ptr() Eduardo Habkost
2020-10-23  7:37 ` [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions Philippe Mathieu-Daudé

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=20201022223140.2083123-2-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=armbru@redhat.com \
    --cc=aurelien@aurel32.net \
    --cc=berrange@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=imammedo@redhat.com \
    --cc=mst@redhat.com \
    --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).