-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qemu: support arbitrary monitor events
Wrap the new virConnectDomainQemuMonitorEventRegister function added in libvirt 1.2.3. This patch copies heavily from network events (commit 6ea5be0) and from event loop callbacks in libvirt-override.c, since in the libvirt_qemu module, we must expose top-level functions rather than class members. * generator.py (qemu_skip_function): Don't generate event code. (qemuBuildWrappers): Delay manual portion until after imports. * libvirt-qemu-override.py (qemuMonitorEventRegister) (qemuMonitorEventDeregister): New file. * libvirt-qemu-override.c (libvirt_qemu_virConnectDomainQemuMonitorEventFreeFunc) (libvirt_qemu_virConnectDomainQemuMonitorEventCallback) (libvirt_qemu_virConnectDomainQemuMonitorEventRegister) (libvirt_qemu_virConnectDomainQemuMonitorEventDeregister) (libvirt_qemu_lookupPythonFunc, getLibvirtQemuDictObject) (getLibvirtQemuModuleObject): New functions. Signed-off-by: Eric Blake <eblake@redhat.com>
- Loading branch information
Showing
3 changed files
with
269 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Manually written part of python bindings for libvirt-qemu | ||
|
||
def _dispatchQemuMonitorEventCallback(conn, dom, event, seconds, micros, details, cbData): | ||
"""Dispatches events to python user qemu monitor event callbacks | ||
""" | ||
cb = cbData["cb"] | ||
opaque = cbData["opaque"] | ||
|
||
cb(conn, libvirt.virDomain(conn, _obj=dom), event, seconds, micros, details, opaque) | ||
return 0 | ||
|
||
def qemuMonitorEventDeregister(conn, callbackID): | ||
"""Removes a qemu monitor event callback. De-registering for a callback | ||
will disable delivery of this event type""" | ||
try: | ||
ret = libvirtmod_qemu.virConnectDomainQemuMonitorEventDeregister(conn._o, callbackID) | ||
if ret == -1: raise libvirt.libvirtError ('virConnectDomainQemuMonitorEventDeregister() failed') | ||
del conn.qemuMonitorEventCallbackID[callbackID] | ||
except AttributeError: | ||
pass | ||
|
||
def qemuMonitorEventRegister(conn, dom, event, cb, opaque, flags=0): | ||
"""Adds a qemu monitor event callback. Registering for a monitor | ||
callback will enable delivery of the events""" | ||
if not hasattr(conn, 'qemuMonitorEventCallbackID'): | ||
conn.qemuMonitorEventCallbackID = {} | ||
cbData = { "cb": cb, "conn": conn, "opaque": opaque } | ||
if dom is None: | ||
ret = libvirtmod_qemu.virConnectDomainQemuMonitorEventRegister(conn._o, None, event, cbData, flags) | ||
else: | ||
ret = libvirtmod_qemu.virConnectDomainQemuMonitorEventRegister(conn._o, dom._o, event, cbData, flags) | ||
if ret == -1: | ||
raise libvirt.libvirtError ('virConnectDomainQemuMonitorEventRegister() failed') | ||
conn.qemuMonitorEventCallbackID[ret] = opaque | ||
return ret |