mirror of https://github.com/oxen-io/lokinet
add jni files
parent
3a0ca84962
commit
b8fb220b3b
@ -0,0 +1,59 @@
|
||||
|
||||
//#include <string.h>
|
||||
#include <jni.h>
|
||||
#include <llarp.h>
|
||||
#include <signal.h>
|
||||
#include <thread>
|
||||
|
||||
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<AndroidMain> Ptr;
|
||||
|
||||
static std::atomic<Ptr> daemon = std::make_unique<AndroidMain>();
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* 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
|
Loading…
Reference in New Issue