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:
1 parent
9d56a6ff01
commit
f7553d10d3
5 files changed
+63
-57
No files matched your search
@@ -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_;
|
||||
|
||||
Reference in new issue
Block a user