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
+26
-27
@@ -6,7 +6,7 @@
|
||||
#include "echoion/core/state/StateVersions.hpp"
|
||||
#include <ConfigManager.hpp>
|
||||
#include <Database.hpp>
|
||||
#include <EventBus.hpp>
|
||||
#include <Events.hpp>
|
||||
#include <Void/Data/Json.hpp>
|
||||
#include <Void/Data/Reflect.hpp>
|
||||
#include <algorithm>
|
||||
@@ -80,9 +80,8 @@ namespace Echoion::Core
|
||||
|
||||
ECHOION_LOG_INFO("Initializing Echoion Core...");
|
||||
|
||||
// Start EventBus processing thread
|
||||
Api::GlobalEventBus::instance().start();
|
||||
ECHOION_LOG_INFO("EventBus started");
|
||||
// The async event bus runs from construction; nothing to start.
|
||||
ECHOION_LOG_INFO("EventBus ready");
|
||||
|
||||
// Initialize network client
|
||||
networkClient_ = std::make_shared<NetworkClient>();
|
||||
@@ -110,6 +109,7 @@ namespace Echoion::Core
|
||||
|
||||
// Initialize music manager
|
||||
musicManager_ = std::make_shared<MusicManager>();
|
||||
musicManager_->setEventBus(&eventBus_);
|
||||
auto musicResult = musicManager_->initialize(networkClient_, database_);
|
||||
if (!musicResult) {
|
||||
return std::unexpected(musicResult.error());
|
||||
@@ -307,8 +307,7 @@ namespace Echoion::Core
|
||||
}
|
||||
registry_.provide<Api::ConfigManager>(
|
||||
alias(&Api::ConfigManager::instance()));
|
||||
registry_.provide<Api::EventBus>(
|
||||
alias(&Api::GlobalEventBus::instance()));
|
||||
registry_.provide<Void::EventBus::EventBus>(alias(&eventBus_));
|
||||
if (networkClient_) {
|
||||
registry_.provide<Api::INetworkClient>(networkClient_);
|
||||
}
|
||||
@@ -395,8 +394,8 @@ namespace Echoion::Core
|
||||
database_.reset();
|
||||
}
|
||||
|
||||
// Stop EventBus
|
||||
Api::GlobalEventBus::instance().stop();
|
||||
// Drain any in-flight event dispatch.
|
||||
eventBus_.flush();
|
||||
ECHOION_LOG_INFO("EventBus stopped");
|
||||
|
||||
// Clear callbacks
|
||||
@@ -1796,13 +1795,13 @@ namespace Echoion::Core
|
||||
ECHOION_LOG_INFO("RPC handlers registered");
|
||||
}
|
||||
|
||||
void Core::setupEventBusSubscriptions() const noexcept
|
||||
void Core::setupEventBusSubscriptions() noexcept
|
||||
{
|
||||
using namespace Api::Events;
|
||||
|
||||
// Subscribe to playback events for RPC broadcasting and database
|
||||
// persistence
|
||||
Api::GlobalEventBus::instance().subscribe<PlaybackStarted>(
|
||||
eventBus_.subscribe<PlaybackStarted>(
|
||||
[this](const PlaybackStarted& evt) mutable {
|
||||
// Broadcast to RPC/WebSocket clients
|
||||
if (rpcServer_) {
|
||||
@@ -1822,7 +1821,7 @@ namespace Echoion::Core
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<PlaybackPaused>(
|
||||
eventBus_.subscribe<PlaybackPaused>(
|
||||
[this](const PlaybackPaused& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data = std::format("{{\"position\":{}}}",
|
||||
@@ -1831,7 +1830,7 @@ namespace Echoion::Core
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<PlaybackResumed>(
|
||||
eventBus_.subscribe<PlaybackResumed>(
|
||||
[this](const PlaybackResumed& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data = std::format("{{\"position\":{}}}",
|
||||
@@ -1840,14 +1839,14 @@ namespace Echoion::Core
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<PlaybackStopped>(
|
||||
eventBus_.subscribe<PlaybackStopped>(
|
||||
[this](const PlaybackStopped& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
rpcServer_->broadcastEvent("playback.stopped", "{}");
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<PlaybackPositionChanged>(
|
||||
eventBus_.subscribe<PlaybackPositionChanged>(
|
||||
[this](const PlaybackPositionChanged& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data =
|
||||
@@ -1859,7 +1858,7 @@ namespace Echoion::Core
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<TrackFinished>(
|
||||
eventBus_.subscribe<TrackFinished>(
|
||||
[this](const TrackFinished& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
rpcServer_->broadcastEvent("playback.finished", "{}");
|
||||
@@ -1873,7 +1872,7 @@ namespace Echoion::Core
|
||||
});
|
||||
|
||||
// Volume and playback mode changes
|
||||
Api::GlobalEventBus::instance().subscribe<VolumeChanged>(
|
||||
eventBus_.subscribe<VolumeChanged>(
|
||||
[this](const VolumeChanged& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data =
|
||||
@@ -1882,7 +1881,7 @@ namespace Echoion::Core
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<ShuffleChanged>(
|
||||
eventBus_.subscribe<ShuffleChanged>(
|
||||
[this](const ShuffleChanged& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data = std::format(
|
||||
@@ -1891,7 +1890,7 @@ namespace Echoion::Core
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<RepeatChanged>(
|
||||
eventBus_.subscribe<RepeatChanged>(
|
||||
[this](const RepeatChanged& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data = std::format(
|
||||
@@ -1901,7 +1900,7 @@ namespace Echoion::Core
|
||||
});
|
||||
|
||||
// Queue events
|
||||
Api::GlobalEventBus::instance().subscribe<TrackQueued>(
|
||||
eventBus_.subscribe<TrackQueued>(
|
||||
[this](const TrackQueued& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data = std::format(
|
||||
@@ -1913,7 +1912,7 @@ namespace Echoion::Core
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<TrackRemoved>(
|
||||
eventBus_.subscribe<TrackRemoved>(
|
||||
[this](const TrackRemoved& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data =
|
||||
@@ -1923,14 +1922,14 @@ namespace Echoion::Core
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<QueueCleared>(
|
||||
eventBus_.subscribe<QueueCleared>(
|
||||
[this](const QueueCleared& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
rpcServer_->broadcastEvent("queue.cleared", "{}");
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<QueueReordered>(
|
||||
eventBus_.subscribe<QueueReordered>(
|
||||
[this](const QueueReordered& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data = std::format(
|
||||
@@ -1942,7 +1941,7 @@ namespace Echoion::Core
|
||||
});
|
||||
|
||||
// Playlist events - save to database via event bus using external ID
|
||||
Api::GlobalEventBus::instance().subscribe<PlaylistLoadStarted>(
|
||||
eventBus_.subscribe<PlaylistLoadStarted>(
|
||||
[this](const PlaylistLoadStarted& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data = std::string("{\"playlistId\":\"") +
|
||||
@@ -1957,7 +1956,7 @@ namespace Echoion::Core
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<PlaylistTrackLoaded>(
|
||||
eventBus_.subscribe<PlaylistTrackLoaded>(
|
||||
[this](const PlaylistTrackLoaded& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data =
|
||||
@@ -1979,7 +1978,7 @@ namespace Echoion::Core
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<PlaylistLoadCompleted>(
|
||||
eventBus_.subscribe<PlaylistLoadCompleted>(
|
||||
[this](const PlaylistLoadCompleted& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data =
|
||||
@@ -1993,7 +1992,7 @@ namespace Echoion::Core
|
||||
});
|
||||
|
||||
// Subscription events
|
||||
Api::GlobalEventBus::instance().subscribe<UserSubscribed>(
|
||||
eventBus_.subscribe<UserSubscribed>(
|
||||
[this](const UserSubscribed& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data =
|
||||
@@ -2003,7 +2002,7 @@ namespace Echoion::Core
|
||||
}
|
||||
});
|
||||
|
||||
Api::GlobalEventBus::instance().subscribe<UserUnsubscribed>(
|
||||
eventBus_.subscribe<UserUnsubscribed>(
|
||||
[this](const UserUnsubscribed& evt) mutable {
|
||||
if (rpcServer_) {
|
||||
std::string data =
|
||||
|
||||
Reference in new issue
Block a user