Signed-off-by: Claudio Bley <cbley@xxxxxxxxxx> --- src/main/java/org/libvirt/Connect.java | 57 ++++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 20 +++++++ .../java/org/libvirt/event/PMWakeupListener.java | 17 ++++++ .../java/org/libvirt/event/PMWakeupReason.java | 5 ++ src/main/java/org/libvirt/jna/Libvirt.java | 6 +++ 5 files changed, 105 insertions(+) create mode 100644 src/main/java/org/libvirt/event/PMWakeupListener.java create mode 100644 src/main/java/org/libvirt/event/PMWakeupReason.java diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index d82dba2..d18a996 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -530,6 +530,63 @@ public class Connect { domainEventRegister(null, l); } + void domainEventRegister(Domain domain, final PMWakeupListener cb) throws LibvirtException { + if (cb == null) + throw new IllegalArgumentException("PMWakeupCallback cannot be null"); + + Libvirt.VirDomainEventCallback virCB = + new Libvirt.VirConnectDomainEventPMChangeCallback() { + @Override + public void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, + int reason, Pointer opaque) { + assert VCP.equals(virConnectPtr); + + try { + Domain d = Domain.constructIncRef(Connect.this, virDomainPointer); + cb.onPMWakeup(d, getConstant(PMWakeupReason.class, reason)); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error handling PMWakeup callback", e); + } + } + }; + + domainEventRegister(domain, DomainEventID.PMWAKEUP, virCB, cb); + } + + /** + * Adds the specified listener to receive PMWakeup events for + * domains of this connection. + * + * @param l the PMWakeup listener + * @throws LibvirtException on failure + * + * @see #removePMWakeupListener + * @see Domain#addPMWakeupListener + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegisterAny" + * >virConnectDomainEventRegisterAny</a> + * + * @since 1.5.2 + */ + public void addPMWakeupListener(final PMWakeupListener l) throws LibvirtException { + domainEventRegister(null, l); + } + + /** + * Removes the specified PMWakeup listener so that it no longer + * receives PMWakeup events. + * + * @param l the PMWakeup listener + * @throws LibvirtException + * + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventDeregisterAny" + * >virConnectDomainEventDeregisterAny</a> + */ + public void removePMWakeupListener(final PMWakeupListener l) throws LibvirtException { + domainEventDeregister(DomainEventID.PMWAKEUP, l); + } + /** * Removes the specified I/O error listener so that it no longer * receives I/O error events. diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index fb59781..6dda2a6 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -15,6 +15,7 @@ import org.libvirt.jna.virSchedParameter; import org.libvirt.jna.virVcpuInfo; import org.libvirt.event.RebootListener; import org.libvirt.event.LifecycleListener; +import org.libvirt.event.PMWakeupListener; import static org.libvirt.Library.libvirt; import static org.libvirt.ErrorHandler.processError; import static org.libvirt.ErrorHandler.processErrorIfZero; @@ -1082,6 +1083,25 @@ public class Domain { } /** + * Adds the specified listener to receive PMWakeup events for this domain. + * + * @param l the PMWakeup listener + * @throws LibvirtException on failure + * + * @see Connect#removePMWakeupListener + * @see Connect#addPMWakeupListener + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegisterAny" + * >virConnectDomainEventRegisterAny</a> + * + * @since 1.5.2 + */ + public void addPMWakeupListener(final PMWakeupListener l) throws LibvirtException + { + virConnect.domainEventRegister(this, l); + } + + /** * Revert the domain to a given snapshot. * * @see <a href= diff --git a/src/main/java/org/libvirt/event/PMWakeupListener.java b/src/main/java/org/libvirt/event/PMWakeupListener.java new file mode 100644 index 0000000..50d69ef --- /dev/null +++ b/src/main/java/org/libvirt/event/PMWakeupListener.java @@ -0,0 +1,17 @@ +package org.libvirt.event; + +import org.libvirt.Domain; + +/** + * Interface for receiving PMWakeup events on a domain. + */ +public interface PMWakeupListener extends EventListener { + + /** + * This method gets called when a domain is woken up. + * + * @param domain the domain that was woken up + * @param reason the reason why that event happened + */ + void onPMWakeup(Domain domain, PMWakeupReason reason); +} diff --git a/src/main/java/org/libvirt/event/PMWakeupReason.java b/src/main/java/org/libvirt/event/PMWakeupReason.java new file mode 100644 index 0000000..12c37bf --- /dev/null +++ b/src/main/java/org/libvirt/event/PMWakeupReason.java @@ -0,0 +1,5 @@ +package org.libvirt.event; + +public enum PMWakeupReason { + UNKNOWN +} diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 5bb9fa0..1eaeab8 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -96,6 +96,12 @@ public interface Libvirt extends Library { Pointer opaque); } + // PMWakeup and PMSuspend have the same callback interface. + interface VirConnectDomainEventPMChangeCallback extends VirDomainEventCallback { + void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, + int reason, Pointer opaque); + } + /** * Error callback */ -- 1.7.9.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list