Commit 0c9599fa authored by fmg005's avatar fmg005

added keyboard interrupt handler

parent 64f93d58
......@@ -100,6 +100,26 @@ void Simulation(const string patient_name, const std::shared_ptr<Config>& cfg)
/* prosim hardware */
HardwareSimulator prosim(logger, &myserial, sim_env, my_pumps);
prosim.LoadConfig(pe);
/*handle keyboard interrupt*/
interrupt_handler = [&logger, &prosim](int sig) {
logger->error("Keyboard interruption, simulation exited");
prosim.SetLocalMode();
exit(EXIT_FAILURE);
};
struct sigaction act;
/*set handler in act struct*/
act.sa_handler = [](int sig){ interrupt_handler(sig);};
/* set the sa_mask to empty
* i.e.no signal will be blocked while handler is running.
*/
sigemptyset(&act.sa_mask);
/* make sure there are no flags bits set*/
act.sa_flags = 0;
/* process the SIGINT->keyboard when it occurs */
sigaction(SIGINT, &act, 0);
/* end handle keyboard interrupt */
prosim.SetRemoteMode(); /* switch remote mode */
// stop when the set time is reached
while (sim_env.time_index <= sim_env.simulation_timesteps ) {
......
......@@ -4,11 +4,14 @@
#include "configure_prosim_paths.h"
#include <libconfig.h++>
#include <functional>
#include <signal.h>
using namespace libconfig;
void Simulation(const std::string, const std::shared_ptr<Config>&);
void Global_LoadConfig( std::shared_ptr<CLA::LOGGER>&, std::unique_ptr<PhysiologyEngine>&,
const std::shared_ptr<Config>&, CLA::Environment&);
std::function <void(int)> interrupt_handler;
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment