blob: 62b1648add8cf929d654cfd2699cf77f66563a37 [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
Paolo Bonzini14cccb62012-12-17 18:19:50 +010013#include "qom/object.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010014#include "qemu/module.h"
Paolo Bonzinia612b2a2012-03-27 18:38:45 +020015#include <assert.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);
43 }
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)