[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 1/2] Allow different types of callbacks (just as the C API).



From: Julian Stecklina <jsteckli os inf tu-dresden de>

---
 src/main/java/org/libvirt/Connect.java     |    3 ++-
 src/main/java/org/libvirt/jna/Libvirt.java |   22 ++++++++++++++++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java
index 7761c1f..dd52774 100644
--- a/src/main/java/org/libvirt/Connect.java
+++ b/src/main/java/org/libvirt/Connect.java
@@ -19,6 +19,7 @@ import org.libvirt.jna.virNodeInfo;
 import com.sun.jna.Memory;
 import com.sun.jna.NativeLong;
 import com.sun.jna.ptr.LongByReference;
+import com.sun.jna.Callback;
 
 /**
  * The Connect object represents a connection to a local or remote
@@ -409,7 +410,7 @@ public class Connect {
      *         identifier for the callback. -1 if an error
      * @throws LibvirtException
      */
-    public int domainEventRegisterAny(Domain domain, int eventId, Libvirt.VirConnectDomainEventGenericCallback cb)
+    public int domainEventRegisterAny(Domain domain, int eventId, Callback cb)
             throws LibvirtException {
         DomainPointer ptr = domain == null ? null : domain.VDP;
         int returnValue = libvirt.virConnectDomainEventRegisterAny(VCP, ptr, eventId, cb, null, null);
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java
index 2c8c03d..ec277c9 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -96,6 +96,14 @@ public interface Libvirt extends Library {
         public void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, Pointer opaque) ;
     }
     
+    interface VirConnectDomainEventCallback extends Callback {
+    	public void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, int event, int detail, Pointer opaque);
+    }
+
+    interface VirConnectDomainEventRTCChangeCallback extends Callback {
+    	public void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, long utcoffset, Pointer opaque);
+    }
+
     Libvirt INSTANCE = (Libvirt) Native.loadLibrary("virt", Libvirt.class);
 
     // Constants we need
@@ -108,7 +116,7 @@ public interface Libvirt extends Library {
     public int virConnCopyLastError(ConnectionPointer virConnectPtr, virError to);
     public int virConnectClose(ConnectionPointer virConnectPtr);
     public int virConnectCompareCPU(ConnectionPointer virConnectPtr, String xmlDesc, int flags);
-    public int virConnectDomainEventRegisterAny(ConnectionPointer virConnectPtr, DomainPointer virDomainPtr, int eventID, Libvirt.VirConnectDomainEventGenericCallback cb, Pointer opaque, Libvirt.VirFreeCallback freecb);
+    public int virConnectDomainEventRegisterAny(ConnectionPointer virConnectPtr, DomainPointer virDomainPtr, int eventID, Callback cb, Pointer opaque, Libvirt.VirFreeCallback freecb);
     public int virConnectDomainEventDeregisterAny(ConnectionPointer virConnectPtr, int callbackID) ;
     public void virConnSetErrorFunc(ConnectionPointer virConnectPtr, Pointer userData, VirErrorCallback callback);
     public int virConnectIsEncrypted(ConnectionPointer virConnectPtr) ;
@@ -157,7 +165,17 @@ public interface Libvirt extends Library {
     public int virCopyLastError(virError error);
     public virError virGetLastError();
     public void virResetLastError();
-    public void virSetErrorFunc(Pointer userData, VirErrorCallback callback);    
+    public void virSetErrorFunc(Pointer userData, VirErrorCallback callback);
+    
+    // Domain constants
+    static final int VIR_DOMAIN_EVENT_ID_LIFECYCLE = 0;       // virConnectDomainEventCallback
+    static final int VIR_DOMAIN_EVENT_ID_REBOOT    = 1;       // virConnectDomainEventGenericCallback
+    static final int VIR_DOMAIN_EVENT_ID_RTC_CHANGE = 2;      // virConnectDomainEventRTCChangeCallback
+    static final int VIR_DOMAIN_EVENT_ID_WATCHDOG = 3;        // virConnectDomainEventWatchdogCallback
+    static final int VIR_DOMAIN_EVENT_ID_IO_ERROR = 4;        // virConnectDomainEventIOErrorCallback
+    static final int VIR_DOMAIN_EVENT_ID_GRAPHICS = 5;        // virConnectDomainEventGraphicsCallback
+    static final int VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON = 6; // virConnectDomainEventIOErrorReasonCallback
+    static final int VIR_DOMAIN_EVENT_ID_CONTROL_ERROR = 7;   // virConnectDomainEventGenericCallback
 
     // Domain functions
     public int virDomainAbortJob(DomainPointer virDomainPtr);
-- 
1.7.3.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]