Browse Source

make Version a plain data class

Brenton Bostick 2 years ago
parent
commit
6102c70855

+ 1 - 7
java/jni/ZT_jnicache.cpp

@@ -114,9 +114,6 @@ jmethodID VirtualNetworkType_fromInt_method;
 // Instance fields
 // Instance fields
 //
 //
 
 
-jfieldID Version_major_field;
-jfieldID Version_minor_field;
-jfieldID Version_revision_field;
 jfieldID VirtualNetworkConfig_assignedAddresses_field;
 jfieldID VirtualNetworkConfig_assignedAddresses_field;
 jfieldID VirtualNetworkConfig_bridge_field;
 jfieldID VirtualNetworkConfig_bridge_field;
 jfieldID VirtualNetworkConfig_broadcastEnabled_field;
 jfieldID VirtualNetworkConfig_broadcastEnabled_field;
@@ -202,7 +199,7 @@ void setupJNICache(JavaVM *vm) {
     EXCEPTIONANDNULLCHECK(PathChecker_onPathLookup_method = env->GetMethodID(PathChecker_class, "onPathLookup", "(JI)Ljava/net/InetSocketAddress;"));
     EXCEPTIONANDNULLCHECK(PathChecker_onPathLookup_method = env->GetMethodID(PathChecker_class, "onPathLookup", "(JI)Ljava/net/InetSocketAddress;"));
     EXCEPTIONANDNULLCHECK(PeerPhysicalPath_ctor = env->GetMethodID(PeerPhysicalPath_class, "<init>", "(Ljava/net/InetSocketAddress;JJZ)V"));
     EXCEPTIONANDNULLCHECK(PeerPhysicalPath_ctor = env->GetMethodID(PeerPhysicalPath_class, "<init>", "(Ljava/net/InetSocketAddress;JJZ)V"));
     EXCEPTIONANDNULLCHECK(Peer_ctor = env->GetMethodID(Peer_class, "<init>", "(JIIIILcom/zerotier/sdk/PeerRole;[Lcom/zerotier/sdk/PeerPhysicalPath;)V"));
     EXCEPTIONANDNULLCHECK(Peer_ctor = env->GetMethodID(Peer_class, "<init>", "(JIIIILcom/zerotier/sdk/PeerRole;[Lcom/zerotier/sdk/PeerPhysicalPath;)V"));
-    EXCEPTIONANDNULLCHECK(Version_ctor = env->GetMethodID(Version_class, "<init>", "()V"));
+    EXCEPTIONANDNULLCHECK(Version_ctor = env->GetMethodID(Version_class, "<init>", "(III)V"));
     EXCEPTIONANDNULLCHECK(VirtualNetworkConfigListener_onNetworkConfigurationUpdated_method = env->GetMethodID(VirtualNetworkConfigListener_class, "onNetworkConfigurationUpdated", "(JLcom/zerotier/sdk/VirtualNetworkConfigOperation;Lcom/zerotier/sdk/VirtualNetworkConfig;)I"));
     EXCEPTIONANDNULLCHECK(VirtualNetworkConfigListener_onNetworkConfigurationUpdated_method = env->GetMethodID(VirtualNetworkConfigListener_class, "onNetworkConfigurationUpdated", "(JLcom/zerotier/sdk/VirtualNetworkConfigOperation;Lcom/zerotier/sdk/VirtualNetworkConfig;)I"));
     EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_ctor = env->GetMethodID(VirtualNetworkConfig_class, "<init>", "()V"));
     EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_ctor = env->GetMethodID(VirtualNetworkConfig_class, "<init>", "()V"));
     EXCEPTIONANDNULLCHECK(VirtualNetworkDNS_ctor = env->GetMethodID(VirtualNetworkDNS_class, "<init>", "()V"));
     EXCEPTIONANDNULLCHECK(VirtualNetworkDNS_ctor = env->GetMethodID(VirtualNetworkDNS_class, "<init>", "()V"));
@@ -225,9 +222,6 @@ void setupJNICache(JavaVM *vm) {
     // Instance fields
     // Instance fields
     //
     //
 
 
-    EXCEPTIONANDNULLCHECK(Version_major_field = env->GetFieldID(Version_class, "major", "I"));
-    EXCEPTIONANDNULLCHECK(Version_minor_field = env->GetFieldID(Version_class, "minor", "I"));
-    EXCEPTIONANDNULLCHECK(Version_revision_field = env->GetFieldID(Version_class, "revision", "I"));
     EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_assignedAddresses_field = env->GetFieldID(VirtualNetworkConfig_class, "assignedAddresses", "[Ljava/net/InetSocketAddress;"));
     EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_assignedAddresses_field = env->GetFieldID(VirtualNetworkConfig_class, "assignedAddresses", "[Ljava/net/InetSocketAddress;"));
     EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_bridge_field = env->GetFieldID(VirtualNetworkConfig_class, "bridge", "Z"));
     EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_bridge_field = env->GetFieldID(VirtualNetworkConfig_class, "bridge", "Z"));
     EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_broadcastEnabled_field = env->GetFieldID(VirtualNetworkConfig_class, "broadcastEnabled", "Z"));
     EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_broadcastEnabled_field = env->GetFieldID(VirtualNetworkConfig_class, "broadcastEnabled", "Z"));

+ 0 - 3
java/jni/ZT_jnicache.h

@@ -83,9 +83,6 @@ extern jmethodID VirtualNetworkType_fromInt_method;
 // Instance fields
 // Instance fields
 //
 //
 
 
-extern jfieldID Version_major_field;
-extern jfieldID Version_minor_field;
-extern jfieldID Version_revision_field;
 extern jfieldID VirtualNetworkConfig_assignedAddresses_field;
 extern jfieldID VirtualNetworkConfig_assignedAddresses_field;
 extern jfieldID VirtualNetworkConfig_bridge_field;
 extern jfieldID VirtualNetworkConfig_bridge_field;
 extern jfieldID VirtualNetworkConfig_broadcastEnabled_field;
 extern jfieldID VirtualNetworkConfig_broadcastEnabled_field;

+ 2 - 5
java/jni/ZT_jniutils.cpp

@@ -312,16 +312,13 @@ jobject newNetworkConfig(JNIEnv *env, const ZT_VirtualNetworkConfig &vnetConfig)
 jobject newVersion(JNIEnv *env, int major, int minor, int rev)
 jobject newVersion(JNIEnv *env, int major, int minor, int rev)
 {
 {
     // create a com.zerotier.sdk.Version object
     // create a com.zerotier.sdk.Version object
-    jobject versionObj = env->NewObject(Version_class, Version_ctor);
+    jobject versionObj = env->NewObject(Version_class, Version_ctor, major, minor, rev);
     if(env->ExceptionCheck() || versionObj == NULL)
     if(env->ExceptionCheck() || versionObj == NULL)
     {
     {
+        LOGE("Error creating new Version object");
         return NULL;
         return NULL;
     }
     }
 
 
-    env->SetIntField(versionObj, Version_major_field, (jint)major);
-    env->SetIntField(versionObj, Version_minor_field, (jint)minor);
-    env->SetIntField(versionObj, Version_revision_field, (jint)rev);
-
     return versionObj;
     return versionObj;
 }
 }
 
 

+ 24 - 7
java/src/com/zerotier/sdk/Version.java

@@ -27,10 +27,27 @@
 
 
 package com.zerotier.sdk;
 package com.zerotier.sdk;
 
 
-public final class Version {
-    private Version() {}
-    
-	public int major = 0;
-	public int minor = 0;
-	public int revision = 0;
-}
+public class Version {
+
+    private final int major;
+    private final int minor;
+    private final int revision;
+
+    public Version(int major, int minor, int revision) {
+        this.major = major;
+        this.minor = minor;
+        this.revision = revision;
+    }
+
+    public int getMajor() {
+        return major;
+    }
+
+    public int getMinor() {
+        return minor;
+    }
+
+    public int getRevision() {
+        return revision;
+    }
+}