summaryrefslogtreecommitdiffstats
path: root/libvirt-override.py
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2011-06-15 19:35:44 -0400
committerCole Robinson <crobinso@redhat.com>2011-06-21 10:08:47 -0400
commite46bf585a6ff8f535c0bccb1667fafd0aebd1904 (patch)
treebd93c7d7fd72c1676883f9f389d34b75247ce739 /libvirt-override.py
parent633bf2494bc3ac550d8f176f0df2eb33faceffcc (diff)
downloadlibvirt-python-split-e46bf585a6ff8f535c0bccb1667fafd0aebd1904.zip
libvirt-python-split-e46bf585a6ff8f535c0bccb1667fafd0aebd1904.tar.gz
libvirt-python-split-e46bf585a6ff8f535c0bccb1667fafd0aebd1904.tar.xz
python: Add bindings for virEvent*Handle/Timeout
Diffstat (limited to 'libvirt-override.py')
-rw-r--r--libvirt-override.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/libvirt-override.py b/libvirt-override.py
index d544a0e..b611ca4 100644
--- a/libvirt-override.py
+++ b/libvirt-override.py
@@ -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