1818#pragma once
1919
2020#include < cstddef>
21+ #include < functional>
2122#include < type_traits>
2223
2324#include " scl/simulation/event.h"
@@ -40,7 +41,8 @@ class SimulatorContext final {
4041 static SimulatorContext create (
4142 std::size_t number_of_parties,
4243 NetworkParams network_params,
43- std::vector<Simulator::SimulationHook>&& hooks);
44+ std::vector<Simulator::SimulationHook>&& hooks,
45+ std::optional<Simulator::OutputHandler>&& output_handler);
4446
4547 /* *
4648 * @brief Get the context of a particular party in the simulation.
@@ -62,6 +64,15 @@ class SimulatorContext final {
6264 }
6365 }
6466
67+ /* *
68+ * @brief Handle a protocol output.
69+ */
70+ void handleOutput (std::size_t pid, std::any output) {
71+ if (m_output_handler.has_value ()) {
72+ m_output_handler.value ()(pid, output);
73+ }
74+ }
75+
6576 /* *
6677 * @brief Start the clock of party.
6778 */
@@ -97,6 +108,9 @@ class SimulatorContext final {
97108 return m_number_of_parties;
98109 }
99110
111+ /* *
112+ * @brief Extract result of a simulation.
113+ */
100114 Simulator::Result toResult () {
101115 return Simulator::Result{std::move (m_events)};
102116 }
@@ -107,6 +121,8 @@ class SimulatorContext final {
107121 std::vector<EventList> m_events;
108122 std::vector<Time::TimePoint> m_clocks;
109123 std::vector<Simulator::SimulationHook> m_hooks;
124+ std::optional<Simulator::OutputHandler> m_output_handler;
125+ std::vector<bool > m_cancellation_map;
110126
111127 SimulatorContext (NetworkParams network_params)
112128 : m_network_params(network_params) {}
@@ -148,6 +164,13 @@ class Context {
148164 m_ctx.startClock (m_id);
149165 }
150166
167+ /* *
168+ * @brief Handle a protocol output.
169+ */
170+ void output (std::any output) {
171+ m_ctx.handleOutput (m_id, output);
172+ }
173+
151174 /* *
152175 * @brief Append an event to this party's list of events.
153176 */
0 commit comments