}
/*
- * 1. This function takes ownership of rsp, err, and id.
- * 2. rsp, err, and id may be NULL.
- * 3. If err != NULL then rsp must be NULL.
+ * Emit QMP response @rsp with ID @id to @mon.
+ * Null @rsp can only happen for commands with QCO_NO_SUCCESS_RESP.
+ * Nothing is emitted then.
*/
-static void monitor_qmp_respond(Monitor *mon, QDict *rsp,
- Error *err, QObject *id)
+static void monitor_qmp_respond(Monitor *mon, QDict *rsp, QObject *id)
{
- if (err) {
- assert(!rsp);
- rsp = qmp_error_response(err);
- }
-
if (rsp) {
if (id) {
qdict_put_obj(rsp, "id", qobject_ref(id));
qmp_queue_response(mon, rsp);
}
-
- qobject_unref(id);
- qobject_unref(rsp);
}
static void monitor_qmp_dispatch(Monitor *mon, QObject *req, QObject *id)
}
}
- /* Respond if necessary */
- monitor_qmp_respond(mon, rsp, NULL, qobject_ref(id));
+ monitor_qmp_respond(mon, rsp, id);
+ qobject_unref(rsp);
}
/*
static void monitor_qmp_bh_dispatcher(void *data)
{
QMPRequest *req_obj = monitor_qmp_requests_pop_any();
+ QDict *rsp;
if (!req_obj) {
return;
monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id);
} else {
assert(req_obj->err);
- monitor_qmp_respond(req_obj->mon, NULL, req_obj->err, NULL);
+ rsp = qmp_error_response(req_obj->err);
+ monitor_qmp_respond(req_obj->mon, rsp, NULL);
+ qobject_unref(rsp);
}
if (req_obj->need_resume) {