CAndroidVMHelper.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. void callCustomMethod(const std::string & cls, const std::string & method, const std::string & signature,
  29. std::function<void(JNIEnv *, jclass, jmethodID)> fun, bool classloaded = false);
  30. static void cacheVM(JNIEnv * env);
  31. static constexpr const char * NATIVE_METHODS_DEFAULT_CLASS = "eu/vcmi/vcmi/NativeMethods";
  32. };
  33. #endif