From 32a35e6808b8c47e91843072bc4da24703421661 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Wed, 22 Apr 2015 21:31:17 -0700 Subject: scaffolding for implementation of status() and networkConfig() They should be able to be called, but will not return valid objects yet Signed-off-by: Grant Limberg --- java/jni/com_zerotierone_sdk_Node.cpp | 100 ++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'java/jni') diff --git a/java/jni/com_zerotierone_sdk_Node.cpp b/java/jni/com_zerotierone_sdk_Node.cpp index 0ba15e73..4ec72aa8 100644 --- a/java/jni/com_zerotierone_sdk_Node.cpp +++ b/java/jni/com_zerotierone_sdk_Node.cpp @@ -659,6 +659,106 @@ JNIEXPORT jlong JNICALL Java_com_zerotierone_sdk_Node_address return (jlong)address; } +/* + * Class: com_zerotierone_sdk_Node + * Method: status + * Signature: (J)Lcom/zerotierone/sdk/NodeStatus; + */ +JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_status + (JNIEnv *env, jobject obj, jlong id) +{ + uint64_t nodeId = (uint64_t) id; + ZT1_Node *node = findNode(nodeId); + if(node == NULL) + { + // cannot find valid node. We should never get here. + return 0; + } + + // static so we only have to look these up once + static jclass nodeStatusClass = NULL; + static jmethodID nodeStatusConstructor = NULL; + + // create a com.zerotierone.sdk.NodeStatus object + if(nodeStatusClass == NULL) + { + nodeStatusClass = env->FindClass("com.zerotierone.sdk.NodeStatus"); + if(nodeStatusClass == NULL) + { + return NULL; + } + } + + if(nodeStatusConstructor == NULL) + { + nodeStatusConstructor = env->GetMethodID( + nodeStatusClass, "", "()V"); + if(nodeStatusConstructor == NULL) + { + return NULL; + } + } + + jobject nodeStatusObj = env->NewObject(nodeStatusClass, nodeStatusConstructor); + if(nodeStatusObj == NULL) + { + return NULL; + } + + ZT1_NodeStatus nodeStatus; + ZT1_Node_status(node, &nodeStatus); + + // TODO: copy data from C to Java + + return nodeStatusObj; +} + +/* + * Class: com_zerotierone_sdk_Node + * Method: networkConfig + * Signature: (J)Lcom/zerotierone/sdk/VirtualNetworkConfig; + */ +JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_networkConfig + (JNIEnv *env, jobject obj, jlong id, jlong nwid) +{ + uint64_t nodeId = (uint64_t) id; + ZT1_Node *node = findNode(nodeId); + if(node == NULL) + { + // cannot find valid node. We should never get here. + return 0; + } + + // create a com.zerotierone.sdk.VirtualNetworkConfig object + jclass vnetConfigClass = env->FindClass("com.zerotierone.sdk.VirtualNetworkConfig"); + if(vnetConfigClass == NULL) + { + return NULL; + } + + jmethodID vnetConfigConstructor = env->GetMethodID( + vnetConfigClass, "", "()V"); + if(vnetConfigConstructor == NULL) + { + return NULL; + } + + jobject vnetConfigObj = env->NewObject(vnetConfigClass, vnetConfigConstructor); + if(vnetConfigObj == NULL) + { + return NULL; + } + + ZT1_VirtualNetworkConfig *vnetConfig = ZT1_Node_networkConfig(node, nwid); + + // TODO: copy data from C to Java + + + return NULL; +} + +/* + * Class: com_zerotierone_sdk_Node * Method: version * Signature: (J)Lcom/zerotierone/sdk/Version; */ -- cgit v1.2.3