[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 14/14] Hook up JSON monitor to emit basic lifecycle events



2009/11/26 Daniel P. Berrange <berrange redhat com>:
> * src/qemu/qemu_monitor_json.c: Hook up reset, shutdown,
>  poweroff and stop events
> ---
>  src/qemu/qemu_monitor_json.c |   69 ++++++++++++++++++++++++++++++++++++++++--
>  1 files changed, 66 insertions(+), 3 deletions(-)
>
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index 9d71826..050472c 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -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
> +qemuMonitorJSONIOProcessEvent(qemuMonitorPtr mon,
> +                              virJSONValuePtr obj)
> +{
> +    char *type;
> +    int i;
> +    VIR_DEBUG("mon=%p obj=%p", mon, obj);
> +
> +    type = virJSONValueObjectGetString(obj, "event");
> +    if (!type) {
> +        VIR_INFO0("missing event type in message");

I thing this should be a warning, not just info.

> +        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 ATTRIBUTE_UNUSED,
> +qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
>                              const char *line,
>                              qemuMonitorMessagePtr msg)
>  {

ACK.

Matthias


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]