Added implementation for Node.version()

Signed-off-by: Grant Limberg <glimberg@gmail.com>
This commit is contained in:
Grant Limberg 2015-04-22 21:29:45 -07:00
parent f5bb57d5aa
commit 3ccaef88b7
4 changed files with 94 additions and 7 deletions

View File

@ -639,6 +639,91 @@ JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_multicastUnsubscribe
return createResultObject(env, rc);
}
/*
* Class: com_zerotierone_sdk_Node
* Method: version
* Signature: (J)Lcom/zerotierone/sdk/Version;
*/
JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_version
(JNIEnv *env, jobject obj)
{
// create a com.zerotierone.sdk.Version object
jclass versionClass = env->FindClass("com.zerotierone.sdk.Version");
if(versionClass == NULL)
{
return NULL;
}
jmethodID versionConstructor = env->GetMethodID(
versionClass, "<init>", "()V");
if(versionConstructor == NULL)
{
return NULL;
}
jobject versionObj = env->NewObject(versionClass, versionConstructor);
if(versionObj == NULL)
{
return NULL;
}
int major = 0;
int minor = 0;
int revision = 0;
unsigned long featureFlags = 0;
ZT1_version(&major, &minor, &revision, &featureFlags);
// copy data to Version object
static jfieldID majorField = NULL;
static jfieldID minorField = NULL;
static jfieldID revisionField = NULL;
static jfieldID featureFlagsField = NULL;
if(majorField == NULL)
{
majorField = env->GetFieldID(versionClass, "major", "Lcom.zerotierone.sdk.Version");
if(majorField = NULL)
{
return NULL;
}
}
if(minorField == NULL)
{
minorField = env->GetFieldID(versionClass, "minor", "Lcom.zerotierone.sdk.Version");
if(minorField == NULL)
{
return NULL;
}
}
if(revisionField == NULL)
{
revisionField = env->GetFieldID(versionClass, "revision", "Lcom.zerotierone.sdk.Version");
if(revisionField == NULL)
{
return NULL;
}
}
if(featureFlagsField == NULL)
{
featureFlagsField = env->GetFieldID(versionClass, "featureFlags", "Lcom.zerotierone.sdk.Version");
if(featureFlagsField == NULL)
{
return NULL;
}
}
env->SetIntField(versionObj, majorField, (jint)major);
env->SetIntField(versionObj, minorField, (jint)minor);
env->SetIntField(versionObj, revisionField, (jint)revision);
env->SetLongField(versionObj, featureFlagsField, (jlong)featureFlags);
return versionObj;
}
#ifdef __cplusplus
} // extern "C"

View File

@ -109,7 +109,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_networkConfig
* Signature: (J)Lcom/zerotierone/sdk/Version;
*/
JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_version
(JNIEnv *, jobject, jlong);
(JNIEnv *, jobject);
#ifdef __cplusplus
}

View File

@ -222,11 +222,11 @@ public class Node {
// TODO: ZT1_Node_peers
private native VirtualNetworkConfig networkConfig(long nodeId);
private native VirtualNetworkConfig networkConfig(long nodeId, long nwid);
// TODO: ZT1_Node_networks
private native Version version(long nodeId);
private native Version version();
}

View File

@ -28,8 +28,10 @@
package com.zerotierone.sdk;
public class Version {
public int major;
public int minor;
public int revision;
public long featureFlags;
public Version() {}
public int major = 0;
public int minor = 0;
public int revision = 0;
public long featureFlags = 0;
}