#undef MAKE_SET_CMD
+/* A filter callback for qemuMonitorJSONParsePropsList.
+ *
+ * Returns 0 if the property should be included in the list,
+ * 1 if the property should be ignored,
+ * -1 on error.
+ */
+typedef int (*qemuMonitorJSONPropsListFilter)(const char *name,
+ virJSONValue *propData,
+ void *data);
+
static int
qemuMonitorJSONParsePropsList(virJSONValue *cmd,
virJSONValue *reply,
- const char *type,
+ qemuMonitorJSONPropsListFilter propFilter,
+ void *filterData,
char ***props)
{
virJSONValue *data;
for (i = 0; i < n; i++) {
virJSONValue *child = virJSONValueArrayGet(data, i);
- const char *tmp;
-
- if (type &&
- STRNEQ_NULLABLE(virJSONValueObjectGetString(child, "type"), type))
- continue;
+ const char *name = virJSONValueObjectGetString(child, "name");
- if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
+ if (!name) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("reply data was missing 'name'"));
return -1;
}
- proplist[count++] = g_strdup(tmp);
+ if (propFilter) {
+ int rc = propFilter(name, child, filterData);
+
+ if (rc < 0)
+ return -1;
+
+ if (rc != 0)
+ continue;
+ }
+
+ proplist[count++] = g_strdup(name);
}
*props = g_steal_pointer(&proplist);
if (qemuMonitorJSONHasError(reply, "DeviceNotFound"))
return 0;
- return qemuMonitorJSONParsePropsList(cmd, reply, NULL, props);
+ return qemuMonitorJSONParsePropsList(cmd, reply, NULL, NULL, props);
}
}
+static int
+qemuMonitorJSONCPUPropsFilter(const char *name G_GNUC_UNUSED,
+ virJSONValue *propData,
+ void *data G_GNUC_UNUSED)
+{
+ if (STRNEQ_NULLABLE(virJSONValueObjectGetString(propData, "type"), "bool"))
+ return 1;
+
+ return 0;
+}
+
+
static int
qemuMonitorJSONGetCPUProperties(qemuMonitor *mon,
const char *cpuQOMPath,
if (qemuMonitorJSONHasError(reply, "DeviceNotFound"))
return 0;
- return qemuMonitorJSONParsePropsList(cmd, reply, "bool", props);
+ return qemuMonitorJSONParsePropsList(cmd, reply,
+ qemuMonitorJSONCPUPropsFilter, NULL,
+ props);
}