JniClass.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Co-Author: Claude Sonnet 4.6 (LLM)
  4. * Company: Lynar Studios
  5. * E-Mail: webmaster@lynarstudios.com
  6. * Created: 2023-04-07
  7. * Changed: 2026-06-23
  8. *
  9. * */
  10. #ifndef LS_STD_JNI_CLASS_HPP
  11. #define LS_STD_JNI_CLASS_HPP
  12. #include "JniClassParameter.hpp"
  13. #include "JniMethod.hpp"
  14. #include "JniReturnValue.hpp"
  15. #include <jni.h>
  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. /*
  22. * @doc: class(name: 'JniClass', package: 'core')
  23. * @doc: core.JniClass.description('This class represents a Java class within the Java Native Interface (JNI).')
  24. * */
  25. namespace ls::standard::core::experimental
  26. {
  27. class LS_STD_DYNAMIC_GOAL JniClass
  28. {
  29. public:
  30. explicit JniClass(const ::std::shared_ptr<ls::standard::core::experimental::JniClassParameter> &_parameter, const ::std::string &_path);
  31. virtual ~JniClass();
  32. [[nodiscard]] ls::standard::core::experimental::JniReturnValue callMethod(const ::std::string &_methodIdentifier);
  33. [[nodiscard]] bool hasMethod(const ::std::string &_methodIdentifier);
  34. bool load(); // nodiscard is optional here
  35. bool loadMethod(const ::std::string &_methodIdentifier, const ::std::string &_methodSignature); // nodiscard is optional here
  36. private:
  37. jclass javaClass{};
  38. ::std::unordered_map<::std::string, ls::standard::core::experimental::JniMethod> methods{};
  39. ::std::shared_ptr<ls::standard::core::experimental::JniClassParameter> parameter{};
  40. ::std::string path{};
  41. void _callBooleanMethod(const ::std::string &_methodIdentifier, ls::standard::core::experimental::JniReturnValue &_returnValue);
  42. void _callByteMethod(const ::std::string &_methodIdentifier, ls::standard::core::experimental::JniReturnValue &_returnValue);
  43. void _callCharMethod(const ::std::string &_methodIdentifier, ls::standard::core::experimental::JniReturnValue &_returnValue);
  44. void _callDoubleMethod(const ::std::string &_methodIdentifier, ls::standard::core::experimental::JniReturnValue &_returnValue);
  45. void _callFloatMethod(const ::std::string &_methodIdentifier, ls::standard::core::experimental::JniReturnValue &_returnValue);
  46. void _callIntMethod(const ::std::string &_methodIdentifier, ls::standard::core::experimental::JniReturnValue &_returnValue);
  47. void _callLongMethod(const ::std::string &_methodIdentifier, ls::standard::core::experimental::JniReturnValue &_returnValue);
  48. void _callShortMethod(const ::std::string &_methodIdentifier, ls::standard::core::experimental::JniReturnValue &_returnValue);
  49. void _createJniApi() const;
  50. [[nodiscard]] bool _hasMethod(const ::std::string &_methodIdentifier);
  51. };
  52. }
  53. #endif