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

[libvirt] [libvirt-java] [PATCH 63/65] Replace Connect.getLibVirVersion method with Library.getVersion



It should not be necessary to create a Connect object in order to
determine the version of the libvirt library.

Introduce Library.getVersion which returns this information.

Deprecate Connect.getLibVirVersion but keep it for backwards compat.

Signed-off-by: Claudio Bley <cbley av-test de>
---
 src/main/java/org/libvirt/Connect.java            |    5 +++--
 src/main/java/org/libvirt/Library.java            |   15 ++++++++++++++-
 src/test/java/org/libvirt/TestJavaBindings.java   |    3 +--
 src/test/java/org/libvirt/TestLibvirtGlobals.java |    4 ++++
 4 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java
index 4ab61b3..72f60f1 100644
--- a/src/main/java/org/libvirt/Connect.java
+++ b/src/main/java/org/libvirt/Connect.java
@@ -1007,11 +1007,12 @@ public class Connect {
      *
      * @return major * 1,000,000 + minor * 1,000 + release
      * @throws LibvirtException
+     * @deprecated use { link Library#getVersion} instead
      */
+    @Deprecated
     public long getLibVirVersion() throws LibvirtException {
         LongByReference libVer = new LongByReference();
-        LongByReference typeVer = new LongByReference();
-        processError(libvirt.virGetVersion(libVer, null, typeVer));
+        processError(libvirt.virGetVersion(libVer, null, null));
         return libVer.getValue();
     }
 
diff --git a/src/main/java/org/libvirt/Library.java b/src/main/java/org/libvirt/Library.java
index 81df223..992e29d 100644
--- a/src/main/java/org/libvirt/Library.java
+++ b/src/main/java/org/libvirt/Library.java
@@ -5,6 +5,7 @@ import static org.libvirt.ErrorHandler.processError;
 
 import com.sun.jna.Native;
 import com.sun.jna.Pointer;
+import com.sun.jna.ptr.LongByReference;
 import com.sun.jna.ptr.PointerByReference;
 
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -18,7 +19,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
  * Additionally, this class contains internal methods to ease
  * implementing the public API.
  */
-final class Library {
+public final class Library {
     private static AtomicBoolean runLoop = new AtomicBoolean();
 
     final static Libvirt libvirt;
@@ -40,6 +41,18 @@ final class Library {
     private Library() {}
 
     /**
+     * Returns the version of the native libvirt library.
+     *
+     * @return major * 1,000,000 + minor * 1,000 + release
+     * @throws LibvirtException
+     */
+    public static long getVersion() throws LibvirtException {
+        LongByReference libVer = new LongByReference();
+        processError(libvirt.virGetVersion(libVer, null, null));
+        return libVer.getValue();
+    }
+
+    /**
      * Free memory pointed to by ptr.
      */
     static void free(Pointer ptr) {
diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java
index 24d850a..86a1f53 100644
--- a/src/test/java/org/libvirt/TestJavaBindings.java
+++ b/src/test/java/org/libvirt/TestJavaBindings.java
@@ -56,7 +56,6 @@ public final class TestJavaBindings extends TestCase {
         assertEquals("conn.getMaxVcpus(xen)", 32, conn.getMaxVcpus("xen"));
         assertNotNull("conn.getHostName()", conn.getHostName());
         assertNotNull("conn.getCapabilities()", conn.getCapabilities());
-        assertTrue("conn.getLibVirVersion()", conn.getLibVirVersion() > 6000);
         assertTrue("conn.connectionVersion()", Connect.connectionVersion(conn) > 6000);        
         assertEquals("conn.getVersion()", 2, conn.getVersion());
         assertTrue("conn.isAlive", conn.isAlive());
@@ -311,7 +310,7 @@ public final class TestJavaBindings extends TestCase {
     }
 
     public void testDomainScreenshot() throws Exception {
-        long version = conn.getLibVirVersion();
+        long version = Library.getVersion();
 
         // virDomainScreenshot works since version 1.0.5 on test://
         // connections
diff --git a/src/test/java/org/libvirt/TestLibvirtGlobals.java b/src/test/java/org/libvirt/TestLibvirtGlobals.java
index b2b0d9f..ab36fb9 100644
--- a/src/test/java/org/libvirt/TestLibvirtGlobals.java
+++ b/src/test/java/org/libvirt/TestLibvirtGlobals.java
@@ -18,4 +18,8 @@ public class TestLibvirtGlobals extends TestCase {
         }
         assertTrue("We should have caught an error", cb.error);
     }
+
+    public void testLibrary() throws Exception {
+        assertTrue("Library.getVersion() > 6000", Library.getVersion() > 6000);
+    }
 }
-- 
1.7.9.5


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