mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
added DataStorePutFunction implementation
updated DataStorePutListener to also have an onDelete() method
This commit is contained in:
parent
53ebd5a9a5
commit
dc00ce4f44
2 changed files with 64 additions and 7 deletions
|
@ -217,14 +217,68 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
int DataStorePutFunction(ZT1_Node *node,void *userData,
|
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;
|
JniRef *ref = (JniRef*)userData;
|
||||||
assert(ref->node == node);
|
assert(ref->node == node);
|
||||||
|
|
||||||
JNIEnv *env = ref->env;
|
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)
|
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;
|
JNIEnv *env = ref->env;
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,11 @@ package com.zerotierone.sdk;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public interface DataStorePutListener {
|
public interface DataStorePutListener {
|
||||||
public int onDataStorePut(Node node,
|
public int onDataStorePut(
|
||||||
String name,
|
String name,
|
||||||
ByteBuffer buffer,
|
byte[] buffer,
|
||||||
long bufferSize,
|
boolean secure);
|
||||||
boolean secure);
|
|
||||||
|
public int onDelete(
|
||||||
|
String name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue