add VirtualNetworkType.fromInt

This commit is contained in:
Brenton Bostick 2023-01-31 13:15:19 -05:00
parent d1460ab65b
commit acf5b3579b
4 changed files with 32 additions and 35 deletions

View File

@ -108,6 +108,7 @@ jmethodID PeerRole_fromInt_method;
jmethodID ResultCode_fromInt_method;
jmethodID VirtualNetworkConfigOperation_fromInt_method;
jmethodID VirtualNetworkStatus_fromInt_method;
jmethodID VirtualNetworkType_fromInt_method;
//
// Instance fields
@ -159,13 +160,6 @@ jfieldID VirtualNetworkRoute_metric_field;
jfieldID VirtualNetworkRoute_target_field;
jfieldID VirtualNetworkRoute_via_field;
//
// Static fields
//
jfieldID VirtualNetworkType_NETWORK_TYPE_PRIVATE_field;
jfieldID VirtualNetworkType_NETWORK_TYPE_PUBLIC_field;
//
// Enums
//
@ -247,6 +241,7 @@ void setupJNICache(JavaVM *vm) {
EXCEPTIONANDNULLCHECK(ResultCode_fromInt_method = env->GetStaticMethodID(ResultCode_class, "fromInt", "(I)Lcom/zerotier/sdk/ResultCode;"));
EXCEPTIONANDNULLCHECK(VirtualNetworkConfigOperation_fromInt_method = env->GetStaticMethodID(VirtualNetworkConfigOperation_class, "fromInt", "(I)Lcom/zerotier/sdk/VirtualNetworkConfigOperation;"));
EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_fromInt_method = env->GetStaticMethodID(VirtualNetworkStatus_class, "fromInt", "(I)Lcom/zerotier/sdk/VirtualNetworkStatus;"));
EXCEPTIONANDNULLCHECK(VirtualNetworkType_fromInt_method = env->GetStaticMethodID(VirtualNetworkType_class, "fromInt", "(I)Lcom/zerotier/sdk/VirtualNetworkType;"));
//
// Instance fields
@ -298,13 +293,6 @@ void setupJNICache(JavaVM *vm) {
EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_target_field = env->GetFieldID(VirtualNetworkRoute_class, "target", "Ljava/net/InetSocketAddress;"));
EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_via_field = env->GetFieldID(VirtualNetworkRoute_class, "via", "Ljava/net/InetSocketAddress;"));
//
// Static fields
//
EXCEPTIONANDNULLCHECK(VirtualNetworkType_NETWORK_TYPE_PRIVATE_field = env->GetStaticFieldID(VirtualNetworkType_class, "NETWORK_TYPE_PRIVATE", "Lcom/zerotier/sdk/VirtualNetworkType;"));
EXCEPTIONANDNULLCHECK(VirtualNetworkType_NETWORK_TYPE_PUBLIC_field = env->GetStaticFieldID(VirtualNetworkType_class, "NETWORK_TYPE_PUBLIC", "Lcom/zerotier/sdk/VirtualNetworkType;"));
//
// Enums
//

View File

@ -77,6 +77,7 @@ extern jmethodID PeerRole_fromInt_method;
extern jmethodID ResultCode_fromInt_method;
extern jmethodID VirtualNetworkConfigOperation_fromInt_method;
extern jmethodID VirtualNetworkStatus_fromInt_method;
extern jmethodID VirtualNetworkType_fromInt_method;
//
// Instance fields
@ -128,13 +129,6 @@ extern jfieldID VirtualNetworkRoute_metric_field;
extern jfieldID VirtualNetworkRoute_target_field;
extern jfieldID VirtualNetworkRoute_via_field;
//
// Static fields
//
extern jfieldID VirtualNetworkType_NETWORK_TYPE_PRIVATE_field;
extern jfieldID VirtualNetworkType_NETWORK_TYPE_PUBLIC_field;
//
// Enums
//

View File

@ -77,20 +77,12 @@ jobject createPeerRole(JNIEnv *env, ZT_PeerRole role)
jobject createVirtualNetworkType(JNIEnv *env, ZT_VirtualNetworkType type)
{
jobject vntypeObject = NULL;
jfieldID field;
switch(type)
{
case ZT_NETWORK_TYPE_PRIVATE:
field = VirtualNetworkType_NETWORK_TYPE_PRIVATE_field;
break;
case ZT_NETWORK_TYPE_PUBLIC:
field = VirtualNetworkType_NETWORK_TYPE_PUBLIC_field;
break;
jobject vntypeObject = env->CallStaticObjectMethod(VirtualNetworkType_class, VirtualNetworkType_fromInt_method, type);
if (env->ExceptionCheck() || vntypeObject == NULL) {
LOGE("Error creating VirtualNetworkType object");
return NULL;
}
vntypeObject = env->GetStaticObjectField(VirtualNetworkType_class, field);
return vntypeObject;
}

View File

@ -27,15 +27,38 @@
package com.zerotier.sdk;
/**
* Virtual network type codes
*
* Defined in ZeroTierOne.h as ZT_VirtualNetworkType
*/
public enum VirtualNetworkType {
/**
* Private networks are authorized via certificates of membership
*/
NETWORK_TYPE_PRIVATE,
NETWORK_TYPE_PRIVATE(0),
/**
* Public networks have no access control -- they'll always be AUTHORIZED
*/
NETWORK_TYPE_PUBLIC
NETWORK_TYPE_PUBLIC(1);
@SuppressWarnings({"FieldCanBeLocal", "unused"})
private final int id;
VirtualNetworkType(int id) {
this.id = id;
}
public static VirtualNetworkType fromInt(int id) {
switch (id) {
case 0:
return NETWORK_TYPE_PRIVATE;
case 1:
return NETWORK_TYPE_PUBLIC;
default:
throw new RuntimeException("Unhandled value: " + id);
}
}
}