summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOsier Yang <jyang@redhat.com>2012-03-23 22:50:36 +0800
committerOsier Yang <jyang@redhat.com>2012-03-23 23:12:18 +0800
commitdc2f75d35a6461c896a738d092dc973067d0dbd4 (patch)
treeae086163d4e9b9847ba170aab173ea50bcc61a4b
parent29b16a45d77586672631537bfe877455fa5527ac (diff)
downloadlibvirt-python-split-dc2f75d35a6461c896a738d092dc973067d0dbd4.zip
libvirt-python-split-dc2f75d35a6461c896a738d092dc973067d0dbd4.tar.gz
libvirt-python-split-dc2f75d35a6461c896a738d092dc973067d0dbd4.tar.xz
Add support for the suspend eventv0.9.11-rc1
This patch introduces a new event type for the QMP event SUSPEND: VIR_DOMAIN_EVENT_ID_PMSUSPEND The event doesn't take any data, but considering there might be reason for wakeup in future, the callback definition is: typedef void (*virConnectDomainEventSuspendCallback)(virConnectPtr conn, virDomainPtr dom, int reason, void *opaque); "reason" is unused currently, always passes "0".
-rw-r--r--libvirt-override-virConnect.py9
-rw-r--r--libvirt-override.c50
2 files changed, 59 insertions, 0 deletions
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py
index 2d48828..811e16b 100644
--- a/libvirt-override-virConnect.py
+++ b/libvirt-override-virConnect.py
@@ -152,6 +152,15 @@
cb(self, virDomain(self, _obj=dom), reason, opaque)
return 0;
+ def _dispatchDomainEventPMSuspendCallback(self, dom, reason, cbData):
+ """Dispatches event to python user domain pmsuspend event callbacks
+ """
+ cb = cbData["cb"]
+ opaque = cbData["opaque"]
+
+ cb(self, virDomain(self, _obj=dom), reason, opaque)
+ return 0;
+
def domainEventDeregisterAny(self, callbackID):
"""Removes a Domain Event Callback. De-registering for a
domain callback will disable delivery of this event type """
diff --git a/libvirt-override.c b/libvirt-override.c
index 51ae1cd..da1bceb 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -5199,6 +5199,53 @@ libvirt_virConnectDomainEventPMWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSE
return ret;
}
+static int
+libvirt_virConnectDomainEventPMSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ int reason,
+ void *opaque)
+{
+ PyObject *pyobj_cbData = (PyObject*)opaque;
+ PyObject *pyobj_dom;
+ PyObject *pyobj_ret;
+ PyObject *pyobj_conn;
+ PyObject *dictKey;
+ int ret = -1;
+
+ LIBVIRT_ENSURE_THREAD_STATE;
+ /* Create a python instance of this virDomainPtr */
+ virDomainRef(dom);
+
+ pyobj_dom = libvirt_virDomainPtrWrap(dom);
+ Py_INCREF(pyobj_cbData);
+
+ dictKey = libvirt_constcharPtrWrap("conn");
+ pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
+ Py_DECREF(dictKey);
+
+ /* Call the Callback Dispatcher */
+ pyobj_ret = PyObject_CallMethod(pyobj_conn,
+ (char*)"_dispatchDomainEventPMSuspendCallback",
+ (char*)"OO",
+ pyobj_dom,
+ reason,
+ pyobj_cbData);
+
+ Py_DECREF(pyobj_cbData);
+ Py_DECREF(pyobj_dom);
+
+ if(!pyobj_ret) {
+ DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
+ PyErr_Print();
+ } else {
+ Py_DECREF(pyobj_ret);
+ ret = 0;
+ }
+
+ LIBVIRT_RELEASE_THREAD_STATE;
+ return ret;
+}
+
static PyObject *
libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self,
PyObject * args)
@@ -5265,6 +5312,9 @@ libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self,
case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMWakeupCallback);
break;
+ case VIR_DOMAIN_EVENT_ID_PMSUSPEND:
+ cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendCallback);
+ break;
}
if (!cb) {