--- libvirt-override-virConnect.py | 10 ++++++++ libvirt-override.c | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py index 87c5483..fb3d476 100644 --- a/libvirt-override-virConnect.py +++ b/libvirt-override-virConnect.py @@ -357,6 +357,16 @@ cb(self, virNodeDevice(self, _obj=dev), event, detail, opaque) return 0 + def _dispatchNodeDeviceEventGenericCallback(self, dev, cbData): + """Dispatches events to python user node device + generic event callbacks + """ + cb = cbData["cb"] + opaque = cbData["opaque"] + + cb(self, virNodeDevice(self, _obj=dev), opaque) + return 0 + def nodeDeviceEventDeregisterAny(self, callbackID): """Removes a Node Device Event Callback. De-registering for a node device callback will disable delivery of this event type""" diff --git a/libvirt-override.c b/libvirt-override.c index f6590e4..07d1d19 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -9067,6 +9067,56 @@ libvirt_virConnectNodeDeviceEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_ return ret; } +static int +libvirt_virConnectNodeDeviceEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED, + virNodeDevicePtr dev, + void *opaque) +{ + PyObject *pyobj_cbData = (PyObject*)opaque; + PyObject *pyobj_dev; + PyObject *pyobj_ret = NULL; + PyObject *pyobj_conn; + PyObject *dictKey; + int ret = -1; + + LIBVIRT_ENSURE_THREAD_STATE; + + if (!(dictKey = libvirt_constcharPtrWrap("conn"))) + goto cleanup; + pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey); + Py_DECREF(dictKey); + + /* Create a python instance of this virNodeDevicePtr */ + virNodeDeviceRef(dev); + if (!(pyobj_dev = libvirt_virNodeDevicePtrWrap(dev))) { + virNodeDeviceFree(dev); + goto cleanup; + } + Py_INCREF(pyobj_cbData); + + /* Call the Callback Dispatcher */ + pyobj_ret = PyObject_CallMethod(pyobj_conn, + (char*)"_dispatchNodeDeviceEventGenericCallback", + (char*)"OO", + pyobj_dev, + pyobj_cbData); + + Py_DECREF(pyobj_cbData); + Py_DECREF(pyobj_dev); + + cleanup: + 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_virConnectNodeDeviceEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -9098,6 +9148,10 @@ libvirt_virConnectNodeDeviceEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED, cb = VIR_NODE_DEVICE_EVENT_CALLBACK(libvirt_virConnectNodeDeviceEventLifecycleCallback); break; + case VIR_NODE_DEVICE_EVENT_ID_UPDATE: + cb = VIR_NODE_DEVICE_EVENT_CALLBACK(libvirt_virConnectNodeDeviceEventGenericCallback); + break; + case VIR_NODE_DEVICE_EVENT_ID_LAST: break; } -- 2.7.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list