X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Fengineer.cpp;h=6a35a06a3317992dae0075dece5eecfe72e43ddd;hb=e60fdcb9617f539b4d578d06ec46eb955c5e0624;hp=308e5b2d4db0e80437a790ac7cbd1bf8ae38075c;hpb=4d84248a4990e913a56f013e67a608ad9698233e;p=r2c2.git diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 308e5b2..6a35a06 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -7,6 +7,7 @@ Distributed under the GPL #include #include +#include #include #include #include @@ -17,6 +18,7 @@ Distributed under the GPL #include #include #include +#include #include #include #include @@ -105,10 +107,24 @@ Engineer::Engineer(int argc, char **argv): i->second->signal_state_changed.connect(sigc::bind(sigc::mem_fun(this, &Engineer::sensor_event), i->second)); view_all(); + + catch_signal(SIGINT); + catch_signal(SIGTERM); + catch_signal(SIGSEGV); + catch_signal(SIGILL); + catch_signal(SIGFPE); + catch_signal(SIGABRT); } Engineer::~Engineer() { + const list &trains = trfc_mgr->get_trains(); + for(list::const_iterator i=trains.begin(); i!=trains.end(); ++i) + (*i)->set_speed(0); + + while(control.get_queue_length()) + control.tick(); + if(!simulate) trfc_mgr->save("engineer.state"); delete trfc_mgr; @@ -501,4 +517,20 @@ void Engineer::train_added(Train &train) place_train(train); } +void Engineer::sighandler(int sig) +{ + if(sig==SIGSEGV || sig==SIGILL || sig==SIGFPE || sig==SIGABRT) + { + signal(sig, SIG_DFL); + IO::print(IO::cerr, "Fatal signal received, terminating\n"); + const map &locos = control.get_locomotives(); + for(map::const_iterator i=locos.begin(); i!=locos.end(); ++i) + i->second->set_speed(0); + control.flush(); + raise(sig); + } + else if(sig==SIGTERM || sig==SIGINT) + exit(0); +} + Application::RegApp Engineer::reg;