From 863ef1f71e420c50caf207dcac54942c4cba95a9 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 6 Aug 2018 10:06:00 +1000 Subject: [PATCH] more android code --- jni/lokinet_android.cpp | 50 ++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/jni/lokinet_android.cpp b/jni/lokinet_android.cpp index 77144dd20..af145c3d8 100755 --- a/jni/lokinet_android.cpp +++ b/jni/lokinet_android.cpp @@ -3,17 +3,16 @@ #include #include #include +#include #include -struct AndroidMain +struct AndroidMain { - llarp_main * m_impl = nullptr; - std::thread * m_thread = nullptr; + llarp_main* m_impl = nullptr; + std::thread* m_thread = nullptr; ~AndroidMain() { - if(m_impl) - llarp_main_free(m_impl); if(m_thread) { m_thread->join(); @@ -21,34 +20,45 @@ struct AndroidMain } } - void Start() + void + Start() { if(m_impl || m_thread) return; - m_impl = llarp_main_init("daemon.ini", true); + m_impl = llarp_main_init("daemon.ini", true); m_thread = new std::thread(std::bind(&AndroidMain::Run, this)); } - void Run() + void + Run() { llarp_main_run(m_impl); + llarp_main_free(m_impl); } - void Stop() + void + Stop() { llarp_main_signal(m_impl, SIGINT); } - typedef std::unique_ptr Ptr; + typedef std::unique_ptr< AndroidMain > Ptr; - static std::atomic daemon = std::make_unique(); + static std::atomic< Ptr > daemon = std::make_unique< AndroidMain >(); } extern "C" { + JNIEXPORT jstring JNICALL + Java_network_loki_lokinet_Lokinet_1JNI_getABICompiledWith(JNIEnv * env, + jclass) + { + // TODO: fixme + return env->NewUTFString("android"); + } -JNIEXPORT jstring JNICALL Java_network_loki_lokinet_Lokinet_1JNI_startLokinet - (JNIEnv * env, jclass jcl) + JNIEXPORT jstring JNICALL Java_network_loki_lokinet_Lokinet_1JNI_startLokinet( + JNIEnv * env, jclass jcl) { if(AndroidMain::daemon->Running()) return env->NewUTFString("already running"); @@ -56,4 +66,18 @@ JNIEXPORT jstring JNICALL Java_network_loki_lokinet_Lokinet_1JNI_startLokinet return env->NewUTFString("ok"); } + JNIEXPORT void JNICALL Java_network_loki_lokinet_Lokinet_1JNI_stopLokinet( + JNIEnv * env, jclass) + { + if(AndroidMain::daemon->Running()) + { + AndroidMain::daemon->Stop(); + } + } + + JNIEXPORT void JNICALL + Java_network_loki_lokinet_Lokinet_1JNI_onNetworkStateChanged(JNIEnv*, jclass, + jboolean) + { + } } \ No newline at end of file