From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwvXP-0007nN-Pc for qemu-devel@nongnu.org; Tue, 17 Jun 2014 11:43:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwvXI-0004tv-G1 for qemu-devel@nongnu.org; Tue, 17 Jun 2014 11:43:07 -0400 Received: from cantor2.suse.de ([195.135.220.15]:35590 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwvXI-0004tp-50 for qemu-devel@nongnu.org; Tue, 17 Jun 2014 11:43:00 -0400 Message-ID: <53A06202.9010206@suse.de> Date: Tue, 17 Jun 2014 17:42:58 +0200 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1402505369-12526-1-git-send-email-pbonzini@redhat.com> <1402505369-12526-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1402505369-12526-3-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 2/5] qom: add object_property_add_alias() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: mtosatti@redhat.com, stefanha@redhat.com Am 11.06.2014 18:49, schrieb Paolo Bonzini: > From: Stefan Hajnoczi >=20 > Sometimes an object needs to present a property which is actually on > another object, or it needs to provide an alias name for an existing > property. >=20 > Examples: > a.foo -> b.foo > a.old_name -> a.new_name >=20 > The new object_property_add_alias() API allows objects to alias a > property on the same object or another object. The source and target > names can be different. >=20 > Signed-off-by: Stefan Hajnoczi > Reviewed-by: Peter Crosthwaite > Signed-off-by: Paolo Bonzini > --- > include/qom/object.h | 20 +++++++++++++++++ > qom/object.c | 61 ++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > 2 files changed, 81 insertions(+) >=20 > diff --git a/include/qom/object.h b/include/qom/object.h > index f8ab845..9c4a5a4 100644 > --- a/include/qom/object.h > +++ b/include/qom/object.h > @@ -1252,6 +1252,26 @@ void object_property_add_uint64_ptr(Object *obj,= const char *name, > const uint64_t *v, Error **Errp); > =20 > /** > + * object_property_add_alias: > + * @obj: the object to add a property to > + * @name: the name of the property > + * @target_obj: the object to forward property access to > + * @target_name: the name of the property on the forwarded object > + * @errp: if an error occurs, a pointer to an area to store the error > + * > + * Add an alias for a property on an object. This function will add a= property > + * of the same type as the forwarded property. > + * > + * The caller must ensure that @target_obj stays alive as= long as > + * this property exists. In the case of a child object or an alias on= the same > + * object this will be the case. For aliases to other objects the cal= ler is > + * responsible for taking a reference. > + */ > +void object_property_add_alias(Object *obj, const char *name, > + Object *target_obj, const char *target_= name, > + Error **errp); > + > +/** > * object_child_foreach: > * @obj: the object whose children will be navigated > * @fn: the iterator function to be called > diff --git a/qom/object.c b/qom/object.c > index fcdd0da..e146ae5 100644 > --- a/qom/object.c > +++ b/qom/object.c > @@ -1532,6 +1532,67 @@ void object_property_add_uint64_ptr(Object *obj,= const char *name, > NULL, NULL, (void *)v, errp); > } > =20 > +typedef struct > +{ Coding Style > + Object *target_obj; > + const char *target_name; > +} AliasProperty; > + > +static void property_get_alias(Object *obj, struct Visitor *v, void *o= paque, > + const char *name, Error **errp) > +{ > + AliasProperty *prop =3D opaque; > + > + object_property_get(prop->target_obj, v, prop->target_name, errp); > +} > + > +static void property_set_alias(Object *obj, struct Visitor *v, void *o= paque, > + const char *name, Error **errp) > +{ > + AliasProperty *prop =3D opaque; > + > + object_property_set(prop->target_obj, v, prop->target_name, errp); > +} > + > +static Object *property_resolve_alias(Object *obj, void *opaque, > + const gchar *part) > +{ > + AliasProperty *prop =3D opaque; > + > + return object_resolve_path_component(prop->target_obj, prop->targe= t_name); > +} > + > +static void property_release_alias(Object *obj, const char *name, void= *opaque) > +{ > + AliasProperty *prop =3D opaque; > + > + g_free(prop); > +} > + > +void object_property_add_alias(Object *obj, const char *name, > + Object *target_obj, const char *target_= name, > + Error **errp) > +{ > + AliasProperty *prop; > + ObjectProperty *target_prop; > + > + target_prop =3D object_property_find(target_obj, target_name, errp= ); > + if (!target_prop) { > + return; > + } > + > + prop =3D g_malloc(sizeof(*prop)); > + prop->target_obj =3D target_obj; > + prop->target_name =3D target_name; > + > + object_property_add_full(obj, name, target_prop->type, > + property_get_alias, > + property_set_alias, > + property_resolve_alias, > + property_release_alias, > + prop, errp); > +} > + > static void object_instance_init(Object *obj) > { > object_property_add_str(obj, "type", qdev_get_type, NULL, NULL); Otherwise looks good to me. Regards, Andreas --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg