mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-19 04:57:53 +00:00
add VirtualNetworkStatus.fromInt
This commit is contained in:
parent
ed3918b508
commit
85bd773c55
@ -107,6 +107,7 @@ jmethodID InetAddress_getByAddress_method;
|
||||
jmethodID PeerRole_fromInt_method;
|
||||
jmethodID ResultCode_fromInt_method;
|
||||
jmethodID VirtualNetworkConfigOperation_fromInt_method;
|
||||
jmethodID VirtualNetworkStatus_fromInt_method;
|
||||
|
||||
//
|
||||
// Instance fields
|
||||
@ -162,13 +163,6 @@ jfieldID VirtualNetworkRoute_via_field;
|
||||
// Static fields
|
||||
//
|
||||
|
||||
jfieldID VirtualNetworkStatus_NETWORK_STATUS_ACCESS_DENIED_field;
|
||||
jfieldID VirtualNetworkStatus_NETWORK_STATUS_AUTHENTICATION_REQUIRED_field;
|
||||
jfieldID VirtualNetworkStatus_NETWORK_STATUS_CLIENT_TOO_OLD_field;
|
||||
jfieldID VirtualNetworkStatus_NETWORK_STATUS_NOT_FOUND_field;
|
||||
jfieldID VirtualNetworkStatus_NETWORK_STATUS_OK_field;
|
||||
jfieldID VirtualNetworkStatus_NETWORK_STATUS_PORT_ERROR_field;
|
||||
jfieldID VirtualNetworkStatus_NETWORK_STATUS_REQUESTING_CONFIGURATION_field;
|
||||
jfieldID VirtualNetworkType_NETWORK_TYPE_PRIVATE_field;
|
||||
jfieldID VirtualNetworkType_NETWORK_TYPE_PUBLIC_field;
|
||||
|
||||
@ -252,6 +246,7 @@ void setupJNICache(JavaVM *vm) {
|
||||
EXCEPTIONANDNULLCHECK(PeerRole_fromInt_method = env->GetStaticMethodID(PeerRole_class, "fromInt", "(I)Lcom/zerotier/sdk/PeerRole;"));
|
||||
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;"));
|
||||
|
||||
//
|
||||
// Instance fields
|
||||
@ -307,13 +302,6 @@ void setupJNICache(JavaVM *vm) {
|
||||
// Static fields
|
||||
//
|
||||
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_ACCESS_DENIED_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_ACCESS_DENIED", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_AUTHENTICATION_REQUIRED_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_AUTHENTICATION_REQUIRED", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_CLIENT_TOO_OLD_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_CLIENT_TOO_OLD", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_NOT_FOUND_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_NOT_FOUND", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_OK_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_OK", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_PORT_ERROR_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_PORT_ERROR", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_REQUESTING_CONFIGURATION_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_REQUESTING_CONFIGURATION", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
|
||||
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;"));
|
||||
|
||||
|
@ -76,6 +76,7 @@ extern jmethodID InetAddress_getByAddress_method;
|
||||
extern jmethodID PeerRole_fromInt_method;
|
||||
extern jmethodID ResultCode_fromInt_method;
|
||||
extern jmethodID VirtualNetworkConfigOperation_fromInt_method;
|
||||
extern jmethodID VirtualNetworkStatus_fromInt_method;
|
||||
|
||||
//
|
||||
// Instance fields
|
||||
@ -131,13 +132,6 @@ extern jfieldID VirtualNetworkRoute_via_field;
|
||||
// Static fields
|
||||
//
|
||||
|
||||
extern jfieldID VirtualNetworkStatus_NETWORK_STATUS_ACCESS_DENIED_field;
|
||||
extern jfieldID VirtualNetworkStatus_NETWORK_STATUS_AUTHENTICATION_REQUIRED_field;
|
||||
extern jfieldID VirtualNetworkStatus_NETWORK_STATUS_CLIENT_TOO_OLD_field;
|
||||
extern jfieldID VirtualNetworkStatus_NETWORK_STATUS_NOT_FOUND_field;
|
||||
extern jfieldID VirtualNetworkStatus_NETWORK_STATUS_OK_field;
|
||||
extern jfieldID VirtualNetworkStatus_NETWORK_STATUS_PORT_ERROR_field;
|
||||
extern jfieldID VirtualNetworkStatus_NETWORK_STATUS_REQUESTING_CONFIGURATION_field;
|
||||
extern jfieldID VirtualNetworkType_NETWORK_TYPE_PRIVATE_field;
|
||||
extern jfieldID VirtualNetworkType_NETWORK_TYPE_PUBLIC_field;
|
||||
|
||||
|
@ -44,36 +44,12 @@ jobject createResultObject(JNIEnv *env, ZT_ResultCode code)
|
||||
|
||||
jobject createVirtualNetworkStatus(JNIEnv *env, ZT_VirtualNetworkStatus status)
|
||||
{
|
||||
jobject statusObject = NULL;
|
||||
|
||||
jfieldID field;
|
||||
switch(status)
|
||||
{
|
||||
case ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION:
|
||||
field = VirtualNetworkStatus_NETWORK_STATUS_REQUESTING_CONFIGURATION_field;
|
||||
break;
|
||||
case ZT_NETWORK_STATUS_OK:
|
||||
field = VirtualNetworkStatus_NETWORK_STATUS_OK_field;
|
||||
break;
|
||||
case ZT_NETWORK_STATUS_AUTHENTICATION_REQUIRED:
|
||||
field = VirtualNetworkStatus_NETWORK_STATUS_AUTHENTICATION_REQUIRED_field;
|
||||
break;
|
||||
case ZT_NETWORK_STATUS_ACCESS_DENIED:
|
||||
field = VirtualNetworkStatus_NETWORK_STATUS_ACCESS_DENIED_field;
|
||||
break;
|
||||
case ZT_NETWORK_STATUS_NOT_FOUND:
|
||||
field = VirtualNetworkStatus_NETWORK_STATUS_NOT_FOUND_field;
|
||||
break;
|
||||
case ZT_NETWORK_STATUS_PORT_ERROR:
|
||||
field = VirtualNetworkStatus_NETWORK_STATUS_PORT_ERROR_field;
|
||||
break;
|
||||
case ZT_NETWORK_STATUS_CLIENT_TOO_OLD:
|
||||
field = VirtualNetworkStatus_NETWORK_STATUS_CLIENT_TOO_OLD_field;
|
||||
break;
|
||||
jobject statusObject = env->CallStaticObjectMethod(VirtualNetworkStatus_class, VirtualNetworkStatus_fromInt_method, status);
|
||||
if (env->ExceptionCheck() || statusObject == NULL) {
|
||||
LOGE("Error creating VirtualNetworkStatus object");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
statusObject = env->GetStaticObjectField(VirtualNetworkStatus_class, field);
|
||||
|
||||
return statusObject;
|
||||
}
|
||||
|
||||
|
@ -27,40 +27,73 @@
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
/**
|
||||
* Virtual network status codes
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_VirtualNetworkStatus
|
||||
*/
|
||||
public enum VirtualNetworkStatus {
|
||||
|
||||
/**
|
||||
* Waiting for network configuration (also means revision == 0)
|
||||
*/
|
||||
NETWORK_STATUS_REQUESTING_CONFIGURATION,
|
||||
NETWORK_STATUS_REQUESTING_CONFIGURATION(0),
|
||||
|
||||
/**
|
||||
* Configuration received and we are authorized
|
||||
*/
|
||||
NETWORK_STATUS_OK,
|
||||
NETWORK_STATUS_OK(1),
|
||||
|
||||
/**
|
||||
* Netconf master said SSO auth required.
|
||||
*/
|
||||
NETWORK_STATUS_AUTHENTICATION_REQUIRED,
|
||||
NETWORK_STATUS_AUTHENTICATION_REQUIRED(2),
|
||||
|
||||
/**
|
||||
* Netconf master told us 'nope'
|
||||
*/
|
||||
NETWORK_STATUS_ACCESS_DENIED,
|
||||
NETWORK_STATUS_ACCESS_DENIED(3),
|
||||
|
||||
/**
|
||||
* Netconf master exists, but this virtual network does not
|
||||
*/
|
||||
NETWORK_STATUS_NOT_FOUND,
|
||||
NETWORK_STATUS_NOT_FOUND(4),
|
||||
|
||||
/**
|
||||
* Initialization of network failed or other internal error
|
||||
*/
|
||||
NETWORK_STATUS_PORT_ERROR,
|
||||
NETWORK_STATUS_PORT_ERROR(5),
|
||||
|
||||
/**
|
||||
* ZeroTier One version too old
|
||||
*/
|
||||
NETWORK_STATUS_CLIENT_TOO_OLD
|
||||
NETWORK_STATUS_CLIENT_TOO_OLD(6);
|
||||
|
||||
@SuppressWarnings({"FieldCanBeLocal", "unused"})
|
||||
private final int id;
|
||||
|
||||
VirtualNetworkStatus(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static VirtualNetworkStatus fromInt(int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
return NETWORK_STATUS_REQUESTING_CONFIGURATION;
|
||||
case 1:
|
||||
return NETWORK_STATUS_OK;
|
||||
case 2:
|
||||
return NETWORK_STATUS_AUTHENTICATION_REQUIRED;
|
||||
case 3:
|
||||
return NETWORK_STATUS_ACCESS_DENIED;
|
||||
case 4:
|
||||
return NETWORK_STATUS_NOT_FOUND;
|
||||
case 5:
|
||||
return NETWORK_STATUS_PORT_ERROR;
|
||||
case 6:
|
||||
return NETWORK_STATUS_CLIENT_TOO_OLD;
|
||||
default:
|
||||
throw new RuntimeException("Unhandled value: " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user