2019-10-08 14:52:01 +00:00
|
|
|
#include "network_loki_lokinet_LokinetConfig.h"
|
|
|
|
#include <llarp.hpp>
|
|
|
|
#include "lokinet_jni_common.hpp"
|
|
|
|
|
2019-10-09 12:42:05 +00:00
|
|
|
extern "C"
|
2019-10-08 14:52:01 +00:00
|
|
|
{
|
|
|
|
JNIEXPORT jobject JNICALL
|
2019-10-09 12:43:25 +00:00
|
|
|
Java_network_loki_lokinet_LokinetConfig_Obtain(JNIEnv* env, jclass)
|
2019-10-08 14:52:01 +00:00
|
|
|
{
|
|
|
|
llarp_config* conf = llarp_default_config();
|
|
|
|
if(conf == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
return env->NewDirectByteBuffer(conf, llarp_config_size());
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
2019-10-09 13:08:38 +00:00
|
|
|
Java_network_loki_lokinet_LokinetConfig_Free(JNIEnv* env, jclass, jobject buf)
|
2019-10-08 14:52:01 +00:00
|
|
|
{
|
|
|
|
llarp_config_free(FromBuffer< llarp_config >(env, buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_network_loki_lokinet_LokinetConfig_Load(JNIEnv* env, jobject self,
|
|
|
|
jstring fname)
|
|
|
|
{
|
2019-10-09 12:40:40 +00:00
|
|
|
llarp_config* conf = GetImpl< llarp_config >(env, self);
|
2019-10-08 14:52:01 +00:00
|
|
|
if(conf == nullptr)
|
|
|
|
return JNI_FALSE;
|
|
|
|
return VisitStringAsStringView< jboolean >(
|
|
|
|
env, fname, [conf](llarp::string_view val) -> jboolean {
|
|
|
|
const auto filename = llarp::string_view_string(val);
|
|
|
|
if(llarp_config_read_file(conf, filename.c_str()))
|
|
|
|
return JNI_TRUE;
|
|
|
|
return JNI_FALSE;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|