From 6094ad7bd72d7c059b2d9c97f3f829d740387cf4 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Wed, 15 Jun 2011 17:54:30 -0400 Subject: [PATCH] Promote virEvent*Handle/Timeout to public API Since we virEventRegisterDefaultImpl is now a public API, callers need a way to invoke the default registered Handle and Timeout functions. We already have general functions for these internally, so promote them to the public API. v2: Actually add APIs to libvirt.h --- daemon/libvirtd.c | 1 - daemon/mdns.c | 1 - include/libvirt/libvirt.h.in | 14 ++++++ python/generator.py | 8 ++++ src/conf/domain_event.c | 1 - src/conf/domain_event.h | 1 - src/fdstream.c | 1 - src/libvirt_private.syms | 9 ---- src/libvirt_public.syms | 6 +++ src/libxl/libxl_driver.c | 1 - src/lxc/lxc_driver.c | 1 - src/network/bridge_driver.c | 1 - src/node_device/node_device_hal.c | 1 - src/node_device/node_device_udev.c | 1 - src/openvz/openvz_driver.c | 1 - src/qemu/qemu_domain.c | 1 - src/qemu/qemu_driver.c | 1 - src/qemu/qemu_monitor.c | 1 - src/remote/remote_driver.c | 1 - src/test/test_driver.c | 1 - src/uml/uml_driver.c | 1 - src/util/event.c | 56 +++++++++++++++++++++++ src/util/event.h | 73 ------------------------------ src/util/util.c | 1 - src/vbox/vbox_tmpl.c | 1 - src/xen/xen_inotify.c | 1 - src/xen/xs_internal.c | 1 - tools/console.c | 1 - 28 files changed, 84 insertions(+), 104 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index bcaa37b444..5f291ec6f8 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -62,7 +62,6 @@ #include "uuid.h" #include "remote_driver.h" #include "conf.h" -#include "event.h" #include "event_poll.h" #include "memory.h" #include "stream.h" diff --git a/daemon/mdns.c b/daemon/mdns.c index 03695fddb8..ca4a433ac2 100644 --- a/daemon/mdns.c +++ b/daemon/mdns.c @@ -39,7 +39,6 @@ #include "libvirtd.h" #include "mdns.h" -#include "event.h" #include "event_poll.h" #include "memory.h" diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index cb9e8ca397..3f634e683f 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -2166,6 +2166,20 @@ void virEventRegisterImpl(virEventAddHandleFunc addHandle, int virEventRegisterDefaultImpl(void); int virEventRunDefaultImpl(void); +int virEventAddHandle(int fd, int events, + virEventHandleCallback cb, + void *opaque, + virFreeCallback ff); +void virEventUpdateHandle(int watch, int events); +int virEventRemoveHandle(int watch); + +int virEventAddTimeout(int frequency, + virEventTimeoutCallback cb, + void *opaque, + virFreeCallback ff); +void virEventUpdateTimeout(int timer, int frequency); +int virEventRemoveTimeout(int timer); + /* * Secret manipulation API */ diff --git a/python/generator.py b/python/generator.py index 7c843d719c..6fdc6f886d 100755 --- a/python/generator.py +++ b/python/generator.py @@ -398,6 +398,14 @@ skip_function = ( 'virStreamRecv', # overridden in libvirt-override-virStream.py 'virStreamSend', # overridden in libvirt-override-virStream.py + # XXX: Skip for now, some work needed to handle Timeout/Handle callbacks + 'virEventAddHandle', + 'virEventRemoveHandle', + 'virEventUpdateHandle', + 'virEventAddTimeout', + 'virEventRemoveTimeout', + 'virEventUpdateTimeout', + # 'Ref' functions have no use for bindings users. "virConnectRef", "virDomainRef", diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index a1f1b0f0ad..785e9e4c86 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -24,7 +24,6 @@ #include #include "domain_event.h" -#include "event.h" #include "logging.h" #include "datatypes.h" #include "memory.h" diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h index a80868b724..ea481b3a0d 100644 --- a/src/conf/domain_event.h +++ b/src/conf/domain_event.h @@ -25,7 +25,6 @@ #ifndef __DOMAIN_EVENT_H__ # define __DOMAIN_EVENT_H__ -# include "event.h" # include "domain_conf.h" typedef struct _virDomainEventCallback virDomainEventCallback; diff --git a/src/fdstream.c b/src/fdstream.c index e19694f249..c1ad787efb 100644 --- a/src/fdstream.c +++ b/src/fdstream.c @@ -38,7 +38,6 @@ #include "datatypes.h" #include "logging.h" #include "memory.h" -#include "event.h" #include "util.h" #include "files.h" #include "configmake.h" diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 03d2ddb6d2..8e844e9df4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -455,15 +455,6 @@ ebtablesContextNew; ebtablesRemoveForwardAllowIn; -# event.h -virEventAddHandle; -virEventAddTimeout; -virEventRemoveHandle; -virEventRemoveTimeout; -virEventUpdateHandle; -virEventUpdateTimeout; - - # event_poll.h virEventPollToNativeEvents; virEventPollFromNativeEvents; diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index b2915f6ef9..39d4cae4ad 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -459,6 +459,12 @@ LIBVIRT_0.9.3 { virDomainGetControlInfo; virDomainPinVcpuFlags; virDomainSendKey; + virEventAddHandle; + virEventAddTimeout; + virEventRemoveHandle; + virEventRemoveTimeout; + virEventUpdateHandle; + virEventUpdateTimeout; virNodeGetCPUStats; virNodeGetMemoryStats; } LIBVIRT_0.9.2; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 86ed8505b4..5a5951fa7f 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -38,7 +38,6 @@ #include "datatypes.h" #include "files.h" #include "memory.h" -#include "event.h" #include "uuid.h" #include "command.h" #include "libxl_driver.h" diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 3b0d2a6d8d..d0f715860d 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -45,7 +45,6 @@ #include "util.h" #include "bridge.h" #include "veth.h" -#include "event.h" #include "nodeinfo.h" #include "uuid.h" #include "stats_linux.h" diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 5e4b4d9a15..4b94959333 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -48,7 +48,6 @@ #include "bridge_driver.h" #include "network_conf.h" #include "driver.h" -#include "event.h" #include "buf.h" #include "util.h" #include "command.h" diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index a90e777d6b..27fedc93b0 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -32,7 +32,6 @@ #include "virterror_internal.h" #include "driver.h" #include "datatypes.h" -#include "event.h" #include "memory.h" #include "uuid.h" #include "logging.h" diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 8b9694e523..2d4e0783fe 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -37,7 +37,6 @@ #include "uuid.h" #include "util.h" #include "buf.h" -#include "event.h" #define VIR_FROM_THIS VIR_FROM_NODEDEV diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 645e42653f..c13f346c08 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -49,7 +49,6 @@ #include "virterror_internal.h" #include "datatypes.h" #include "openvz_driver.h" -#include "event.h" #include "buf.h" #include "util.h" #include "openvz_conf.h" diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 06d2a5e28e..5fe66ac672 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -30,7 +30,6 @@ #include "logging.h" #include "virterror_internal.h" #include "c-ctype.h" -#include "event.h" #include "cpu/cpu.h" #include "ignore-value.h" #include "uuid.h" diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 19f22e5a51..01587e8986 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -62,7 +62,6 @@ #include "virterror_internal.h" #include "logging.h" #include "datatypes.h" -#include "event.h" #include "buf.h" #include "util.h" #include "nodeinfo.h" diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 14289212eb..89a3f642a2 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -32,7 +32,6 @@ #include "qemu_monitor_text.h" #include "qemu_monitor_json.h" #include "qemu_conf.h" -#include "event.h" #include "virterror_internal.h" #include "memory.h" #include "logging.h" diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 13f8820c1d..d7ce76e31b 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -80,7 +80,6 @@ #include "qemu_protocol.h" #include "memory.h" #include "util.h" -#include "event.h" #include "ignore-value.h" #include "files.h" #include "command.h" diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f5221437a5..6c8b9cf801 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -44,7 +44,6 @@ #include "interface_conf.h" #include "domain_conf.h" #include "domain_event.h" -#include "event.h" #include "storage_conf.h" #include "node_device_conf.h" #include "xml.h" diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 1d26422a14..e557fe89c2 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -47,7 +47,6 @@ #include "uml_driver.h" #include "uml_conf.h" -#include "event.h" #include "buf.h" #include "util.h" #include "nodeinfo.h" diff --git a/src/util/event.c b/src/util/event.c index 11f025b446..41082217cf 100644 --- a/src/util/event.c +++ b/src/util/event.c @@ -37,6 +37,16 @@ static virEventAddTimeoutFunc addTimeoutImpl = NULL; static virEventUpdateTimeoutFunc updateTimeoutImpl = NULL; static virEventRemoveTimeoutFunc removeTimeoutImpl = NULL; +/** + * virEventAddHandle: register a callback for monitoring file handle events + * + * @fd: file handle to monitor for events + * @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, @@ -48,10 +58,25 @@ int virEventAddHandle(int fd, return addHandleImpl(fd, events, cb, opaque, ff); } +/** + * virEventUpdateHandle: change event set for a monitored file handle + * + * @watch: watch whose file handle to update + * @events: bitset of events to watch from virEventHandleType constants + * + * Will not fail if fd exists + */ void virEventUpdateHandle(int watch, int events) { updateHandleImpl(watch, events); } +/** + * virEventRemoveHandle: unregister a callback from a file handle + * + * @watch: watch whose file handle to remove + * + * returns -1 if the file handle was not registered, 0 upon success + */ int virEventRemoveHandle(int watch) { if (!removeHandleImpl) return -1; @@ -59,6 +84,19 @@ int virEventRemoveHandle(int watch) { return removeHandleImpl(watch); } +/** + * virEventAddTimeout: register a callback for a timer event + * + * @frequency: time between events in milliseconds + * @cb: callback to invoke when an event occurs + * @opaque: user data to pass to callback + * + * Setting frequency to -1 will disable the timer. Setting the frequency + * to zero will cause it to fire on every event loop iteration. + * + * returns -1 if the timer cannot be registered, a positive + * integer timer id upon success + */ int virEventAddTimeout(int timeout, virEventTimeoutCallback cb, void *opaque, @@ -69,10 +107,28 @@ int virEventAddTimeout(int timeout, return addTimeoutImpl(timeout, cb, opaque, ff); } +/** + * virEventUpdateTimeoutImpl: change frequency for a timer + * + * @timer: timer id to change + * @frequency: time between events in milliseconds + * + * Setting frequency to -1 will disable the timer. Setting the frequency + * to zero will cause it to fire on every event loop iteration. + * + * Will not fail if timer exists + */ void virEventUpdateTimeout(int timer, int timeout) { updateTimeoutImpl(timer, timeout); } +/** + * virEventRemoveTimeout: unregister a callback for a timer + * + * @timer: the timer id to remove + * + * returns -1 if the timer was not registered, 0 upon success + */ int virEventRemoveTimeout(int timer) { if (!removeTimeoutImpl) return -1; diff --git a/src/util/event.h b/src/util/event.h index 68b06c6aff..2fef3149c4 100644 --- a/src/util/event.h +++ b/src/util/event.h @@ -24,78 +24,5 @@ #ifndef __VIR_EVENT_H__ # define __VIR_EVENT_H__ # 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 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, - virFreeCallback ff); - -/** - * virEventUpdateHandle: change event set for a monitored file handle - * - * @watch: watch whose file handle to update - * @events: bitset of events to watch from virEventHandleType constants - * - * Will not fail if fd exists - */ -void virEventUpdateHandle(int watch, int events); - -/** - * virEventRemoveHandle: unregister a callback from a file handle - * - * @watch: watch whose file handle to remove - * - * returns -1 if the file handle was not registered, 0 upon success - */ -int virEventRemoveHandle(int watch); - -/** - * virEventAddTimeout: register a callback for a timer event - * - * @frequency: time between events in milliseconds - * @cb: callback to invoke when an event occurs - * @opaque: user data to pass to callback - * - * Setting frequency to -1 will disable the timer. Setting the frequency - * to zero will cause it to fire on every event loop iteration. - * - * returns -1 if the timer cannot be registered, a positive - * integer timer id upon success - */ -int virEventAddTimeout(int frequency, - virEventTimeoutCallback cb, - void *opaque, - virFreeCallback ff); - -/** - * virEventUpdateTimeoutImpl: change frequency for a timer - * - * @timer: timer id to change - * @frequency: time between events in milliseconds - * - * Setting frequency to -1 will disable the timer. Setting the frequency - * to zero will cause it to fire on every event loop iteration. - * - * Will not fail if timer exists - */ -void virEventUpdateTimeout(int timer, int frequency); - -/** - * virEventRemoveTimeout: unregister a callback for a timer - * - * @timer: the timer id to remove - * - * returns -1 if the timer was not registered, 0 upon success - */ -int virEventRemoveTimeout(int timer); #endif /* __VIR_EVENT_H__ */ diff --git a/src/util/util.c b/src/util/util.c index 8f6d887229..463d2b8eaa 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -68,7 +68,6 @@ #include "dirname.h" #include "virterror_internal.h" #include "logging.h" -#include "event.h" #include "buf.h" #include "util.h" #include "memory.h" diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index f2233a54b0..7fd120078c 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -49,7 +49,6 @@ #include "storage_conf.h" #include "storage_file.h" #include "uuid.h" -#include "event.h" #include "memory.h" #include "nodeinfo.h" #include "logging.h" diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c index 71bb6bee28..24b437638d 100644 --- a/src/xen/xen_inotify.c +++ b/src/xen/xen_inotify.c @@ -31,7 +31,6 @@ #include "datatypes.h" #include "driver.h" #include "memory.h" -#include "event.h" #include "xen_driver.h" #include "conf.h" #include "domain_conf.h" diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c index b684d3d25f..04bf93a548 100644 --- a/src/xen/xs_internal.c +++ b/src/xen/xs_internal.c @@ -29,7 +29,6 @@ #include "datatypes.h" #include "driver.h" #include "memory.h" -#include "event.h" #include "logging.h" #include "uuid.h" #include "xen_driver.h" diff --git a/tools/console.c b/tools/console.c index 0428239ab3..7ca95a3e1d 100644 --- a/tools/console.c +++ b/tools/console.c @@ -43,7 +43,6 @@ # include "memory.h" # include "virterror_internal.h" -# include "event.h" /* ie Ctrl-] as per telnet */ # define CTRL_CLOSE_BRACKET '\35'