Function qemuMonitorJSONBuildCPUModelInfoToJSON
builds and returns JSON of form
{"model": {"name": "IvyBridge", "props": {}}}
from qemuMonitorCPUModelInfo.
Function qemuMonitorJSONBuildCPUModelInfoToJSON
returns virJsonValuePtr on success and NULL on failure.
---
src/qemu/qemu_monitor_json.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 4368aaaa0..44c1b2f15 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5337,6 +5337,54 @@ qemuMonitorJSONParseCPUModelProperty(const char *key,
return 0;
}
+/* model_json: {"model": {"name": "IvyBridge",
"props": {}}}
+ */
+static virJSONValuePtr
+qemuMonitorJSONBuildCPUModelInfoToJSON(qemuMonitorCPUModelInfoPtr model)
+{
+ virJSONValuePtr cpu_props = NULL;
+ virJSONValuePtr model_json = NULL;
+ size_t i;
+
+ if (!(cpu_props = virJSONValueNewObject()))
+ goto cleanup;
+
+ for (i = 0; i < model->nprops; i++) {
+ qemuMonitorCPUPropertyPtr prop = model->props + i;
+
+ switch (prop->type) {
+ case QEMU_MONITOR_CPU_PROPERTY_BOOLEAN:
+ if (virJSONValueObjectAppendBoolean(cpu_props, prop->name,
prop->value.boolean) < 0)
+ goto cleanup;
+ break;
+
+ case QEMU_MONITOR_CPU_PROPERTY_STRING:
+ if (virJSONValueObjectAppendString(cpu_props, prop->name,
prop->value.string) < 0)
+ goto cleanup;
+ break;
+
+ case QEMU_MONITOR_CPU_PROPERTY_NUMBER:
+ if (virJSONValueObjectAppendNumberLong(cpu_props, prop->name,
prop->value.number) < 0)
+ goto cleanup;
+ break;
+
+ case QEMU_MONITOR_CPU_PROPERTY_LAST:
+ default:
+ virReportEnumRangeError(qemuMonitorCPUPropertyPtr, prop->type);
+ goto cleanup;
+ }
+ }
+
+ if (virJSONValueObjectCreate(&model_json, "s:name", model->name,
+ "a:props", &cpu_props, NULL)
< 0) {
+ virJSONValueFree(cpu_props);
+ goto cleanup;
+ }
+
+ cleanup:
+ return model_json;
+}
+
/* model_json: {"model": {"name": "IvyBridge",
"props": {}}}
*/
static qemuMonitorCPUModelInfoPtr
--
2.14.1