Signed-off-by: Claudio Bley <cbley@xxxxxxxxxx> --- src/main/java/org/libvirt/Connect.java | 59 ++++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 20 +++++++ .../java/org/libvirt/event/PMSuspendListener.java | 17 ++++++ .../java/org/libvirt/event/PMSuspendReason.java | 5 ++ 4 files changed, 101 insertions(+) create mode 100644 src/main/java/org/libvirt/event/PMSuspendListener.java create mode 100644 src/main/java/org/libvirt/event/PMSuspendReason.java diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index d18a996..10fc2e8 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -553,6 +553,65 @@ public class Connect { domainEventRegister(domain, DomainEventID.PMWAKEUP, virCB, cb); } + void domainEventRegister(Domain domain, final PMSuspendListener cb) throws LibvirtException { + if (cb == null) + throw new IllegalArgumentException("PMSuspendCallback 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.onPMSuspend(d, getConstant(PMSuspendReason.class, reason)); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error in PMSuspend callback", e); + } + } + }; + + domainEventRegister(domain, DomainEventID.PMSUSPEND, virCB, cb); + } + + /** + * Adds the specified listener to receive PMSuspend events for + * domains of this connection. + * + * @param l the PMSuspend listener + * @throws LibvirtException on failure + * + * @see #removePMSuspendListener + * @see Domain#addPMSuspendListener + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegisterAny" + * >virConnectDomainEventRegisterAny</a> + * + * @since 1.5.2 + */ + public void addPMSuspendListener(final PMSuspendListener l) throws LibvirtException { + domainEventRegister(null, l); + } + + /** + * Removes the specified PMSuspend listener so that it no longer + * receives PMSuspend events. + * + * @param l the PMSuspend listener + * @throws LibvirtException + * + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventDeregisterAny" + * >virConnectDomainEventDeregisterAny</a> + * + * @since 1.5.2 + */ + public void removePMSuspendListener(final PMSuspendListener l) throws LibvirtException { + domainEventDeregister(DomainEventID.PMWAKEUP, l); + } + /** * Adds the specified listener to receive PMWakeup events for * domains of this connection. diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 6dda2a6..f3fffdd 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -16,6 +16,7 @@ import org.libvirt.jna.virVcpuInfo; import org.libvirt.event.RebootListener; import org.libvirt.event.LifecycleListener; import org.libvirt.event.PMWakeupListener; +import org.libvirt.event.PMSuspendListener; import static org.libvirt.Library.libvirt; import static org.libvirt.ErrorHandler.processError; import static org.libvirt.ErrorHandler.processErrorIfZero; @@ -1102,6 +1103,25 @@ public class Domain { } /** + * Adds the specified listener to receive PMSuspend events for this domain. + * + * @param l the PMSuspend listener + * @throws LibvirtException on failure + * + * @see Connect#removePMSuspendListener + * @see Connect#addPMSuspendListener + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegisterAny" + * >virConnectDomainEventRegisterAny</a> + * + * @since 1.5.2 + */ + public void addPMSuspendListener(final PMSuspendListener 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/PMSuspendListener.java b/src/main/java/org/libvirt/event/PMSuspendListener.java new file mode 100644 index 0000000..ec111e1 --- /dev/null +++ b/src/main/java/org/libvirt/event/PMSuspendListener.java @@ -0,0 +1,17 @@ +package org.libvirt.event; + +import org.libvirt.Domain; + +/** + * Interface for receiving PMSuspend events on a domain. + */ +public interface PMSuspendListener extends EventListener { + + /** + * This method gets called when a domain is suspended. + * + * @param domain the domain that was suspended + * @param reason the reason why that event happened + */ + void onPMSuspend(Domain domain, PMSuspendReason reason); +} diff --git a/src/main/java/org/libvirt/event/PMSuspendReason.java b/src/main/java/org/libvirt/event/PMSuspendReason.java new file mode 100644 index 0000000..58f06a1 --- /dev/null +++ b/src/main/java/org/libvirt/event/PMSuspendReason.java @@ -0,0 +1,5 @@ +package org.libvirt.event; + +public enum PMSuspendReason { + UNKNOWN +} -- 1.7.9.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list