added DataStorePutFunction implementation

updated  DataStorePutListener to also have an onDelete() method
This commit is contained in:
Grant Limberg 2015-04-24 19:28:44 -07:00
parent 53ebd5a9a5
commit dc00ce4f44
2 changed files with 64 additions and 7 deletions

View File

@ -217,14 +217,68 @@ namespace {
}
int DataStorePutFunction(ZT1_Node *node,void *userData,
const char *,const void *,unsigned long,int)
const char *objectName,
const void *buffer,
unsigned long bufferSize,
int secure)
{
JniRef *ref = (JniRef*)userData;
assert(ref->node == node);
JNIEnv *env = ref->env;
return 0;
static jclass dataStorePutClass = NULL;
static jmethodID callbackMethod = NULL;
static jmethodID deleteMethod = NULL;
if(dataStorePutClass == NULL)
{
dataStorePutClass = env->GetObjectClass(ref->dataStorePutListener);
if(dataStorePutClass == NULL)
{
return -1;
}
}
if(callbackMethod == NULL)
{
callbackMethod = env->GetMethodID(dataStorePutClass,
"onDataStorePut",
"(Ljava/lang/String;[BZ)I");
if(callbackMethod == NULL)
{
return -2;
}
}
if(deleteMethod == NULL)
{
deleteMethod = env->GetMethodID(dataStorePutClass,
"onDelete", "(Ljava/lang/String;)I");
if(deleteMethod == NULL)
{
return -3;
}
}
jstring nameStr = env->NewStringUTF(objectName);
if(buffer == NULL)
{
// delete operation
return env->CallIntMethod(dataStorePutClass, deleteMethod, nameStr);
}
else
{
// set operation
jbyteArray bufferObj = env->NewByteArray(bufferSize);
env->SetByteArrayRegion(bufferObj, 0, bufferSize, (jbyte*)buffer);
bool secure = secure != 0;
return env->CallIntMethod(dataStorePutClass, callbackMethod,
nameStr, bufferObj, secure);
}
}
int WirePacketSendFunction(ZT1_Node *node,void *userData,const struct sockaddr_storage *,unsigned int,const void *,unsigned int)
@ -234,6 +288,7 @@ namespace {
JNIEnv *env = ref->env;
return 0;
}

View File

@ -29,9 +29,11 @@ package com.zerotierone.sdk;
import java.nio.ByteBuffer;
public interface DataStorePutListener {
public int onDataStorePut(Node node,
String name,
ByteBuffer buffer,
long bufferSize,
boolean secure);
public int onDataStorePut(
String name,
byte[] buffer,
boolean secure);
public int onDelete(
String name);
}