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 01/12] qom: Helpers for pointer properties
Date: Fri, 9 Oct 2020 12:01:11 -0400 [thread overview]
Message-ID: <20201009160122.1662082-2-ehabkost@redhat.com> (raw)
In-Reply-To: <20201009160122.1662082-1-ehabkost@redhat.com>
Reduce some code duplication and make future refactoring easier,
by adding object_property_add_uint_ptr() and
object_class_property_add_uint_ptr() helpers.
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 | 168 ++++++++++++++++++++-------------------------------
1 file changed, 64 insertions(+), 104 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index 1065355233..313d2f9834 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2529,24 +2529,44 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name,
*field = value;
}
+static ObjectProperty *
+object_property_add_uint_ptr(Object *obj, const char *name,
+ const char *type,
+ ObjectPropertyAccessor getter,
+ ObjectPropertyAccessor setter,
+ ObjectPropertyFlags flags,
+ void *ptr)
+{
+ return object_property_add(obj, name, type,
+ (flags & OBJ_PROP_FLAG_READ) ? getter : NULL,
+ (flags & OBJ_PROP_FLAG_WRITE) ? setter : NULL,
+ NULL, ptr);
+}
+
+static ObjectProperty *
+object_class_property_add_uint_ptr(ObjectClass *oc, const char *name,
+ const char *type,
+ ObjectPropertyAccessor getter,
+ ObjectPropertyAccessor setter,
+ ObjectPropertyFlags flags,
+ void *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);
+}
+
ObjectProperty *
object_property_add_uint8_ptr(Object *obj, const char *name,
const uint8_t *v,
ObjectPropertyFlags flags)
{
- ObjectPropertyAccessor *getter = NULL;
- ObjectPropertyAccessor *setter = NULL;
-
- if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) {
- getter = property_get_uint8_ptr;
- }
-
- if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
- setter = property_set_uint8_ptr;
- }
-
- return object_property_add(obj, name, "uint8",
- getter, setter, NULL, (void *)v);
+ return object_property_add_uint_ptr(obj, name, "uint8",
+ property_get_uint8_ptr,
+ property_set_uint8_ptr,
+ flags,
+ (void *)v);
}
ObjectProperty *
@@ -2554,19 +2574,10 @@ object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name,
const uint8_t *v,
ObjectPropertyFlags flags)
{
- ObjectPropertyAccessor *getter = NULL;
- ObjectPropertyAccessor *setter = NULL;
-
- if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) {
- getter = property_get_uint8_ptr;
- }
-
- if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
- setter = property_set_uint8_ptr;
- }
-
- return object_class_property_add(klass, name, "uint8",
- getter, setter, NULL, (void *)v);
+ return object_class_property_add_uint_ptr(klass, name, "uint8",
+ property_get_uint8_ptr,
+ property_set_uint8_ptr,
+ flags, (void *)v);
}
ObjectProperty *
@@ -2574,19 +2585,11 @@ object_property_add_uint16_ptr(Object *obj, const char *name,
const uint16_t *v,
ObjectPropertyFlags flags)
{
- ObjectPropertyAccessor *getter = NULL;
- ObjectPropertyAccessor *setter = NULL;
-
- if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) {
- getter = property_get_uint16_ptr;
- }
-
- if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
- setter = property_set_uint16_ptr;
- }
-
- return object_property_add(obj, name, "uint16",
- getter, setter, NULL, (void *)v);
+ return object_property_add_uint_ptr(obj, name, "uint16",
+ property_get_uint16_ptr,
+ property_set_uint16_ptr,
+ flags,
+ (void *)v);
}
ObjectProperty *
@@ -2594,19 +2597,10 @@ object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name,
const uint16_t *v,
ObjectPropertyFlags flags)
{
- ObjectPropertyAccessor *getter = NULL;
- ObjectPropertyAccessor *setter = NULL;
-
- if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) {
- getter = property_get_uint16_ptr;
- }
-
- if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
- setter = property_set_uint16_ptr;
- }
-
- return object_class_property_add(klass, name, "uint16",
- getter, setter, NULL, (void *)v);
+ return object_class_property_add_uint_ptr(klass, name, "uint16",
+ property_get_uint16_ptr,
+ property_set_uint16_ptr,
+ flags, (void *)v);
}
ObjectProperty *
@@ -2614,19 +2608,11 @@ object_property_add_uint32_ptr(Object *obj, const char *name,
const uint32_t *v,
ObjectPropertyFlags flags)
{
- ObjectPropertyAccessor *getter = NULL;
- ObjectPropertyAccessor *setter = NULL;
-
- if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) {
- getter = property_get_uint32_ptr;
- }
-
- if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
- setter = property_set_uint32_ptr;
- }
-
- return object_property_add(obj, name, "uint32",
- getter, setter, NULL, (void *)v);
+ return object_property_add_uint_ptr(obj, name, "uint32",
+ property_get_uint32_ptr,
+ property_set_uint32_ptr,
+ flags,
+ (void *)v);
}
ObjectProperty *
@@ -2634,19 +2620,10 @@ object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
const uint32_t *v,
ObjectPropertyFlags flags)
{
- ObjectPropertyAccessor *getter = NULL;
- ObjectPropertyAccessor *setter = NULL;
-
- if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) {
- getter = property_get_uint32_ptr;
- }
-
- if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
- setter = property_set_uint32_ptr;
- }
-
- return object_class_property_add(klass, name, "uint32",
- getter, setter, NULL, (void *)v);
+ return object_class_property_add_uint_ptr(klass, name, "uint32",
+ property_get_uint32_ptr,
+ property_set_uint32_ptr,
+ flags, (void *)v);
}
ObjectProperty *
@@ -2654,19 +2631,11 @@ object_property_add_uint64_ptr(Object *obj, const char *name,
const uint64_t *v,
ObjectPropertyFlags flags)
{
- ObjectPropertyAccessor *getter = NULL;
- ObjectPropertyAccessor *setter = NULL;
-
- if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) {
- getter = property_get_uint64_ptr;
- }
-
- if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
- setter = property_set_uint64_ptr;
- }
-
- return object_property_add(obj, name, "uint64",
- getter, setter, NULL, (void *)v);
+ return object_property_add_uint_ptr(obj, name, "uint64",
+ property_get_uint64_ptr,
+ property_set_uint64_ptr,
+ flags,
+ (void *)v);
}
ObjectProperty *
@@ -2674,19 +2643,10 @@ object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
const uint64_t *v,
ObjectPropertyFlags flags)
{
- ObjectPropertyAccessor *getter = NULL;
- ObjectPropertyAccessor *setter = NULL;
-
- if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) {
- getter = property_get_uint64_ptr;
- }
-
- if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
- setter = property_set_uint64_ptr;
- }
-
- return object_class_property_add(klass, name, "uint64",
- getter, setter, NULL, (void *)v);
+ return object_class_property_add_uint_ptr(klass, name, "uint64",
+ property_get_uint64_ptr,
+ property_set_uint64_ptr,
+ flags, (void *)v);
}
typedef struct {
--
2.26.2
next prev parent reply other threads:[~2020-10-09 16:12 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 ` Eduardo Habkost [this message]
2020-10-09 16:01 ` [PATCH 02/12] qom: Introduce PointerProperty struct Eduardo Habkost
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-2-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).