target/mips: Add comments for vendor-specific ASEs
[qemu/ar7.git] / qom / qom-hmp-cmds.c
blobf704b6949a1bc964008803bff4350d6b38f5ece2
1 /*
2 * HMP commands related to QOM
4 * This work is licensed under the terms of the GNU GPL, version 2 or
5 * later. See the COPYING file in the top-level directory.
6 */
8 #include "qemu/osdep.h"
9 #include "hw/qdev-core.h"
10 #include "monitor/hmp.h"
11 #include "monitor/monitor.h"
12 #include "qapi/error.h"
13 #include "qapi/qapi-commands-qom.h"
14 #include "qapi/qmp/qdict.h"
15 #include "qapi/qmp/qjson.h"
16 #include "qapi/qmp/qstring.h"
17 #include "qom/object.h"
19 void hmp_qom_list(Monitor *mon, const QDict *qdict)
21 const char *path = qdict_get_try_str(qdict, "path");
22 ObjectPropertyInfoList *list;
23 Error *err = NULL;
25 if (path == NULL) {
26 monitor_printf(mon, "/\n");
27 return;
30 list = qmp_qom_list(path, &err);
31 if (err == NULL) {
32 ObjectPropertyInfoList *start = list;
33 while (list != NULL) {
34 ObjectPropertyInfo *value = list->value;
36 monitor_printf(mon, "%s (%s)\n",
37 value->name, value->type);
38 list = list->next;
40 qapi_free_ObjectPropertyInfoList(start);
42 hmp_handle_error(mon, err);
45 void hmp_qom_set(Monitor *mon, const QDict *qdict)
47 const char *path = qdict_get_str(qdict, "path");
48 const char *property = qdict_get_str(qdict, "property");
49 const char *value = qdict_get_str(qdict, "value");
50 Error *err = NULL;
51 QObject *obj;
53 obj = qobject_from_json(value, &err);
54 if (err == NULL) {
55 qmp_qom_set(path, property, obj, &err);
58 hmp_handle_error(mon, err);
61 void hmp_qom_get(Monitor *mon, const QDict *qdict)
63 const char *path = qdict_get_str(qdict, "path");
64 const char *property = qdict_get_str(qdict, "property");
65 Error *err = NULL;
66 QObject *obj = qmp_qom_get(path, property, &err);
68 if (err == NULL) {
69 QString *str = qobject_to_json_pretty(obj);
70 monitor_printf(mon, "%s\n", qstring_get_str(str));
71 qobject_unref(str);
74 hmp_handle_error(mon, err);
77 typedef struct QOMCompositionState {
78 Monitor *mon;
79 int indent;
80 } QOMCompositionState;
82 static void print_qom_composition(Monitor *mon, Object *obj, int indent);
84 static int print_qom_composition_child(Object *obj, void *opaque)
86 QOMCompositionState *s = opaque;
88 print_qom_composition(s->mon, obj, s->indent);
90 return 0;
93 static void print_qom_composition(Monitor *mon, Object *obj, int indent)
95 QOMCompositionState s = {
96 .mon = mon,
97 .indent = indent + 2,
99 char *name;
101 if (obj == object_get_root()) {
102 name = g_strdup("");
103 } else {
104 name = object_get_canonical_path_component(obj);
106 monitor_printf(mon, "%*s/%s (%s)\n", indent, "", name,
107 object_get_typename(obj));
108 g_free(name);
109 object_child_foreach(obj, print_qom_composition_child, &s);
112 void hmp_info_qom_tree(Monitor *mon, const QDict *dict)
114 const char *path = qdict_get_try_str(dict, "path");
115 Object *obj;
116 bool ambiguous = false;
118 if (path) {
119 obj = object_resolve_path(path, &ambiguous);
120 if (!obj) {
121 monitor_printf(mon, "Path '%s' could not be resolved.\n", path);
122 return;
124 if (ambiguous) {
125 monitor_printf(mon, "Warning: Path '%s' is ambiguous.\n", path);
126 return;
128 } else {
129 obj = qdev_get_machine();
131 print_qom_composition(mon, obj, 0);