diff options
author | Grant Limberg <glimberg@gmail.com> | 2015-04-22 21:31:17 -0700 |
---|---|---|
committer | Grant Limberg <glimberg@gmail.com> | 2015-04-22 21:31:17 -0700 |
commit | 32a35e6808b8c47e91843072bc4da24703421661 (patch) | |
tree | af8c0cc6bb9d32727809c566da13aa1dde6506ce /java/jni | |
parent | 34028aa7c87efbd3b0b5e9b67a39187c8070af0c (diff) | |
download | infinitytier-32a35e6808b8c47e91843072bc4da24703421661.tar.gz infinitytier-32a35e6808b8c47e91843072bc4da24703421661.zip |
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 <glimberg@gmail.com>
Diffstat (limited to 'java/jni')
-rw-r--r-- | java/jni/com_zerotierone_sdk_Node.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
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, "<init>", "()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, "<init>", "()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; */ |