]>
Commit | Line | Data |
---|---|---|
8b45d447 AL |
1 | /* |
2 | * Device Container | |
3 | * | |
4 | * Copyright IBM, Corp. 2012 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <[email protected]> | |
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 | ||
13 | #include "qemu/object.h" | |
14 | #include "module.h" | |
a612b2a6 | 15 | #include <assert.h> |
8b45d447 AL |
16 | |
17 | static TypeInfo container_info = { | |
18 | .name = "container", | |
19 | .instance_size = sizeof(Object), | |
20 | .parent = TYPE_OBJECT, | |
21 | }; | |
22 | ||
83f7d43a | 23 | static void container_register_types(void) |
8b45d447 AL |
24 | { |
25 | type_register_static(&container_info); | |
26 | } | |
27 | ||
a612b2a6 PB |
28 | Object *container_get(const char *path) |
29 | { | |
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]); | |
36 | obj = object_get_root(); | |
37 | ||
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 | ||
46 | return obj; | |
47 | } | |
48 | ||
49 | ||
83f7d43a | 50 | type_init(container_register_types) |