60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <ExtensionPlugin.hpp>
|
|
#include <Void/Plugin/Manager.hpp>
|
|
|
|
#include <filesystem>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace Echoion::Core
|
|
{
|
|
class CommandManager;
|
|
class MusicManager;
|
|
class ITrackSource;
|
|
|
|
class PluginHost final : public std::enable_shared_from_this<PluginHost>
|
|
{
|
|
public:
|
|
PluginHost(CommandManager& commands, std::shared_ptr<MusicManager> music,
|
|
std::function<bool(uint64_t)> isAdmin,
|
|
std::function<void(std::shared_ptr<ITrackSource>)> mediaSink = {});
|
|
~PluginHost();
|
|
|
|
void loadDirectory(const std::filesystem::path& directory);
|
|
void setChangeCallback(std::function<void()> callback);
|
|
void dispatch(const Api::PluginEvent& event) const;
|
|
[[nodiscard]] Api::Result<std::string> call(
|
|
std::string_view plugin, std::string_view method,
|
|
std::string params, uint64_t clientId) const;
|
|
[[nodiscard]] std::vector<Api::ExtensionWebAsset> webAssets() const;
|
|
[[nodiscard]] std::vector<std::string> names() const;
|
|
struct State {
|
|
std::string name;
|
|
std::string json;
|
|
std::uint32_t version{};
|
|
};
|
|
[[nodiscard]] std::vector<State> snapshotStates() const;
|
|
void restoreStates(const std::vector<State>& states);
|
|
|
|
private:
|
|
void publish(std::string_view name);
|
|
void unpublish(std::string_view name);
|
|
void notifyChanged() const;
|
|
|
|
CommandManager& commands_;
|
|
std::shared_ptr<MusicManager> music_;
|
|
std::function<bool(uint64_t)> isAdmin_;
|
|
std::function<void(std::shared_ptr<ITrackSource>)> mediaSink_;
|
|
Void::Plugin::PluginManager plugins_;
|
|
Void::Plugin::ReloadCallbackId reloadCallback_{};
|
|
mutable std::mutex mutex_;
|
|
std::vector<std::shared_ptr<class PluginTrackSource>> sources_;
|
|
std::function<void()> changeCallback_;
|
|
};
|
|
}
|