lokinet/jni/lokinet_config.cpp

36 lines
1.1 KiB
C++
Raw Normal View History

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)
2019-10-08 14:52:01 +00:00
return nullptr;
return env->NewDirectByteBuffer(conf, llarp_config_size());
}
JNIEXPORT void JNICALL
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));
2019-10-08 14:52:01 +00:00
}
JNIEXPORT jboolean JNICALL
Java_network_loki_lokinet_LokinetConfig_Load(JNIEnv* env, jobject self, jstring fname)
2019-10-08 14:52:01 +00:00
{
llarp_config* conf = GetImpl<llarp_config>(env, self);
if (conf == nullptr)
2019-10-08 14:52:01 +00:00
return JNI_FALSE;
return VisitStringAsStringView<jboolean>(
2019-10-08 14:52:01 +00:00
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()))
2019-10-08 14:52:01 +00:00
return JNI_TRUE;
return JNI_FALSE;
});
}
}