mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-19 09:25:28 +00:00
38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
|
#include "network_loki_lokinet_LokinetConfig.h"
|
||
|
#include <llarp.hpp>
|
||
|
#include "lokinet_jni_common.hpp"
|
||
|
|
||
|
extern "C
|
||
|
{
|
||
|
JNIEXPORT jobject JNICALL
|
||
|
Java_network_loki_lokinet_LokinetConfig_Obtain(JNIEnv* env, jclass* c)
|
||
|
{
|
||
|
llarp_config* conf = llarp_default_config();
|
||
|
if(conf == nullptr)
|
||
|
return nullptr;
|
||
|
return env->NewDirectByteBuffer(conf, llarp_config_size());
|
||
|
}
|
||
|
|
||
|
JNIEXPORT void JNICALL
|
||
|
Java_network_loki_lokinet_LokinetConfig_Free(JNIEnv* env, jclass c,
|
||
|
jobject buf)
|
||
|
{
|
||
|
llarp_config_free(FromBuffer< llarp_config >(env, buf));
|
||
|
}
|
||
|
|
||
|
JNIEXPORT jboolean JNICALL
|
||
|
Java_network_loki_lokinet_LokinetConfig_Load(JNIEnv* env, jobject self,
|
||
|
jstring fname)
|
||
|
{
|
||
|
llarp_config* conf = FromObjectMember< llarp_config >(env, self, "impl");
|
||
|
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;
|
||
|
});
|
||
|
}
|
||
|
}
|