2012-08-15 17:24:11 -04:00
|
|
|
#include "Globals.h"
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2012-09-26 10:36:08 -04:00
|
|
|
#include "OSSupport/CriticalSection.h"
|
|
|
|
#include "OSSupport/MakeDir.h"
|
2012-08-17 18:20:35 -04:00
|
|
|
#include "ToJava.h"
|
2012-08-15 17:24:11 -04:00
|
|
|
|
2012-09-26 10:36:08 -04:00
|
|
|
#include "Root.h"
|
2012-09-30 12:37:44 -04:00
|
|
|
#include "WebAdmin.h"
|
2012-09-26 10:36:08 -04:00
|
|
|
|
2012-08-15 17:24:11 -04:00
|
|
|
#include <android/log.h>
|
|
|
|
|
2012-09-30 12:37:44 -04:00
|
|
|
#ifdef _WIN32 // For IntelliSense parsing
|
|
|
|
typedef void jobject;
|
|
|
|
typedef int jint;
|
|
|
|
typedef bool jboolean;
|
|
|
|
typedef void JavaVM;
|
|
|
|
typedef void JNIEnv;
|
|
|
|
#endif
|
|
|
|
|
2012-08-15 17:24:11 -04:00
|
|
|
cCriticalSection g_CriticalSection;
|
|
|
|
|
|
|
|
JNIEnv* g_CurrentJNIEnv = 0;
|
2012-08-17 18:20:35 -04:00
|
|
|
jobject g_JavaThread = 0;
|
2012-08-18 17:00:51 -04:00
|
|
|
JavaVM* g_JavaVM = 0;
|
2012-08-17 18:20:35 -04:00
|
|
|
//jobject g_JavaActivity = 0;
|
2012-08-15 17:24:11 -04:00
|
|
|
|
2012-08-16 16:28:14 -04:00
|
|
|
cRoot * pRoot = NULL;
|
|
|
|
|
2012-08-17 18:20:35 -04:00
|
|
|
|
2012-08-18 17:00:51 -04:00
|
|
|
class cMainThread :
|
|
|
|
public cIsThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cMainThread() :
|
|
|
|
cIsThread("cMainThread")
|
|
|
|
{
|
|
|
|
//Start();
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "cMainThread");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stop(void)
|
|
|
|
{
|
|
|
|
m_ShouldTerminate = true;
|
|
|
|
Wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual void Execute(void) override
|
|
|
|
{
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "Execute");
|
|
|
|
pRoot = new cRoot();
|
|
|
|
pRoot->Start();
|
|
|
|
delete pRoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
} ;
|
|
|
|
|
|
|
|
cMainThread * pMainThread = NULL;
|
|
|
|
|
|
|
|
jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
|
|
|
{
|
2012-09-30 12:37:44 -04:00
|
|
|
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "JNI_OnLoad JNI_OnLoad JNI_OnLoad JNI_OnLoad");
|
2012-08-18 17:00:51 -04:00
|
|
|
g_JavaVM = vm;
|
|
|
|
return JNI_VERSION_1_4;
|
|
|
|
}
|
2012-08-17 18:20:35 -04:00
|
|
|
|
2012-08-15 17:24:11 -04:00
|
|
|
/* Called when program/activity is created */
|
2012-08-18 17:00:51 -04:00
|
|
|
extern "C" void Java_com_mcserver_MCServerActivity_NativeOnCreate( JNIEnv* env, jobject thiz )
|
2012-08-15 17:24:11 -04:00
|
|
|
{
|
|
|
|
g_CriticalSection.Lock();
|
|
|
|
g_CurrentJNIEnv = env;
|
2012-08-17 18:20:35 -04:00
|
|
|
g_JavaThread = thiz;
|
2012-09-30 12:37:44 -04:00
|
|
|
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "Logging from C++!");
|
2012-08-15 17:24:11 -04:00
|
|
|
g_CriticalSection.Unlock();
|
|
|
|
|
2012-08-16 16:28:14 -04:00
|
|
|
mkdir("/sdcard/mcserver", S_IRWXU | S_IRWXG | S_IRWXO);
|
|
|
|
|
|
|
|
pRoot = new cRoot();
|
|
|
|
pRoot->Start();
|
2012-08-18 17:00:51 -04:00
|
|
|
delete pRoot; pRoot = NULL;
|
2012-08-15 17:24:11 -04:00
|
|
|
}
|
|
|
|
|
2012-08-16 16:28:14 -04:00
|
|
|
|
2012-08-15 17:24:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-18 17:00:51 -04:00
|
|
|
extern "C" void Java_com_mcserver_MCServerActivity_NativeCleanUp( JNIEnv* env, jobject thiz )
|
2012-08-15 17:24:11 -04:00
|
|
|
{
|
|
|
|
g_CriticalSection.Lock();
|
|
|
|
g_CurrentJNIEnv = env;
|
2012-08-17 18:20:35 -04:00
|
|
|
g_JavaThread = thiz;
|
2012-08-15 17:24:11 -04:00
|
|
|
g_CriticalSection.Unlock();
|
|
|
|
|
2012-08-18 17:00:51 -04:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "pRoot: %p", pRoot);
|
|
|
|
if( pRoot != NULL )
|
|
|
|
{
|
|
|
|
pRoot->ServerCommand("stop");
|
|
|
|
}
|
2012-08-15 17:24:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-18 17:00:51 -04:00
|
|
|
extern "C" jboolean Java_com_mcserver_MCServerActivity_NativeIsServerRunning( JNIEnv* env, jobject thiz )
|
|
|
|
{
|
|
|
|
return pRoot != NULL;
|
2012-09-30 12:37:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" jint Java_com_mcserver_MCServerActivity_NativeGetWebAdminPort( JNIEnv* env, jobject thiz )
|
|
|
|
{
|
|
|
|
if( pRoot != NULL && pRoot->GetWebAdmin() != NULL )
|
|
|
|
{
|
|
|
|
return pRoot->GetWebAdmin()->GetPort();
|
|
|
|
}
|
|
|
|
return 0;
|
2012-08-18 17:00:51 -04:00
|
|
|
}
|