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 | 50 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 83f092236..3a28f3865 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5338,6 +5338,56 @@ qemuMonitorJSONParseCPUModelProperty(const char *key,
}
+/* model_json: {"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;
+ }
+ }
+
+ ignore_value(virJSONValueObjectCreate(&model_json, "s:name",
model->name,
+ "a:props", &cpu_props, NULL));
+
+ cleanup:
+ virJSONValueFree(cpu_props);
+ return model_json;
+}
+
+
/* model_json: {"name": "IvyBridge", "props": {}}
*/
static qemuMonitorCPUModelInfoPtr
--
2.14.1