Migrate to VoidLibrary (toolchain + API groundwork)
This commit is contained in:
1 parent
5e1e3d66c4
commit
e17cfed56f
38 files changed
+3077
-2505
No files matched your search
@@ -0,0 +1,158 @@
|
||||
#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;
|
||||
|
||||
// Get queue as summaries (minimal data)
|
||||
[[nodiscard]] virtual Result<std::vector<TrackSummary>>
|
||||
getQueueSummaries() const = 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
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreInterface.hpp"
|
||||
|
||||
// Platform-specific export macros
|
||||
#ifdef _WIN32
|
||||
#ifdef ECHOION_API_EXPORT
|
||||
#define ECHOION_API __declspec(dllexport)
|
||||
#else
|
||||
#define ECHOION_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ECHOION_API __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
namespace Echoion::Api
|
||||
{
|
||||
|
||||
// API export functions
|
||||
extern "C" {
|
||||
// Create a new core instance
|
||||
ECHOION_API CoreInterfacePtr CreateCore();
|
||||
|
||||
// Destroy a core instance
|
||||
ECHOION_API void DestroyCore(ICoreInterface* core);
|
||||
|
||||
// Get API version
|
||||
ECHOION_API const char* GetApiVersion();
|
||||
|
||||
// Check if API is compatible
|
||||
ECHOION_API bool IsApiCompatible(uint32_t major, uint32_t minor);
|
||||
}
|
||||
|
||||
} // namespace Echoion::Api
|
||||
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace Echoion::Api
|
||||
{
|
||||
|
||||
// Opaque handle types to avoid including full headers
|
||||
// These are used in interfaces to break dependencies
|
||||
|
||||
// Forward declarations for Core types (Plugin never needs full definition)
|
||||
struct AppConfig;
|
||||
struct HotReloadState;
|
||||
struct PlaybackState;
|
||||
struct TrackInfo;
|
||||
struct QueueEntry;
|
||||
|
||||
// Opaque handle wrapper - type-safe void pointer replacement
|
||||
template <typename T> class OpaqueHandle
|
||||
{
|
||||
public:
|
||||
|
||||
OpaqueHandle() = default;
|
||||
explicit OpaqueHandle(std::shared_ptr<T> ptr) : ptr_(std::move(ptr))
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isValid() const { return ptr_ != nullptr; }
|
||||
[[nodiscard]] T* get() const { return ptr_.get(); }
|
||||
[[nodiscard]] T& operator*() const { return *ptr_; }
|
||||
[[nodiscard]] T* operator->() const { return ptr_.get(); }
|
||||
|
||||
void reset() { ptr_.reset(); }
|
||||
void reset(T* ptr) { ptr_.reset(ptr); }
|
||||
|
||||
[[nodiscard]] std::shared_ptr<T> toSharedPtr() const
|
||||
{
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<T> ptr_;
|
||||
};
|
||||
|
||||
// Specific handle types
|
||||
using AppConfigHandle = OpaqueHandle<AppConfig>;
|
||||
using HotReloadStateHandle = OpaqueHandle<HotReloadState>;
|
||||
using PlaybackStateHandle = OpaqueHandle<PlaybackState>;
|
||||
using TrackInfoHandle = OpaqueHandle<TrackInfo>;
|
||||
using QueueEntryHandle = OpaqueHandle<QueueEntry>;
|
||||
|
||||
// Serialization helpers for cross-boundary communication
|
||||
using SerializedConfig = std::string; // JSON string
|
||||
using SerializedState = std::string; // JSON string
|
||||
|
||||
} // namespace Echoion::Api
|
||||
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
#include "PluginTypes.hpp"
|
||||
#include "Types.hpp"
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Api
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
class IPluginInterface;
|
||||
using PluginInterfacePtr = std::shared_ptr<IPluginInterface>;
|
||||
|
||||
// Plugin interface that the Core will use
|
||||
// MINIMAL VERSION - only depends on Types.hpp and PluginTypes.hpp
|
||||
// NO dependencies on TrackTypes, ConfigTypes, RpcTypes, etc.
|
||||
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() = 0;
|
||||
[[nodiscard]] virtual Result<std::optional<ClientInfo>>
|
||||
getClient(uint64_t clientId) = 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 short>& data) = 0;
|
||||
virtual Result<void>
|
||||
setWhisperList(const std::vector<uint64_t>& clientIds) = 0;
|
||||
|
||||
// Server connection
|
||||
// ServerConfig is defined in PluginTypes.hpp (self-contained)
|
||||
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;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Api
|
||||
Reference in new issue
Block a user