2017-05-25 19:57:20 +02:00
|
|
|
/*
|
|
|
|
* CAndroidVMHelper.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-07-22 21:27:25 +02:00
|
|
|
#include "Global.h"
|
|
|
|
|
2017-06-29 01:03:37 +02:00
|
|
|
#ifdef VCMI_ANDROID
|
2017-07-23 19:23:48 +02:00
|
|
|
|
2017-05-25 19:57:20 +02:00
|
|
|
#include <jni.h>
|
|
|
|
#include <string>
|
|
|
|
|
2023-02-26 11:18:24 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2017-05-25 19:57:20 +02:00
|
|
|
/// helper class that allows access to java vm to communicate with java code from native
|
2023-02-25 09:15:09 +02:00
|
|
|
class DLL_LINKAGE CAndroidVMHelper
|
2017-05-25 19:57:20 +02:00
|
|
|
{
|
|
|
|
JNIEnv * envPtr;
|
|
|
|
bool detachInDestructor;
|
|
|
|
|
|
|
|
jclass findClass(const std::string & name, bool classloaded);
|
|
|
|
|
|
|
|
public:
|
|
|
|
CAndroidVMHelper();
|
|
|
|
|
|
|
|
~CAndroidVMHelper();
|
|
|
|
|
|
|
|
JNIEnv * get();
|
|
|
|
|
|
|
|
jclass findClassloadedClass(const std::string & name);
|
|
|
|
|
|
|
|
void callStaticVoidMethod(const std::string & cls, const std::string & method, bool classloaded = false);
|
|
|
|
|
|
|
|
std::string callStaticStringMethod(const std::string & cls, const std::string & method, bool classloaded = false);
|
|
|
|
|
2017-07-23 19:23:48 +02:00
|
|
|
void callCustomMethod(const std::string & cls, const std::string & method, const std::string & signature,
|
|
|
|
std::function<void(JNIEnv *, jclass, jmethodID)> fun, bool classloaded = false);
|
|
|
|
|
2017-05-25 19:57:20 +02:00
|
|
|
static void cacheVM(JNIEnv * env);
|
|
|
|
|
2023-02-25 09:34:37 +02:00
|
|
|
static void initClassloader(void * baseEnv);
|
|
|
|
|
2023-02-26 11:19:24 +02:00
|
|
|
static bool alwaysUseLoadedClass;
|
|
|
|
|
2017-05-25 19:57:20 +02:00
|
|
|
static constexpr const char * NATIVE_METHODS_DEFAULT_CLASS = "eu/vcmi/vcmi/NativeMethods";
|
|
|
|
};
|
2017-06-29 01:03:37 +02:00
|
|
|
|
2023-02-26 11:18:24 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2017-06-29 01:03:37 +02:00
|
|
|
#endif
|