mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
update native call
This commit is contained in:
parent
54f5d292ff
commit
464d373f74
2 changed files with 31 additions and 18 deletions
|
@ -11,13 +11,16 @@ struct AndroidMain
|
|||
llarp_main* m_impl = nullptr;
|
||||
std::thread* m_thread = nullptr;
|
||||
|
||||
void
|
||||
Start()
|
||||
bool
|
||||
Start(const char* conf)
|
||||
{
|
||||
if(m_impl || m_thread)
|
||||
return;
|
||||
m_impl = llarp_main_init("daemon.ini", true);
|
||||
m_impl = llarp_main_init(conf, true);
|
||||
if(m_impl == nullptr)
|
||||
return false;
|
||||
m_thread = new std::thread(std::bind(&AndroidMain::Run, this));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -58,26 +61,36 @@ extern "C"
|
|||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_network_loki_lokinet_Lokinet_1JNI_startLokinet(JNIEnv* env, jclass jcl)
|
||||
Java_network_loki_lokinet_Lokinet_1JNI_startLokinet(JNIEnv* env, jclass jcl,
|
||||
jstring configfile)
|
||||
{
|
||||
if(daemon->Running())
|
||||
return env->NewStringUTF("already running");
|
||||
daemon->Start();
|
||||
return env->NewStringUTF("ok");
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_network_loki_lokinet_Lokinet_1JNI_stopLokinet(JNIEnv* env, jclass)
|
||||
{
|
||||
if(daemon->Running())
|
||||
std::string conf;
|
||||
{
|
||||
daemon->Stop();
|
||||
const char* nativeString = env->GetStringUTFChars(configfile, JNI_FALSE);
|
||||
conf = nativeString;
|
||||
env->ReleaseStringUTFChars(configfile, nativeString);
|
||||
}
|
||||
if(daemon->Start(conf.c_str()))
|
||||
return env->NewStringUTF("ok");
|
||||
else
|
||||
return env->NewStringUTF("failed to start");
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_network_loki_lokinet_Lokinet_1JNI_onNetworkStateChanged(JNIEnv*, jclass,
|
||||
jboolean)
|
||||
JNIEXPORT void JNICALL
|
||||
Java_network_loki_lokinet_Lokinet_1JNI_stopLokinet(JNIEnv* env, jclass)
|
||||
{
|
||||
if(daemon->Running())
|
||||
{
|
||||
daemon->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_network_loki_lokinet_Lokinet_1JNI_onNetworkStateChanged(JNIEnv*, jclass,
|
||||
jboolean)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -18,10 +18,10 @@ JNIEXPORT jstring JNICALL Java_network_loki_lokinet_Lokinet_1JNI_getABICompiledW
|
|||
/*
|
||||
* Class: network_loki_lokinet_Lokinet_JNI
|
||||
* Method: startLokinet
|
||||
* Signature: ()Ljava/lang/String;
|
||||
* Signature: (Ljava/lang/String;)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_network_loki_lokinet_Lokinet_1JNI_startLokinet
|
||||
(JNIEnv *, jclass);
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: network_loki_lokinet_Lokinet_JNI
|
||||
|
|
Loading…
Reference in a new issue