mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 21:34:54 +03:00
qemu: monitor: Introduce qemuMonitorJSONGetReply, a better qemuMonitorJSONCheckReply
Rather than simply checking that the 'return' field is of the expected type we can directly return it as the caller is very likely going to use it. Extract the code into the new function and add a wrapper to preserve old functionality. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
b4f8313787
commit
a434684a57
@ -396,15 +396,15 @@ qemuMonitorJSONCheckError(virJSONValue *cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static virJSONValue *
|
||||||
qemuMonitorJSONCheckReply(virJSONValue *cmd,
|
qemuMonitorJSONGetReply(virJSONValue *cmd,
|
||||||
virJSONValue *reply,
|
virJSONValue *reply,
|
||||||
virJSONType type)
|
virJSONType type)
|
||||||
{
|
{
|
||||||
virJSONValue *data;
|
virJSONValue *data;
|
||||||
|
|
||||||
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
||||||
return -1;
|
return NULL;
|
||||||
|
|
||||||
data = virJSONValueObjectGet(reply, "return");
|
data = virJSONValueObjectGet(reply, "return");
|
||||||
if (virJSONValueGetType(data) != type) {
|
if (virJSONValueGetType(data) != type) {
|
||||||
@ -417,9 +417,21 @@ qemuMonitorJSONCheckReply(virJSONValue *cmd,
|
|||||||
_("unexpected type returned by QEMU command '%s'"),
|
_("unexpected type returned by QEMU command '%s'"),
|
||||||
qemuMonitorJSONCommandName(cmd));
|
qemuMonitorJSONCommandName(cmd));
|
||||||
|
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuMonitorJSONCheckReply(virJSONValue *cmd,
|
||||||
|
virJSONValue *reply,
|
||||||
|
virJSONType type)
|
||||||
|
{
|
||||||
|
if (!qemuMonitorJSONGetReply(cmd, reply, type))
|
||||||
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user