mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-26 03:21:44 +03:00
Hook up JSON monitor to emit basic lifecycle events
* src/qemu/qemu_monitor_json.c: Hook up reset, shutdown, poweroff and stop events
This commit is contained in:
parent
89832303d7
commit
421d995005
@ -45,8 +45,51 @@
|
||||
|
||||
#define LINE_ENDING "\r\n"
|
||||
|
||||
static void qemuMonitorJSONHandleShutdown(qemuMonitorPtr mon, virJSONValuePtr data);
|
||||
static void qemuMonitorJSONHandleReset(qemuMonitorPtr mon, virJSONValuePtr data);
|
||||
static void qemuMonitorJSONHandlePowerdown(qemuMonitorPtr mon, virJSONValuePtr data);
|
||||
static void qemuMonitorJSONHandleStop(qemuMonitorPtr mon, virJSONValuePtr data);
|
||||
|
||||
struct {
|
||||
const char *type;
|
||||
void (*handler)(qemuMonitorPtr mon, virJSONValuePtr data);
|
||||
} eventHandlers[] = {
|
||||
{ "SHUTDOWN", qemuMonitorJSONHandleShutdown, },
|
||||
{ "RESET", qemuMonitorJSONHandleReset, },
|
||||
{ "POWERDOWN", qemuMonitorJSONHandlePowerdown, },
|
||||
{ "STOP", qemuMonitorJSONHandleStop, },
|
||||
};
|
||||
|
||||
|
||||
static int
|
||||
qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
||||
qemuMonitorJSONIOProcessEvent(qemuMonitorPtr mon,
|
||||
virJSONValuePtr obj)
|
||||
{
|
||||
char *type;
|
||||
int i;
|
||||
VIR_DEBUG("mon=%p obj=%p", mon, obj);
|
||||
|
||||
type = virJSONValueObjectGetString(obj, "event");
|
||||
if (!type) {
|
||||
VIR_WARN0("missing event type in message");
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < ARRAY_CARDINALITY(eventHandlers) ; i++) {
|
||||
if (STREQ(eventHandlers[i].type, type)) {
|
||||
virJSONValuePtr data = virJSONValueObjectGet(obj, "data");
|
||||
VIR_DEBUG("handle %s handler=%p data=%p", type,
|
||||
eventHandlers[i].handler, data);
|
||||
(eventHandlers[i].handler)(mon, data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
|
||||
const char *line,
|
||||
qemuMonitorMessagePtr msg)
|
||||
{
|
||||
@ -73,8 +116,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
||||
}
|
||||
|
||||
if (virJSONValueObjectHasKey(obj, "event") == 1) {
|
||||
VIR_DEBUG0("Got an event");
|
||||
ret = 0;
|
||||
ret = qemuMonitorJSONIOProcessEvent(mon, obj);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -413,6 +455,27 @@ error:
|
||||
}
|
||||
|
||||
|
||||
static void qemuMonitorJSONHandleShutdown(qemuMonitorPtr mon, virJSONValuePtr data ATTRIBUTE_UNUSED)
|
||||
{
|
||||
qemuMonitorEmitShutdown(mon);
|
||||
}
|
||||
|
||||
static void qemuMonitorJSONHandleReset(qemuMonitorPtr mon, virJSONValuePtr data ATTRIBUTE_UNUSED)
|
||||
{
|
||||
qemuMonitorEmitReset(mon);
|
||||
}
|
||||
|
||||
static void qemuMonitorJSONHandlePowerdown(qemuMonitorPtr mon, virJSONValuePtr data ATTRIBUTE_UNUSED)
|
||||
{
|
||||
qemuMonitorEmitPowerdown(mon);
|
||||
}
|
||||
|
||||
static void qemuMonitorJSONHandleStop(qemuMonitorPtr mon, virJSONValuePtr data ATTRIBUTE_UNUSED)
|
||||
{
|
||||
qemuMonitorEmitStop(mon);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
qemuMonitorJSONStartCPUs(qemuMonitorPtr mon,
|
||||
virConnectPtr conn ATTRIBUTE_UNUSED)
|
||||
|
Loading…
Reference in New Issue
Block a user