164 lines
6.3 KiB
C++
164 lines
6.3 KiB
C++
#pragma once
|
|
|
|
#include "Types.hpp"
|
|
#include "TrackTypes.hpp"
|
|
#include "PluginTypes.hpp"
|
|
#include "ConfigTypes.hpp"
|
|
#include "RpcTypes.hpp"
|
|
#include "NetworkTypes.hpp"
|
|
#include <filesystem>
|
|
#include <future>
|
|
#include <memory>
|
|
#include <functional>
|
|
#include <expected>
|
|
|
|
namespace Echoion::Api {
|
|
|
|
// Forward declarations
|
|
class IAudioDecoder;
|
|
class IMusicManager;
|
|
class ICommandManager;
|
|
class IPluginInterface;
|
|
class ICoreInterface;
|
|
|
|
// Network client interface
|
|
class INetworkClient {
|
|
public:
|
|
virtual ~INetworkClient() = default;
|
|
|
|
// Initialize with optional proxy
|
|
virtual Result<void> initialize(const std::optional<ProxyConfig>& proxy = std::nullopt) = 0;
|
|
virtual void shutdown() = 0;
|
|
|
|
// Synchronous requests
|
|
[[nodiscard]] virtual Result<HttpResponse> get(std::string_view url,
|
|
const std::vector<HttpHeader>& headers = {}) = 0;
|
|
[[nodiscard]] virtual Result<HttpResponse> post(std::string_view url,
|
|
std::string_view body, const std::vector<HttpHeader>& headers = {}) = 0;
|
|
[[nodiscard]] virtual Result<HttpResponse> request(const HttpRequest& req) = 0;
|
|
|
|
// Asynchronous requests
|
|
[[nodiscard]] virtual std::future<Result<HttpResponse>> getAsync(std::string_view url,
|
|
const std::vector<HttpHeader>& headers = {}) = 0;
|
|
[[nodiscard]] virtual std::future<Result<HttpResponse>> postAsync(std::string_view url,
|
|
std::string_view body, const std::vector<HttpHeader>& headers = {}) = 0;
|
|
[[nodiscard]] virtual std::future<Result<HttpResponse>> requestAsync(const HttpRequest& req) = 0;
|
|
|
|
// Proxy configuration
|
|
virtual void setProxy(const std::optional<ProxyConfig>& proxy) = 0;
|
|
[[nodiscard]] virtual std::optional<ProxyConfig> getProxy() const = 0;
|
|
virtual void clearProxy() = 0;
|
|
|
|
// Retry configuration
|
|
virtual void setRetryConfig(const RetryConfig& config) = 0;
|
|
[[nodiscard]] virtual RetryConfig getRetryConfig() const = 0;
|
|
};
|
|
|
|
// Plugin interface that the core will use
|
|
class IPluginInterface {
|
|
public:
|
|
virtual ~IPluginInterface() = default;
|
|
|
|
// Lifecycle
|
|
virtual Result<void> initialize() = 0;
|
|
virtual Result<void> shutdown() = 0;
|
|
|
|
// Client operations
|
|
[[nodiscard]] virtual Result<std::vector<ClientInfo>> getClients() const = 0;
|
|
[[nodiscard]] virtual Result<std::optional<ClientInfo>> getClient(uint64_t clientId) const = 0;
|
|
virtual Result<void> moveClient(uint64_t clientId, uint64_t channelId) = 0;
|
|
virtual Result<void> kickClient(uint64_t clientId, const std::string& reason) = 0;
|
|
|
|
// Channel operations
|
|
[[nodiscard]] virtual Result<std::vector<ChannelInfo>> getChannels() const = 0;
|
|
[[nodiscard]] virtual Result<std::optional<ChannelInfo>> getChannel(uint64_t channelId) const = 0;
|
|
|
|
// Messaging
|
|
virtual Result<void> sendTextMessage(uint64_t targetId, const std::string& message) = 0;
|
|
virtual Result<void> sendChannelMessage(uint64_t channelId, const std::string& message) = 0;
|
|
virtual Result<void> sendServerMessage(const std::string& message) = 0;
|
|
|
|
// Audio
|
|
virtual Result<void> sendAudioData(const std::span<const uint8_t>& data) = 0;
|
|
virtual Result<void> setWhisperList(const std::vector<uint64_t>& clientIds) = 0;
|
|
|
|
// Server connection
|
|
virtual Result<void> connectToServer(const ServerConfig& config) = 0;
|
|
virtual Result<void> disconnectFromServer() = 0;
|
|
[[nodiscard]] virtual bool isConnected() const = 0;
|
|
virtual Result<void> reconnect() = 0;
|
|
|
|
// Event subscription
|
|
virtual void registerEventCallback(const EventCallback& callback) = 0;
|
|
virtual void unregisterEventCallback(const EventCallback& callback) = 0;
|
|
};
|
|
|
|
using PluginInterfacePtr = std::shared_ptr<IPluginInterface>;
|
|
|
|
// Core interface that the plugin will use to communicate with the core
|
|
class ICoreInterface {
|
|
public:
|
|
virtual ~ICoreInterface() = default;
|
|
|
|
// Lifecycle
|
|
// Plugin passes config file path, Core loads config internally (no AppConfig dependency in Plugin)
|
|
virtual Result<void> initialize(const std::filesystem::path& configPath) = 0;
|
|
virtual Result<void> shutdown() = 0;
|
|
virtual bool isInitialized() const noexcept = 0;
|
|
|
|
// Playback control
|
|
virtual Result<void> play(const TrackInfo& track) = 0;
|
|
virtual Result<void> pause() = 0;
|
|
virtual Result<void> resume() = 0;
|
|
virtual Result<void> stop() = 0;
|
|
virtual Result<void> skip(uint32_t count = 1) = 0;
|
|
virtual Result<void> seek(std::chrono::milliseconds position) = 0;
|
|
virtual Result<void> setVolume(float volume) = 0;
|
|
|
|
// Queue management
|
|
virtual Result<uint64_t> queueTrack(const TrackInfo& track, uint64_t clientId) = 0;
|
|
virtual Result<void> removeFromQueue(uint64_t queueId) = 0;
|
|
virtual Result<void> clearQueue() = 0;
|
|
[[nodiscard]] virtual Result<std::vector<QueueEntry>> getQueue() const = 0;
|
|
virtual Result<void> moveInQueue(uint64_t queueId, uint32_t newPosition) = 0;
|
|
|
|
// Track info
|
|
[[nodiscard]] virtual Result<std::optional<QueueEntry>> getCurrentTrack() const = 0;
|
|
[[nodiscard]] virtual Result<PlaybackState> getPlaybackState() const = 0;
|
|
|
|
// Playlist
|
|
virtual Result<void> loadPlaylist(const std::string& playlistId, uint64_t clientId) = 0;
|
|
virtual Result<std::vector<PlaylistInfo>> getPlaylists() const = 0;
|
|
|
|
// Configuration
|
|
virtual Result<void> updateConfig(const AppConfig& config) = 0;
|
|
[[nodiscard]] virtual Result<AppConfig> getConfig() const = 0;
|
|
|
|
// Hot reload
|
|
virtual Result<HotReloadState> prepareForHotReload() = 0;
|
|
virtual Result<void> restoreAfterHotReload(const HotReloadState& state) = 0;
|
|
|
|
// Event handling
|
|
virtual void registerEventCallback(const EventCallback& callback) = 0;
|
|
virtual void unregisterEventCallback(const EventCallback& callback) = 0;
|
|
|
|
// Plugin event processing
|
|
virtual Result<void> onPluginEvent(const PluginEvent& event) = 0;
|
|
|
|
// Status
|
|
[[nodiscard]] virtual std::string getVersion() const = 0;
|
|
[[nodiscard]] virtual std::chrono::system_clock::time_point getUptime() const = 0;
|
|
|
|
// Plugin interface
|
|
virtual void setPluginInterface(PluginInterfacePtr pluginInterface) = 0;
|
|
|
|
// Trigger auto-connect (call after setPluginInterface)
|
|
virtual void triggerAutoConnect() = 0;
|
|
};
|
|
|
|
using CoreInterfacePtr = std::shared_ptr<ICoreInterface>;
|
|
using CoreCreateFunc = std::function<CoreInterfacePtr()>;
|
|
using CoreDestroyFunc = std::function<void(ICoreInterface*)>;
|
|
|
|
} // namespace Echoion::Api
|