Statistics
| Branch: | Revision:

root / qom / container.c @ 85df3786

History | View | Annotate | Download (1.1 kB)

1 8b45d447 Anthony Liguori
/*
2 8b45d447 Anthony Liguori
 * Device Container
3 8b45d447 Anthony Liguori
 *
4 8b45d447 Anthony Liguori
 * Copyright IBM, Corp. 2012
5 8b45d447 Anthony Liguori
 *
6 8b45d447 Anthony Liguori
 * Authors:
7 8b45d447 Anthony Liguori
 *  Anthony Liguori   <aliguori@us.ibm.com>
8 8b45d447 Anthony Liguori
 *
9 8b45d447 Anthony Liguori
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 8b45d447 Anthony Liguori
 * See the COPYING file in the top-level directory.
11 8b45d447 Anthony Liguori
 */
12 8b45d447 Anthony Liguori
13 8b45d447 Anthony Liguori
#include "qemu/object.h"
14 8b45d447 Anthony Liguori
#include "module.h"
15 a612b2a6 Paolo Bonzini
#include <assert.h>
16 8b45d447 Anthony Liguori
17 8b45d447 Anthony Liguori
static TypeInfo container_info = {
18 8b45d447 Anthony Liguori
    .name          = "container",
19 8b45d447 Anthony Liguori
    .instance_size = sizeof(Object),
20 8b45d447 Anthony Liguori
    .parent        = TYPE_OBJECT,
21 8b45d447 Anthony Liguori
};
22 8b45d447 Anthony Liguori
23 83f7d43a Andreas Färber
static void container_register_types(void)
24 8b45d447 Anthony Liguori
{
25 8b45d447 Anthony Liguori
    type_register_static(&container_info);
26 8b45d447 Anthony Liguori
}
27 8b45d447 Anthony Liguori
28 a612b2a6 Paolo Bonzini
Object *container_get(const char *path)
29 a612b2a6 Paolo Bonzini
{
30 a612b2a6 Paolo Bonzini
    Object *obj, *child;
31 a612b2a6 Paolo Bonzini
    gchar **parts;
32 a612b2a6 Paolo Bonzini
    int i;
33 a612b2a6 Paolo Bonzini
34 a612b2a6 Paolo Bonzini
    parts = g_strsplit(path, "/", 0);
35 a612b2a6 Paolo Bonzini
    assert(parts != NULL && parts[0] != NULL && !parts[0][0]);
36 a612b2a6 Paolo Bonzini
    obj = object_get_root();
37 a612b2a6 Paolo Bonzini
38 a612b2a6 Paolo Bonzini
    for (i = 1; parts[i] != NULL; i++, obj = child) {
39 a612b2a6 Paolo Bonzini
        child = object_resolve_path_component(obj, parts[i]);
40 a612b2a6 Paolo Bonzini
        if (!child) {
41 a612b2a6 Paolo Bonzini
            child = object_new("container");
42 a612b2a6 Paolo Bonzini
            object_property_add_child(obj, parts[i], child, NULL);
43 a612b2a6 Paolo Bonzini
        }
44 a612b2a6 Paolo Bonzini
    }
45 a612b2a6 Paolo Bonzini
46 a612b2a6 Paolo Bonzini
    return obj;
47 a612b2a6 Paolo Bonzini
}
48 a612b2a6 Paolo Bonzini
49 a612b2a6 Paolo Bonzini
50 83f7d43a Andreas Färber
type_init(container_register_types)