Removed old JNI header, checked code.
This commit is contained in:
parent
5db59bc645
commit
56c362518e
@ -3,16 +3,16 @@
|
|||||||
#define MODULE_NAME "siwg"
|
#define MODULE_NAME "siwg"
|
||||||
|
|
||||||
// include the Defold SDK
|
// include the Defold SDK
|
||||||
|
#define DLIB_LOG_DOMAIN LIB_NAME
|
||||||
#include <dmsdk/sdk.h>
|
#include <dmsdk/sdk.h>
|
||||||
|
|
||||||
#if defined(DM_PLATFORM_ANDROID)
|
#if defined(DM_PLATFORM_ANDROID)
|
||||||
|
|
||||||
#include <dmsdk/dlib/android.h>
|
// #include "siwg_jni.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <dmsdk/dlib/android.h>
|
||||||
#include "siwg.h"
|
#include "siwg.h"
|
||||||
// #include "siwg_jni.h"
|
|
||||||
#include "siwg_callback.h"
|
#include "siwg_callback.h"
|
||||||
#include "com_aterve_siwg_SiwgJNI.h"
|
#include "com_aterve_siwg_SiwgJNI.h"
|
||||||
|
|
||||||
|
@ -60,26 +60,7 @@ static void siwg_invoke_callback(MESSAGE_ID type, const char*json)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lua_pushnumber(L, type);
|
lua_pushnumber(L, type);
|
||||||
int count_table_elements = 1;
|
dmScript::JsonToLua(L, json, strlen(json)); // throws lua error if it fails
|
||||||
bool is_fail = false;
|
|
||||||
dmJson::Document doc;
|
|
||||||
dmJson::Result r = dmJson::Parse(json, &doc);
|
|
||||||
if (r == dmJson::RESULT_OK && doc.m_NodeCount > 0) {
|
|
||||||
char error_str_out[128];
|
|
||||||
if (dmScript::JsonToLua(L, &doc, 0, error_str_out, sizeof(error_str_out)) < 0) {
|
|
||||||
dmLogError("Failed converting object JSON to Lua; %s", error_str_out);
|
|
||||||
is_fail = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dmLogError("Failed to parse JSON object(%d): (%s)", r, json);
|
|
||||||
is_fail = true;
|
|
||||||
}
|
|
||||||
dmJson::Free(&doc);
|
|
||||||
if (is_fail) {
|
|
||||||
lua_pop(L, 2);
|
|
||||||
assert(top == lua_gettop(L));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int number_of_arguments = 3;
|
int number_of_arguments = 3;
|
||||||
int ret = lua_pcall(L, number_of_arguments, 0, 0);
|
int ret = lua_pcall(L, number_of_arguments, 0, 0);
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#if defined(DM_PLATFORM_ANDROID)
|
|
||||||
|
|
||||||
#include <dmsdk/sdk.h>
|
|
||||||
#include <jni.h>
|
|
||||||
|
|
||||||
struct ThreadAttacher {
|
|
||||||
JNIEnv *env;
|
|
||||||
bool has_attached;
|
|
||||||
ThreadAttacher() : env(NULL), has_attached(false) {
|
|
||||||
if (dmGraphics::GetNativeAndroidJavaVM()->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) {
|
|
||||||
dmGraphics::GetNativeAndroidJavaVM()->AttachCurrentThread(&env, NULL);
|
|
||||||
has_attached = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
~ThreadAttacher() {
|
|
||||||
if (has_attached) {
|
|
||||||
if (env->ExceptionCheck()) {
|
|
||||||
env->ExceptionDescribe();
|
|
||||||
}
|
|
||||||
env->ExceptionClear();
|
|
||||||
dmGraphics::GetNativeAndroidJavaVM()->DetachCurrentThread();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ClassLoader {
|
|
||||||
private:
|
|
||||||
JNIEnv *env;
|
|
||||||
jobject class_loader_object;
|
|
||||||
jmethodID find_class;
|
|
||||||
public:
|
|
||||||
ClassLoader(JNIEnv *env) : env(env) {
|
|
||||||
jclass activity_class = env->FindClass("android/app/NativeActivity");
|
|
||||||
jmethodID get_class_loader = env->GetMethodID(activity_class, "getClassLoader", "()Ljava/lang/ClassLoader;");
|
|
||||||
class_loader_object = env->CallObjectMethod(dmGraphics::GetNativeAndroidActivity(), get_class_loader);
|
|
||||||
jclass class_loader = env->FindClass("java/lang/ClassLoader");
|
|
||||||
find_class = env->GetMethodID(class_loader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
|
|
||||||
env->DeleteLocalRef(activity_class);
|
|
||||||
env->DeleteLocalRef(class_loader);
|
|
||||||
}
|
|
||||||
~ClassLoader() {
|
|
||||||
env->DeleteLocalRef(class_loader_object);
|
|
||||||
}
|
|
||||||
jclass load(const char *class_name) {
|
|
||||||
jstring str_class_name = env->NewStringUTF(class_name);
|
|
||||||
jclass loaded_class = (jclass)env->CallObjectMethod(class_loader_object, find_class, str_class_name);
|
|
||||||
env->DeleteLocalRef(str_class_name);
|
|
||||||
return loaded_class;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
x
Reference in New Issue
Block a user