JniClass.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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-11
  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::experimental
  21. {
  22. class LS_STD_DYNAMIC_GOAL JniClass
  23. {
  24. public:
  25. explicit JniClass(const ::std::shared_ptr<ls::std::core::experimental::JniClassParameter> &_parameter, const ::std::string &_path);
  26. virtual ~JniClass();
  27. [[nodiscard]] ls::std::core::experimental::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::experimental::JniMethod> methods{};
  34. ::std::shared_ptr<ls::std::core::experimental::JniClassParameter> parameter{};
  35. ::std::string path{};
  36. void _callBooleanMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  37. void _callByteMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  38. void _callCharMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  39. void _callIntMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  40. void _callLongMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  41. void _callShortMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  42. void _createJniApi();
  43. [[nodiscard]] bool _hasMethod(const ::std::string &_methodIdentifier);
  44. };
  45. }
  46. #endif