Signed-off-by: Claudio Bley <cbley@xxxxxxxxxx> --- src/main/java/org/libvirt/Connect.java | 41 ++++++++++++++++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 17 +++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index 50a9524..99ac207 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -93,6 +93,12 @@ public class Connect { void onPMWakeup(Connect connect, Domain domain, int reason); } + + public interface PMSuspendCallback { + final int eventID = DomainEventID.PMSUSPEND; + + void onPMSuspend(Connect connect, Domain domain, int reason); + } } /** @@ -549,6 +555,41 @@ public class Connect { return domainEventRegister(domain, cb.eventID, virCB); } + int domainEventRegister(Domain domain, final DomainEvent.PMSuspendCallback 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, com.sun.jna.Pointer opaque) { + assert(VCP.equals(virConnectPtr)); + Domain d = new Domain(Connect.this, virDomainPointer); + cb.onPMSuspend(Connect.this, d, reason); + } + }; + + return domainEventRegister(domain, cb.eventID, virCB); + } + + /** + * Adds a callback to receive notifications of PMSuspend events + * occurring on some domain. + * + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegisterAny">Libvirt + * Documentation</a> + * @param cb + * the PMSuspendCallback instance + * @return The return value from this method is a positive integer identifier for the callback. + * @throws LibvirtException on failure + */ + public int domainEventRegister(final DomainEvent.PMSuspendCallback cb) throws LibvirtException + { + return domainEventRegister(null, cb); + } + /** * Adds a callback to receive notifications of PMWakeup events * occurring on some domain. diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 30184ad..87ba31c 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -933,6 +933,23 @@ public class Domain { } /** + * Adds a callback to receive notifications of PMSuspend events + * occurring on this domain. + * + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegisterAny">Libvirt + * Documentation</a> + * @param cb + * the PMSuspendCallback instance + * @return The return value from this method is a positive integer identifier for the callback. + * @throws LibvirtException on failure + */ + public int domainEventRegister(final Connect.DomainEvent.PMSuspendCallback cb) throws LibvirtException + { + return virConnect.domainEventRegister(this, cb); + } + + /** * Revert the domain to a given snapshot. * * @see <a href= -- 1.7.9.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list