qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qom: helper macro for adding read-only properties
@ 2013-09-15 17:23 Michael S. Tsirkin
  2013-09-15 17:54 ` Peter Maydell
  2013-09-16  6:32 ` Andreas Färber
  0 siblings, 2 replies; 14+ messages in thread
From: Michael S. Tsirkin @ 2013-09-15 17:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Stefan Hajnoczi, Andreas Färber,
	Anthony Liguori

Add a helper macro for adding read-only properties, that works in the
common case where the value is a constant.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---

I'm using this patch in my acpi work - any objections
to applying it on my tree?

 include/qom/object.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index 1a7b71a..4787de6 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -17,6 +17,7 @@
 #include <glib.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include "qemu/typedefs.h"
 #include "qemu/queue.h"
 
 struct Visitor;
@@ -792,6 +793,26 @@ void object_property_add(Object *obj, const char *name, const char *type,
                          ObjectPropertyRelease *release,
                          void *opaque, struct Error **errp);
 
+/* Add a property that is an integer constant. */
+#define OBJECT_ADD_PROP_CONST(obj, name, value)                      \
+    do {                                                                    \
+        void OBJECT_ADD_PROP_GET(Object *OBJECT_ADD_PROP_OBJ,               \
+                                 struct Visitor *OBJECT_ADD_PROP_VISITOR,   \
+                                 void *OBJECT_ADD_PROP_OPAQUE,              \
+                                 const char *OBJECT_ADD_PROP_NAME,          \
+                                 struct Error **OBJECT_ADD_PROP_VALUE_ERR)  \
+        {                                                                   \
+            int64_t OBJECT_ADD_PROP_VALUE = value;                          \
+                                                                            \
+            visit_type_int64(OBJECT_ADD_PROP_VISITOR,                       \
+                             &OBJECT_ADD_PROP_VALUE,                        \
+                             OBJECT_ADD_PROP_NAME,                          \
+                             OBJECT_ADD_PROP_VALUE_ERR);                    \
+        }                                                                   \
+        object_property_add(obj, name, "int", OBJECT_ADD_PROP_GET,          \
+                            NULL, NULL, NULL, NULL);                        \
+    } while (0)
+
 void object_property_del(Object *obj, const char *name, struct Error **errp);
 
 /**
-- 
MST

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-09-16 17:03 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-15 17:23 [Qemu-devel] [PATCH] qom: helper macro for adding read-only properties Michael S. Tsirkin
2013-09-15 17:54 ` Peter Maydell
2013-09-15 20:06   ` Michael S. Tsirkin
2013-09-16  6:32 ` Andreas Färber
2013-09-16 12:33   ` Michael S. Tsirkin
2013-09-16 15:24     ` Andreas Färber
2013-09-16 15:41       ` Paolo Bonzini
2013-09-16 15:48       ` Michael S. Tsirkin
2013-09-16 15:56         ` Paolo Bonzini
2013-09-16 16:01           ` Michael S. Tsirkin
2013-09-16 16:07             ` Paolo Bonzini
2013-09-16 16:51               ` Michael S. Tsirkin
2013-09-16 17:03                 ` Paolo Bonzini
2013-09-16 16:07   ` Michael S. Tsirkin

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).