python: Implement bindings for virStreamEventAddCallback
[libvirt-python/ericb.git] / libvirt-override-virConnect.py
blob362be75d2b75db1a604749bc3910fc5020700773
1 def __del__(self):
2 try:
3 for cb,opaque in self.domainEventCallbacks.items():
4 del self.domainEventCallbacks[cb]
5 del self.domainEventCallbacks
6 libvirtmod.virConnectDomainEventDeregister(self._o, self)
7 except AttributeError:
8 pass
10 if self._o != None:
11 libvirtmod.virConnectClose(self._o)
12 self._o = None
14 def domainEventDeregister(self, cb):
15 """Removes a Domain Event Callback. De-registering for a
16 domain callback will disable delivery of this event type """
17 try:
18 del self.domainEventCallbacks[cb]
19 if len(self.domainEventCallbacks) == 0:
20 del self.domainEventCallbacks
21 ret = libvirtmod.virConnectDomainEventDeregister(self._o, self)
22 if ret == -1: raise libvirtError ('virConnectDomainEventDeregister() failed', conn=self)
23 except AttributeError:
24 pass
26 def domainEventRegister(self, cb, opaque):
27 """Adds a Domain Event Callback. Registering for a domain
28 callback will enable delivery of the events """
29 try:
30 self.domainEventCallbacks[cb] = opaque
31 except AttributeError:
32 self.domainEventCallbacks = {cb:opaque}
33 ret = libvirtmod.virConnectDomainEventRegister(self._o, self)
34 if ret == -1: raise libvirtError ('virConnectDomainEventRegister() failed', conn=self)
36 def dispatchDomainEventCallbacks(self, dom, event, detail):
37 """Dispatches events to python user domain event callbacks
38 """
39 try:
40 for cb,opaque in self.domainEventCallbacks.items():
41 cb(self,dom,event,detail,opaque)
42 return 0
43 except AttributeError:
44 pass
46 def dispatchDomainEventLifecycleCallback(self, dom, event, detail, cbData):
47 """Dispatches events to python user domain lifecycle event callbacks
48 """
49 cb = cbData["cb"]
50 opaque = cbData["opaque"]
52 cb(self, virDomain(self, _obj=dom), event, detail, opaque)
53 return 0
55 def dispatchDomainEventGenericCallback(self, dom, cbData):
56 """Dispatches events to python user domain generic event callbacks
57 """
58 try:
59 cb = cbData["cb"]
60 opaque = cbData["opaque"]
62 cb(self, virDomain(self, _obj=dom), opaque)
63 return 0
64 except AttributeError:
65 pass
67 def dispatchDomainEventRTCChangeCallback(self, dom, offset, cbData):
68 """Dispatches events to python user domain RTC change event callbacks
69 """
70 try:
71 cb = cbData["cb"]
72 opaque = cbData["opaque"]
74 cb(self, virDomain(self, _obj=dom), offset ,opaque)
75 return 0
76 except AttributeError:
77 pass
79 def dispatchDomainEventWatchdogCallback(self, dom, action, cbData):
80 """Dispatches events to python user domain watchdog event callbacks
81 """
82 try:
83 cb = cbData["cb"]
84 opaque = cbData["opaque"]
86 cb(self, virDomain(self, _obj=dom), action, opaque)
87 return 0
88 except AttributeError:
89 pass
91 def dispatchDomainEventIOErrorCallback(self, dom, srcPath, devAlias, action, cbData):
92 """Dispatches events to python user domain IO error event callbacks
93 """
94 try:
95 cb = cbData["cb"]
96 opaque = cbData["opaque"]
98 cb(self, virDomain(self, _obj=dom), srcPath, devAlias, action, opaque)
99 return 0
100 except AttributeError:
101 pass
103 def dispatchDomainEventIOErrorReasonCallback(self, dom, srcPath, devAlias, action, reason, cbData):
104 """Dispatches events to python user domain IO error event callbacks
106 try:
107 cb = cbData["cb"]
108 opaque = cbData["opaque"]
110 cb(self, virDomain(self, _obj=dom), srcPath, devAlias, action, reason, opaque)
111 return 0
112 except AttributeError:
113 pass
115 def dispatchDomainEventGraphicsCallback(self, dom, phase, localAddr, remoteAddr, authScheme, subject, cbData):
116 """Dispatches events to python user domain graphics event callbacks
118 try:
119 cb = cbData["cb"]
120 opaque = cbData["opaque"]
122 cb(self, virDomain(self, _obj=dom), phase, localAddr, remoteAddr, authScheme, subject, opaque)
123 return 0
124 except AttributeError:
125 pass
127 def dispatchDomainEventBlockPullCallback(self, dom, path, status, cbData):
128 """Dispatches events to python user domain blockPull event callbacks
130 try:
131 cb = cbData["cb"]
132 opaque = cbData["opaque"]
134 cb(self, virDomain(self, _obj=dom), path, status, opaque)
135 return 0
136 except AttributeError:
137 pass
139 def domainEventDeregisterAny(self, callbackID):
140 """Removes a Domain Event Callback. De-registering for a
141 domain callback will disable delivery of this event type """
142 try:
143 ret = libvirtmod.virConnectDomainEventDeregisterAny(self._o, callbackID)
144 if ret == -1: raise libvirtError ('virConnectDomainEventDeregisterAny() failed', conn=self)
145 del self.domainEventCallbackID[callbackID]
146 except AttributeError:
147 pass
149 def domainEventRegisterAny(self, dom, eventID, cb, opaque):
150 """Adds a Domain Event Callback. Registering for a domain
151 callback will enable delivery of the events """
152 if not hasattr(self, 'domainEventCallbackID'):
153 self.domainEventCallbackID = {}
154 cbData = { "cb": cb, "conn": self, "opaque": opaque }
155 if dom is None:
156 ret = libvirtmod.virConnectDomainEventRegisterAny(self._o, None, eventID, cbData)
157 else:
158 ret = libvirtmod.virConnectDomainEventRegisterAny(self._o, dom._o, eventID, cbData)
159 if ret == -1:
160 raise libvirtError ('virConnectDomainEventRegisterAny() failed', conn=self)
161 self.domainEventCallbackID[ret] = opaque
162 return ret