JniClass.hpp 2.6 KB

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