[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 11/13] qom: Add object_get_container()
From: |
Peter Xu |
Subject: |
[PATCH v2 11/13] qom: Add object_get_container() |
Date: |
Thu, 21 Nov 2024 14:22:00 -0500 |
Add a helper to fetch a root container (under object_get_root()). Sanity
check on the type of the object.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
include/qom/object.h | 10 ++++++++++
qom/object.c | 10 ++++++++++
2 files changed, 20 insertions(+)
diff --git a/include/qom/object.h b/include/qom/object.h
index 597e961b8c..4eeee7f7c4 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1524,6 +1524,16 @@ const char *object_property_get_type(Object *obj, const
char *name,
*/
Object *object_get_root(void);
+/**
+ * object_get_container:
+ * @name: the name of container to lookup
+ *
+ * Lookup a root level container.
+ *
+ * Returns: the container with @name.
+ */
+Object *object_get_container(const char *name);
+
/**
* object_get_objects_root:
diff --git a/qom/object.c b/qom/object.c
index 2fb0b8418e..25316b9536 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1756,6 +1756,16 @@ static Object *object_root_initialize(void)
return root;
}
+Object *object_get_container(const char *name)
+{
+ Object *container;
+
+ container = object_resolve_path_component(object_get_root(), name);
+ assert(object_dynamic_cast(container, TYPE_CONTAINER));
+
+ return container;
+}
+
Object *object_get_root(void)
{
static Object *root;
--
2.45.0
- [PATCH v2 01/13] qom: Add TYPE_CONTAINER macro, (continued)
- [PATCH v2 01/13] qom: Add TYPE_CONTAINER macro, Peter Xu, 2024/11/21
- [PATCH v2 03/13] tests: Fix test-qdev-global-props on anonymous qdev realize(), Peter Xu, 2024/11/21
- [PATCH v2 02/13] qom: New object_property_add_new_container(), Peter Xu, 2024/11/21
- [PATCH v2 04/13] tests: Explicitly create containers in test_qom_partial_path(), Peter Xu, 2024/11/21
- [PATCH v2 07/13] qom: Create system containers explicitly, Peter Xu, 2024/11/21
- [PATCH v2 08/13] qdev: Make qdev_get_machine() not use container_get(), Peter Xu, 2024/11/21
- [PATCH v2 05/13] ppc/e500: Avoid abuse of container_get(), Peter Xu, 2024/11/21
- [PATCH v2 06/13] hw/ppc: Explicitly create the drc container, Peter Xu, 2024/11/21
- [PATCH v2 10/13] qom: Use machine_get_container(), Peter Xu, 2024/11/21
- [PATCH v2 09/13] qdev: Add machine_get_container(), Peter Xu, 2024/11/21
- [PATCH v2 11/13] qom: Add object_get_container(),
Peter Xu <=
- [PATCH v2 12/13] qom: Use object_get_container(), Peter Xu, 2024/11/21
- [PATCH v2 13/13] qom: Remove container_get(), Peter Xu, 2024/11/21