From patchwork Sun Mar 2 13:07:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 325571 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 51C602C00C2 for ; Mon, 3 Mar 2014 00:10:07 +1100 (EST) Received: from localhost ([::1]:35391 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WK69c-0005x2-CG for incoming@patchwork.ozlabs.org; Sun, 02 Mar 2014 08:10:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WK67K-0002hr-JZ for qemu-devel@nongnu.org; Sun, 02 Mar 2014 08:07:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WK67E-0000se-IS for qemu-devel@nongnu.org; Sun, 02 Mar 2014 08:07:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41705) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WK67E-0000sL-90 for qemu-devel@nongnu.org; Sun, 02 Mar 2014 08:07:36 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s22D7UtE007710 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 2 Mar 2014 08:07:30 -0500 Received: from localhost.tlv.redhat.com (dhcp-4-195.tlv.redhat.com [10.35.4.195]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s22D6pui012367; Sun, 2 Mar 2014 08:07:24 -0500 From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Sun, 2 Mar 2014 15:07:10 +0200 Message-Id: <1393765632-2753-8-git-send-email-marcel.a@redhat.com> In-Reply-To: <1393765632-2753-1-git-send-email-marcel.a@redhat.com> References: <1393765632-2753-1-git-send-email-marcel.a@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, blauwirbel@gmail.com, mdroth@linux.vnet.ibm.com, mst@redhat.com, armbru@redhat.com, mtosatti@redhat.com, agraf@suse.de, ehabkost@redhat.com, lcapitulino@redhat.com, peter.crosthwaite@petalogix.com, quintela@redhat.com, imammedo@redhat.com, aliguori@amazon.com, pbonzini@redhat.com, scottwood@freescale.com, edgar.iglesias@gmail.com, afaerber@suse.de, rth@twiddle.net Subject: [Qemu-devel] [PATCH RFC V2 7/9] qom: add object_property_is_set X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 9c7c361..4a4f026 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 660859c..5b9d8af 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) {