CAndroidVMHelper.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * CAndroidVMHelper.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "Global.h"
  12. #ifdef VCMI_ANDROID
  13. #include <jni.h>
  14. #include <string>
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. /// helper class that allows access to java vm to communicate with java code from native
  17. class DLL_LINKAGE CAndroidVMHelper
  18. {
  19. JNIEnv * envPtr;
  20. bool detachInDestructor;
  21. jclass findClass(const std::string & name, bool classloaded);
  22. public:
  23. CAndroidVMHelper();
  24. ~CAndroidVMHelper();
  25. JNIEnv * get();
  26. jclass findClassloadedClass(const std::string & name);
  27. void callStaticVoidMethod(const std::string & cls, const std::string & method, bool classloaded = false);
  28. std::string callStaticStringMethod(const std::string & cls, const std::string & method, bool classloaded = false);
  29. void callCustomMethod(const std::string & cls, const std::string & method, const std::string & signature,
  30. std::function<void(JNIEnv *, jclass, jmethodID)> fun, bool classloaded = false);
  31. static void cacheVM(JNIEnv * env);
  32. static void initClassloader(void * baseEnv);
  33. static bool alwaysUseLoadedClass;
  34. static constexpr const char * NATIVE_METHODS_DEFAULT_CLASS = "eu/vcmi/vcmi/NativeMethods";
  35. };
  36. VCMI_LIB_NAMESPACE_END
  37. #endif