for (i = 0; i < G_N_ELEMENTS(virQEMUCapsDeviceProps); i++) {
virQEMUCapsObjectTypeProps *device = virQEMUCapsDeviceProps + i;
- VIR_AUTOSTRINGLIST values = NULL;
- int nvalues;
+ g_autoptr(virHashTable) qemuprops = NULL;
+ size_t j;
if (device->capsCondition >= 0 &&
!virQEMUCapsGet(qemuCaps, device->capsCondition))
continue;
- if ((nvalues = qemuMonitorGetDeviceProps(mon, device->type, &values)) < 0)
+ if (!(qemuprops = qemuMonitorGetDeviceProps(mon, device->type)))
return -1;
- virQEMUCapsProcessStringFlags(qemuCaps,
- device->nprops,
- device->props,
- nvalues, values);
+ for (j = 0; j < device->nprops; j++) {
+ virJSONValuePtr entry = virHashLookup(qemuprops, device->props[j].value);
+
+ if (!entry)
+ continue;
+
+ virQEMUCapsSet(qemuCaps, device->props[j].flag);
+ }
}
return 0;
}
-int
+virHashTablePtr
qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
- const char *device,
- char ***props)
+ const char *device)
{
- VIR_DEBUG("device=%s props=%p", device, props);
+ VIR_DEBUG("device=%s", device);
- QEMU_CHECK_MONITOR(mon);
+ QEMU_CHECK_MONITOR_NULL(mon);
- return qemuMonitorJSONGetDeviceProps(mon, device, props);
+ return qemuMonitorJSONGetDeviceProps(mon, device);
}
int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
char ***types);
-int qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
- const char *device,
- char ***props);
+virHashTablePtr qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
+ const char *device);
int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
const char *object,
char ***props);
}
-int
+static int
+qemuMonitorJSONGetDevicePropsWorker(size_t pos G_GNUC_UNUSED,
+ virJSONValuePtr item,
+ void *opaque)
+{
+ const char *name = virJSONValueObjectGetString(item, "name");
+ virHashTablePtr devices = opaque;
+
+ if (!name) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("reply data was missing 'name'"));
+ return -1;
+ }
+
+ if (virHashAddEntry(devices, name, item) < 0)
+ return -1;
+
+ return 0;
+}
+
+
+virHashTablePtr
qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
- const char *device,
- char ***props)
+ const char *device)
{
+ g_autoptr(virHashTable) props = virHashNew(virJSONValueHashFree);
g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL;
- *props = NULL;
-
if (!(cmd = qemuMonitorJSONMakeCommand("device-list-properties",
"s:typename", device,
NULL)))
- return -1;
+ return NULL;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
- return -1;
+ return NULL;
+ /* return empty hash */
if (qemuMonitorJSONHasError(reply, "DeviceNotFound"))
- return 0;
+ return g_steal_pointer(&props);
+
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
+ return NULL;
+
+ if (virJSONValueArrayForeachSteal(virJSONValueObjectGetArray(reply, "return"),
+ qemuMonitorJSONGetDevicePropsWorker,
+ props) < 0)
+ return NULL;
- return qemuMonitorJSONParsePropsList(cmd, reply, NULL, props);
+ return g_steal_pointer(&props);
}
qemuMonitorJSONObjectPropertyPtr prop)
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
-int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
- const char *device,
- char ***props)
- ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+virHashTablePtr qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
+ const char *device)
+ ATTRIBUTE_NONNULL(2);
int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
const char *object,
char ***props)