Own the event bus in Core; inject it into MusicManager

Core holds a Void::EventBus::EventBus (Async), provides it as a service, and
runs its 18 event subscriptions against it directly (setupEventBusSubscriptions
is no longer const since it now mutates the owned bus). MusicManager gets the
bus via setEventBus() and publishes through a small emit<T>() helper (14
former GlobalEventBus publish sites). Delete EventBus.cpp (the singleton
definition). Build green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-23 13:56:32 +03:00
1 parent 9d56a6ff01
commit f7553d10d3
5 files changed
+63 -57

No files matched your search

+7 -1
View File
@@ -7,6 +7,7 @@
#include "RpcServer.hpp"
#include <ConfigTypes.hpp>
#include <CoreInterface.hpp>
#include <Void/Async/EventBus.hpp>
#include <Database.hpp>
#include <RpcTypes.hpp>
#include <StateBlob.hpp>
@@ -150,7 +151,7 @@ namespace Echoion::Core
[[nodiscard]] bool isAdmin(uint64_t clientId) const;
void updateWhisperList();
void setupRpcHandlers();
void setupEventBusSubscriptions() const noexcept;
void setupEventBusSubscriptions() noexcept;
// Components
std::shared_ptr<NetworkClient> networkClient_;
@@ -186,6 +187,11 @@ namespace Echoion::Core
// shims over the same instances.
Void::Service::ServiceRegistry registry_;
// Application event bus (async): playback/queue/subscription events
// published by MusicManager and consumed here for RPC broadcast +
// DB persistence. Owned by Core, provided as a service.
Void::EventBus::EventBus eventBus_{Void::EventBus::Mode::Async};
public:
// Access the service registry (composition root).
+15
View File
@@ -9,6 +9,7 @@
#include <ConfigTypes.hpp>
#include <TrackTypes.hpp>
#include <Types.hpp>
#include <Void/Async/EventBus.hpp>
#include <atomic>
#include <condition_variable>
#include <filesystem>
@@ -36,6 +37,10 @@ namespace Echoion::Core
std::shared_ptr<Api::Database> database = nullptr);
void shutdown();
// Inject the application event bus (owned by Core). Must be set
// before playback so emitted events reach subscribers.
void setEventBus(Void::EventBus::EventBus* bus) { eventBus_ = bus; }
[[nodiscard]] Api::Result<std::string>
play(const std::string& query, uint64_t clientId);
[[nodiscard]] Api::Result<void> pause();
@@ -157,6 +162,14 @@ namespace Echoion::Core
private:
// Publish a domain event on the injected bus (no-op until set).
template <typename T> void emit(T event)
{
if (eventBus_) {
eventBus_->publish<T>(std::move(event));
}
}
void playbackThread();
[[nodiscard]] Api::Result<Api::TrackInfo>
resolveQuery(const std::string& query);
@@ -207,6 +220,8 @@ namespace Echoion::Core
std::thread playlistAutoStartThread_;
std::shared_ptr<NetworkClient> networkClient_;
// Non-owning application event bus (provided by Core).
Void::EventBus::EventBus* eventBus_ = nullptr;
std::unique_ptr<YouTubeClient> youTubeClient_;
std::unique_ptr<AudioDecoder> audioDecoder_;
std::unique_ptr<SubscriptionManager> subscriptionManager_;