gdextension_library_loader.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**************************************************************************/
  2. /* gdextension_library_loader.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef GDEXTENSION_LIBRARY_LOADER_H
  31. #define GDEXTENSION_LIBRARY_LOADER_H
  32. #include <functional>
  33. #include "core/extension/gdextension_loader.h"
  34. #include "core/io/config_file.h"
  35. #include "core/os/shared_object.h"
  36. class GDExtensionLibraryLoader : public GDExtensionLoader {
  37. friend class GDExtensionManager;
  38. friend class GDExtension;
  39. private:
  40. String resource_path;
  41. void *library = nullptr; // pointer if valid.
  42. String library_path;
  43. String entry_symbol;
  44. bool is_static_library = false;
  45. #ifdef TOOLS_ENABLED
  46. bool is_reloadable = false;
  47. #endif
  48. Vector<SharedObject> library_dependencies;
  49. HashMap<String, String> class_icon_paths;
  50. #ifdef TOOLS_ENABLED
  51. uint64_t resource_last_modified_time = 0;
  52. uint64_t library_last_modified_time = 0;
  53. void update_last_modified_time(uint64_t p_resource_last_modified_time, uint64_t p_library_last_modified_time) {
  54. resource_last_modified_time = p_resource_last_modified_time;
  55. library_last_modified_time = p_library_last_modified_time;
  56. }
  57. #endif
  58. public:
  59. static String find_extension_library(const String &p_path, Ref<ConfigFile> p_config, std::function<bool(String)> p_has_feature, PackedStringArray *r_tags = nullptr);
  60. static Vector<SharedObject> find_extension_dependencies(const String &p_path, Ref<ConfigFile> p_config, std::function<bool(String)> p_has_feature);
  61. virtual Error open_library(const String &p_path) override;
  62. virtual Error initialize(GDExtensionInterfaceGetProcAddress p_get_proc_address, const Ref<GDExtension> &p_extension, GDExtensionInitialization *r_initialization) override;
  63. virtual void close_library() override;
  64. virtual bool is_library_open() const override;
  65. virtual bool has_library_changed() const override;
  66. virtual bool library_exists() const override;
  67. Error parse_gdextension_file(const String &p_path);
  68. };
  69. #endif // GDEXTENSION_LIBRARY_LOADER_H