#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Echoion::Core { class CommandManager; class MusicManager; class ITrackSource; class PluginHost final : public std::enable_shared_from_this { public: struct Configuration { std::filesystem::path configDirectory; std::filesystem::path stateDirectory; std::string publicUrl; std::optional proxy; std::string shortenerProvider = "url-shortener-internal"; }; PluginHost(CommandManager& commands, std::shared_ptr music, std::function isAdmin, std::function)> mediaSink, Configuration configuration); ~PluginHost(); void loadDirectory(const std::filesystem::path& directory); void loadManagedDirectory(const std::filesystem::path& directory); // Bind and validate cross-plugin services after every startup // directory has been loaded. [[nodiscard]] bool finalizeLoading(); [[nodiscard]] Api::Result manage(const std::string& requestJson); void setChangeCallback(std::function callback); void dispatch(const Api::PluginEvent& event) const; [[nodiscard]] Api::Result call(std::string_view plugin, std::string_view method, std::string params, uint64_t clientId) const; [[nodiscard]] std::vector webAssets() const; [[nodiscard]] std::vector names() const; [[nodiscard]] bool reconfigure(Configuration configuration); [[nodiscard]] std::shared_ptr shortener() const; [[nodiscard]] Void::ShortUrl::ResolveResult resolveShortLink(std::string_view key) const; struct State { std::string name; std::string json; std::uint32_t version{}; }; [[nodiscard]] std::vector snapshotStates() const; void restoreStates(const std::vector& states); private: void publish(std::string name); void unpublish(std::string name); void notifyChanged() const; [[nodiscard]] std::string pluginConfiguration(std::string_view name) const; [[nodiscard]] bool bindShortenerServices(); CommandManager& commands_; std::shared_ptr music_; std::function isAdmin_; std::function)> mediaSink_; Void::Plugin::PluginManager plugins_; Void::Service::ServiceRegistry shortenerRegistry_; Void::Service::ServiceRegistry internalShortenerRegistry_; std::unique_ptr< Void::Service::PluginServiceBinding> shortenerBinding_; std::unique_ptr< Void::Service::PluginServiceBinding> internalShortenerBinding_; Void::Plugin::ReloadCallbackId reloadCallback_{}; mutable std::mutex reconfigureMutex_; mutable std::mutex mutex_; Configuration configuration_; std::vector> sources_; std::function changeCallback_; struct ManagedPlugin { std::string version; std::filesystem::path path; }; std::filesystem::path managedDirectory_; std::unordered_map managed_; std::unordered_map loadedPaths_; }; } // namespace Echoion::Core