add PeerRole.fromInt

This commit is contained in:
Brenton Bostick
2023-01-31 12:29:38 -05:00
parent 7c5f256d4a
commit 056cef7292
4 changed files with 36 additions and 29 deletions

View File

@ -126,24 +126,12 @@ jobject createEvent(JNIEnv *env, ZT_Event event)
jobject createPeerRole(JNIEnv *env, ZT_PeerRole role)
{
jobject peerRoleObject = NULL;
jfieldID field;
switch(role)
{
case ZT_PEER_ROLE_LEAF:
field = PeerRole_PEER_ROLE_LEAF_field;
break;
case ZT_PEER_ROLE_MOON:
field = PeerRole_PEER_ROLE_MOON_field;
break;
case ZT_PEER_ROLE_PLANET:
field = PeerRole_PEER_ROLE_PLANET_field;
break;
jobject peerRoleObject = env->CallStaticObjectMethod(PeerRole_class, PeerRole_fromInt_method, role);
if (env->ExceptionCheck() || peerRoleObject == NULL) {
LOGE("Error creating PeerRole object");
return NULL;
}
peerRoleObject = env->GetStaticObjectField(PeerRole_class, field);
return peerRoleObject;
}