Re: [PATCH 2/7] Update event demo program to support network events too

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

 



On 12.12.2013 19:04, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>
> 
> ---
>  examples/object-events/event-test.c | 45 +++++++++++++++++++++++++++++++++++--
>  1 file changed, 43 insertions(+), 2 deletions(-)
> 
> diff --git a/examples/object-events/event-test.c b/examples/object-events/event-test.c
> index 52aa3d0..6a279cf 100644
> --- a/examples/object-events/event-test.c
> +++ b/examples/object-events/event-test.c
> @@ -223,6 +223,27 @@ static const char *eventDetailToString(int event, int detail) {
>      return ret;
>  }
>  
> +static const char *
> +networkEventToString(int event)
> +{
> +    const char *ret = "";
> +    switch ((virNetworkEventLifecycleType) event) {
> +        case VIR_NETWORK_EVENT_DEFINED:
> +            ret ="Defined";
> +            break;
> +        case VIR_NETWORK_EVENT_UNDEFINED:
> +            ret ="Undefined";
> +            break;
> +        case VIR_NETWORK_EVENT_STARTED:
> +            ret ="Started";
> +            break;
> +        case VIR_NETWORK_EVENT_STOPPED:
> +            ret ="Stopped";
> +            break;
> +    }
> +    return ret;
> +}
> +
>  static int myDomainEventCallback1(virConnectPtr conn ATTRIBUTE_UNUSED,
>                                    virDomainPtr dom,
>                                    int event,
> @@ -432,6 +453,18 @@ myDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
>      return 0;
>  }
>  
> +static int myNetworkEventCallback2(virConnectPtr conn ATTRIBUTE_UNUSED,
> +                                  virNetworkPtr dom,
> +                                  int event,
> +                                  int detail,
> +                                  void *opaque ATTRIBUTE_UNUSED)
> +{
> +    printf("%s EVENT: Network %s %s %d\n", __func__, virNetworkGetName(dom),
> +           networkEventToString(event), detail);
> +    return 0;
> +}
> +
> +
>  static void myFreeFunc(void *opaque)
>  {
>      char *str = opaque;
> @@ -472,6 +505,7 @@ int main(int argc, char **argv)
>      int callback13ret = -1;
>      int callback14ret = -1;
>      int callback15ret = -1;
> +    int callback16ret = -1;
>      struct sigaction action_stop;
>  
>      memset(&action_stop, 0, sizeof(action_stop));
> @@ -510,7 +544,7 @@ int main(int argc, char **argv)
>      sigaction(SIGTERM, &action_stop, NULL);
>      sigaction(SIGINT, &action_stop, NULL);
>  
> -    VIR_DEBUG("Registering domain event cbs");
> +    VIR_DEBUG("Registering event cbs");
>  
>      /* Add 2 callbacks to prove this works with more than just one */
>      callback1ret = virConnectDomainEventRegister(dconn, myDomainEventCallback1,
> @@ -585,6 +619,11 @@ int main(int argc, char **argv)
>                                                       VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED,
>                                                       VIR_DOMAIN_EVENT_CALLBACK(myDomainEventDeviceRemovedCallback),
>                                                       strdup("device removed"), myFreeFunc);
> +    callback16ret = virConnectNetworkEventRegisterAny(dconn,
> +                                                      NULL,
> +                                                      VIR_NETWORK_EVENT_ID_LIFECYCLE,
> +                                                      VIR_NETWORK_EVENT_CALLBACK(myNetworkEventCallback2),
> +                                                      strdup("callback 2"), myFreeFunc);

Again, s/callback 2/network callback/ or something.

ACK once you do that.


Michal

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]