mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-20 17:52:46 +00:00
added DataStorePutFunction implementation
updated DataStorePutListener to also have an onDelete() method
This commit is contained in:
parent
53ebd5a9a5
commit
dc00ce4f44
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user