qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH target-arm v4 02/12] qom: Add object_property_add_bo


From: Peter Crosthwaite
Subject: [Qemu-devel] [PATCH target-arm v4 02/12] qom: Add object_property_add_bool_ptr()
Date: Tue, 10 Dec 2013 18:54:07 -0800

Integers have an API to add a property via a pointer to storage -
object_property_add_uintXX_ptr(). This is convenient for defining
dynamic properties without having to define local setters and getters.

This patch does the same for the boolean type - object can now easily
define boolean properties with the trivial setters and getters.

Signed-off-by: Peter Crosthwaite <address@hidden>
---

 include/qom/object.h | 13 +++++++++++++
 qom/object.c         | 24 ++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index a275db2..c68aba3 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1113,6 +1113,19 @@ void object_property_add_bool(Object *obj, const char 
*name,
                               Error **errp);
 
 /**
+ * object_property_add_bool_ptr:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @v: pointer to value
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add a bool property in memory.  This function will add a
+ * property of type 'bool'.
+ */
+void object_property_add_bool_ptr(Object *obj, const char *name,
+                                  const bool *v, Error **errp);
+
+/**
  * object_property_add_uint8_ptr:
  * @obj: the object to add a property to
  * @name: the name of the property
diff --git a/qom/object.c b/qom/object.c
index 07b454b..6c9cef9 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1345,6 +1345,23 @@ static char *qdev_get_type(Object *obj, Error **errp)
     return g_strdup(object_get_typename(obj));
 }
 
+static void property_get_bool_ptr(Object *obj, Visitor *v,
+                                  void *opaque, const char *name,
+                                  Error **errp)
+{
+    bool value = *(bool *)opaque;
+    visit_type_bool(v, &value, name, errp);
+}
+
+static void property_set_bool_ptr(Object *obj, Visitor *v,
+                                  void *opaque, const char *name,
+                                  Error **errp)
+{
+    bool value;
+    visit_type_bool(v, &value, name, errp);
+    *(bool *)opaque = value;
+}
+
 static void property_get_uint8_ptr(Object *obj, Visitor *v,
                                    void *opaque, const char *name,
                                    Error **errp)
@@ -1413,6 +1430,13 @@ static void property_set_uint64_ptr(Object *obj, Visitor 
*v,
     *(uint64_t *)opaque = value;
 }
 
+void object_property_add_bool_ptr(Object *obj, const char *name,
+                                  const bool *v, Error **errp)
+{
+    object_property_add(obj, name, "bool", property_get_bool_ptr,
+                        property_set_bool_ptr, NULL, (void *)v, errp);
+}
+
 void object_property_add_uint8_ptr(Object *obj, const char *name,
                                    const uint8_t *v, Error **errp)
 {
-- 
1.8.5.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]