From b8fb220b3b4ae5f9408bef023645444664062b0c Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 6 Aug 2018 09:49:23 +1000 Subject: [PATCH] add jni files --- jni/lokinet_android.cpp | 59 ++++++++++++++++++++++++++ jni/network_loki_lokinet_Lokinet_JNI.h | 45 ++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100755 jni/lokinet_android.cpp create mode 100644 jni/network_loki_lokinet_Lokinet_JNI.h diff --git a/jni/lokinet_android.cpp b/jni/lokinet_android.cpp new file mode 100755 index 000000000..77144dd20 --- /dev/null +++ b/jni/lokinet_android.cpp @@ -0,0 +1,59 @@ + +//#include +#include +#include +#include +#include + +struct AndroidMain +{ + 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(); + delete m_thread; + } + } + + void Start() + { + if(m_impl || m_thread) + return; + m_impl = llarp_main_init("daemon.ini", true); + m_thread = new std::thread(std::bind(&AndroidMain::Run, this)); + } + + void Run() + { + llarp_main_run(m_impl); + } + + void Stop() + { + llarp_main_signal(m_impl, SIGINT); + } + + typedef std::unique_ptr Ptr; + + static std::atomic daemon = std::make_unique(); +} + +extern "C" +{ + +JNIEXPORT jstring JNICALL Java_network_loki_lokinet_Lokinet_1JNI_startLokinet + (JNIEnv * env, jclass jcl) + { + if(AndroidMain::daemon->Running()) + return env->NewUTFString("already running"); + AndroidMain::daemon->Start(); + return env->NewUTFString("ok"); + } + +} \ No newline at end of file diff --git a/jni/network_loki_lokinet_Lokinet_JNI.h b/jni/network_loki_lokinet_Lokinet_JNI.h new file mode 100644 index 000000000..b4c36ad36 --- /dev/null +++ b/jni/network_loki_lokinet_Lokinet_JNI.h @@ -0,0 +1,45 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class network_loki_lokinet_Lokinet_JNI */ + +#ifndef _Included_network_loki_lokinet_Lokinet_JNI +#define _Included_network_loki_lokinet_Lokinet_JNI +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: network_loki_lokinet_Lokinet_JNI + * Method: getABICompiledWith + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_network_loki_lokinet_Lokinet_1JNI_getABICompiledWith + (JNIEnv *, jclass); + +/* + * Class: network_loki_lokinet_Lokinet_JNI + * Method: startLokinet + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_network_loki_lokinet_Lokinet_1JNI_startLokinet + (JNIEnv *, jclass); + +/* + * Class: network_loki_lokinet_Lokinet_JNI + * Method: stopLokinet + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_network_loki_lokinet_Lokinet_1JNI_stopLokinet + (JNIEnv *, jclass); + +/* + * Class: network_loki_lokinet_Lokinet_JNI + * Method: onNetworkStateChanged + * Signature: (Z)V + */ +JNIEXPORT void JNICALL Java_network_loki_lokinet_Lokinet_1JNI_onNetworkStateChanged + (JNIEnv *, jclass, jboolean); + +#ifdef __cplusplus +} +#endif +#endif