diff options
author | Grant Limberg <glimberg@gmail.com> | 2015-06-10 20:16:13 -0700 |
---|---|---|
committer | Grant Limberg <glimberg@gmail.com> | 2015-06-10 20:16:13 -0700 |
commit | 472206dfb23e8c2d285d5cdf19ba1444d07e4d52 (patch) | |
tree | 7f7fd95ec9f7100aee34eafa242eaf2c3883380c /java | |
parent | 7e84f5a7dbb50913a78311df4f748455be0e1097 (diff) | |
download | infinitytier-472206dfb23e8c2d285d5cdf19ba1444d07e4d52.tar.gz infinitytier-472206dfb23e8c2d285d5cdf19ba1444d07e4d52.zip |
Rename JniCache to JniLookup
Removed caching capabilities as the cached methods, fields, and objects appears to be broken on Android
Diffstat (limited to 'java')
-rw-r--r-- | java/CMakeLists.txt | 2 | ||||
-rw-r--r-- | java/jni/Android.mk | 2 | ||||
-rw-r--r-- | java/jni/ZT1_jnicache.cpp | 242 | ||||
-rw-r--r-- | java/jni/ZT1_jnilookup.cpp | 158 | ||||
-rw-r--r-- | java/jni/ZT1_jnilookup.h (renamed from java/jni/ZT1_jnicache.h) | 23 | ||||
-rw-r--r-- | java/jni/ZT1_jniutils.cpp | 132 | ||||
-rw-r--r-- | java/jni/com_zerotierone_sdk_Node.cpp | 68 |
7 files changed, 266 insertions, 361 deletions
diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt index db3eec1c..382fd3cd 100644 --- a/java/CMakeLists.txt +++ b/java/CMakeLists.txt @@ -54,7 +54,7 @@ set(src_files ../osdep/OSUtils.cpp jni/com_zerotierone_sdk_Node.cpp jni/ZT1_jniutils.cpp - jni/ZT1_jnicache.cpp + jni/ZT1_jnilookup.cpp ) set(include_dirs diff --git a/java/jni/Android.mk b/java/jni/Android.mk index bbf14348..9986c2c3 100644 --- a/java/jni/Android.mk +++ b/java/jni/Android.mk @@ -39,6 +39,6 @@ LOCAL_SRC_FILES := \ LOCAL_SRC_FILES += \ com_zerotierone_sdk_Node.cpp \ ZT1_jniutils.cpp \ - ZT1_jnicache.cpp + ZT1_jnilookup.cpp include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file diff --git a/java/jni/ZT1_jnicache.cpp b/java/jni/ZT1_jnicache.cpp deleted file mode 100644 index 4deec61f..00000000 --- a/java/jni/ZT1_jnicache.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/* - * ZeroTier One - Network Virtualization Everywhere - * Copyright (C) 2011-2015 ZeroTier, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * -- - * - * ZeroTier may be used and distributed under the terms of the GPLv3, which - * are available at: http://www.gnu.org/licenses/gpl-3.0.html - * - * If you would like to embed ZeroTier into a commercial application or - * redistribute it in a modified binary form, please contact ZeroTier Networks - * LLC. Start here: http://www.zerotier.com/ - */ - -#include "ZT1_jnicache.h" -#include "ZT1_jniutils.h" - -JniCache::JniCache() - : m_jvm(NULL) - , m_classes() - , m_fields() - , m_staticFields() - , m_methods() - , m_staticMethods() -{ - LOGV("JNI Cache Created"); -} - -JniCache::JniCache(JavaVM *jvm) - : m_jvm(jvm) - , m_classes() - , m_fields() - , m_staticFields() - , m_methods() - , m_staticMethods() -{ - LOGV("JNI Cache Created"); -} - -JniCache::~JniCache() -{ - LOGV("JNI Cache Destroyed"); - clearCache(); -} - -void JniCache::clearCache() -{ - if(m_jvm) - { - JNIEnv *env = NULL; - if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) - return; - - for(ClassMap::iterator iter = m_classes.begin(), end = m_classes.end(); - iter != end; ++iter) - { - env->DeleteGlobalRef(iter->second); - } - } - - m_classes.clear(); - m_fields.clear(); - m_staticFields.clear(); - m_methods.clear(); - m_staticMethods.clear(); -} - -void JniCache::setJavaVM(JavaVM *jvm) -{ - LOGV("Assigned JVM to object"); - m_jvm = jvm; -} - - -jclass JniCache::findClass(const std::string &name) -{ - if(!m_jvm) - return NULL; - - ClassMap::iterator found = m_classes.find(name); - - if(found == m_classes.end()) - { - // get the class from the JVM - JNIEnv *env = NULL; - if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) - { - LOGE("Error retreiving JNI Environment"); - return NULL; - } - - jclass localCls = env->FindClass(name.c_str()); - if(env->ExceptionCheck()) - { - LOGE("Error finding class: %s", name.c_str()); - return NULL; - } - - jclass cls = (jclass)env->NewGlobalRef(localCls); - - //m_classes.insert(std::make_pair(name, cls)); - - return cls; - } - - LOGV("Returning cached %s", name.c_str()); - return found->second; -} - - -jmethodID JniCache::findMethod(jclass cls, const std::string &methodName, const std::string &methodSig) -{ - if(!m_jvm) - return NULL; - - std::string id = methodName + methodSig; - - MethodMap::iterator found = m_methods.find(id); - if(found == m_methods.end()) - { - JNIEnv *env = NULL; - if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) - { - return NULL; - } - - jmethodID mid = env->GetMethodID(cls, methodName.c_str(), methodSig.c_str()); - if(env->ExceptionCheck()) - { - return NULL; - } - - //m_methods.insert(std::make_pair(id, mid)); - - return mid; - } - - return found->second; -} - -jmethodID JniCache::findStaticMethod(jclass cls, const std::string &methodName, const std::string &methodSig) -{ - if(!m_jvm) - return NULL; - - std::string id = methodName + methodSig; - - MethodMap::iterator found = m_staticMethods.find(id); - if(found == m_staticMethods.end()) - { - JNIEnv *env = NULL; - if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) - { - return NULL; - } - - jmethodID mid = env->GetStaticMethodID(cls, methodName.c_str(), methodSig.c_str()); - if(env->ExceptionCheck()) - { - return NULL; - } - - //m_staticMethods.insert(std::make_pair(id, mid)); - - return mid; - } - - return found->second; -} - -jfieldID JniCache::findField(jclass cls, const std::string &fieldName, const std::string &typeStr) -{ - if(!m_jvm) - return NULL; - - std::string id = fieldName + typeStr; - - FieldMap::iterator found = m_fields.find(id); - if(found == m_fields.end()) - { - JNIEnv *env = NULL; - if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) - { - return NULL; - } - - jfieldID fid = env->GetFieldID(cls, fieldName.c_str(), typeStr.c_str()); - if(env->ExceptionCheck()) - { - return NULL; - } - - //m_fields.insert(std::make_pair(id, fid)); - - return fid; - } - - return found->second; -} - -jfieldID JniCache::findStaticField(jclass cls, const std::string &fieldName, const std::string &typeStr) -{ - if(!m_jvm) - return NULL; - - std::string id = fieldName + typeStr; - - FieldMap::iterator found = m_staticFields.find(id); - if(found == m_staticFields.end()) - { - JNIEnv *env = NULL; - if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) - { - return NULL; - } - - jfieldID fid = env->GetStaticFieldID(cls, fieldName.c_str(), typeStr.c_str()); - if(env->ExceptionCheck()) - { - return NULL; - } - - //m_staticFields.insert(std::make_pair(id, fid)); - - return fid; - } - - return found->second; -}
\ No newline at end of file diff --git a/java/jni/ZT1_jnilookup.cpp b/java/jni/ZT1_jnilookup.cpp new file mode 100644 index 00000000..d8f5cc7f --- /dev/null +++ b/java/jni/ZT1_jnilookup.cpp @@ -0,0 +1,158 @@ +/* + * ZeroTier One - Network Virtualization Everywhere + * Copyright (C) 2011-2015 ZeroTier, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * -- + * + * ZeroTier may be used and distributed under the terms of the GPLv3, which + * are available at: http://www.gnu.org/licenses/gpl-3.0.html + * + * If you would like to embed ZeroTier into a commercial application or + * redistribute it in a modified binary form, please contact ZeroTier Networks + * LLC. Start here: http://www.zerotier.com/ + */ + +#include "ZT1_jnilookup.h" +#include "ZT1_jniutils.h" + +JniLookup::JniLookup() + : m_jvm(NULL) +{ + LOGV("JNI Cache Created"); +} + +JniLookup::JniLookup(JavaVM *jvm) + : m_jvm(jvm) +{ + LOGV("JNI Cache Created"); +} + +JniLookup::~JniLookup() +{ + LOGV("JNI Cache Destroyed"); +} + + +void JniLookup::setJavaVM(JavaVM *jvm) +{ + LOGV("Assigned JVM to object"); + m_jvm = jvm; +} + + +jclass JniLookup::findClass(const std::string &name) +{ + if(!m_jvm) + return NULL; + + // get the class from the JVM + JNIEnv *env = NULL; + if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) + { + LOGE("Error retreiving JNI Environment"); + return NULL; + } + + jclass cls = env->FindClass(name.c_str()); + if(env->ExceptionCheck()) + { + LOGE("Error finding class: %s", name.c_str()); + return NULL; + } + + return cls; +} + + +jmethodID JniLookup::findMethod(jclass cls, const std::string &methodName, const std::string &methodSig) +{ + if(!m_jvm) + return NULL; + + JNIEnv *env = NULL; + if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) + { + return NULL; + } + + jmethodID mid = env->GetMethodID(cls, methodName.c_str(), methodSig.c_str()); + if(env->ExceptionCheck()) + { + return NULL; + } + + return mid; +} + +jmethodID JniLookup::findStaticMethod(jclass cls, const std::string &methodName, const std::string &methodSig) +{ + if(!m_jvm) + return NULL; + + JNIEnv *env = NULL; + if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) + { + return NULL; + } + + jmethodID mid = env->GetStaticMethodID(cls, methodName.c_str(), methodSig.c_str()); + if(env->ExceptionCheck()) + { + return NULL; + } + + return mid; +} + +jfieldID JniLookup::findField(jclass cls, const std::string &fieldName, const std::string &typeStr) +{ + if(!m_jvm) + return NULL; + + JNIEnv *env = NULL; + if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) + { + return NULL; + } + + jfieldID fid = env->GetFieldID(cls, fieldName.c_str(), typeStr.c_str()); + if(env->ExceptionCheck()) + { + return NULL; + } + + return fid; +} + +jfieldID JniLookup::findStaticField(jclass cls, const std::string &fieldName, const std::string &typeStr) +{ + if(!m_jvm) + return NULL; + + JNIEnv *env = NULL; + if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) + { + return NULL; + } + + jfieldID fid = env->GetStaticFieldID(cls, fieldName.c_str(), typeStr.c_str()); + if(env->ExceptionCheck()) + { + return NULL; + } + + return fid; +}
\ No newline at end of file diff --git a/java/jni/ZT1_jnicache.h b/java/jni/ZT1_jnilookup.h index 43f43a08..cf496f88 100644 --- a/java/jni/ZT1_jnicache.h +++ b/java/jni/ZT1_jnilookup.h @@ -25,8 +25,8 @@ * LLC. Start here: http://www.zerotier.com/ */ -#ifndef ZT1_JNICACHE_H_ -#define ZT1_JNICACHE_H_ +#ifndef ZT1_JNILOOKUP_H_ +#define ZT1_JNILOOKUP_H_ #include <jni.h> #include <map> @@ -34,14 +34,13 @@ -class JniCache { +class JniLookup { public: - JniCache(); - JniCache(JavaVM *jvm); - ~JniCache(); + JniLookup(); + JniLookup(JavaVM *jvm); + ~JniLookup(); void setJavaVM(JavaVM *jvm); - void clearCache(); jclass findClass(const std::string &name); jmethodID findMethod(jclass cls, const std::string &methodName, const std::string &methodSig); @@ -49,17 +48,7 @@ public: jfieldID findField(jclass cls, const std::string &fieldName, const std::string &typeStr); jfieldID findStaticField(jclass cls, const std::string &fieldName, const std::string &typeStr); private: - typedef std::map<std::string, jmethodID> MethodMap; - typedef std::map<std::string, jfieldID> FieldMap; - typedef std::map<std::string, jclass> ClassMap; - JavaVM *m_jvm; - ClassMap m_classes; - FieldMap m_fields; - FieldMap m_staticFields; - MethodMap m_methods; - MethodMap m_staticMethods; - }; #endif
\ No newline at end of file diff --git a/java/jni/ZT1_jniutils.cpp b/java/jni/ZT1_jniutils.cpp index 1e8a48bf..ac04eb58 100644 --- a/java/jni/ZT1_jniutils.cpp +++ b/java/jni/ZT1_jniutils.cpp @@ -1,9 +1,9 @@ #include "ZT1_jniutils.h" -#include "ZT1_jnicache.h" +#include "ZT1_jnilookup.h" #include <string> #include <assert.h> -extern JniCache cache; +extern JniLookup lookup; #ifdef __cplusplus extern "C" { @@ -15,7 +15,7 @@ jobject createResultObject(JNIEnv *env, ZT1_ResultCode code) jobject resultObject = NULL; - resultClass = cache.findClass("com/zerotier/sdk/ResultCode"); + resultClass = lookup.findClass("com/zerotier/sdk/ResultCode"); if(resultClass == NULL) { LOGE("Couldnt find ResultCode class"); @@ -48,7 +48,7 @@ jobject createResultObject(JNIEnv *env, ZT1_ResultCode code) break; } - jfieldID enumField = cache.findStaticField(resultClass, fieldName.c_str(), "Lcom/zerotier/sdk/ResultCode;"); + jfieldID enumField = lookup.findStaticField(resultClass, fieldName.c_str(), "Lcom/zerotier/sdk/ResultCode;"); if(env->ExceptionCheck() || enumField == NULL) { LOGE("Error on FindStaticField"); @@ -68,7 +68,7 @@ jobject createVirtualNetworkStatus(JNIEnv *env, ZT1_VirtualNetworkStatus status) { jobject statusObject = NULL; - jclass statusClass = cache.findClass("com/zerotier/sdk/VirtualNetworkStatus"); + jclass statusClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkStatus"); if(statusClass == NULL) { return NULL; // exception thrown @@ -97,7 +97,7 @@ jobject createVirtualNetworkStatus(JNIEnv *env, ZT1_VirtualNetworkStatus status) break; } - jfieldID enumField = cache.findStaticField(statusClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkStatus;"); + jfieldID enumField = lookup.findStaticField(statusClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkStatus;"); statusObject = env->GetStaticObjectField(statusClass, enumField); @@ -109,7 +109,7 @@ jobject createEvent(JNIEnv *env, ZT1_Event event) jclass eventClass = NULL; jobject eventObject = NULL; - eventClass = cache.findClass("com/zerotier/sdk/Event"); + eventClass = lookup.findClass("com/zerotier/sdk/Event"); if(eventClass == NULL) { return NULL; @@ -147,7 +147,7 @@ jobject createEvent(JNIEnv *env, ZT1_Event event) break; } - jfieldID enumField = cache.findStaticField(eventClass, fieldName.c_str(), "Lcom/zerotier/sdk/Event;"); + jfieldID enumField = lookup.findStaticField(eventClass, fieldName.c_str(), "Lcom/zerotier/sdk/Event;"); eventObject = env->GetStaticObjectField(eventClass, enumField); @@ -159,7 +159,7 @@ jobject createPeerRole(JNIEnv *env, ZT1_PeerRole role) jclass peerRoleClass = NULL; jobject peerRoleObject = NULL; - peerRoleClass = cache.findClass("com/zerotier/sdk/PeerRole"); + peerRoleClass = lookup.findClass("com/zerotier/sdk/PeerRole"); if(peerRoleClass == NULL) { return NULL; @@ -179,7 +179,7 @@ jobject createPeerRole(JNIEnv *env, ZT1_PeerRole role) break; } - jfieldID enumField = cache.findStaticField(peerRoleClass, fieldName.c_str(), "Lcom/zerotier/sdk/PeerRole;"); + jfieldID enumField = lookup.findStaticField(peerRoleClass, fieldName.c_str(), "Lcom/zerotier/sdk/PeerRole;"); peerRoleObject = env->GetStaticObjectField(peerRoleClass, enumField); @@ -191,7 +191,7 @@ jobject createVirtualNetworkType(JNIEnv *env, ZT1_VirtualNetworkType type) jclass vntypeClass = NULL; jobject vntypeObject = NULL; - vntypeClass = cache.findClass("com/zerotier/sdk/VirtualNetworkType"); + vntypeClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkType"); if(env->ExceptionCheck() || vntypeClass == NULL) { return NULL; @@ -208,7 +208,7 @@ jobject createVirtualNetworkType(JNIEnv *env, ZT1_VirtualNetworkType type) break; } - jfieldID enumField = cache.findStaticField(vntypeClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkType;"); + jfieldID enumField = lookup.findStaticField(vntypeClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkType;"); vntypeObject = env->GetStaticObjectField(vntypeClass, enumField); return vntypeObject; } @@ -218,7 +218,7 @@ jobject createVirtualNetworkConfigOperation(JNIEnv *env, ZT1_VirtualNetworkConfi jclass vnetConfigOpClass = NULL; jobject vnetConfigOpObject = NULL; - vnetConfigOpClass = cache.findClass("com/zerotier/sdk/VirtualNetworkConfigOperation"); + vnetConfigOpClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkConfigOperation"); if(env->ExceptionCheck() || vnetConfigOpClass == NULL) { return NULL; @@ -241,7 +241,7 @@ jobject createVirtualNetworkConfigOperation(JNIEnv *env, ZT1_VirtualNetworkConfi break; } - jfieldID enumField = cache.findStaticField(vnetConfigOpClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkConfigOperation;"); + jfieldID enumField = lookup.findStaticField(vnetConfigOpClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkConfigOperation;"); vnetConfigOpObject = env->GetStaticObjectField(vnetConfigOpClass, enumField); return vnetConfigOpObject; } @@ -252,14 +252,14 @@ jobject newInetAddress(JNIEnv *env, const sockaddr_storage &addr) jclass inetAddressClass = NULL; jmethodID inetAddress_getByAddress = NULL; - inetAddressClass = cache.findClass("java/net/InetAddress"); + inetAddressClass = lookup.findClass("java/net/InetAddress"); if(env->ExceptionCheck() || inetAddressClass == NULL) { LOGE("Error finding InetAddress class"); return NULL; } - inetAddress_getByAddress = cache.findStaticMethod( + inetAddress_getByAddress = lookup.findStaticMethod( inetAddressClass, "getByAddress", "([B)Ljava/net/InetAddress;"); if(env->ExceptionCheck() || inetAddress_getByAddress == NULL) { @@ -315,7 +315,7 @@ jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr) jclass inetSocketAddressClass = NULL; jmethodID inetSocketAddress_constructor = NULL; - inetSocketAddressClass = cache.findClass("java/net/InetSocketAddress"); + inetSocketAddressClass = lookup.findClass("java/net/InetSocketAddress"); if(env->ExceptionCheck() || inetSocketAddressClass == NULL) { LOGE("Error finding InetSocketAddress Class"); @@ -330,7 +330,7 @@ jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr) return NULL; } - inetSocketAddress_constructor = cache.findMethod( + inetSocketAddress_constructor = lookup.findMethod( inetSocketAddressClass, "<init>", "(Ljava/net/InetAddress;I)V"); if(env->ExceptionCheck() || inetSocketAddress_constructor == NULL) { @@ -380,13 +380,13 @@ jobject newMulticastGroup(JNIEnv *env, const ZT1_MulticastGroup &mc) jfieldID macField = NULL; jfieldID adiField = NULL; - multicastGroupClass = cache.findClass("com/zerotier/sdk/MulticastGroup"); + multicastGroupClass = lookup.findClass("com/zerotier/sdk/MulticastGroup"); if(env->ExceptionCheck() || multicastGroupClass == NULL) { return NULL; } - multicastGroup_constructor = cache.findMethod( + multicastGroup_constructor = lookup.findMethod( multicastGroupClass, "<init>", "()V"); if(env->ExceptionCheck() || multicastGroup_constructor == NULL) { @@ -399,13 +399,13 @@ jobject newMulticastGroup(JNIEnv *env, const ZT1_MulticastGroup &mc) return NULL; } - macField = cache.findField(multicastGroupClass, "mac", "J"); + macField = lookup.findField(multicastGroupClass, "mac", "J"); if(env->ExceptionCheck() || macField == NULL) { return NULL; } - adiField = cache.findField(multicastGroupClass, "adi", "J"); + adiField = lookup.findField(multicastGroupClass, "adi", "J"); if(env->ExceptionCheck() || adiField == NULL) { return NULL; @@ -431,56 +431,56 @@ jobject newPeerPhysicalPath(JNIEnv *env, const ZT1_PeerPhysicalPath &ppp) jmethodID ppp_constructor = NULL; - pppClass = cache.findClass("com/zerotier/sdk/PeerPhysicalPath"); + pppClass = lookup.findClass("com/zerotier/sdk/PeerPhysicalPath"); if(env->ExceptionCheck() || pppClass == NULL) { LOGE("Error finding PeerPhysicalPath class"); return NULL; } - addressField = cache.findField(pppClass, "address", "Ljava/net/InetSocketAddress;"); + addressField = lookup.findField(pppClass, "address", "Ljava/net/InetSocketAddress;"); if(env->ExceptionCheck() || addressField == NULL) { LOGE("Error finding address field"); return NULL; } - lastSendField = cache.findField(pppClass, "lastSend", "J"); + lastSendField = lookup.findField(pppClass, "lastSend", "J"); if(env->ExceptionCheck() || lastSendField == NULL) { LOGE("Error finding lastSend field"); return NULL; } - lastReceiveField = cache.findField(pppClass, "lastReceive", "J"); + lastReceiveField = lookup.findField(pppClass, "lastReceive", "J"); if(env->ExceptionCheck() || lastReceiveField == NULL) { LOGE("Error finding lastReceive field"); return NULL; } - fixedField = cache.findField(pppClass, "fixed", "Z"); + fixedField = lookup.findField(pppClass, "fixed", "Z"); if(env->ExceptionCheck() || fixedField == NULL) { LOGE("Error finding fixed field"); return NULL; } - activeField = cache.findField(pppClass, "active", "Z"); + activeField = lookup.findField(pppClass, "active", "Z"); if(env->ExceptionCheck() || activeField == NULL) { LOGE("Error finding active field"); return NULL; } - preferredField = cache.findField(pppClass, "preferred", "Z"); + preferredField = lookup.findField(pppClass, "preferred", "Z"); if(env->ExceptionCheck() || preferredField == NULL) { LOGE("Error finding preferred field"); return NULL; } - ppp_constructor = cache.findMethod(pppClass, "<init>", "()V"); + ppp_constructor = lookup.findMethod(pppClass, "<init>", "()V"); if(env->ExceptionCheck() || ppp_constructor == NULL) { LOGE("Error finding PeerPhysicalPath constructor"); @@ -532,77 +532,77 @@ jobject newPeer(JNIEnv *env, const ZT1_Peer &peer) jmethodID peer_constructor = NULL; - peerClass = cache.findClass("com/zerotier/sdk/Peer"); + peerClass = lookup.findClass("com/zerotier/sdk/Peer"); if(env->ExceptionCheck() || peerClass == NULL) { LOGE("Error finding Peer class"); return NULL; } - addressField = cache.findField(peerClass, "address", "J"); + addressField = lookup.findField(peerClass, "address", "J"); if(env->ExceptionCheck() || addressField == NULL) { LOGE("Error finding address field of Peer object"); return NULL; } - lastUnicastFrameField = cache.findField(peerClass, "lastUnicastFrame", "J"); + lastUnicastFrameField = lookup.findField(peerClass, "lastUnicastFrame", "J"); if(env->ExceptionCheck() || lastUnicastFrameField == NULL) { LOGE("Error finding lastUnicastFrame field of Peer object"); return NULL; } - lastMulticastFrameField = cache.findField(peerClass, "lastMulticastFrame", "J"); + lastMulticastFrameField = lookup.findField(peerClass, "lastMulticastFrame", "J"); if(env->ExceptionCheck() || lastMulticastFrameField == NULL) { LOGE("Error finding lastMulticastFrame field of Peer object"); return NULL; } - versionMajorField = cache.findField(peerClass, "versionMajor", "I"); + versionMajorField = lookup.findField(peerClass, "versionMajor", "I"); if(env->ExceptionCheck() || versionMajorField == NULL) { LOGE("Error finding versionMajor field of Peer object"); return NULL; } - versionMinorField = cache.findField(peerClass, "versionMinor", "I"); + versionMinorField = lookup.findField(peerClass, "versionMinor", "I"); if(env->ExceptionCheck() || versionMinorField == NULL) { LOGE("Error finding versionMinor field of Peer object"); return NULL; } - versionRevField = cache.findField(peerClass, "versionRev", "I"); + versionRevField = lookup.findField(peerClass, "versionRev", "I"); if(env->ExceptionCheck() || versionRevField == NULL) { LOGE("Error finding versionRev field of Peer object"); return NULL; } - latencyField = cache.findField(peerClass, "latency", "I"); + latencyField = lookup.findField(peerClass, "latency", "I"); if(env->ExceptionCheck() || latencyField == NULL) { LOGE("Error finding latency field of Peer object"); return NULL; } - roleField = cache.findField(peerClass, "role", "Lcom/zerotier/sdk/PeerRole;"); + roleField = lookup.findField(peerClass, "role", "Lcom/zerotier/sdk/PeerRole;"); if(env->ExceptionCheck() || roleField == NULL) { LOGE("Error finding role field of Peer object"); return NULL; } - pathsField = cache.findField(peerClass, "paths", "[Lcom/zerotier/sdk/PeerPhysicalPath;"); + pathsField = lookup.findField(peerClass, "paths", "[Lcom/zerotier/sdk/PeerPhysicalPath;"); if(env->ExceptionCheck() || pathsField == NULL) { LOGE("Error finding paths field of Peer object"); return NULL; } - peer_constructor = cache.findMethod(peerClass, "<init>", "()V"); + peer_constructor = lookup.findMethod(peerClass, "<init>", "()V"); if(env->ExceptionCheck() || peer_constructor == NULL) { LOGE("Error finding Peer constructor"); @@ -625,7 +625,7 @@ jobject newPeer(JNIEnv *env, const ZT1_Peer &peer) env->SetIntField(peerObject, latencyField, peer.latency); env->SetObjectField(peerObject, roleField, createPeerRole(env, peer.role)); - jclass peerPhysicalPathClass = cache.findClass("com/zerotier/sdk/PeerPhysicalPath"); + jclass peerPhysicalPathClass = lookup.findClass("com/zerotier/sdk/PeerPhysicalPath"); if(env->ExceptionCheck() || peerPhysicalPathClass == NULL) { LOGE("Error finding PeerPhysicalPath class"); @@ -675,14 +675,14 @@ jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig jfieldID multicastSubscriptionsField = NULL; jfieldID assignedAddressesField = NULL; - vnetConfigClass = cache.findClass("com/zerotier/sdk/VirtualNetworkConfig"); + vnetConfigClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkConfig"); if(vnetConfigClass == NULL) { LOGE("Couldn't find com.zerotier.sdk.VirtualNetworkConfig"); return NULL; } - vnetConfig_constructor = cache.findMethod( + vnetConfig_constructor = lookup.findMethod( vnetConfigClass, "<init>", "()V"); if(env->ExceptionCheck() || vnetConfig_constructor == NULL) { @@ -697,98 +697,98 @@ jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig return NULL; } - nwidField = cache.findField(vnetConfigClass, "nwid", "J"); + nwidField = lookup.findField(vnetConfigClass, "nwid", "J"); if(env->ExceptionCheck() || nwidField == NULL) { LOGE("Error getting nwid field"); return NULL; } - macField = cache.findField(vnetConfigClass, "mac", "J"); + macField = lookup.findField(vnetConfigClass, "mac", "J"); if(env->ExceptionCheck() || macField == NULL) { LOGE("Error getting mac field"); return NULL; } - nameField = cache.findField(vnetConfigClass, "name", "Ljava/lang/String;"); + nameField = lookup.findField(vnetConfigClass, "name", "Ljava/lang/String;"); if(env->ExceptionCheck() || nameField == NULL) { LOGE("Error getting name field"); return NULL; } - statusField = cache.findField(vnetConfigClass, "status", "Lcom/zerotier/sdk/VirtualNetworkStatus;"); + statusField = lookup.findField(vnetConfigClass, "status", "Lcom/zerotier/sdk/VirtualNetworkStatus;"); if(env->ExceptionCheck() || statusField == NULL) { LOGE("Error getting status field"); return NULL; } - typeField = cache.findField(vnetConfigClass, "type", "Lcom/zerotier/sdk/VirtualNetworkType;"); + typeField = lookup.findField(vnetConfigClass, "type", "Lcom/zerotier/sdk/VirtualNetworkType;"); if(env->ExceptionCheck() || typeField == NULL) { LOGE("Error getting type field"); return NULL; } - mtuField = cache.findField(vnetConfigClass, "mtu", "I"); + mtuField = lookup.findField(vnetConfigClass, "mtu", "I"); if(env->ExceptionCheck() || mtuField == NULL) { LOGE("Error getting mtu field"); return NULL; } - dhcpField = cache.findField(vnetConfigClass, "dhcp", "Z"); + dhcpField = lookup.findField(vnetConfigClass, "dhcp", "Z"); if(env->ExceptionCheck() || dhcpField == NULL) { LOGE("Error getting dhcp field"); return NULL; } - bridgeField = cache.findField(vnetConfigClass, "bridge", "Z"); + bridgeField = lookup.findField(vnetConfigClass, "bridge", "Z"); if(env->ExceptionCheck() || bridgeField == NULL) { LOGE("Error getting bridge field"); return NULL; } - broadcastEnabledField = cache.findField(vnetConfigClass, "broadcastEnabled", "Z"); + broadcastEnabledField = lookup.findField(vnetConfigClass, "broadcastEnabled", "Z"); if(env->ExceptionCheck() || broadcastEnabledField == NULL) { LOGE("Error getting broadcastEnabled field"); return NULL; } - portErrorField = cache.findField(vnetConfigClass, "portError", "I"); + portErrorField = lookup.findField(vnetConfigClass, "portError", "I"); if(env->ExceptionCheck() || portErrorField == NULL) { LOGE("Error getting portError field"); return NULL; } - enabledField = cache.findField(vnetConfigClass, "enabled", "Z"); + enabledField = lookup.findField(vnetConfigClass, "enabled", "Z"); if(env->ExceptionCheck() || enabledField == NULL) { LOGE("Error getting enabled field"); return NULL; } - netconfRevisionField = cache.findField(vnetConfigClass, "netconfRevision", "J"); + netconfRevisionField = lookup.findField(vnetConfigClass, "netconfRevision", "J"); if(env->ExceptionCheck() || netconfRevisionField == NULL) { LOGE("Error getting netconfRevision field"); return NULL; } - multicastSubscriptionsField = cache.findField(vnetConfigClass, "multicastSubscriptions", "[Lcom/zerotier/sdk/MulticastGroup;"); + multicastSubscriptionsField = lookup.findField(vnetConfigClass, "multicastSubscriptions", "[Lcom/zerotier/sdk/MulticastGroup;"); if(env->ExceptionCheck() || multicastSubscriptionsField == NULL) { LOGE("Error getting multicastSubscriptions field"); return NULL; } - assignedAddressesField = cache.findField(vnetConfigClass, "assignedAddresses", "[Ljava/net/InetSocketAddress;"); + assignedAddressesField = lookup.findField(vnetConfigClass, "assignedAddresses", "[Ljava/net/InetSocketAddress;"); if(env->ExceptionCheck() || assignedAddressesField == NULL) { LOGE("Error getting assignedAddresses field"); @@ -825,7 +825,7 @@ jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig env->SetBooleanField(vnetConfigObj, enabledField, vnetConfig.enabled); env->SetIntField(vnetConfigObj, portErrorField, vnetConfig.portError); - jclass multicastGroupClass = cache.findClass("com/zerotier/sdk/MulticastGroup"); + jclass multicastGroupClass = lookup.findClass("com/zerotier/sdk/MulticastGroup"); if(env->ExceptionCheck() || multicastGroupClass == NULL) { LOGE("Error finding MulticastGroup class"); @@ -850,7 +850,7 @@ jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig } env->SetObjectField(vnetConfigObj, multicastSubscriptionsField, mcastSubsArrayObj); - jclass inetSocketAddressClass = cache.findClass("java/net/InetSocketAddress"); + jclass inetSocketAddressClass = lookup.findClass("java/net/InetSocketAddress"); if(env->ExceptionCheck() || inetSocketAddressClass == NULL) { LOGE("Error finding InetSocketAddress class"); @@ -887,13 +887,13 @@ jobject newVersion(JNIEnv *env, int major, int minor, int rev, long featureFlags jclass versionClass = NULL; jmethodID versionConstructor = NULL; - versionClass = cache.findClass("com/zerotier/sdk/Version"); + versionClass = lookup.findClass("com/zerotier/sdk/Version"); if(env->ExceptionCheck() || versionClass == NULL) { return NULL; } - versionConstructor = cache.findMethod( + versionConstructor = lookup.findMethod( versionClass, "<init>", "()V"); if(env->ExceptionCheck() || versionConstructor == NULL) { @@ -912,25 +912,25 @@ jobject newVersion(JNIEnv *env, int major, int minor, int rev, long featureFlags jfieldID revisionField = NULL; jfieldID featureFlagsField = NULL; - majorField = cache.findField(versionClass, "major", "I"); + majorField = lookup.findField(versionClass, "major", "I"); if(env->ExceptionCheck() || majorField == NULL) { return NULL; } - minorField = cache.findField(versionClass, "minor", "I"); + minorField = lookup.findField(versionClass, "minor", "I"); if(env->ExceptionCheck() || minorField == NULL) { return NULL; } - revisionField = cache.findField(versionClass, "revision", "I"); + revisionField = lookup.findField(versionClass, "revision", "I"); if(env->ExceptionCheck() || revisionField == NULL) { return NULL; } - featureFlagsField = cache.findField(versionClass, "featureFlags", "J"); + featureFlagsField = lookup.findField(versionClass, "featureFlags", "J"); if(env->ExceptionCheck() || featureFlagsField == NULL) { return NULL; diff --git a/java/jni/com_zerotierone_sdk_Node.cpp b/java/jni/com_zerotierone_sdk_Node.cpp index 9516db41..aa42c548 100644 --- a/java/jni/com_zerotierone_sdk_Node.cpp +++ b/java/jni/com_zerotierone_sdk_Node.cpp @@ -27,7 +27,7 @@ #include "com_zerotierone_sdk_Node.h" #include "ZT1_jniutils.h" -#include "ZT1_jnicache.h" +#include "ZT1_jnilookup.h" #include <ZeroTierOne.h> @@ -36,8 +36,8 @@ #include <assert.h> #include <string.h> -// global static JNI Cache Object -JniCache cache; +// global static JNI Lookup Object +JniLookup lookup; #ifdef __cplusplus extern "C" { @@ -104,7 +104,7 @@ namespace { return -1; } - jmethodID configListenerCallbackMethod = cache.findMethod(configListenerClass, + jmethodID configListenerCallbackMethod = lookup.findMethod(configListenerClass, "onNetworkConfigurationUpdated", "(JLcom/zerotier/sdk/VirtualNetworkConfigOperation;Lcom/zerotier/sdk/VirtualNetworkConfig;)I"); if(configListenerCallbackMethod == NULL) @@ -158,7 +158,7 @@ namespace { return; } - jmethodID frameListenerCallbackMethod = cache.findMethod( + jmethodID frameListenerCallbackMethod = lookup.findMethod( frameListenerClass, "onVirtualNetworkFrame", "(JJJJJ[B)V"); if(env->ExceptionCheck() || frameListenerCallbackMethod == NULL) @@ -204,7 +204,7 @@ namespace { return; } - jmethodID onEventMethod = cache.findMethod(eventListenerClass, + jmethodID onEventMethod = lookup.findMethod(eventListenerClass, "onEvent", "(Lcom/zerotier/sdk/Event;)V"); if(onEventMethod == NULL) { @@ -213,7 +213,7 @@ namespace { } - jmethodID onOutOfDateMethod = cache.findMethod(eventListenerClass, + jmethodID onOutOfDateMethod = lookup.findMethod(eventListenerClass, "onOutOfDate", "(Lcom/zerotier/sdk/Version;)V"); if(onOutOfDateMethod == NULL) { @@ -222,7 +222,7 @@ namespace { } - jmethodID onNetworkErrorMethod = cache.findMethod(eventListenerClass, + jmethodID onNetworkErrorMethod = lookup.findMethod(eventListenerClass, "onNetworkError", "(Lcom/zerotier/sdk/Event;Ljava/net/InetSocketAddress;)V"); if(onNetworkErrorMethod == NULL) { @@ -231,7 +231,7 @@ namespace { } - jmethodID onTraceMethod = cache.findMethod(eventListenerClass, + jmethodID onTraceMethod = lookup.findMethod(eventListenerClass, "onTrace", "(Ljava/lang/String;)V"); if(onTraceMethod == NULL) { @@ -316,7 +316,7 @@ namespace { return -2; } - jmethodID dataStoreGetCallbackMethod = cache.findMethod( + jmethodID dataStoreGetCallbackMethod = lookup.findMethod( dataStoreGetClass, "onDataStoreGet", "(Ljava/lang/String;[BJ[J)J"); @@ -388,7 +388,7 @@ namespace { return -1; } - jmethodID dataStorePutCallbackMethod = cache.findMethod( + jmethodID dataStorePutCallbackMethod = lookup.findMethod( dataStorePutClass, "onDataStorePut", "(Ljava/lang/String;[BZ)I"); @@ -398,7 +398,7 @@ namespace { return -2; } - jmethodID deleteMethod = cache.findMethod(dataStorePutClass, + jmethodID deleteMethod = lookup.findMethod(dataStorePutClass, "onDelete", "(Ljava/lang/String;)I"); if(deleteMethod == NULL) { @@ -453,7 +453,7 @@ namespace { return -1; } - jmethodID packetSenderCallbackMethod = cache.findMethod(packetSenderClass, + jmethodID packetSenderCallbackMethod = lookup.findMethod(packetSenderClass, "onSendPacketRequested", "(Ljava/net/InetSocketAddress;[B)I"); if(packetSenderCallbackMethod == NULL) { @@ -487,13 +487,13 @@ namespace { JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { - cache.setJavaVM(vm); + lookup.setJavaVM(vm); return JNI_VERSION_1_6; } JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) { - cache.clearCache(); + } @@ -514,7 +514,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init( env->GetJavaVM(&ref->jvm); jclass cls = env->GetObjectClass(obj); - jfieldID fid = cache.findField( + jfieldID fid = lookup.findField( cls, "getListener", "Lcom/zerotier/sdk/DataStoreGetListener;"); if(fid == NULL) @@ -529,7 +529,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init( } ref->dataStoreGetListener = env->NewGlobalRef(tmp); - fid = cache.findField( + fid = lookup.findField( cls, "putListener", "Lcom/zerotier/sdk/DataStorePutListener;"); if(fid == NULL) @@ -544,7 +544,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init( } ref->dataStorePutListener = env->NewGlobalRef(tmp); - fid = cache.findField( + fid = lookup.findField( cls, "sender", "Lcom/zerotier/sdk/PacketSender;"); if(fid == NULL) { @@ -558,7 +558,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init( } ref->packetSender = env->NewGlobalRef(tmp); - fid = cache.findField( + fid = lookup.findField( cls, "frameListener", "Lcom/zerotier/sdk/VirtualNetworkFrameListener;"); if(fid == NULL) { @@ -572,7 +572,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init( } ref->frameListener = env->NewGlobalRef(tmp); - fid = cache.findField( + fid = lookup.findField( cls, "configListener", "Lcom/zerotier/sdk/VirtualNetworkConfigListener;"); if(fid == NULL) { @@ -586,7 +586,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init( } ref->configListener = env->NewGlobalRef(tmp); - fid = cache.findField( + fid = lookup.findField( cls, "eventListener", "Lcom/zerotier/sdk/EventListener;"); if(fid == NULL) { @@ -758,7 +758,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket( uint64_t now = (uint64_t)in_now; // get the java.net.InetSocketAddress class and getAddress() method - jclass inetAddressClass = cache.findClass("java/net/InetAddress"); + jclass inetAddressClass = lookup.findClass("java/net/InetAddress"); if(inetAddressClass == NULL) { LOGE("Can't find InetAddress class"); @@ -766,7 +766,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket( return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL); } - jmethodID getAddressMethod = cache.findMethod( + jmethodID getAddressMethod = lookup.findMethod( inetAddressClass, "getAddress", "()[B"); if(getAddressMethod == NULL) { @@ -774,13 +774,13 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket( return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL); } - jclass InetSocketAddressClass = cache.findClass("java/net/InetSocketAddress"); + jclass InetSocketAddressClass = lookup.findClass("java/net/InetSocketAddress"); if(InetSocketAddressClass == NULL) { return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL); } - jmethodID inetSockGetAddressMethod = cache.findMethod( + jmethodID inetSockGetAddressMethod = lookup.findMethod( InetSocketAddressClass, "getAddress", "()Ljava/net/InetAddress;"); jobject addrObject = env->CallObjectMethod(in_remoteAddress, inetSockGetAddressMethod); @@ -790,7 +790,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket( return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL); } - jmethodID inetSock_getPort = cache.findMethod( + jmethodID inetSock_getPort = lookup.findMethod( InetSocketAddressClass, "getPort", "()I"); if(env->ExceptionCheck() || inetSock_getPort == NULL) @@ -1059,13 +1059,13 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_status jmethodID nodeStatusConstructor = NULL; // create a com.zerotier.sdk.NodeStatus object - nodeStatusClass = cache.findClass("com/zerotier/sdk/NodeStatus"); + nodeStatusClass = lookup.findClass("com/zerotier/sdk/NodeStatus"); if(nodeStatusClass == NULL) { return NULL; } - nodeStatusConstructor = cache.findMethod( + nodeStatusConstructor = lookup.findMethod( nodeStatusClass, "<init>", "()V"); if(nodeStatusConstructor == NULL) { @@ -1086,25 +1086,25 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_status jfieldID secretIdentityField = NULL; jfieldID onlineField = NULL; - addressField = cache.findField(nodeStatusClass, "address", "J"); + addressField = lookup.findField(nodeStatusClass, "address", "J"); if(addressField == NULL) { return NULL; } - publicIdentityField = cache.findField(nodeStatusClass, "publicIdentity", "Ljava/lang/String;"); + publicIdentityField = lookup.findField(nodeStatusClass, "publicIdentity", "Ljava/lang/String;"); if(publicIdentityField == NULL) { return NULL; } - secretIdentityField = cache.findField(nodeStatusClass, "secretIdentity", "Ljava/lang/String;"); + secretIdentityField = lookup.findField(nodeStatusClass, "secretIdentity", "Ljava/lang/String;"); if(secretIdentityField == NULL) { return NULL; } - onlineField = cache.findField(nodeStatusClass, "online", "Z"); + onlineField = lookup.findField(nodeStatusClass, "online", "Z"); if(onlineField == NULL) { return NULL; @@ -1207,7 +1207,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_zerotier_sdk_Node_peers( return NULL; } - jclass peerClass = cache.findClass("com/zerotier/sdk/Peer"); + jclass peerClass = lookup.findClass("com/zerotier/sdk/Peer"); if(env->ExceptionCheck() || peerClass == NULL) { LOGE("Error finding Peer class"); @@ -1265,7 +1265,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_zerotier_sdk_Node_networks( return NULL; } - jclass vnetConfigClass = cache.findClass("com/zerotier/sdk/VirtualNetworkConfig"); + jclass vnetConfigClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkConfig"); if(env->ExceptionCheck() || vnetConfigClass == NULL) { LOGE("Error finding VirtualNetworkConfig class"); |