blob: 455e8410c66dad02eee86ff94f3a77ed26216295 [file] [log] [blame]
Anthony Liguori8b45d442011-12-23 09:08:05 -06001/*
2 * Device Container
3 *
4 * Copyright IBM, Corp. 2012
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 */
12
Peter Maydell9bbc8532016-01-29 17:50:02 +000013#include "qemu/osdep.h"
Paolo Bonzini14cccb62012-12-17 18:19:50 +010014#include "qom/object.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010015#include "qemu/module.h"
Anthony Liguori8b45d442011-12-23 09:08:05 -060016
Andreas Färber8c43a6f2013-01-10 16:19:07 +010017static const TypeInfo container_info = {
Anthony Liguori8b45d442011-12-23 09:08:05 -060018 .name = "container",
Anthony Liguori8b45d442011-12-23 09:08:05 -060019 .parent = TYPE_OBJECT,
20};
21
Andreas Färber83f7d432012-02-09 15:20:55 +010022static void container_register_types(void)
Anthony Liguori8b45d442011-12-23 09:08:05 -060023{
24 type_register_static(&container_info);
25}
26
Andreas Färberdfe47e72012-04-05 13:21:46 +020027Object *container_get(Object *root, const char *path)
Paolo Bonzinia612b2a2012-03-27 18:38:45 +020028{
29 Object *obj, *child;
Markus Armbrusterddfb0ba2020-05-05 17:29:10 +020030 char **parts;
Paolo Bonzinia612b2a2012-03-27 18:38:45 +020031 int i;
32
33 parts = g_strsplit(path, "/", 0);
34 assert(parts != NULL && parts[0] != NULL && !parts[0][0]);
Andreas Färberdfe47e72012-04-05 13:21:46 +020035 obj = root;
Paolo Bonzinia612b2a2012-03-27 18:38:45 +020036
37 for (i = 1; parts[i] != NULL; i++, obj = child) {
38 child = object_resolve_path_component(obj, parts[i]);
39 if (!child) {
40 child = object_new("container");
Markus Armbrusterd2623122020-05-05 17:29:22 +020041 object_property_add_child(obj, parts[i], child);
Marc-André Lureauf8df5f92016-12-14 22:42:55 +030042 object_unref(child);
Paolo Bonzinia612b2a2012-03-27 18:38:45 +020043 }
44 }
45
Stefan Weilf156f232012-04-28 02:20:19 +000046 g_strfreev(parts);
47
Paolo Bonzinia612b2a2012-03-27 18:38:45 +020048 return obj;
49}
50
51
Andreas Färber83f7d432012-02-09 15:20:55 +010052type_init(container_register_types)