qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"John Snow" <jsnow@redhat.com>
Subject: [PATCH 02/12] qom: Introduce PointerProperty struct
Date: Fri,  9 Oct 2020 12:01:12 -0400	[thread overview]
Message-ID: <20201009160122.1662082-3-ehabkost@redhat.com> (raw)
In-Reply-To: <20201009160122.1662082-1-ehabkost@redhat.com>

PointerProperty will hold additional info about pointer
properties.  It will allow us to implement more complex logic in
pointer 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
---
 qom/object.c | 46 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 36 insertions(+), 10 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index 313d2f9834..17692ed5c3 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2449,17 +2449,30 @@ static char *object_get_type(Object *obj, Error **errp)
     return g_strdup(object_get_typename(obj));
 }
 
+typedef struct {
+    /* Pointer to property value */
+    void *ptr;
+} PointerProperty;
+
+static void *pointer_property_get_ptr(Object *obj, PointerProperty *prop)
+{
+    return prop->ptr;
+}
+
 static void property_get_uint8_ptr(Object *obj, Visitor *v, const char *name,
                                    void *opaque, Error **errp)
 {
-    uint8_t value = *(uint8_t *)opaque;
+    PointerProperty *prop = opaque;
+    uint8_t *field = pointer_property_get_ptr(obj, prop);
+    uint8_t value = *field;
     visit_type_uint8(v, name, &value, errp);
 }
 
 static void property_set_uint8_ptr(Object *obj, Visitor *v, const char *name,
                                    void *opaque, Error **errp)
 {
-    uint8_t *field = opaque;
+    PointerProperty *prop = opaque;
+    uint8_t *field = pointer_property_get_ptr(obj, prop);
     uint8_t value;
 
     if (!visit_type_uint8(v, name, &value, errp)) {
@@ -2472,14 +2485,17 @@ static void property_set_uint8_ptr(Object *obj, Visitor *v, const char *name,
 static void property_get_uint16_ptr(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
 {
-    uint16_t value = *(uint16_t *)opaque;
+    PointerProperty *prop = opaque;
+    uint16_t *field = pointer_property_get_ptr(obj, prop);
+    uint16_t value = *field;
     visit_type_uint16(v, name, &value, errp);
 }
 
 static void property_set_uint16_ptr(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
 {
-    uint16_t *field = opaque;
+    PointerProperty *prop = opaque;
+    uint16_t *field = pointer_property_get_ptr(obj, prop);
     uint16_t value;
 
     if (!visit_type_uint16(v, name, &value, errp)) {
@@ -2492,14 +2508,17 @@ static void property_set_uint16_ptr(Object *obj, Visitor *v, const char *name,
 static void property_get_uint32_ptr(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
 {
-    uint32_t value = *(uint32_t *)opaque;
+    PointerProperty *prop = opaque;
+    uint32_t *field = pointer_property_get_ptr(obj, prop);
+    uint32_t value = *field;
     visit_type_uint32(v, name, &value, errp);
 }
 
 static void property_set_uint32_ptr(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
 {
-    uint32_t *field = opaque;
+    PointerProperty *prop = opaque;
+    uint32_t *field = pointer_property_get_ptr(obj, prop);
     uint32_t value;
 
     if (!visit_type_uint32(v, name, &value, errp)) {
@@ -2512,14 +2531,17 @@ static void property_set_uint32_ptr(Object *obj, Visitor *v, const char *name,
 static void property_get_uint64_ptr(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
 {
-    uint64_t value = *(uint64_t *)opaque;
+    PointerProperty *prop = opaque;
+    uint64_t *field = pointer_property_get_ptr(obj, prop);
+    uint64_t value = *field;
     visit_type_uint64(v, name, &value, errp);
 }
 
 static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
 {
-    uint64_t *field = opaque;
+    PointerProperty *prop = opaque;
+    uint64_t *field = pointer_property_get_ptr(obj, prop);
     uint64_t value;
 
     if (!visit_type_uint64(v, name, &value, errp)) {
@@ -2537,10 +2559,12 @@ object_property_add_uint_ptr(Object *obj, const char *name,
                             ObjectPropertyFlags flags,
                             void *ptr)
 {
+    PointerProperty *prop = g_new0(PointerProperty, 1);
+    prop->ptr = ptr;
     return object_property_add(obj, name, type,
                                (flags & OBJ_PROP_FLAG_READ) ? getter : NULL,
                                (flags & OBJ_PROP_FLAG_WRITE) ? setter : NULL,
-                               NULL, ptr);
+                               NULL, (void *)prop);
 }
 
 static ObjectProperty *
@@ -2551,10 +2575,12 @@ object_class_property_add_uint_ptr(ObjectClass *oc, const char *name,
                                    ObjectPropertyFlags flags,
                                    void *ptr)
 {
+    PointerProperty *prop = g_new0(PointerProperty, 1);
+    prop->ptr = ptr;
     return object_class_property_add(oc, name, type,
                                      (flags & OBJ_PROP_FLAG_READ) ? getter : NULL,
                                      (flags & OBJ_PROP_FLAG_WRITE) ? setter : NULL,
-                                     NULL, ptr);
+                                     NULL, (void *)prop);
 }
 
 ObjectProperty *
-- 
2.26.2



  parent reply	other threads:[~2020-10-09 16:13 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-09 16:01 [PATCH 00/12] qom: Make all -object types use only class properties Eduardo Habkost
2020-10-09 16:01 ` [PATCH 01/12] qom: Helpers for pointer properties Eduardo Habkost
2020-10-09 16:01 ` Eduardo Habkost [this message]
2020-10-09 16:01 ` [PATCH 03/12] qom: Make object_class_property_add_uint*_ptr() get offset Eduardo Habkost
2020-10-09 17:24   ` Eric Blake
2020-10-09 17:31     ` Eduardo Habkost
2020-10-21 12:24   ` Igor Mammedov
2020-10-21 13:30     ` Eduardo Habkost
2020-10-22  5:06       ` Markus Armbruster
2020-10-22 21:34         ` Eduardo Habkost
2020-10-23 15:33       ` Igor Mammedov
2020-10-27 22:18         ` Eduardo Habkost
2020-10-28 15:22         ` Paolo Bonzini
2020-10-28 15:53           ` Igor Mammedov
2020-10-29 12:56           ` Eduardo Habkost
2020-10-29 13:37             ` Igor Mammedov
2020-10-09 16:01 ` [PATCH 04/12] sev: Use class properties Eduardo Habkost
2020-10-09 16:01 ` [PATCH 05/12] rng: " Eduardo Habkost
2020-10-09 16:01 ` [PATCH 06/12] can_host: " Eduardo Habkost
2020-10-12 14:52   ` Pavel Pisa
2020-10-09 16:01 ` [PATCH 07/12] colo: " Eduardo Habkost
2020-10-09 16:01 ` [PATCH 08/12] netfilter: Reorder functions Eduardo Habkost
2020-10-09 16:01 ` [PATCH 09/12] netfilter: Use class properties Eduardo Habkost
2020-10-09 16:01 ` [PATCH 10/12] input: " Eduardo Habkost
2020-10-13 12:54   ` Gerd Hoffmann
2020-10-09 16:01 ` [PATCH 11/12] [RFC] qom: Property lock mechanism Eduardo Habkost
2020-10-09 16:01 ` [PATCH 12/12] [RFC] qom: Lock properties of all TYPE_USER_CREATABLE types Eduardo Habkost
2020-10-09 21:31   ` [PATCH] check-qom-proplist: Don't register instance props for user-creatable type Eduardo Habkost

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=20201009160122.1662082-3-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@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).