Anthony Liguori | 8b45d44 | 2011-12-23 09:08:05 -0600 | [diff] [blame] | 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 | |
Peter Maydell | 9bbc853 | 2016-01-29 17:50:02 +0000 | [diff] [blame] | 13 | #include "qemu/osdep.h" |
Paolo Bonzini | 14cccb6 | 2012-12-17 18:19:50 +0100 | [diff] [blame] | 14 | #include "qom/object.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 15 | #include "qemu/module.h" |
Anthony Liguori | 8b45d44 | 2011-12-23 09:08:05 -0600 | [diff] [blame] | 16 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 17 | static const TypeInfo container_info = { |
Anthony Liguori | 8b45d44 | 2011-12-23 09:08:05 -0600 | [diff] [blame] | 18 | .name = "container", |
| 19 | .instance_size = sizeof(Object), |
| 20 | .parent = TYPE_OBJECT, |
| 21 | }; |
| 22 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 23 | static void container_register_types(void) |
Anthony Liguori | 8b45d44 | 2011-12-23 09:08:05 -0600 | [diff] [blame] | 24 | { |
| 25 | type_register_static(&container_info); |
| 26 | } |
| 27 | |
Andreas Färber | dfe47e7 | 2012-04-05 13:21:46 +0200 | [diff] [blame] | 28 | Object *container_get(Object *root, const char *path) |
Paolo Bonzini | a612b2a | 2012-03-27 18:38:45 +0200 | [diff] [blame] | 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]); |
Andreas Färber | dfe47e7 | 2012-04-05 13:21:46 +0200 | [diff] [blame] | 36 | obj = root; |
Paolo Bonzini | a612b2a | 2012-03-27 18:38:45 +0200 | [diff] [blame] | 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); |
Marc-André Lureau | f8df5f9 | 2016-12-14 22:42:55 +0300 | [diff] [blame] | 43 | object_unref(child); |
Paolo Bonzini | a612b2a | 2012-03-27 18:38:45 +0200 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
Stefan Weil | f156f23 | 2012-04-28 02:20:19 +0000 | [diff] [blame] | 47 | g_strfreev(parts); |
| 48 | |
Paolo Bonzini | a612b2a | 2012-03-27 18:38:45 +0200 | [diff] [blame] | 49 | return obj; |
| 50 | } |
| 51 | |
| 52 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 53 | type_init(container_register_types) |