Files
EchoionApi/include/echoion/api/interfaces/CoreInterface.hpp
T
faumarayandClaude Opus 4.8 c2b68dea2f Drop dead public API (network async/batch, getQueueSummaries)
INetworkClient loses the unused getAsync/postAsync/requestAsync (0
call-sites); ICoreInterface loses getQueueSummaries (0 call-sites).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 14:27:22 +03:00

155 lines
5.2 KiB
C++

#pragma once
#include "OpaqueHandle.hpp"
#include "PluginTypes.hpp"
#include "StateBlob.hpp"
#include "Types.hpp"
#include <PluginInterface.hpp>
#include <expected>
#include <filesystem>
#include <functional>
#include <future>
#include <memory>
#include <string>
#include <vector>
namespace Echoion::Api
{
// Forward declarations - Core provides implementations
struct TrackInfo;
struct QueueEntry;
struct PlaylistInfo;
// Minimal PlaybackState for Plugin
struct PlaybackSummary {
std::optional<TrackSummary> currentTrack;
bool isPlaying = false;
bool isPaused = false;
std::chrono::milliseconds position{0};
float volume = 0.5f;
bool repeat = false;
bool shuffle = false;
};
// Callback types for async operations
using TrackCallback = std::function<void(const TrackSummary&)>;
using StateCallback = std::function<void(const PlaybackSummary&)>;
// Forward declarations
class ICoreInterface;
using CoreInterfacePtr = std::shared_ptr<ICoreInterface>;
using CoreCreateFunc = std::function<CoreInterfacePtr()>;
using CoreDestroyFunc = std::function<void(ICoreInterface*)>;
// Core interface that the Plugin will use to communicate with the Core
// MINIMAL VERSION - breaks dependencies on Core-specific types
class ICoreInterface
{
public:
virtual ~ICoreInterface() = default;
// Lifecycle
// Plugin passes config file path, Core loads config internally
virtual Result<void>
initialize(const std::filesystem::path& configPath) = 0;
virtual Result<void> shutdown() = 0;
virtual bool isInitialized() const noexcept = 0;
// Playback control - using string identifiers instead of TrackInfo
virtual Result<void> play(const std::string& trackId) = 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 - using string identifiers
virtual Result<uint64_t> queueTrack(const std::string& trackId,
uint64_t clientId) = 0;
virtual Result<void> removeFromQueue(uint64_t queueId) = 0;
virtual Result<void> clearQueue() = 0;
virtual Result<void> moveInQueue(uint64_t queueId,
uint32_t newPosition) = 0;
// Track info - return summaries instead of full TrackInfo
[[nodiscard]] virtual Result<std::optional<TrackSummary>>
getCurrentTrackSummary() const = 0;
[[nodiscard]] virtual Result<PlaybackSummary>
getPlaybackSummary() const = 0;
// Playlist - using string identifiers
virtual Result<void> loadPlaylist(const std::string& playlistId,
uint64_t clientId) = 0;
[[nodiscard]] virtual Result<std::vector<std::string>>
getPlaylistIds() const = 0;
// Configuration - using serialization instead of AppConfig
// Plugin sends JSON string, Core parses internally
virtual Result<void>
updateConfigJson(const std::string& configJson) = 0;
[[nodiscard]] virtual Result<std::string> getConfigJson() const = 0;
// Hot reload - using serialization instead of HotReloadState
// Returns opaque handle that Plugin just passes back
[[nodiscard]] virtual Result<std::string> prepareForHotReload() = 0;
virtual Result<void>
restoreAfterHotReload(const std::string& state) = 0;
// Decoupled state management - Plugin never knows state internals
// Core handles all serialization/deserialization internally
// State format can change without Plugin rebuild
[[nodiscard]] virtual StateBlob saveState() = 0;
virtual Result<void> restoreState(const StateBlob& state) = 0;
// Version info for state compatibility checking
[[nodiscard]] virtual uint32_t getStateFormatVersion() const = 0;
[[nodiscard]] virtual bool
canRestoreStateVersion(uint32_t version) const = 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;
// === Advanced methods for Core-to-Core communication (not for
// Plugin) === These are only called by Core implementations, not
// Plugin They use OpaqueHandle for type safety without exposing
// types
// Full TrackInfo access (for internal use)
[[nodiscard]] virtual Result<OpaqueHandle<TrackInfo>>
getCurrentTrackHandle() const = 0;
// Full QueueEntry access (for internal use)
[[nodiscard]] virtual Result<std::vector<OpaqueHandle<QueueEntry>>>
getQueueHandles() const = 0;
// Raw config access (for internal use)
[[nodiscard]] virtual Result<AppConfigHandle>
getConfigHandle() const = 0;
virtual Result<void>
updateConfigFromHandle(AppConfigHandle config) = 0;
};
} // namespace Echoion::Api