This method constructs a new Domain class instance while increasing the reference count on the virDomainPtr in order to make sure the Domain object "owns" the given virDomainPtr. Signed-off-by: Claudio Bley <cbley@xxxxxxxxxx> --- src/main/java/org/libvirt/Domain.java | 14 ++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 39cb7c5..ec95f5f 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -201,6 +201,20 @@ public class Domain { } /** + * Constructs a new Domain object increasing the reference count + * on the DomainPointer. + * <p> + * This factory method is mostly useful with callback functions, + * since the virDomainPtr passed is only valid for the duration of + * execution of the callback. + */ + static Domain constructIncRef(Connect virConnect, DomainPointer VDP) throws LibvirtException { + processError(libvirt.virDomainRef(VDP)); + + return new Domain(virConnect, VDP); + } + + /** * Requests that the current background job be aborted at the soonest * opportunity. This will block until the job has either completed, or * aborted. diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 9eb9e86..ba8b073 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -31,7 +31,6 @@ import com.sun.jna.ptr.PointerByReference; * * LIBVIRT_0.6.0 * virConnectRef - * virDomainRef * virNetworkRef * virStoragePoolRef * virStorageVolRef @@ -258,6 +257,7 @@ public interface Libvirt extends Library { int virDomainMemoryStats(DomainPointer virDomainPtr, virDomainMemoryStats[] stats, int nr_stats, int flags); int virDomainPinVcpu(DomainPointer virDomainPtr, int vcpu, byte[] cpumap, int maplen); int virDomainReboot(DomainPointer virDomainPtr, int flags); + int virDomainRef(DomainPointer virDomainPtr); int virDomainRestore(ConnectionPointer virConnectPtr, String from); int virDomainRevertToSnapshot(DomainSnapshotPointer virDomainSnapshotPtr, int flags); int virDomainResume(DomainPointer virDomainPtr); -- 1.7.9.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list