1 /* 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 13 #include "qemu/osdep.h" 14 #include "qom/object.h" 15 #include "qemu/module.h" 16 17 static const TypeInfo container_info = { 18 .name = TYPE_CONTAINER, 19 .parent = TYPE_OBJECT, 20 }; 21 22 static void container_register_types(void) 23 { 24 type_register_static(&container_info); 25 } 26 27 Object *object_property_add_new_container(Object *obj, const char *name) 28 { 29 Object *child = object_new(TYPE_CONTAINER); 30 31 object_property_add_child(obj, name, child); 32 object_unref(child); 33 34 return child; 35 } 36 37 Object *container_get(Object *root, const char *path) 38 { 39 Object *obj, *child; 40 char **parts; 41 int i; 42 43 parts = g_strsplit(path, "/", 0); 44 assert(parts != NULL && parts[0] != NULL && !parts[0][0]); 45 obj = root; 46 47 for (i = 1; parts[i] != NULL; i++, obj = child) { 48 child = object_resolve_path_component(obj, parts[i]); 49 if (!child) { 50 child = object_property_add_new_container(obj, parts[i]); 51 } 52 } 53 54 g_strfreev(parts); 55 56 return obj; 57 } 58 59 60 type_init(container_register_types) 61