From patchwork Sat Feb 4 08:02:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 139549 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8994B104792 for ; Sat, 4 Feb 2012 19:44:53 +1100 (EST) Received: from localhost ([::1]:38709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rtaaz-0002EW-VP for incoming@patchwork.ozlabs.org; Sat, 04 Feb 2012 03:03:41 -0500 Received: from eggs.gnu.org ([140.186.70.92]:34690) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rtaaf-0001mg-Pb for qemu-devel@nongnu.org; Sat, 04 Feb 2012 03:03:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RtaaZ-0005De-5Z for qemu-devel@nongnu.org; Sat, 04 Feb 2012 03:03:18 -0500 Received: from mail-ww0-f41.google.com ([74.125.82.41]:45371) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RtaaY-00058h-9e for qemu-devel@nongnu.org; Sat, 04 Feb 2012 03:03:14 -0500 Received: by mail-ww0-f41.google.com with SMTP id dt11so1786120wgb.4 for ; Sat, 04 Feb 2012 00:03:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=Zxs2LEHhXClNluj4HQ/rbeZC4Y54LpbsvLTlYFZhl7g=; b=RhtVlW32YtgRxEqKlYdMVP2F5VUmSD4G6oT4VhqnSdcsgudziYg1112jtt3tEjgoPz JN8y1t5qdnA7ewoOU7vf3JYnAxvS+M06CoUVBmqWeVpOotFgg++AbHxr30y5ycRW15Ob apnU6WULK9RY3g3UtmYJh1LmtyX1tmix6E3+o= Received: by 10.180.94.68 with SMTP id da4mr16148400wib.22.1328342593707; Sat, 04 Feb 2012 00:03:13 -0800 (PST) Received: from yakj.usersys.redhat.com.ACCOR.COM (218.104-246-81.adsl-static.isp.belgacom.be. [81.246.104.218]) by mx.google.com with ESMTPS id m8sm24963019wia.11.2012.02.04.00.03.12 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 04 Feb 2012 00:03:13 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sat, 4 Feb 2012 09:02:42 +0100 Message-Id: <1328342577-25732-13-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1328342577-25732-1-git-send-email-pbonzini@redhat.com> References: <1328342577-25732-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.41 Subject: [Qemu-devel] [PATCH v2 12/27] qom: add property get/set wrappers for links 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 These can set a link to any object, as long as it is included in the composition tree. Signed-off-by: Paolo Bonzini --- include/qemu/object.h | 24 ++++++++++++++++++++++++ qom/object.c | 25 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 0 deletions(-) diff --git a/include/qemu/object.h b/include/qemu/object.h index 4ec7942..910b767 100644 --- a/include/qemu/object.h +++ b/include/qemu/object.h @@ -658,6 +658,30 @@ char *object_property_get_str(Object *obj, const char *name, struct Error **errp); /** + * object_property_set_link: + * @value: the value to be written to the property + * @name: the name of the property + * @errp: returns an error if this function fails + * + * Writes an object's canonical path to a property. + */ +void object_property_set_link(Object *obj, Object *value, + const char *name, struct Error **errp); + +/** + * object_property_get_link: + * @obj: the object + * @name: the name of the property + * @errp: returns an error if this function fails + * + * Returns: the value of the property, resolved from a path to an Object, + * or NULL if an error occurs (including when the property value is not a + * string or not a valid object path). + */ +Object *object_property_get_link(Object *obj, const char *name, + struct Error **errp); + +/** * object_property_set_bool: * @value: the value to be written to the property * @name: the name of the property diff --git a/qom/object.c b/qom/object.c index e8418bc..b3cff50 100644 --- a/qom/object.c +++ b/qom/object.c @@ -710,6 +710,30 @@ char *object_property_get_str(Object *obj, const char *name, return retval; } +void object_property_set_link(Object *obj, Object *value, + const char *name, Error **errp) +{ + object_property_set_str(obj, object_get_canonical_path(value), + name, errp); +} + +Object *object_property_get_link(Object *obj, const char *name, + Error **errp) +{ + char *str = object_property_get_str(obj, name, errp); + Object *target = NULL; + + if (str && *str) { + target = object_resolve_path(str, NULL); + if (!target) { + error_set(errp, QERR_DEVICE_NOT_FOUND, str); + } + } + + g_free(str); + return target; +} + void object_property_set_bool(Object *obj, bool value, const char *name, Error **errp) {