CAndroidVMHelper.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. /// helper class that allows access to java vm to communicate with java code from native
  16. class CAndroidVMHelper
  17. {
  18. JNIEnv * envPtr;
  19. bool detachInDestructor;
  20. jclass findClass(const std::string & name, bool classloaded);
  21. public:
  22. CAndroidVMHelper();
  23. ~CAndroidVMHelper();
  24. JNIEnv * get();
  25. jclass findClassloadedClass(const std::string & name);
  26. void callStaticVoidMethod(const std::string & cls, const std::string & method, bool classloaded = false);
  27. std::string callStaticStringMethod(const std::string & cls, const std::string & method, bool classloaded = false);
  28. static void cacheVM(JNIEnv * env);
  29. static void cacheVM(JavaVM * vm);
  30. static constexpr const char * NATIVE_METHODS_DEFAULT_CLASS = "eu/vcmi/vcmi/NativeMethods";
  31. };
  32. #endif