From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:59114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RuPRh-0008U8-DJ for qemu-devel@nongnu.org; Mon, 06 Feb 2012 09:21:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RuPRa-0000tL-Q2 for qemu-devel@nongnu.org; Mon, 06 Feb 2012 09:21:29 -0500 Received: from mail-pz0-f45.google.com ([209.85.210.45]:56882) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RuPRa-0000tB-G3 for qemu-devel@nongnu.org; Mon, 06 Feb 2012 09:21:22 -0500 Received: by dadp14 with SMTP id p14so6479015dad.4 for ; Mon, 06 Feb 2012 06:21:21 -0800 (PST) Message-ID: <4F2FE1DE.6010800@codemonkey.ws> Date: Mon, 06 Feb 2012 08:21:18 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1328342577-25732-1-git-send-email-pbonzini@redhat.com> <1328342577-25732-10-git-send-email-pbonzini@redhat.com> In-Reply-To: <1328342577-25732-10-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 09/27] qom: add object_resolve_path_type List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org On 02/04/2012 02:02 AM, Paolo Bonzini wrote: > Signed-off-by: Paolo Bonzini Reviewed-by: Anthony Liguori Regards, Anthony Liguori > --- > include/qemu/object.h | 25 +++++++++++++++++++++++-- > qom/object.c | 26 ++++++++++++++++++-------- > 2 files changed, 41 insertions(+), 10 deletions(-) > > diff --git a/include/qemu/object.h b/include/qemu/object.h > index f36aff6..4ec7942 100644 > --- a/include/qemu/object.h > +++ b/include/qemu/object.h > @@ -773,14 +773,35 @@ gchar *object_get_canonical_path(Object *obj); > * specifying objects easy. At each level of the composition tree, the partial > * path is matched as an absolute path. The first match is not returned. At > * least two matches are searched for. A successful result is only returned if > - * only one match is founded. If more than one match is found, a flag is > - * return to indicate that the match was ambiguous. > + * only one match is found. If more than one match is found, a flag is > + * returned to indicate that the match was ambiguous. > * > * Returns: The matched object or NULL on path lookup failure. > */ > Object *object_resolve_path(const char *path, bool *ambiguous); > > /** > + * object_resolve_path_type: > + * @path: the path to resolve > + * @typename: the type to look for. > + * @ambiguous: returns true if the path resolution failed because of an > + * ambiguous match > + * > + * This is similar to object_resolve_path. However, when looking for a > + * partial path only matches that implement the given type are considered. > + * This restricts the search and avoids spuriously flagging matches as > + * ambiguous. > + * > + * For both partial and absolute paths, the return value goes through > + * a dynamic cast to @typename. This is important if either the link, > + * or the typename itself are of interface types. > + * > + * Returns: The matched object or NULL on path lookup failure. > + */ > +Object *object_resolve_path_type(const char *path, const char *typename, > + bool *ambiguous); > + > +/** > * object_property_add_child: > * @obj: the object to add a property to > * @name: the name of the property > diff --git a/qom/object.c b/qom/object.c > index 314fc7a..ea4a1f5 100644 > --- a/qom/object.c > +++ b/qom/object.c > @@ -947,17 +947,18 @@ gchar *object_get_canonical_path(Object *obj) > > static Object *object_resolve_abs_path(Object *parent, > gchar **parts, > + const char *typename, > int index) > { > ObjectProperty *prop; > Object *child; > > if (parts[index] == NULL) { > - return parent; > + return object_dynamic_cast(parent, typename); > } > > if (strcmp(parts[index], "") == 0) { > - return object_resolve_abs_path(parent, parts, index + 1); > + return object_resolve_abs_path(parent, parts, typename, index + 1); > } > > prop = object_property_find(parent, parts[index]); > @@ -979,17 +980,18 @@ static Object *object_resolve_abs_path(Object *parent, > return NULL; > } > > - return object_resolve_abs_path(child, parts, index + 1); > + return object_resolve_abs_path(child, parts, typename, index + 1); > } > > static Object *object_resolve_partial_path(Object *parent, > gchar **parts, > + const char *typename, > bool *ambiguous) > { > Object *obj; > ObjectProperty *prop; > > - obj = object_resolve_abs_path(parent, parts, 0); > + obj = object_resolve_abs_path(parent, parts, typename, 0); > > QTAILQ_FOREACH(prop,&parent->properties, node) { > Object *found; > @@ -998,7 +1000,8 @@ static Object *object_resolve_partial_path(Object *parent, > continue; > } > > - found = object_resolve_partial_path(prop->opaque, parts, ambiguous); > + found = object_resolve_partial_path(prop->opaque, parts, > + typename, ambiguous); > if (found) { > if (obj) { > if (ambiguous) { > @@ -1017,7 +1020,8 @@ static Object *object_resolve_partial_path(Object *parent, > return obj; > } > > -Object *object_resolve_path(const char *path, bool *ambiguous) > +Object *object_resolve_path_type(const char *path, const char *typename, > + bool *ambiguous) > { > bool partial_path = true; > Object *obj; > @@ -1037,9 +1041,10 @@ Object *object_resolve_path(const char *path, bool *ambiguous) > if (ambiguous) { > *ambiguous = false; > } > - obj = object_resolve_partial_path(object_get_root(), parts, ambiguous); > + obj = object_resolve_partial_path(object_get_root(), parts, > + typename, ambiguous); > } else { > - obj = object_resolve_abs_path(object_get_root(), parts, 1); > + obj = object_resolve_abs_path(object_get_root(), parts, typename, 1); > } > > g_strfreev(parts); > @@ -1047,6 +1052,11 @@ Object *object_resolve_path(const char *path, bool *ambiguous) > return obj; > } > > +Object *object_resolve_path(const char *path, bool *ambiguous) > +{ > + return object_resolve_path_type(path, TYPE_OBJECT, ambiguous); > +} > + > typedef struct StringProperty > { > char *(*get)(Object *, Error **);