diff options
Diffstat (limited to '')
-rw-r--r-- | jni/Android.mk | 2 | ||||
-rw-r--r-- | jni/ToJava.cpp | 3 | ||||
-rw-r--r-- | jni/ToJava.h | 47 | ||||
-rw-r--r-- | jni/app-android.cpp | 57 |
4 files changed, 66 insertions, 43 deletions
diff --git a/jni/Android.mk b/jni/Android.mk index b55990005..68c807c6e 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -9,7 +9,7 @@ LOCAL_SRC_FILES := $(shell find lua-5.1.4 jsoncpp-src-0.5.0 zlib-1.2.7 source sq LOCAL_SRC_FILES := $(filter-out %SquirrelFunctions.cpp %SquirrelBindings.cpp %cPlugin_Squirrel.cpp %cSquirrelCommandBinder.cpp %minigzip.c %lua.c %tolua.c %toluabind.c %LeakFinder.cpp %StackWalker.cpp %example.c,$(LOCAL_SRC_FILES))
LOCAL_SRC_FILES := $(patsubst %.cpp,../%.cpp,$(LOCAL_SRC_FILES))
LOCAL_SRC_FILES := $(patsubst %.c,../%.c,$(LOCAL_SRC_FILES))
-LOCAL_SRC_FILES += app-android.cpp
+LOCAL_SRC_FILES += app-android.cpp ToJava.cpp
LOCAL_CFLAGS := -DANDROID_NDK \
-ffast-math \
diff --git a/jni/ToJava.cpp b/jni/ToJava.cpp new file mode 100644 index 000000000..10d4e84a0 --- /dev/null +++ b/jni/ToJava.cpp @@ -0,0 +1,3 @@ +#include "Globals.h"
+
+#include "ToJava.h"
\ No newline at end of file diff --git a/jni/ToJava.h b/jni/ToJava.h new file mode 100644 index 000000000..59dc4c366 --- /dev/null +++ b/jni/ToJava.h @@ -0,0 +1,47 @@ +#pragma once
+
+#include <jni.h>
+#include <android/log.h>
+extern JNIEnv* g_CurrentJNIEnv;
+
+extern jobject g_JavaThread;
+//extern jobject g_JavaActivity;
+
+//__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList);
+
+static void CallJavaFunction_Void_String( jobject a_Object, const std::string & a_FunctionName, const std::string & a_StringParam )
+{
+ //__android_log_print(ANDROID_LOG_ERROR,"MCServer", "JNIEnv: %i Object: %i", g_CurrentJNIEnv, a_Object );
+ jclass cls = g_CurrentJNIEnv->GetObjectClass( a_Object );
+ //__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jclass: %i", cls );
+ jmethodID mid = g_CurrentJNIEnv->GetMethodID( cls, a_FunctionName.c_str(), "(Ljava/lang/String;)V"); // void a_FunctionName( String )
+ //__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jmethodID: %i", mid );
+ if (mid != 0)
+ {
+ //__android_log_print(ANDROID_LOG_ERROR,"MCServer", "Going to call right NOW! %s", a_FunctionName.c_str() );
+ g_CurrentJNIEnv->CallVoidMethod( a_Object, mid, g_CurrentJNIEnv->NewStringUTF( a_StringParam.c_str() ) );
+ }
+ else
+ {
+ __android_log_print(ANDROID_LOG_ERROR,"MCServer", "It was 0, derp" );
+ }
+}
+
+
+static void CallJavaFunction_Void_Void( jobject a_Object, const std::string & a_FunctionName )
+{
+ __android_log_print(ANDROID_LOG_ERROR,"MCServer", "JNIEnv: %i Object: %i", g_CurrentJNIEnv, a_Object );
+ jclass cls = g_CurrentJNIEnv->GetObjectClass( a_Object );
+ __android_log_print(ANDROID_LOG_ERROR,"MCServer", "jclass: %i", cls );
+ jmethodID mid = g_CurrentJNIEnv->GetMethodID( cls, a_FunctionName.c_str(), "()V"); // void a_FunctionName( String )
+ __android_log_print(ANDROID_LOG_ERROR,"MCServer", "jmethodID: %i", mid );
+ if (mid != 0)
+ {
+ __android_log_print(ANDROID_LOG_ERROR,"MCServer", "Going to call right NOW! %s", a_FunctionName.c_str() );
+ g_CurrentJNIEnv->CallVoidMethod( a_Object, mid );
+ }
+ else
+ {
+ __android_log_print(ANDROID_LOG_ERROR,"MCServer", "It was 0, derp" );
+ }
+}
\ No newline at end of file diff --git a/jni/app-android.cpp b/jni/app-android.cpp index d02947440..461f433bf 100644 --- a/jni/app-android.cpp +++ b/jni/app-android.cpp @@ -13,24 +13,34 @@ #include "cCriticalSection.h"
#include "cRoot.h"
#include "cMakeDir.h"
+#include "ToJava.h"
#include <android/log.h>
cCriticalSection g_CriticalSection;
JNIEnv* g_CurrentJNIEnv = 0;
-jobject g_JavaRenderer = 0;
+jobject g_JavaThread = 0;
+//jobject g_JavaActivity = 0;
cRoot * pRoot = NULL;
+
+
+
+
/* Called when program/activity is created */
-extern "C" void Java_com_mcserver_MainThread_NativeOnCreate( JNIEnv* env )
+extern "C" void Java_com_mcserver_MainThread_NativeOnCreate( JNIEnv* env, jobject thiz )
{
g_CriticalSection.Lock();
g_CurrentJNIEnv = env;
+ g_JavaThread = thiz;
//if( !cLogger::GetSingletonPtr() ) new cLogger();
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "Logging from C++!");
g_CriticalSection.Unlock();
+
+ //CallJavaFunction_Void_Void(g_JavaActivity, "TestTest" );
+ //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", "herpderpderp!!" );
mkdir("/sdcard/mcserver", S_IRWXU | S_IRWXG | S_IRWXO);
@@ -39,57 +49,20 @@ extern "C" void Java_com_mcserver_MainThread_NativeOnCreate( JNIEnv* env ) delete pRoot;
}
-extern "C" void Java_com_mcserver_MCServerActivity_NativeCleanUp( JNIEnv* env )
-{
- g_CriticalSection.Lock();
- g_CurrentJNIEnv = env;
-
- g_CriticalSection.Unlock();
- pRoot->ServerCommand("stop");
-}
-/* Call to initialize the graphics state */
-extern "C" void Java_com_ballz_CppWrapperRenderer_NativeInitGL( JNIEnv* env, jobject thiz )
-{
- g_CriticalSection.Lock();
- g_CurrentJNIEnv = env;
- g_JavaRenderer = thiz;
- g_CriticalSection.Unlock();
-}
-extern "C" void Java_com_ballz_CppWrapperRenderer_NativeResize( JNIEnv* env, jobject thiz, jint w, jint h )
+extern "C" void Java_com_mcserver_MainThread_NativeCleanUp( JNIEnv* env, jobject thiz )
{
g_CriticalSection.Lock();
g_CurrentJNIEnv = env;
- g_JavaRenderer = thiz;
-
+ g_JavaThread = thiz;
g_CriticalSection.Unlock();
-}
-
-extern "C" void Java_com_ballz_CppWrapperRenderer_NativeRender( JNIEnv* env, jobject thiz )
-{
- g_CriticalSection.Lock();
- g_CurrentJNIEnv = env;
- g_JavaRenderer = thiz;
-
- g_CriticalSection.Unlock();
+ pRoot->ServerCommand("stop");
}
-extern "C" void Java_com_ballz_CppWrapperGLSurfaceView_NativeTouchScreen( JNIEnv* env, jobject thiz, jint mouseid, jint touched )
-{
- g_CriticalSection.Lock();
- g_CurrentJNIEnv = env;
- g_CriticalSection.Unlock();
-}
-extern "C" void Java_com_ballz_CppWrapperGLSurfaceView_NativeTouchEvent( JNIEnv* env, jobject thiz, jint mouseid, jfloat x, jfloat y )
-{
- g_CriticalSection.Lock();
- g_CurrentJNIEnv = env;
- g_CriticalSection.Unlock();
-}
\ No newline at end of file |