35 #define BOOST_ALLOW_DEPRECATED_HEADERS 37 #include <boost/lexical_cast.hpp> 38 #include <boost/uuid/uuid_generators.hpp> 39 #include <boost/uuid/uuid_io.hpp> 54 std::ostream& output = std::cout;
55 std::ostream& error = std::cerr;
62 bool allow_empty =
false;
63 bool write_output =
true;
64 bool require_success =
false;
65 bool report_progress =
true;
68 Simulation* GLOBAL_SIMULATION_INSTANCE{
nullptr};
70 template <
typename Func>
71 auto handle_cloe_error(std::ostream& out, Func f) -> decltype(f()) {
75 out <<
"Error: " << e.what() << std::endl;
76 if (e.has_explanation()) {
77 out <<
" Note:\n" << fable::indent_string(e.explanation(),
" ") << std::endl;
83 inline int run(
const RunOptions& opt,
const std::vector<std::string>& filepaths) {
84 cloe::logger::get(
"cloe")->info(
"Cloe {}", CLOE_ENGINE_VERSION);
89 if (!opt.uuid.empty()) {
91 }
else if (std::getenv(CLOE_SIMULATION_UUID_VAR) !=
nullptr) {
92 uuid = std::getenv(CLOE_SIMULATION_UUID_VAR);
94 uuid = boost::lexical_cast<std::string>(boost::uuids::random_generator()());
96 stack_opt.environment->set(CLOE_SIMULATION_UUID_VAR, uuid);
101 handle_cloe_error(*stack_opt.error, [&]() {
102 s = cloe::new_stack(stack_opt, filepaths);
103 if (!opt.allow_empty) {
104 s.check_completeness();
113 GLOBAL_SIMULATION_INSTANCE = ∼
120 auto result = handle_cloe_error(*stack_opt.error, [&]() { return sim.run(); });
121 if (result.outcome == SimulationOutcome::NoStart) {
128 if (opt.write_output) {
131 opt.output << cloe::Json(result).dump(opt.json_indent) << std::endl;
133 switch (result.outcome) {
134 case SimulationOutcome::Success:
135 return EXIT_OUTCOME_SUCCESS;
136 case SimulationOutcome::Stopped:
137 return (opt.require_success ? EXIT_OUTCOME_STOPPED : EXIT_OUTCOME_SUCCESS);
138 case SimulationOutcome::Aborted:
139 return EXIT_OUTCOME_ABORTED;
140 case SimulationOutcome::NoStart:
141 return EXIT_OUTCOME_NOSTART;
142 case SimulationOutcome::Failure:
143 return EXIT_OUTCOME_FAILURE;
145 return EXIT_OUTCOME_UNKNOWN;
165 static size_t interrupts = 0;
173 std::cerr << std::endl;
174 if (++interrupts == 3) {
175 std::signal(sig, SIG_DFL);
177 if (GLOBAL_SIMULATION_INSTANCE) {
size_t write_output(const SimulationResult &) const
Definition: simulation.cpp:1308
Definition: main_stack.hpp:38
void set_report_progress(bool value)
Definition: simulation.hpp:138
Definition: stack.hpp:888
Definition: coordinator.cpp:39
Definition: simulation.hpp:102
void handle_signal(int)
Definition: main_run.hpp:164
void signal_abort()
Definition: simulation.cpp:1384
Definition: main_run.hpp:52