Migrate core infrastructure to VoidLibrary
This commit is contained in:
1 parent
53801f2b53
commit
2bdb63766d
65 files changed
+16109
-12011
No files matched your search
+155
-85
@@ -1,111 +1,181 @@
|
||||
#pragma once
|
||||
|
||||
#include <echoion/api.hpp>
|
||||
#include <echoion/api/Database.hpp>
|
||||
#include "MusicManager.hpp"
|
||||
#include "CommandManager.hpp"
|
||||
#include "ConfigLoader.hpp"
|
||||
#include "MusicManager.hpp"
|
||||
#include "NetworkClient.hpp"
|
||||
#include "RpcServer.hpp"
|
||||
#include "ConfigLoader.hpp"
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <ConfigTypes.hpp>
|
||||
#include <CoreInterface.hpp>
|
||||
#include <Database.hpp>
|
||||
#include <RpcTypes.hpp>
|
||||
#include <StateBlob.hpp>
|
||||
#include <TrackTypes.hpp>
|
||||
#include <Types.hpp>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
// Main Core implementation of ICoreInterface
|
||||
class Core : public Api::ICoreInterface {
|
||||
public:
|
||||
Core();
|
||||
~Core() override;
|
||||
// Main Core implementation of ICoreInterface
|
||||
class Core : public Api::ICoreInterface
|
||||
{
|
||||
public:
|
||||
|
||||
// ICoreInterface implementation
|
||||
Api::Result<void> initialize(const std::filesystem::path& configPath) override;
|
||||
Api::Result<void> shutdown() override;
|
||||
[[nodiscard]] bool isInitialized() const noexcept override;
|
||||
Core();
|
||||
~Core() override;
|
||||
|
||||
// Playback control
|
||||
Api::Result<void> play(const Api::TrackInfo& track) override;
|
||||
Api::Result<void> pause() override;
|
||||
Api::Result<void> resume() override;
|
||||
Api::Result<void> stop() override;
|
||||
Api::Result<void> skip(uint32_t count) override;
|
||||
Api::Result<void> seek(std::chrono::milliseconds position) override;
|
||||
Api::Result<void> setVolume(float volume) override;
|
||||
// ICoreInterface - Lifecycle
|
||||
Api::Result<void>
|
||||
initialize(const std::filesystem::path& configPath) override;
|
||||
Api::Result<void> shutdown() override;
|
||||
[[nodiscard]] bool isInitialized() const noexcept override;
|
||||
|
||||
// Queue management
|
||||
Api::Result<uint64_t> queueTrack(const Api::TrackInfo& track, uint64_t clientId) override;
|
||||
Api::Result<void> removeFromQueue(uint64_t queueId) override;
|
||||
Api::Result<void> clearQueue() override;
|
||||
[[nodiscard]] Api::Result<std::vector<Api::QueueEntry>> getQueue() const override;
|
||||
Api::Result<void> moveInQueue(uint64_t queueId, uint32_t newPosition) override;
|
||||
// ICoreInterface - Playback control (decoupled)
|
||||
Api::Result<void> play(const std::string& trackId) override;
|
||||
Api::Result<void> pause() override;
|
||||
Api::Result<void> resume() override;
|
||||
Api::Result<void> stop() override;
|
||||
Api::Result<void> skip(uint32_t count) override;
|
||||
Api::Result<void> seek(std::chrono::milliseconds position) override;
|
||||
Api::Result<void> setVolume(float volume) override;
|
||||
|
||||
// Track info
|
||||
[[nodiscard]] Api::Result<std::optional<Api::QueueEntry>> getCurrentTrack() const override;
|
||||
[[nodiscard]] Api::Result<Api::PlaybackState> getPlaybackState() const override;
|
||||
// ICoreInterface - Queue management (decoupled)
|
||||
Api::Result<uint64_t> queueTrack(const std::string& trackId,
|
||||
uint64_t clientId) override;
|
||||
Api::Result<void> removeFromQueue(uint64_t queueId) override;
|
||||
Api::Result<void> clearQueue() override;
|
||||
[[nodiscard]] Api::Result<std::vector<Api::TrackSummary>>
|
||||
getQueueSummaries() const override;
|
||||
Api::Result<void> moveInQueue(uint64_t queueId,
|
||||
uint32_t newPosition) override;
|
||||
|
||||
// Playlist
|
||||
Api::Result<void> loadPlaylist(const std::string& playlistId, uint64_t clientId) override;
|
||||
[[nodiscard]] Api::Result<std::vector<Api::PlaylistInfo>> getPlaylists() const override;
|
||||
// ICoreInterface - Track info (decoupled)
|
||||
[[nodiscard]] Api::Result<std::optional<Api::TrackSummary>>
|
||||
getCurrentTrackSummary() const override;
|
||||
[[nodiscard]] Api::Result<Api::PlaybackSummary>
|
||||
getPlaybackSummary() const override;
|
||||
|
||||
// Configuration
|
||||
Api::Result<void> updateConfig(const Api::AppConfig& config) override;
|
||||
[[nodiscard]] Api::Result<Api::AppConfig> getConfig() const override;
|
||||
// Reload config from disk (stored path from initialize)
|
||||
Api::Result<void> reloadConfig();
|
||||
// ICoreInterface - Playlist (decoupled)
|
||||
Api::Result<void> loadPlaylist(const std::string& playlistId,
|
||||
uint64_t clientId) override;
|
||||
[[nodiscard]] Api::Result<std::vector<std::string>>
|
||||
getPlaylistIds() const override;
|
||||
|
||||
// Hot reload
|
||||
Api::Result<Api::HotReloadState> prepareForHotReload() override;
|
||||
Api::Result<void> restoreAfterHotReload(const Api::HotReloadState& state) override;
|
||||
// ICoreInterface - Configuration (decoupled)
|
||||
Api::Result<void>
|
||||
updateConfigJson(const std::string& configJson) override;
|
||||
[[nodiscard]] Api::Result<std::string>
|
||||
getConfigJson() const override;
|
||||
|
||||
// Event handling
|
||||
void registerEventCallback(const Api::EventCallback& callback) override;
|
||||
void unregisterEventCallback(const Api::EventCallback& callback) override;
|
||||
// ICoreInterface - Hot reload (decoupled)
|
||||
[[nodiscard]] Api::Result<std::string>
|
||||
prepareForHotReload() override;
|
||||
Api::Result<void>
|
||||
restoreAfterHotReload(const std::string& state) override;
|
||||
|
||||
// Plugin event processing
|
||||
Api::Result<void> onPluginEvent(const Api::PluginEvent& event) override;
|
||||
// ICoreInterface - Decoupled state management
|
||||
[[nodiscard]] Api::StateBlob saveState() override;
|
||||
Api::Result<void>
|
||||
restoreState(const Api::StateBlob& state) override;
|
||||
[[nodiscard]] uint32_t getStateFormatVersion() const override;
|
||||
[[nodiscard]] bool
|
||||
canRestoreStateVersion(uint32_t version) const override;
|
||||
|
||||
// Status
|
||||
[[nodiscard]] std::string getVersion() const override;
|
||||
[[nodiscard]] std::chrono::system_clock::time_point getUptime() const override;
|
||||
// ICoreInterface - Event handling
|
||||
void registerEventCallback(
|
||||
const Api::EventCallback& callback) override;
|
||||
void unregisterEventCallback(
|
||||
const Api::EventCallback& callback) override;
|
||||
|
||||
// Additional methods for plugin integration
|
||||
void setPluginInterface(Api::PluginInterfacePtr pluginInterface) override;
|
||||
void setAudioDataCallback(const MusicManager::AudioDataCallback& callback);
|
||||
void triggerAutoConnect() override;
|
||||
// ICoreInterface - Plugin event processing
|
||||
Api::Result<void>
|
||||
onPluginEvent(const Api::PluginEvent& event) override;
|
||||
|
||||
private:
|
||||
void onMusicEvent(const Api::PluginEvent& event);
|
||||
void broadcastEvent(const Api::PluginEvent& event);
|
||||
[[nodiscard]] bool isAdmin(uint64_t clientId) const;
|
||||
void updateWhisperList();
|
||||
void setupRpcHandlers();
|
||||
// ICoreInterface - Status
|
||||
[[nodiscard]] std::string getVersion() const override;
|
||||
[[nodiscard]] std::chrono::system_clock::time_point
|
||||
getUptime() const override;
|
||||
|
||||
// Components
|
||||
std::shared_ptr<NetworkClient> networkClient_;
|
||||
std::shared_ptr<MusicManager> musicManager_;
|
||||
std::unique_ptr<CommandManager> commandManager_;
|
||||
Api::PluginInterfacePtr pluginInterface_;
|
||||
// ICoreInterface - Plugin interface
|
||||
void setPluginInterface(
|
||||
Api::PluginInterfacePtr pluginInterface) override;
|
||||
void triggerAutoConnect() override;
|
||||
|
||||
// State
|
||||
Api::AppConfig config_; // Config loaded internally
|
||||
std::filesystem::path configPath_; // Path to config file for reload
|
||||
std::chrono::system_clock::time_point startTime_;
|
||||
std::atomic<bool> initialized_{false};
|
||||
// ICoreInterface - Advanced (for internal Core-to-Core use)
|
||||
[[nodiscard]] Api::Result<Api::OpaqueHandle<Api::TrackInfo>>
|
||||
getCurrentTrackHandle() const override;
|
||||
[[nodiscard]] Api::Result<
|
||||
std::vector<Api::OpaqueHandle<Api::QueueEntry>>>
|
||||
getQueueHandles() const override;
|
||||
[[nodiscard]] Api::Result<Api::AppConfigHandle>
|
||||
getConfigHandle() const override;
|
||||
Api::Result<void>
|
||||
updateConfigFromHandle(Api::AppConfigHandle config) override;
|
||||
|
||||
// Event callbacks
|
||||
std::vector<Api::EventCallback> eventCallbacks_;
|
||||
mutable std::mutex eventMutex_;
|
||||
// Additional methods for internal use (not in interface)
|
||||
void setAudioDataCallback(
|
||||
const MusicManager::AudioDataCallback& callback);
|
||||
Api::Result<void> reloadConfig();
|
||||
|
||||
// Admin tracking
|
||||
std::vector<uint64_t> adminClients_;
|
||||
mutable std::mutex adminMutex_;
|
||||
|
||||
// Database for persistence
|
||||
std::shared_ptr<Api::Database> database_;
|
||||
|
||||
// RPC server for Desktop/API clients
|
||||
std::shared_ptr<RpcServer> rpcServer_;
|
||||
};
|
||||
// Internal implementations using full types
|
||||
Api::Result<void> playTrack(const Api::TrackInfo& track);
|
||||
Api::Result<uint64_t> queueTrackFull(const Api::TrackInfo& track,
|
||||
uint64_t clientId);
|
||||
[[nodiscard]] Api::Result<std::vector<Api::QueueEntry>>
|
||||
getQueue() const;
|
||||
[[nodiscard]] Api::Result<std::optional<Api::QueueEntry>>
|
||||
getCurrentTrack() const;
|
||||
[[nodiscard]] Api::Result<Api::PlaybackState>
|
||||
getPlaybackState() const;
|
||||
[[nodiscard]] Api::Result<std::vector<Api::PlaylistInfo>>
|
||||
getPlaylists() const;
|
||||
Api::Result<void> updateConfig(const Api::AppConfig& config);
|
||||
[[nodiscard]] Api::Result<Api::AppConfig> getConfig() const;
|
||||
[[nodiscard]] Api::Result<Api::HotReloadState>
|
||||
prepareForHotReloadFull();
|
||||
Api::Result<void>
|
||||
restoreAfterHotReloadFull(const Api::HotReloadState& state);
|
||||
|
||||
// Generate RPC tokens for existing subscribers
|
||||
void generateRpcTokensForSubscribers();
|
||||
|
||||
private:
|
||||
|
||||
void onMusicEvent(const Api::PluginEvent& event);
|
||||
void broadcastEvent(const Api::PluginEvent& event);
|
||||
[[nodiscard]] bool isAdmin(uint64_t clientId) const;
|
||||
void updateWhisperList();
|
||||
void setupRpcHandlers();
|
||||
void setupEventBusSubscriptions() const noexcept;
|
||||
|
||||
// Components
|
||||
std::shared_ptr<NetworkClient> networkClient_;
|
||||
std::shared_ptr<MusicManager> musicManager_;
|
||||
std::unique_ptr<CommandManager> commandManager_;
|
||||
Api::PluginInterfacePtr pluginInterface_;
|
||||
|
||||
// State
|
||||
Api::AppConfig config_;
|
||||
std::filesystem::path configPath_;
|
||||
std::chrono::system_clock::time_point startTime_;
|
||||
std::atomic<bool> initialized_{false};
|
||||
|
||||
// Event callbacks
|
||||
std::vector<Api::EventCallback> eventCallbacks_;
|
||||
mutable std::mutex eventMutex_;
|
||||
|
||||
// Admin tracking
|
||||
std::vector<uint64_t> adminClients_;
|
||||
mutable std::mutex adminMutex_;
|
||||
|
||||
// Database for persistence
|
||||
std::shared_ptr<Api::Database> database_;
|
||||
|
||||
// RPC server for Desktop/API clients
|
||||
std::shared_ptr<RpcServer> rpcServer_;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
Reference in new issue
Block a user