From patchwork Mon May 11 13:48:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 470840 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 DF746140187 for ; Tue, 12 May 2015 00:00:00 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=i1uN4b+n; dkim-atps=neutral Received: from localhost ([::1]:37609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YroFS-0003XK-Qy for incoming@patchwork.ozlabs.org; Mon, 11 May 2015 09:59:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yro5u-0002Zp-Qj for qemu-devel@nongnu.org; Mon, 11 May 2015 09:50:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yro5q-0006zm-OH for qemu-devel@nongnu.org; Mon, 11 May 2015 09:50:06 -0400 Received: from mail-wg0-x232.google.com ([2a00:1450:400c:c00::232]:33307) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yro5q-0006ue-I7 for qemu-devel@nongnu.org; Mon, 11 May 2015 09:50:02 -0400 Received: by wgin8 with SMTP id n8so128920653wgi.0 for ; Mon, 11 May 2015 06:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=P+haRBhkkRApMa3N2b9rrlWcaSAP3TtQoSFMBHBZikI=; b=i1uN4b+nE0hsbTRE2OomDVEF4N872Payh/czTv/4+0SicWewwyWJNOMa1yYH0+5Ujs bUb2zLB4GbhclZPypHC90rSVqtS1KrZ/cAj8c1IqgFvWGxeqNaqdcvH8wI5CpgQlMdXU WG3ZK7UOrwJ+v+GUfHh7vBedaoqFPDC0ECMpchjJ9KmHfreE0a6o0asurMNjqp7dTLEz CTJq7P1UI6SK+HAlKCklEpEVFPWj+E9myXS6omVaJPdVrP3a+aXNcdIAArr3XYg3kIRz m6/7hiKvWBnCH/svDcK5eD7wT2MGAtvWZzV/1o/5WRemhSyaitu4l6mkmaynyfSrgcT+ JpCg== X-Received: by 10.180.92.228 with SMTP id cp4mr20646818wib.62.1431352200854; Mon, 11 May 2015 06:50:00 -0700 (PDT) Received: from 640k.localdomain (dynamic-adsl-94-39-186-233.clienti.tiscali.it. [94.39.186.233]) by mx.google.com with ESMTPSA id m1sm167235wiw.7.2015.05.11.06.49.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 May 2015 06:49:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 11 May 2015 15:48:57 +0200 Message-Id: <1431352157-40283-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1431352157-40283-1-git-send-email-pbonzini@redhat.com> References: <1431352157-40283-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::232 Cc: lersek@redhat.com, kraxel@redhat.com, mst@redhat.com Subject: [Qemu-devel] [PATCH 11/31] qom: add object_property_add_const_link 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 Suggested-by: Eduardo Habkost Signed-off-by: Paolo Bonzini Reviewed-by: Eduardo Habkost --- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index d2d7748..0505f20 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1290,6 +1290,24 @@ void object_property_add_alias(Object *obj, const char *name, Error **errp); /** + * object_property_add_const_link: + * @obj: the object to add a property to + * @name: the name of the property + * @target: the object to be referred by the link + * @errp: if an error occurs, a pointer to an area to store the error + * + * Add an unmodifiable link for a property on an object. This function will + * add a property of type link where TYPE is the type of @target. + * + * The caller must ensure that @target stays alive as long as + * this property exists. In the case @target is a child of @obj, + * this will be the case. Otherwise, the caller is responsible for + * taking a reference. + */ +void object_property_add_const_link(Object *obj, const char *name, + Object *target, Error **errp); + +/** * object_property_set_description: * @obj: the object owning the property * @name: the name of the property diff --git a/qom/object.c b/qom/object.c index b8dff43..ba89518 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1266,6 +1266,22 @@ out: g_free(full_type); } +void object_property_add_const_link(Object *obj, const char *name, + Object *target, Error **errp) +{ + char *link_type; + ObjectProperty *op; + + link_type = g_strdup_printf("link<%s>", object_get_typename(target)); + op = object_property_add(obj, name, link_type, + object_get_child_property, NULL, + NULL, target, errp); + if (op != NULL) { + op->resolve = object_resolve_child_property; + } + g_free(link_type); +} + gchar *object_get_canonical_path_component(Object *obj) { ObjectProperty *prop = NULL;