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
This commit is contained in:
Cole Robinson 2011-06-15 17:54:30 -04:00
parent 3b04871e80
commit 6094ad7bd7
28 changed files with 84 additions and 104 deletions

View File

@ -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"

View File

@ -39,7 +39,6 @@
#include "libvirtd.h"
#include "mdns.h"
#include "event.h"
#include "event_poll.h"
#include "memory.h"

View File

@ -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
*/

View File

@ -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",

View File

@ -24,7 +24,6 @@
#include <config.h>
#include "domain_event.h"
#include "event.h"
#include "logging.h"
#include "datatypes.h"
#include "memory.h"

View File

@ -25,7 +25,6 @@
#ifndef __DOMAIN_EVENT_H__
# define __DOMAIN_EVENT_H__
# include "event.h"
# include "domain_conf.h"
typedef struct _virDomainEventCallback virDomainEventCallback;

View File

@ -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"

View File

@ -455,15 +455,6 @@ ebtablesContextNew;
ebtablesRemoveForwardAllowIn;
# event.h
virEventAddHandle;
virEventAddTimeout;
virEventRemoveHandle;
virEventRemoveTimeout;
virEventUpdateHandle;
virEventUpdateTimeout;
# event_poll.h
virEventPollToNativeEvents;
virEventPollFromNativeEvents;

View File

@ -459,6 +459,12 @@ LIBVIRT_0.9.3 {
virDomainGetControlInfo;
virDomainPinVcpuFlags;
virDomainSendKey;
virEventAddHandle;
virEventAddTimeout;
virEventRemoveHandle;
virEventRemoveTimeout;
virEventUpdateHandle;
virEventUpdateTimeout;
virNodeGetCPUStats;
virNodeGetMemoryStats;
} LIBVIRT_0.9.2;

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -37,7 +37,6 @@
#include "uuid.h"
#include "util.h"
#include "buf.h"
#include "event.h"
#define VIR_FROM_THIS VIR_FROM_NODEDEV

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -47,7 +47,6 @@
#include "uml_driver.h"
#include "uml_conf.h"
#include "event.h"
#include "buf.h"
#include "util.h"
#include "nodeinfo.h"

View File

@ -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;

View File

@ -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__ */

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -43,7 +43,6 @@
# include "memory.h"
# include "virterror_internal.h"
# include "event.h"
/* ie Ctrl-] as per telnet */
# define CTRL_CLOSE_BRACKET '\35'