1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-08-03 08:21:58 +03:00

python: Add bindings for virEvent*Handle/Timeout

This commit is contained in:
Cole Robinson
2011-06-15 19:35:44 -04:00
parent 633bf2494b
commit e46bf585a6
3 changed files with 221 additions and 36 deletions

View File

@ -131,3 +131,57 @@ def eventInvokeTimeoutCallback (timer, callback, opaque):
Invoke the Event Impl Timeout Callback in C
"""
libvirtmod.virEventInvokeTimeoutCallback(timer, callback, opaque);
def _dispatchEventHandleCallback(watch, fd, events, cbData):
cb = cbData["cb"]
opaque = cbData["opaque"]
cb(watch, fd, events, opaque)
return 0
def _dispatchEventTimeoutCallback(timer, cbData):
cb = cbData["cb"]
opaque = cbData["opaque"]
cb(timer, opaque)
return 0
def virEventAddHandle(fd, events, cb, opaque):
"""
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
Example callback prototype is:
def cb(watch, # int id of the handle
fd, # int file descriptor the event occured on
events, # int bitmap of events that have occured
opaque): # opaque data passed to eventAddHandle
"""
cbData = {"cb" : cb, "opaque" : opaque}
ret = libvirtmod.virEventAddHandle(fd, events, cbData)
if ret == -1: raise libvirtError ('virEventAddHandle() failed')
return ret
def virEventAddTimeout(timeout, cb, opaque):
"""
register a callback for a timer event
@timeout: time between events in milliseconds
@cb: callback to invoke when an event occurs
@opaque: user data to pass to callback
Setting timeout to -1 will disable the timer. Setting the timeout
to zero will cause it to fire on every event loop iteration.
Example callback prototype is:
def cb(timer, # int id of the timer
opaque): # opaque data passed to eventAddTimeout
"""
cbData = {"cb" : cb, "opaque" : opaque}
ret = libvirtmod.virEventAddTimeout(timeout, cbData)
if ret == -1: raise libvirtError ('virEventAddTimeout() failed')
return ret