1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-07-27 11:41:52 +03:00

Bind connection close callback APIs to python binding

Add code in the python binding to cope with the new APIs
virConnectRegisterCloseCallback and
virConnectUnregisterCloseCallback. Also demonstrate their
use in the python domain events demo

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange
2012-07-30 17:30:42 +01:00
parent ca7f58d203
commit ac532dd37d
3 changed files with 133 additions and 2 deletions

View File

@ -287,3 +287,26 @@
retlist.append(virSecret(self, _obj=secret_ptr))
return retlist
def _dispatchCloseCallback(self, reason, cbData):
"""Dispatches events to python user close callback"""
cb = cbData["cb"]
opaque = cbData["opaque"]
cb(self, reason, opaque)
return 0
def unregisterCloseCallback(self):
"""Removes a close event callback"""
ret = libvirtmod.virConnectUnregisterCloseCallback(self._o)
if ret == -1: raise libvirtError ('virConnectUnregisterCloseCallback() failed', conn=self)
def registerCloseCallback(self, cb, opaque):
"""Adds a close event callback, providing a notification
when a connection fails / closes"""
cbData = { "cb": cb, "conn": self, "opaque": opaque }
ret = libvirtmod.virConnectRegisterCloseCallback(self._o, cbData)
if ret == -1:
raise libvirtError ('virConnectRegisterCloseCallback() failed', conn=self)
return ret