[libvirt] [PATCH 01/13] Introduce a new public API for domain events

Daniel Veillard veillard at redhat.com
Mon Mar 22 14:29:25 UTC 2010


On Fri, Mar 19, 2010 at 03:38:49PM +0000, Daniel P. Berrange wrote:
> The current API for domain events has a number of problems
> 
>  - Only allows for domain lifecycle change events
>  - Does not allow the same callback to be registered multiple times
>  - Does not allow filtering of events to a specific domain
> 
> This introduces a new more general purpose domain events API
> 
>   typedef enum {
>      VIR_DOMAIN_EVENT_ID_LIFECYCLE = 0,       /* virConnectDomainEventCallback */
>       ...more events later..
>   }
> 
>   int virConnectDomainEventRegisterAny(virConnectPtr conn,
>                                        virDomainPtr dom, /* Optional, to filter */
>                                        int eventID,
>                                        virConnectDomainEventGenericCallback cb,
>                                        void *opaque,
>                                        virFreeCallback freecb);
> 
>   int virConnectDomainEventDeregisterAny(virConnectPtr conn,
>                                          int callbackID);
> 
> Since different event types can received different data in the callback,
> the API is defined with a generic callback. Specific events will each
> have a custom signature for their callback. Thus when registering an
> event it is neccessary to cast the callback to the generic signature

  okay, following our previous discussion about events API, the only
drawback is that it limits the filtering to domain only kind of objects,
but we can add similar entry points if needed on other main types later.

[...]
> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index 0d1b5b5..62a51ea 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -1837,6 +1837,40 @@ int virDomainGetJobInfo(virDomainPtr dom,
>  int virDomainAbortJob(virDomainPtr dom);
>  
>  
> +/* A generic callback definition. Specific events usually have a customization
> + * with extra parameters */
> +typedef void (*virConnectDomainEventGenericCallback)(virConnectPtr conn,
> +                                                     virDomainPtr dom,
> +                                                     void *opaque);
> +
> +/* Use this to cast the event specific callback into the generic one
> + * for use for virDomainEventRegister */
> +#define VIR_DOMAIN_EVENT_CALLBACK(cb) ((virConnectDomainEventGenericCallback)(cb))

  cosmetic, would be nicer if that fit in 80 columns

> +
> +typedef enum {
> +    VIR_DOMAIN_EVENT_ID_LIFECYCLE = 0,       /* virConnectDomainEventCallback */
> +
> +    /*
> +     * NB: this enum value will increase over time as new events are
> +     * added to the libvirt API. It reflects the last event ID supported
> +     * by this version of the libvirt API.
> +     */
> +    VIR_DOMAIN_EVENT_ID_LAST
> +} virDomainEventID;
> +
> +
> +/* Use VIR_DOMAIN_EVENT_CALLBACK() to cast the 'cb' parameter  */
> +int virConnectDomainEventRegisterAny(virConnectPtr conn,
> +                                     virDomainPtr dom, /* Optional, to filter */
> +                                     int eventID,
> +                                     virConnectDomainEventGenericCallback cb,
> +                                     void *opaque,
> +                                     virFreeCallback freecb);
> +
> +int virConnectDomainEventDeregisterAny(virConnectPtr conn,
> +                                       int callbackID);
> +
>  #ifdef __cplusplus
>  }
>  #endif
[...]

  ACK,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list