9ae3a8
From 5b321366d742d4efe826036108b06796563ea0ed Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <5b321366d742d4efe826036108b06796563ea0ed.1387298827.git.minovotn@redhat.com>
9ae3a8
In-Reply-To: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
9ae3a8
References: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
9ae3a8
From: "Michael S. Tsirkin" <mst@redhat.com>
9ae3a8
Date: Tue, 17 Dec 2013 15:17:53 +0100
9ae3a8
Subject: [PATCH 25/56] qom: add pointer to int property helpers
9ae3a8
9ae3a8
RH-Author: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
Message-id: <1387293161-4085-26-git-send-email-mst@redhat.com>
9ae3a8
Patchwork-id: 56331
9ae3a8
O-Subject: [PATCH qemu-kvm RHEL7.0 v2 25/57] qom: add pointer to int property helpers
9ae3a8
Bugzilla: 1034876
9ae3a8
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
9ae3a8
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
9ae3a8
Make it easy to add read-only helpers for simple
9ae3a8
integer properties in memory.
9ae3a8
9ae3a8
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
9ae3a8
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
9ae3a8
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
9ae3a8
Tested-by: Igor Mammedov <imammedo@redhat.com>
9ae3a8
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
(cherry picked from commit e732ea638705da35445a42dee32691fbe813d3e0)
9ae3a8
---
9ae3a8
 include/qom/object.h | 21 ++++++++++++++++++
9ae3a8
 qom/object.c         | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
9ae3a8
 2 files changed, 81 insertions(+)
9ae3a8
9ae3a8
Signed-off-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
---
9ae3a8
 include/qom/object.h | 21 ++++++++++++++++++
9ae3a8
 qom/object.c         | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
9ae3a8
 2 files changed, 81 insertions(+)
9ae3a8
9ae3a8
diff --git a/include/qom/object.h b/include/qom/object.h
9ae3a8
index dbe1413..193bfeb 100644
9ae3a8
--- a/include/qom/object.h
9ae3a8
+++ b/include/qom/object.h
9ae3a8
@@ -790,6 +790,27 @@ void object_property_add(Object *obj, const char *name, const char *type,
9ae3a8
 void object_property_del(Object *obj, const char *name, Error **errp);
9ae3a8
 
9ae3a8
 /**
9ae3a8
+ * object_property_add_uint8_ptr:
9ae3a8
+ * object_property_add_uint16_ptr:
9ae3a8
+ * object_property_add_uint32_ptr:
9ae3a8
+ * object_property_add_uint64_ptr:
9ae3a8
+ * @obj: the object to add a property to
9ae3a8
+ * @name: the name of the property
9ae3a8
+ * @v: pointer to value
9ae3a8
+ *
9ae3a8
+ * Add an integer property in memory.  This function will add a
9ae3a8
+ * property of the appropriate type.
9ae3a8
+ */
9ae3a8
+void object_property_add_uint8_ptr(Object *obj, const char *name,
9ae3a8
+                                   const uint8_t *v, Error **errp);
9ae3a8
+void object_property_add_uint16_ptr(Object *obj, const char *name,
9ae3a8
+                                    const uint16_t *v, Error **errp);
9ae3a8
+void object_property_add_uint32_ptr(Object *obj, const char *name,
9ae3a8
+                                    const uint32_t *v, Error **errp);
9ae3a8
+void object_property_add_uint64_ptr(Object *obj, const char *name,
9ae3a8
+                                    const uint64_t *v, Error **Errp);
9ae3a8
+
9ae3a8
+/**
9ae3a8
  * object_property_find:
9ae3a8
  * @obj: the object
9ae3a8
  * @name: the name of the property
9ae3a8
diff --git a/qom/object.c b/qom/object.c
9ae3a8
index 05e2636..d04a96b 100644
9ae3a8
--- a/qom/object.c
9ae3a8
+++ b/qom/object.c
9ae3a8
@@ -1331,6 +1331,66 @@ static char *qdev_get_type(Object *obj, Error **errp)
9ae3a8
     return g_strdup(object_get_typename(obj));
9ae3a8
 }
9ae3a8
 
9ae3a8
+static void property_get_uint8_ptr(Object *obj, Visitor *v,
9ae3a8
+                                   void *opaque, const char *name,
9ae3a8
+                                   Error **errp)
9ae3a8
+{
9ae3a8
+    uint8_t value = *(uint8_t *)opaque;
9ae3a8
+    visit_type_uint8(v, &value, name, errp);
9ae3a8
+}
9ae3a8
+
9ae3a8
+static void property_get_uint16_ptr(Object *obj, Visitor *v,
9ae3a8
+                                   void *opaque, const char *name,
9ae3a8
+                                   Error **errp)
9ae3a8
+{
9ae3a8
+    uint16_t value = *(uint16_t *)opaque;
9ae3a8
+    visit_type_uint16(v, &value, name, errp);
9ae3a8
+}
9ae3a8
+
9ae3a8
+static void property_get_uint32_ptr(Object *obj, Visitor *v,
9ae3a8
+                                   void *opaque, const char *name,
9ae3a8
+                                   Error **errp)
9ae3a8
+{
9ae3a8
+    uint32_t value = *(uint32_t *)opaque;
9ae3a8
+    visit_type_uint32(v, &value, name, errp);
9ae3a8
+}
9ae3a8
+
9ae3a8
+static void property_get_uint64_ptr(Object *obj, Visitor *v,
9ae3a8
+                                   void *opaque, const char *name,
9ae3a8
+                                   Error **errp)
9ae3a8
+{
9ae3a8
+    uint64_t value = *(uint64_t *)opaque;
9ae3a8
+    visit_type_uint64(v, &value, name, errp);
9ae3a8
+}
9ae3a8
+
9ae3a8
+void object_property_add_uint8_ptr(Object *obj, const char *name,
9ae3a8
+                                   const uint8_t *v, Error **errp)
9ae3a8
+{
9ae3a8
+    object_property_add(obj, name, "uint8", property_get_uint8_ptr,
9ae3a8
+                        NULL, NULL, (void *)v, errp);
9ae3a8
+}
9ae3a8
+
9ae3a8
+void object_property_add_uint16_ptr(Object *obj, const char *name,
9ae3a8
+                                    const uint16_t *v, Error **errp)
9ae3a8
+{
9ae3a8
+    object_property_add(obj, name, "uint16", property_get_uint16_ptr,
9ae3a8
+                        NULL, NULL, (void *)v, errp);
9ae3a8
+}
9ae3a8
+
9ae3a8
+void object_property_add_uint32_ptr(Object *obj, const char *name,
9ae3a8
+                                    const uint32_t *v, Error **errp)
9ae3a8
+{
9ae3a8
+    object_property_add(obj, name, "uint32", property_get_uint32_ptr,
9ae3a8
+                        NULL, NULL, (void *)v, errp);
9ae3a8
+}
9ae3a8
+
9ae3a8
+void object_property_add_uint64_ptr(Object *obj, const char *name,
9ae3a8
+                                    const uint64_t *v, Error **errp)
9ae3a8
+{
9ae3a8
+    object_property_add(obj, name, "uint64", property_get_uint64_ptr,
9ae3a8
+                        NULL, NULL, (void *)v, errp);
9ae3a8
+}
9ae3a8
+
9ae3a8
 static void object_instance_init(Object *obj)
9ae3a8
 {
9ae3a8
     object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
9ae3a8
-- 
9ae3a8
1.7.11.7
9ae3a8