[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [RFC 04/41] qom/object: Introduce helper to resolve path from non-direct parent
From: Zhao Liu <zhao1.liu@xxxxxxxxx> When we support child<> property creation from cli, the peripheral container (/machine/peripheral) may not be the direct parent of the devices created from cli. For this case, add a helper to resolve path from non-direct parent. Signed-off-by: Zhao Liu <zhao1.liu@xxxxxxxxx> --- include/qom/object.h | 15 +++++++++++++++ qom/object.c | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index afccd24ca7ab..494eef801be3 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1562,6 +1562,21 @@ Object *object_resolve_path_type(const char *path, const char *typename, */ Object *object_resolve_path_at(Object *parent, const char *path); +/** + * object_resolve_path_from: + * @parent: the object from which to resolve the path + * @path: the path to resolve + * @ambiguous: returns true if the path resolution failed because of an + * ambiguous match + * + * This is like object_resolve_path_at(), except @parent may be the + * partial parent of @path. + * + * Returns: The resolved object or NULL on path lookup failure. + */ +Object *object_resolve_path_from(Object *parent, const char *path, + bool *ambiguous); + /** * object_resolve_path_component: * @parent: the object in which to resolve the path diff --git a/qom/object.c b/qom/object.c index 95c0dc8285fe..da29e88816b5 100644 --- a/qom/object.c +++ b/qom/object.c @@ -2192,6 +2192,24 @@ Object *object_resolve_path_at(Object *parent, const char *path) return object_resolve_abs_path(parent, parts, TYPE_OBJECT); } +Object *object_resolve_path_from(Object *parent, const char *path, + bool *ambiguousp) +{ + g_auto(GStrv) parts = NULL; + bool ambiguous = false; + Object *obj; + + parts = g_strsplit(path, "/", 0); + assert(parts); + + obj = object_resolve_partial_path(parent, parts, TYPE_OBJECT, + &ambiguous); + if (ambiguousp) { + *ambiguousp = ambiguous; + } + return obj; +} + typedef struct StringProperty { char *(*get)(Object *, Error **); -- 2.34.1
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |