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>
|
|
|
|
|
|
|
|
#include "cCriticalSection.h"
|
|
|
|
#include "cRoot.h"
|
2012-08-16 16:28:14 -04:00
|
|
|
#include "cMakeDir.h"
|
2012-08-17 18:20:35 -04:00
|
|
|
#include "ToJava.h"
|
2012-08-15 17:24:11 -04:00
|
|
|
|
|
|
|
#include <android/log.h>
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "JNI_OnLoad JNI_OnLoad JNI_OnLoad JNI_OnLoad");
|
|
|
|
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-08-15 17:24:11 -04:00
|
|
|
//if( !cLogger::GetSingletonPtr() ) new cLogger();
|
2012-08-16 16:28:14 -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-17 18:20:35 -04:00
|
|
|
|
|
|
|
//CallJavaFunction_Void_Void(g_JavaActivity, "TestTest" );
|
|
|
|
//CallJavaFunction_Void_String(g_JavaThread, "AddToLog", "herpderpderp!!" );
|
2012-08-15 17:24:11 -04:00
|
|
|
|
2012-08-16 16:28:14 -04:00
|
|
|
mkdir("/sdcard/mcserver", S_IRWXU | S_IRWXG | S_IRWXO);
|
|
|
|
|
2012-08-18 17:00:51 -04:00
|
|
|
// __android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "Before mainthread");
|
|
|
|
// pMainThread = new cMainThread();
|
|
|
|
// pMainThread->Start();
|
|
|
|
// __android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "AFter mainthread");
|
|
|
|
|
2012-08-16 16:28:14 -04:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
// pMainThread->Stop();
|
|
|
|
// delete pMainThread; pMainThread = NULL;
|
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;
|
|
|
|
}
|