moved creation of VirtualNetworkConfig objects to ZT1_jniutils
added implementation of networks() method
This commit is contained in:
parent
6f07a476a6
commit
99af0f3a88
3 changed files with 259 additions and 211 deletions
|
@ -622,6 +622,227 @@ jobject newPeer(JNIEnv *env, const ZT1_Peer &peer)
|
|||
return peerObject;
|
||||
}
|
||||
|
||||
jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig)
|
||||
{
|
||||
static jclass vnetConfigClass = NULL;
|
||||
static jmethodID vnetConfig_constructor = NULL;
|
||||
static jfieldID nwidField = NULL;
|
||||
static jfieldID macField = NULL;
|
||||
static jfieldID nameField = NULL;
|
||||
static jfieldID statusField = NULL;
|
||||
static jfieldID typeField = NULL;
|
||||
static jfieldID mtuField = NULL;
|
||||
static jfieldID dhcpField = NULL;
|
||||
static jfieldID bridgeField = NULL;
|
||||
static jfieldID broadcastEnabledField = NULL;
|
||||
static jfieldID portErrorField = NULL;
|
||||
static jfieldID enabledField = NULL;
|
||||
static jfieldID netconfRevisionField = NULL;
|
||||
static jfieldID multicastSubscriptionsField = NULL;
|
||||
static jfieldID assignedAddressesField = NULL;
|
||||
|
||||
if(vnetConfigClass == NULL)
|
||||
{
|
||||
vnetConfigClass = env->FindClass("com/zerotierone/sdk/VirtualNetworkConfig");
|
||||
if(vnetConfigClass == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(vnetConfig_constructor == NULL)
|
||||
{
|
||||
jmethodID vnetConfig_constructor = env->GetMethodID(
|
||||
vnetConfigClass, "<init>", "()V");
|
||||
if(vnetConfig_constructor == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
jobject vnetConfigObj = env->NewObject(vnetConfigClass, vnetConfig_constructor);
|
||||
if(vnetConfigObj == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(nwidField == NULL)
|
||||
{
|
||||
nwidField = env->GetFieldID(vnetConfigClass, "nwid", "J");
|
||||
if(nwidField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(macField == NULL)
|
||||
{
|
||||
macField = env->GetFieldID(vnetConfigClass, "mac", "J");
|
||||
if(macField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(nameField == NULL)
|
||||
{
|
||||
nameField = env->GetFieldID(vnetConfigClass, "name", "Ljava/lang/String;");
|
||||
if(nameField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(statusField == NULL)
|
||||
{
|
||||
statusField = env->GetFieldID(vnetConfigClass, "status", "Lcom/zerotierone/sdk/VirtualNetworStatus;");
|
||||
if(statusField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(typeField == NULL)
|
||||
{
|
||||
typeField = env->GetFieldID(vnetConfigClass, "type", "Lcom/zerotierone/sdk/VirtualNetworkType;");
|
||||
if(typeField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(mtuField == NULL)
|
||||
{
|
||||
mtuField = env->GetFieldID(vnetConfigClass, "mtu", "I");
|
||||
if(mtuField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(dhcpField == NULL)
|
||||
{
|
||||
dhcpField = env->GetFieldID(vnetConfigClass, "dhcp", "Z");
|
||||
if(dhcpField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(bridgeField == NULL)
|
||||
{
|
||||
bridgeField = env->GetFieldID(vnetConfigClass, "bridge", "Z");
|
||||
if(bridgeField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(broadcastEnabledField == NULL)
|
||||
{
|
||||
broadcastEnabledField = env->GetFieldID(vnetConfigClass, "broadcastEnabled", "Z");
|
||||
if(broadcastEnabledField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(portErrorField == NULL)
|
||||
{
|
||||
portErrorField == env->GetFieldID(vnetConfigClass, "portError", "Z");
|
||||
if(portErrorField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(enabledField == NULL)
|
||||
{
|
||||
enabledField = env->GetFieldID(vnetConfigClass, "enabled", "Z");
|
||||
if(enabledField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(netconfRevisionField == NULL)
|
||||
{
|
||||
netconfRevisionField = env->GetFieldID(vnetConfigClass, "netconfRevision", "J");
|
||||
if(netconfRevisionField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(multicastSubscriptionsField == NULL)
|
||||
{
|
||||
multicastSubscriptionsField = env->GetFieldID(vnetConfigClass, "multicastSubscriptions", "Ljava/util/ArrayList;");
|
||||
if(multicastSubscriptionsField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(assignedAddressesField == NULL)
|
||||
{
|
||||
assignedAddressesField = env->GetFieldID(vnetConfigClass, "assignedAddresses", "Ljava/util/ArrayList;");
|
||||
if(assignedAddressesField == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
env->SetLongField(vnetConfigObj, nwidField, vnetConfig.nwid);
|
||||
env->SetLongField(vnetConfigObj, macField, vnetConfig.mac);
|
||||
jstring nameStr = env->NewStringUTF(vnetConfig.name);
|
||||
if(nameStr == NULL)
|
||||
{
|
||||
return NULL; // out of memory
|
||||
}
|
||||
env->SetObjectField(vnetConfigObj, nameField, nameStr);
|
||||
|
||||
jobject statusObject = createVirtualNetworkStatus(env, vnetConfig.status);
|
||||
if(statusObject == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
env->SetObjectField(vnetConfigObj, statusField, statusObject);
|
||||
|
||||
jobject typeObject = createVirtualNetworkType(env, vnetConfig.type);
|
||||
if(typeObject == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
env->SetObjectField(vnetConfigObj, typeField, typeObject);
|
||||
|
||||
env->SetIntField(vnetConfigObj, mtuField, vnetConfig.mtu);
|
||||
env->SetBooleanField(vnetConfigObj, dhcpField, vnetConfig.dhcp);
|
||||
env->SetBooleanField(vnetConfigObj, bridgeField, vnetConfig.bridge);
|
||||
env->SetBooleanField(vnetConfigObj, broadcastEnabledField, vnetConfig.broadcastEnabled);
|
||||
env->SetBooleanField(vnetConfigObj, portErrorField, vnetConfig.portError);
|
||||
|
||||
|
||||
jobject mcastSubsArrayObj = newArrayList(env);
|
||||
for(unsigned int i = 0; i < vnetConfig.multicastSubscriptionCount; ++i)
|
||||
{
|
||||
jobject mcastObj = newMulticastGroup(env, vnetConfig.multicastSubscriptions[i]);
|
||||
appendItemToArrayList(env, mcastSubsArrayObj, mcastObj);
|
||||
}
|
||||
env->SetObjectField(vnetConfigObj, multicastSubscriptionsField, mcastSubsArrayObj);
|
||||
|
||||
|
||||
jobject assignedAddrArrayObj = newArrayList(env);
|
||||
for(unsigned int i = 0; i < vnetConfig.assignedAddressCount; ++i)
|
||||
{
|
||||
jobject inetAddrObj = newInetAddress(env, vnetConfig.assignedAddresses[i]);
|
||||
appendItemToArrayList(env, assignedAddrArrayObj, inetAddrObj);
|
||||
}
|
||||
|
||||
env->SetObjectField(vnetConfigObj, assignedAddressesField, assignedAddrArrayObj);
|
||||
|
||||
return vnetConfigObj;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue