update native call

pull/13/head
Jeff Becker 6 years ago
parent 54f5d292ff
commit 464d373f74

@ -11,13 +11,16 @@ struct AndroidMain
llarp_main* m_impl = nullptr; llarp_main* m_impl = nullptr;
std::thread* m_thread = nullptr; std::thread* m_thread = nullptr;
void bool
Start() Start(const char* conf)
{ {
if(m_impl || m_thread) if(m_impl || m_thread)
return; 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)); m_thread = new std::thread(std::bind(&AndroidMain::Run, this));
return true;
} }
bool bool
@ -58,26 +61,36 @@ extern "C"
} }
JNIEXPORT jstring JNICALL 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()) if(daemon->Running())
return env->NewStringUTF("already running"); return env->NewStringUTF("already running");
daemon->Start(); std::string conf;
return env->NewStringUTF("ok");
}
JNIEXPORT void JNICALL
Java_network_loki_lokinet_Lokinet_1JNI_stopLokinet(JNIEnv* env, jclass)
{
if(daemon->Running())
{ {
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 JNIEXPORT void JNICALL
Java_network_loki_lokinet_Lokinet_1JNI_onNetworkStateChanged(JNIEnv*, jclass, Java_network_loki_lokinet_Lokinet_1JNI_stopLokinet(JNIEnv* env, jclass)
jboolean) {
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 * Class: network_loki_lokinet_Lokinet_JNI
* Method: startLokinet * Method: startLokinet
* Signature: ()Ljava/lang/String; * Signature: (Ljava/lang/String;)Ljava/lang/String;
*/ */
JNIEXPORT jstring JNICALL Java_network_loki_lokinet_Lokinet_1JNI_startLokinet JNIEXPORT jstring JNICALL Java_network_loki_lokinet_Lokinet_1JNI_startLokinet
(JNIEnv *, jclass); (JNIEnv *, jclass, jstring);
/* /*
* Class: network_loki_lokinet_Lokinet_JNI * Class: network_loki_lokinet_Lokinet_JNI

Loading…
Cancel
Save