Decompose Core: split RPC/event setup into files + dedupe init guards

Move Core::setupRpcHandlers (→ CoreRpcHandlers.cpp) and
Core::setupEventBusSubscriptions (→ CoreEventRelay.cpp) out of the
2100-line Core.cpp (now ~1535). They stay Core member functions —
definitions live in dedicated translation units — which gives the
file-decomposition without a risky 500-line this→core rewrite into separate
classes. The RpcAuthRequest struct moves to RpcDtos.hpp as Dto::AuthRequest;
the toJson<T> helper also moves there so both units share it.

Add Core::requireInitialized() and collapse the 28 identical
`if (!initialized_) return fail(ServiceUnavailable,…)` guards into
`if (auto r = requireInitialized(); !r) return std::unexpected(r.error());`.

Build green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-24 00:26:26 +03:00
1 parent 0779fdcf20
commit 30884ad0b5
5 files changed
+604 -585

No files matched your search

+3
View File
@@ -162,6 +162,9 @@ namespace Echoion::Core
// the global Void::Log sink (logSink_ must outlive logging).
void installLogging();
// Guard helper: ok if initialized, else a ServiceUnavailable error.
[[nodiscard]] Api::Result<void> requireInitialized() const noexcept;
// Components
std::shared_ptr<NetworkClient> networkClient_;
std::shared_ptr<MusicManager> musicManager_;
+18
View File
@@ -1,17 +1,35 @@
#pragma once
#include <TrackTypes.hpp>
#include <Void/Data/Json.hpp>
#include <Void/Data/Reflect.hpp>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
namespace Echoion::Core
{
// Serialize any reflectable DTO to a JSON string (correct escaping).
template <typename T> [[nodiscard]] std::string toJson(const T& dto)
{
return Void::Json::serialize(Void::Json::to_json(dto));
}
} // namespace Echoion::Core
// Reflectable DTOs for the RPC responses and event-broadcast payloads. These
// are serialized with Void::Json (reflection) instead of hand-built strings,
// so member names are the JSON keys and values are always correctly escaped.
namespace Echoion::Core::Dto
{
// ── RPC request payloads (parsed) ───────────────────────────────────────
struct AuthRequest {
std::optional<std::string> nickname;
std::optional<std::string> token;
};
// ── RPC handler responses ───────────────────────────────────────────────
struct Track {