mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-22 06:17:48 +00:00
implement VirtualNetworkConfigFunctionCallback
This commit is contained in:
parent
99af0f3a88
commit
28168fa673
@ -215,11 +215,47 @@ jobject createVirtualNetworkType(JNIEnv *env, ZT1_VirtualNetworkType type)
|
||||
break;
|
||||
}
|
||||
|
||||
jfieldID enumField = env->GetStaticFieldID(vntypeClass, fieldName.c_str(), "Lcom/zerotierone/sdk/VirtyalNetworkType;");
|
||||
jfieldID enumField = env->GetStaticFieldID(vntypeClass, fieldName.c_str(), "Lcom/zerotierone/sdk/VirtualNetworkType;");
|
||||
vntypeObject = env->GetStaticObjectField(vntypeClass, enumField);
|
||||
return vntypeObject;
|
||||
}
|
||||
|
||||
jobject createVirtualNetworkConfigOperation(JNIEnv *env, ZT1_VirtualNetworkConfigOperation op)
|
||||
{
|
||||
static jclass vnetConfigOpClass = NULL;
|
||||
jobject vnetConfigOpObject = NULL;
|
||||
|
||||
if(vnetConfigOpClass == NULL)
|
||||
{
|
||||
vnetConfigOpClass = env->FindClass("com/zerotierone/sdk/VirtualNetworkConfigOperation");
|
||||
if(vnetConfigOpClass == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
std::string fieldName;
|
||||
switch(op)
|
||||
{
|
||||
case ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_UP:
|
||||
fieldName = "VIRTUAL_NETWORK_CONFIG_OPERATION_UP";
|
||||
break;
|
||||
case ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE:
|
||||
fieldName = "VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE";
|
||||
break;
|
||||
case ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN:
|
||||
fieldName = "VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN";
|
||||
break;
|
||||
case ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY:
|
||||
fieldName = "VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY";
|
||||
break;
|
||||
}
|
||||
|
||||
jfieldID enumField = env->GetStaticFieldID(vnetConfigOpClass, fieldName.c_str(), "Lcom/zerotierone/sdk/VirtualNetworkConfigOperation;");
|
||||
vnetConfigOpObject = env->GetStaticObjectField(vnetConfigOpClass, enumField);
|
||||
return vnetConfigOpObject;
|
||||
}
|
||||
|
||||
jobject newArrayList(JNIEnv *env)
|
||||
{
|
||||
if(arrayListClass == NULL)
|
||||
@ -843,6 +879,7 @@ jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig
|
||||
return vnetConfigObj;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -12,6 +12,7 @@ jobject createVirtualNetworkStatus(JNIEnv *env, ZT1_VirtualNetworkStatus status)
|
||||
jobject createVirtualNetworkType(JNIEnv *env, ZT1_VirtualNetworkType type);
|
||||
jobject createEvent(JNIEnv *env, ZT1_Event event);
|
||||
jobject createPeerRole(JNIEnv *env, ZT1_PeerRole role);
|
||||
jobject createVirtualNetworkConfigOperation(JNIEnv *env, ZT1_VirtualNetworkConfigOperation op);
|
||||
|
||||
jobject newArrayList(JNIEnv *env);
|
||||
bool appendItemToArrayList(JNIEnv *env, jobject array, jobject object);
|
||||
|
@ -65,14 +65,49 @@ namespace {
|
||||
};
|
||||
|
||||
|
||||
int VirtualNetworkConfigFunctionCallback(ZT1_Node *node,void *userData,uint64_t,enum ZT1_VirtualNetworkConfigOperation,const ZT1_VirtualNetworkConfig *)
|
||||
int VirtualNetworkConfigFunctionCallback(ZT1_Node *node,void *userData,uint64_t nwid,enum ZT1_VirtualNetworkConfigOperation operation, const ZT1_VirtualNetworkConfig *config)
|
||||
{
|
||||
JniRef *ref = (JniRef*)userData;
|
||||
assert(ref->node == node);
|
||||
|
||||
JNIEnv *env = ref->env;
|
||||
|
||||
return 0;
|
||||
static jclass configListenerClass = NULL;
|
||||
static jmethodID callbackMethod = NULL;
|
||||
|
||||
if(configListenerClass == NULL)
|
||||
{
|
||||
configListenerClass = env->GetObjectClass(ref->configListener);
|
||||
if(configListenerClass == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(callbackMethod == NULL)
|
||||
{
|
||||
callbackMethod = env->GetMethodID(configListenerClass,
|
||||
"onNetworkConfigurationUpdated",
|
||||
"(JLcom/zerotierone/sdk/VirtualNetworkConfigOperation;Lcom/zerotierone/sdk/VirtualNetworkConfig;)I");
|
||||
if(callbackMethod == NULL)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
jobject operationObject = createVirtualNetworkConfigOperation(env, operation);
|
||||
if(operationObject == NULL)
|
||||
{
|
||||
return -3;
|
||||
}
|
||||
|
||||
jobject networkConfigObject = newNetworkConfig(env, *config);
|
||||
if(networkConfigObject == NULL)
|
||||
{
|
||||
return -4;
|
||||
}
|
||||
|
||||
return env->CallIntMethod(ref->configListener, callbackMethod, (jlong)nwid, operationObject, networkConfigObject);
|
||||
}
|
||||
|
||||
void VirtualNetworkFrameFunctionCallback(ZT1_Node *node,void *userData,uint64_t,uint64_t,uint64_t,unsigned int,unsigned int,const void *,unsigned int)
|
||||
|
@ -30,9 +30,8 @@ package com.zerotierone.sdk;
|
||||
|
||||
|
||||
public interface VirtualNetworkConfigListener {
|
||||
public void onNetworkConfigurationUpdated(
|
||||
Node node,
|
||||
long someValue,
|
||||
public int onNetworkConfigurationUpdated(
|
||||
long nwid,
|
||||
VirtualNetworkConfigOperation op,
|
||||
VirtualNetworkConfig config);
|
||||
}
|
Loading…
Reference in New Issue
Block a user