mirror of
https://github.com/libretro/RetroArch
synced 2025-02-24 18:39:59 +00:00
(Android) refactor JNI code - still can't load ClassLoader
This commit is contained in:
parent
5065e12ae7
commit
04cabb0996
@ -36,29 +36,11 @@ struct droid
|
||||
int32_t last_orient;
|
||||
bool window_ready;
|
||||
float disp_refresh_rate;
|
||||
};
|
||||
|
||||
struct jni_params
|
||||
{
|
||||
JavaVM *java_vm;
|
||||
jobject class_obj;
|
||||
char class_name[128];
|
||||
char method_name[128];
|
||||
char method_signature[128];
|
||||
char obj_method_name[128];
|
||||
char obj_method_signature[128];
|
||||
};
|
||||
|
||||
struct jni_out_params_char
|
||||
{
|
||||
char *out;
|
||||
size_t out_sizeof;
|
||||
char in[128];
|
||||
jobject class_loader_obj;
|
||||
};
|
||||
|
||||
extern struct droid g_android;
|
||||
|
||||
void jni_get(void *params, void *out_params, unsigned out_type);
|
||||
bool android_run_events(struct android_app* android_app);
|
||||
|
||||
#endif
|
||||
|
106
android/native/jni/jni_wrapper.c
Normal file
106
android/native/jni/jni_wrapper.c
Normal file
@ -0,0 +1,106 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2012 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
#include "jni_wrapper.h"
|
||||
#include "../../../retroarch_logger.h"
|
||||
|
||||
jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||
{
|
||||
(void)reserved;
|
||||
|
||||
/*
|
||||
JNIEnv *env;
|
||||
jclass loader;
|
||||
|
||||
(*vm)->AttachCurrentThread(vm, &env, 0);
|
||||
|
||||
loader = (*env)->FindClass(env, "org/retroarch/browser/ModuleActivity");
|
||||
|
||||
if (loader == NULL)
|
||||
{
|
||||
RARCH_ERR("JNI - Can't find LoaderClass.\n");
|
||||
goto do_exit;
|
||||
}
|
||||
*/
|
||||
|
||||
RARCH_LOG("JNI - Successfully executed JNI_OnLoad.\n");
|
||||
|
||||
return JNI_VERSION_1_4;
|
||||
|
||||
do_exit:
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void jni_get(void *params, void *out_params, unsigned out_type)
|
||||
{
|
||||
JNIEnv *env;
|
||||
|
||||
if (!params)
|
||||
return;
|
||||
|
||||
struct jni_params *in_params = (struct jni_params*)params;
|
||||
|
||||
if (!in_params)
|
||||
return;
|
||||
|
||||
JavaVM *vm = in_params->java_vm;
|
||||
jobject obj = NULL;
|
||||
jmethodID gseid = NULL;
|
||||
|
||||
(*vm)->AttachCurrentThread(vm, &env, 0);
|
||||
|
||||
if (in_params->class_obj)
|
||||
{
|
||||
jclass acl = (*env)->GetObjectClass(env, in_params->class_obj); //class pointer
|
||||
jmethodID giid = (*env)->GetMethodID(env, acl, in_params->method_name, in_params->method_signature);
|
||||
obj = (*env)->CallObjectMethod(env, in_params->class_obj, giid); //Got our object
|
||||
}
|
||||
|
||||
if (in_params->obj_method_name && obj)
|
||||
{
|
||||
jclass class_obj = (*env)->GetObjectClass(env, obj); //class pointer of object
|
||||
gseid = (*env)->GetMethodID(env, class_obj, in_params->obj_method_name,
|
||||
in_params->obj_method_signature);
|
||||
}
|
||||
|
||||
switch (out_type)
|
||||
{
|
||||
case JNI_OUT_CHAR:
|
||||
if(gseid != NULL)
|
||||
{
|
||||
struct jni_out_params_char *out_params_char = (struct jni_out_params_char*)out_params;
|
||||
|
||||
if (!out_params_char)
|
||||
goto do_exit;
|
||||
|
||||
jstring jsParam1 = (*env)->CallObjectMethod(env, obj,
|
||||
gseid, (*env)->NewStringUTF(env, out_params_char->in));
|
||||
const char *test_argv = (*env)->GetStringUTFChars(env, jsParam1, 0);
|
||||
strncpy(out_params_char->out, test_argv, out_params_char->out_sizeof);
|
||||
(*env)->ReleaseStringUTFChars(env, jsParam1, test_argv);
|
||||
}
|
||||
break;
|
||||
case JNI_OUT_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
do_exit:
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
}
|
45
android/native/jni/jni_wrapper.h
Normal file
45
android/native/jni/jni_wrapper.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2012 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _JNI_WRAPPER_H
|
||||
#define _JNI_WRAPPER_H
|
||||
|
||||
enum
|
||||
{
|
||||
JNI_OUT_NONE = 0,
|
||||
JNI_OUT_CHAR
|
||||
};
|
||||
|
||||
struct jni_params
|
||||
{
|
||||
JavaVM *java_vm;
|
||||
jobject class_obj;
|
||||
char class_name[128];
|
||||
char method_name[128];
|
||||
char method_signature[128];
|
||||
char obj_method_name[128];
|
||||
char obj_method_signature[128];
|
||||
};
|
||||
|
||||
struct jni_out_params_char
|
||||
{
|
||||
char *out;
|
||||
size_t out_sizeof;
|
||||
char in[128];
|
||||
};
|
||||
|
||||
void jni_get(void *params, void *out_params, unsigned out_type);
|
||||
#endif
|
@ -20,8 +20,8 @@
|
||||
#include <string.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <jni.h>
|
||||
#include "android_general.h"
|
||||
#include "jni_wrapper.h"
|
||||
#include "../../../general.h"
|
||||
#include "../../../performance.h"
|
||||
#include "../../../driver.h"
|
||||
@ -68,53 +68,6 @@ static void print_cur_config(struct android_app* android_app)
|
||||
AConfiguration_getUiModeNight(android_app->config));
|
||||
}
|
||||
|
||||
#define JNI_OUT_CHAR 0
|
||||
|
||||
void jni_get(void *params, void *out_params, unsigned out_type)
|
||||
{
|
||||
JNIEnv *env;
|
||||
struct jni_params *in_params = (struct jni_params*)params;
|
||||
|
||||
JavaVM *vm = in_params->java_vm;
|
||||
jobject obj = NULL;
|
||||
jmethodID gseid = NULL;
|
||||
|
||||
(*vm)->AttachCurrentThread(vm, &env, 0);
|
||||
|
||||
if (in_params->class_obj)
|
||||
{
|
||||
jclass acl = (*env)->GetObjectClass(env, in_params->class_obj); //class pointer
|
||||
jmethodID giid = (*env)->GetMethodID(env, acl, in_params->method_name, in_params->method_signature);
|
||||
obj = (*env)->CallObjectMethod(env, in_params->class_obj, giid); //Got our object
|
||||
}
|
||||
|
||||
if (in_params->obj_method_name && obj)
|
||||
{
|
||||
jclass class_obj = (*env)->GetObjectClass(env, obj); //class pointer of object
|
||||
gseid = (*env)->GetMethodID(env, class_obj, in_params->obj_method_name,
|
||||
in_params->obj_method_signature);
|
||||
}
|
||||
|
||||
switch (out_type)
|
||||
{
|
||||
case JNI_OUT_CHAR:
|
||||
if(gseid != NULL)
|
||||
{
|
||||
struct jni_out_params_char *out_params_char = (struct jni_out_params_char*)out_params;
|
||||
jstring jsParam1 = (*env)->CallObjectMethod(env, obj,
|
||||
gseid, (*env)->NewStringUTF(env, out_params_char->in));
|
||||
const char *test_argv = (*env)->GetStringUTFChars(env, jsParam1, 0);
|
||||
strncpy(out_params_char->out, test_argv, out_params_char->out_sizeof);
|
||||
(*env)->ReleaseStringUTFChars(env, jsParam1, test_argv);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the next main command.
|
||||
*/
|
||||
@ -349,11 +302,14 @@ static void* android_app_entry(void* param)
|
||||
char rom_path[512];
|
||||
char libretro_path[512];
|
||||
|
||||
JNI_OnLoad(g_android.app->activity->vm, NULL);
|
||||
|
||||
// Get arguments */
|
||||
struct jni_params jni_args;
|
||||
|
||||
jni_args.java_vm = g_android.app->activity->vm;
|
||||
jni_args.class_obj = g_android.app->activity->clazz;
|
||||
|
||||
snprintf(jni_args.method_name, sizeof(jni_args.method_name), "getIntent");
|
||||
snprintf(jni_args.method_signature, sizeof(jni_args.method_signature), "()Landroid/content/Intent;");
|
||||
snprintf(jni_args.obj_method_name, sizeof(jni_args.obj_method_name), "getStringExtra");
|
||||
|
@ -18,6 +18,10 @@
|
||||
#include "../../msvc/msvc_compat.h"
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
#include "../../android/native/jni/jni_wrapper.c"
|
||||
#endif
|
||||
|
||||
/*============================================================
|
||||
LOGGERS
|
||||
============================================================ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user