JniClass.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-04-07
  6. * Changed: 2024-05-31
  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/definition.hpp>
  16. #include <ls-std/core/interface/IJniApi.hpp>
  17. #include <ls-std/os/dynamic-goal.hpp>
  18. #include <memory>
  19. #include <string>
  20. #include <unordered_map>
  21. namespace ls::std::core::experimental
  22. {
  23. ls_std_class JniClass
  24. {
  25. public:
  26. explicit JniClass(const ::std::shared_ptr<ls::std::core::experimental::JniClassParameter> &_parameter, const ::std::string &_path);
  27. virtual ~JniClass();
  28. [[nodiscard]] ls::std::core::experimental::JniReturnValue callMethod(const ::std::string &_methodIdentifier);
  29. [[nodiscard]] bool hasMethod(const ::std::string &_methodIdentifier);
  30. bool load(); // nodiscard is optional here
  31. bool loadMethod(const ::std::string &_methodIdentifier, const ::std::string &_methodSignature); // nodiscard is optional here
  32. private:
  33. jclass javaClass{};
  34. ::std::unordered_map<::std::string, ls::std::core::experimental::JniMethod> methods{};
  35. ::std::shared_ptr<ls::std::core::experimental::JniClassParameter> parameter{};
  36. ::std::string path{};
  37. void _callBooleanMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  38. void _callByteMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  39. void _callCharMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  40. void _callDoubleMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  41. void _callFloatMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  42. void _callIntMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  43. void _callLongMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  44. void _callShortMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  45. void _createJniApi() const;
  46. [[nodiscard]] bool _hasMethod(const ::std::string &_methodIdentifier);
  47. };
  48. }
  49. #endif