[PATCH 02/12] Domain Events - Internal API This patch -Removes EventImpl from being a private function -Introduces the virDomainEventCallbackListPtr, and virDomainEventQueuePtr objects
diff --git a/proxy/Makefile.am b/proxy/Makefile.am index 5902cab..75ba6b4 100644 --- a/proxy/Makefile.am +++ b/proxy/Makefile.am @@ -17,6 +17,7 @@ libvirt_proxy_SOURCES = libvirt_proxy.c @top_srcdir@/src/xend_internal.c \ @top_srcdir@/src/memory.c \ @top_srcdir@/src/domain_conf.c \ @top_srcdir@/src/util.c \ + @top_srcdir@/src/event.c \ @top_srcdir@/src/uuid.c libvirt_proxy_LDFLAGS = $(WARN_CFLAGS) libvirt_proxy_DEPENDENCIES = diff --git a/src/event.c b/src/event.c index 49a9e61..1e2b234 100644 --- a/src/event.c +++ b/src/event.c @@ -34,14 +34,15 @@ static virEventAddTimeoutFunc addTimeoutImpl = NULL; static virEventUpdateTimeoutFunc updateTimeoutImpl = NULL; static virEventRemoveTimeoutFunc removeTimeoutImpl = NULL; -int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaque) { +int virEventAddHandle(int fd, virEventHandleType events, + virEventHandleCallback cb, void *opaque) { if (!addHandleImpl) return -1; return addHandleImpl(fd, events, cb, opaque); } -void virEventUpdateHandle(int fd, int events) { +void virEventUpdateHandle(int fd, virEventHandleType events) { updateHandleImpl(fd, events); } @@ -70,12 +71,22 @@ int virEventRemoveTimeout(int timer) { return removeTimeoutImpl(timer); } -void __virEventRegisterImpl(virEventAddHandleFunc addHandle, - virEventUpdateHandleFunc updateHandle, - virEventRemoveHandleFunc removeHandle, - virEventAddTimeoutFunc addTimeout, - virEventUpdateTimeoutFunc updateTimeout, - virEventRemoveTimeoutFunc removeTimeout) { +/** + * virEventRegisterImpl: + * Register an EventImpl + * @addHandle: the callback to add fd handles + * @updateHandle: the callback to update fd handles + * @removeHandle: the callback to remove fd handles + * @addTimeout: the callback to add a timeout + * @updateTimeout: the callback to update a timeout + * @removeTimeout: the callback to remove a timeout + */ +void virEventRegisterImpl(virEventAddHandleFunc addHandle, + virEventUpdateHandleFunc updateHandle, + virEventRemoveHandleFunc removeHandle, + virEventAddTimeoutFunc addTimeout, + virEventUpdateTimeoutFunc updateTimeout, + virEventRemoveTimeoutFunc removeTimeout) { addHandleImpl = addHandle; updateHandleImpl = updateHandle; removeHandleImpl = removeHandle; diff --git a/src/event.h b/src/event.h index 758573c..5cd6310 100644 --- a/src/event.h +++ b/src/event.h @@ -23,38 +23,29 @@ #ifndef __VIR_EVENT_H__ #define __VIR_EVENT_H__ - - -/** - * virEventHandleCallback: callback for receiving file handle events - * - * @fd: file handle on which the event occurred - * @events: bitset of events from POLLnnn constants - * @opaque: user data registered with handle - */ -typedef void (*virEventHandleCallback)(int fd, int events, void *opaque); - +#include "internal.h" /** * virEventAddHandle: register a callback for monitoring file handle events * * @fd: file handle to monitor for events - * @events: bitset of events to watch from POLLnnn constants + * @events: bitset of events to watch from virEventHandleType constants * @cb: callback to invoke when an event occurs * @opaque: user data to pass to callback * * returns -1 if the file handle cannot be registered, 0 upon success */ -int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaque); +int virEventAddHandle(int fd, virEventHandleType events, + virEventHandleCallback cb, void *opaque); /** * virEventUpdateHandle: change event set for a monitored file handle * * @fd: file handle to monitor for events - * @events: bitset of events to watch from POLLnnn constants + * @events: bitset of events to watch from virEventHandleType constants * * Will not fail if fd exists */ -void virEventUpdateHandle(int fd, int events); +void virEventUpdateHandle(int fd, virEventHandleType events); /** * virEventRemoveHandle: unregister a callback from a file handle @@ -66,14 +57,6 @@ void virEventUpdateHandle(int fd, int events); int virEventRemoveHandle(int fd); /** - * virEventTimeoutCallback: callback for receiving timer events - * - * @timer: timer id emitting the event - * @opaque: user data registered with handle - */ -typedef void (*virEventTimeoutCallback)(int timer, void *opaque); - -/** * virEventAddTimeout: register a callback for a timer event * * @frequency: time between events in milliseconds @@ -110,21 +93,4 @@ void virEventUpdateTimeout(int timer, int frequency); */ int virEventRemoveTimeout(int timer); -typedef int (*virEventAddHandleFunc)(int, int, virEventHandleCallback, void *); -typedef void (*virEventUpdateHandleFunc)(int, int); -typedef int (*virEventRemoveHandleFunc)(int); - -typedef int (*virEventAddTimeoutFunc)(int, virEventTimeoutCallback, void *); -typedef void (*virEventUpdateTimeoutFunc)(int, int); -typedef int (*virEventRemoveTimeoutFunc)(int); - -void __virEventRegisterImpl(virEventAddHandleFunc addHandle, - virEventUpdateHandleFunc updateHandle, - virEventRemoveHandleFunc removeHandle, - virEventAddTimeoutFunc addTimeout, - virEventUpdateTimeoutFunc updateTimeout, - virEventRemoveTimeoutFunc removeTimeout); - -#define virEventRegisterImpl(ah,rh,at,rt) __virEventRegisterImpl(ah,rh,at,rt) - #endif /* __VIR_EVENT_H__ */ diff --git a/src/internal.h b/src/internal.h index 2ae764d..311cc81 100644 --- a/src/internal.h +++ b/src/internal.h @@ -383,4 +383,76 @@ char *virStringListJoin(const virStringList *list, const char *pre, const char *post, const char *sep); void virStringListFree(virStringList *list); +/** + * Domain Event Notification + */ + +struct _virDomainEventCallback { + virConnectPtr conn; + virConnectDomainEventCallback cb; + void *opaque; +}; +typedef struct _virDomainEventCallback virDomainEventCallback; +typedef virDomainEventCallback *virDomainEventCallbackPtr; + +struct _virDomainEventCallbackList { + unsigned int count; + virDomainEventCallbackPtr *callbacks; +}; +typedef struct _virDomainEventCallbackList virDomainEventCallbackList; +typedef virDomainEventCallbackList *virDomainEventCallbackListPtr; + +void __virDomainEventCallbackListFree(virDomainEventCallbackListPtr list); +#define virDomainEventCallbackListFree(x) __virDomainEventCallbackListFree(x) + +int __virDomainEventCallbackListAdd(virConnectPtr conn, + virDomainEventCallbackListPtr cbList, + virConnectDomainEventCallback callback, + void *opaque); +#define virDomainEventCallbackListAdd(a,b,c,d) \ + __virDomainEventCallbackListAdd((a),(b),(c),(d)) + +int __virDomainEventCallbackListRemove(virConnectPtr conn, + virDomainEventCallbackListPtr cbList, + virConnectDomainEventCallback callback); +#define virDomainEventCallbackListRemove(a,b,c) \ + __virDomainEventCallbackListRemove((a),(b),(c)) + +int __virEventHandleTypeToPollEvent(virEventHandleType events); +#define virEventHandleTypeToPollEvent(x) __virEventHandleTypeToPollEvent(x) + +virEventHandleType __virPollEventToEventHandleType(int events); +#define virPollEventToEventHandleType(x) __virPollEventToEventHandleType(x) + +/** + * Dispatching domain events that come in while + * in a call / response rpc + */ +struct _virDomainEvent { + virDomainPtr dom; + virDomainEventType event; +}; +typedef struct _virDomainEvent virDomainEvent; +typedef virDomainEvent *virDomainEventPtr; + +struct _virDomainEventQueue { + unsigned int count; + virDomainEventPtr *events; +}; +typedef struct _virDomainEventQueue virDomainEventQueue; +typedef virDomainEventQueue *virDomainEventQueuePtr; + +int __virDomainEventCallbackQueuePush(virDomainEventQueuePtr evtQueue, + virDomainPtr dom, + virDomainEventType event); +#define virDomainEventCallbackQueuePush(a,b,c) \ + __virDomainEventCallbackQueuePush((a),(b),(c)) + +virDomainEventPtr +__virDomainEventCallbackQueuePop(virDomainEventQueuePtr evtQueue); +#define virDomainEventCallbackQueuePop(x) __virDomainEventCallbackQueuePop(x) + +void __virDomainEventQueueFree(virDomainEventQueuePtr queue); +#define virDomainEventQueueFree(x) __virDomainEventQueueFree(x) + #endif /* __VIR_INTERNAL_H__ */
-- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list