qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Marcel Apfelbaum <marcel.a@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.crosthwaite@xilinx.com, mst@redhat.com,
	anthony@codemonkey.ws, imammedo@redhat.com, pbonzini@redhat.com,
	afaerber@suse.de
Subject: [Qemu-devel]  [PATCH] qom: add object_property_is_set
Date: Tue, 18 Feb 2014 18:46:27 +0200	[thread overview]
Message-ID: <1392741987-6356-1-git-send-email-marcel.a@redhat.com> (raw)

Sometimes is not enough to get property's value,
but it is needed to know if the value was actually set.

This is especially useful when querying bool properties
and having different defaults on different scenarios.

Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
---
 include/qom/object.h | 11 +++++++++++
 qom/object.c         | 12 ++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index e0ff212..9257bb1 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -319,6 +319,7 @@ typedef struct ObjectProperty
 {
     gchar *name;
     gchar *type;
+    bool is_set;
     ObjectPropertyAccessor *get;
     ObjectPropertyAccessor *set;
     ObjectPropertyRelease *release;
@@ -931,6 +932,16 @@ void object_property_set(Object *obj, struct Visitor *v, const char *name,
                          Error **errp);
 
 /**
+ * object_property_is_set:
+ * @obj: the object
+ * @name: the name of the property
+ * @errp: returns an error if this function fails
+ *
+ * Returns: true if object's property is set, false otherwise.
+ */
+bool object_property_is_set(Object *obj, const char *name,
+                            Error **errp);
+/**
  * object_property_parse:
  * @obj: the object
  * @string: the string that will be used to parse the property value.
diff --git a/qom/object.c b/qom/object.c
index 62e7e41..229a601 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -817,9 +817,21 @@ void object_property_set(Object *obj, Visitor *v, const char *name,
         error_set(errp, QERR_PERMISSION_DENIED);
     } else {
         prop->set(obj, v, prop->opaque, name, errp);
+        prop->is_set = true;
     }
 }
 
+bool object_property_is_set(Object *obj, const char *name,
+                            Error **errp)
+{
+    ObjectProperty *prop = object_property_find(obj, name, errp);
+    if (prop == NULL) {
+        return false;
+    }
+
+    return prop->is_set;
+}
+
 void object_property_set_str(Object *obj, const char *value,
                              const char *name, Error **errp)
 {
-- 
1.8.3.1

             reply	other threads:[~2014-02-18 16:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-18 16:46 Marcel Apfelbaum [this message]
2014-02-18 16:51 ` [Qemu-devel] [PATCH] qom: add object_property_is_set Paolo Bonzini
2014-02-18 17:11   ` Marcel Apfelbaum
2014-02-18 17:26     ` Paolo Bonzini
2014-02-18 17:49       ` Andreas Färber
2014-02-19  7:11         ` Marcel Apfelbaum
2014-02-19  7:03       ` Marcel Apfelbaum

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=1392741987-6356-1-git-send-email-marcel.a@redhat.com \
    --to=marcel.a@redhat.com \
    --cc=afaerber@suse.de \
    --cc=anthony@codemonkey.ws \
    --cc=imammedo@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@xilinx.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).