From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLG0p-0000vn-U8 for qemu-devel@nongnu.org; Sun, 15 Sep 2013 13:21:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VLG0j-0002O4-Um for qemu-devel@nongnu.org; Sun, 15 Sep 2013 13:21:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36512) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLG0j-0002Ny-LY for qemu-devel@nongnu.org; Sun, 15 Sep 2013 13:21:25 -0400 Date: Sun, 15 Sep 2013 20:23:31 +0300 From: "Michael S. Tsirkin" Message-ID: <20130915172331.GA2821@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] qom: helper macro for adding read-only properties List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Stefan Hajnoczi , Andreas =?iso-8859-1?Q?F=E4rber?= , 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 --- 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 #include #include +#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