From e46bf585a6ff8f535c0bccb1667fafd0aebd1904 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Wed, 15 Jun 2011 19:35:44 -0400 Subject: python: Add bindings for virEvent*Handle/Timeout --- libvirt-override.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'libvirt-override.py') 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 -- cgit