diff options
author | Grant Limberg <glimberg@gmail.com> | 2015-04-24 18:49:52 -0700 |
---|---|---|
committer | Grant Limberg <glimberg@gmail.com> | 2015-04-24 18:49:52 -0700 |
commit | 4137246653461ef80a531fd6adfc8def8c7e0eda (patch) | |
tree | 46856e0a7864d884c596450bb753661da542f9e1 /java/jni/com_zerotierone_sdk_Node.cpp | |
parent | 28168fa673c359270089439179aa09107a882902 (diff) | |
download | infinitytier-4137246653461ef80a531fd6adfc8def8c7e0eda.tar.gz infinitytier-4137246653461ef80a531fd6adfc8def8c7e0eda.zip |
implemented VirtualNetworkFrameFunctionCallback
Diffstat (limited to 'java/jni/com_zerotierone_sdk_Node.cpp')
-rw-r--r-- | java/jni/com_zerotierone_sdk_Node.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/java/jni/com_zerotierone_sdk_Node.cpp b/java/jni/com_zerotierone_sdk_Node.cpp index fe8c8c3e..81af5e3f 100644 --- a/java/jni/com_zerotierone_sdk_Node.cpp +++ b/java/jni/com_zerotierone_sdk_Node.cpp @@ -65,7 +65,12 @@ namespace { }; - int VirtualNetworkConfigFunctionCallback(ZT1_Node *node,void *userData,uint64_t nwid,enum ZT1_VirtualNetworkConfigOperation operation, const ZT1_VirtualNetworkConfig *config) + 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); @@ -110,14 +115,49 @@ namespace { 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) + void VirtualNetworkFrameFunctionCallback(ZT1_Node *node,void *userData, + uint64_t nwid, + uint64_t sourceMac, + uint64_t destMac, + unsigned int etherType, + unsigned int vlanid, + const void *frameData, + unsigned int frameLength) { JniRef *ref = (JniRef*)userData; assert(ref->node == node); JNIEnv *env = ref->env; + + static jclass frameListenerClass = NULL; + static jmethodID callbackMethod = NULL; + + if(frameListenerClass == NULL) + { + frameListenerClass = env->GetObjectClass(ref->frameListener); + if(frameListenerClass == NULL) + { + return; + } + } + + if(callbackMethod == NULL) + { + callbackMethod = env->GetMethodID(frameListenerClass, + "onVirtualNetworkFrame", "(JJJJJ[B)V"); + if(callbackMethod == NULL) + { + return; + } + } + + jbyteArray dataArray = env->NewByteArray(frameLength); + env->SetByteArrayRegion(dataArray, 0, frameLength, (jbyte*)frameData); + + env->CallVoidMethod(ref->frameListener, callbackMethod, nwid, sourceMac, destMac, etherType, vlanid, dataArray); } + void EventCallback(ZT1_Node *node,void *userData,enum ZT1_Event,const void *) { JniRef *ref = (JniRef*)userData; |