JniClass.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-04-07
  6. * Changed: 2023-04-08
  7. *
  8. * */
  9. #ifndef LS_STD_JNI_CLASS_HPP
  10. #define LS_STD_JNI_CLASS_HPP
  11. #include "JniClassParameter.hpp"
  12. #include "JniMethod.hpp"
  13. #include "JniReturnValue.hpp"
  14. #include <jni.h>
  15. #include <ls-std/core/interface/IJniApi.hpp>
  16. #include <ls-std/os/dynamic-goal.hpp>
  17. #include <memory>
  18. #include <string>
  19. #include <unordered_map>
  20. namespace ls::std::core
  21. {
  22. class LS_STD_DYNAMIC_GOAL JniClass
  23. {
  24. public:
  25. explicit JniClass(const ::std::shared_ptr<ls::std::core::JniClassParameter> &_parameter, const ::std::string &_path);
  26. virtual ~JniClass();
  27. [[nodiscard]] ls::std::core::JniReturnValue callMethod(const ::std::string &_methodIdentifier);
  28. [[nodiscard]] bool hasMethod(const ::std::string &_methodIdentifier);
  29. bool load(); // nodiscard is optional here
  30. bool loadMethod(const ::std::string &_methodIdentifier, const ::std::string &_methodSignature); // nodiscard is optional here
  31. private:
  32. jclass javaClass{};
  33. ::std::unordered_map<::std::string, ls::std::core::JniMethod> methods{};
  34. ::std::shared_ptr<ls::std::core::JniClassParameter> parameter{};
  35. ::std::string path{};
  36. void _callByteMethod(const ::std::string &_methodIdentifier, ls::std::core::JniReturnValue &_returnValue);
  37. void _callIntMethod(const ::std::string &_methodIdentifier, ls::std::core::JniReturnValue &_returnValue);
  38. void _createJniApi();
  39. [[nodiscard]] bool _hasMethod(const ::std::string &_methodIdentifier);
  40. };
  41. }
  42. #endif