blob: f6ccaf7ea780349e9fac89dea8384cfc0f6fb429 [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",
19 .instance_size = sizeof(Object),
20 .parent = TYPE_OBJECT,
21};
22
Andreas Färber83f7d432012-02-09 15:20:55 +010023static void container_register_types(void)
Anthony Liguori8b45d442011-12-23 09:08:05 -060024{
25 type_register_static(&container_info);
26}
27
Andreas Färberdfe47e72012-04-05 13:21:46 +020028Object *container_get(Object *root, const char *path)
Paolo Bonzinia612b2a2012-03-27 18:38:45 +020029{
30 Object *obj, *child;
31 gchar **parts;
32 int i;
33
34 parts = g_strsplit(path, "/", 0);
35 assert(parts != NULL && parts[0] != NULL && !parts[0][0]);
Andreas Färberdfe47e72012-04-05 13:21:46 +020036 obj = root;
Paolo Bonzinia612b2a2012-03-27 18:38:45 +020037
38 for (i = 1; parts[i] != NULL; i++, obj = child) {
39 child = object_resolve_path_component(obj, parts[i]);
40 if (!child) {
41 child = object_new("container");
42 object_property_add_child(obj, parts[i], child, NULL);
Marc-André Lureauf8df5f92016-12-14 22:42:55 +030043 object_unref(child);
Paolo Bonzinia612b2a2012-03-27 18:38:45 +020044 }
45 }
46
Stefan Weilf156f232012-04-28 02:20:19 +000047 g_strfreev(parts);
48
Paolo Bonzinia612b2a2012-03-27 18:38:45 +020049 return obj;
50}
51
52
Andreas Färber83f7d432012-02-09 15:20:55 +010053type_init(container_register_types)