#pragma once // M9.8c host-side ownership of the launcher phase together with the remote session, // so the visible mode and the session lifetime cannot diverge (ADR-0084). Entering the // local fixture, cancelling or failing drops the session at once: no retries, grant use // or intentions continue behind a LOCAL FIXTURE banner. Dropping a session leaves its // unresolved intentions unknown. `Session` provides // step(time_point, const Intention&, UiState&, Launcher&). #include "evo/client/input.hpp" #include "evo/client/launcher.hpp" #include "evo/client/ui_state.hpp" #include #include #include namespace evo::client { template class SessionHost { public: [[nodiscard]] const Launcher& launcher() const noexcept { return launcher_; } [[nodiscard]] Session* session() noexcept { return session_ ? &*session_ : nullptr; } [[nodiscard]] const Session* session() const noexcept { return session_ ? &*session_ : nullptr; } // Adopts a freshly opened session (from choosing or failed). Any previous session // is dropped first; on refusal no session remains. [[nodiscard]] bool connect(std::optional opened) { session_.reset(); if (!opened || !launcher_.begin_connect()) return false; session_.emplace(std::move(*opened)); return true; } void enter_fixture() noexcept { session_.reset(); launcher_.start_fixture(); } void cancel() noexcept { session_.reset(); launcher_.cancel(); } // Services the session only while connecting or connected; a failure observed // during the step ends it immediately (Retry opens a new one). void step(std::chrono::steady_clock::time_point now, const Intention& intention, UiState& ui) { if (session_ && live()) session_->step(now, intention, ui, launcher_); if (!live()) session_.reset(); } private: [[nodiscard]] bool live() const noexcept { return launcher_.phase() == LaunchPhase::connecting || launcher_.phase() == LaunchPhase::connected; } Launcher launcher_; std::optional session_; }; } // namespace evo::client