#include <config.h>
#ifdef HAVE_VERSION_H
#include <version.h>
#endif
#include <csignal>
#include <netload/NLBuilder.h>
#include <utils/common/MsgHandler.h>
#include <utils/common/SystemFrame.h>
#include <utils/options/OptionsIO.h>
#include <utils/xml/XMLSubSys.h>
#include <traci-server/TraCIServer.h>
void
signalHandler(int signum) {
if (MSNet::hasInstance()) {
switch (signum) {
case SIGINT:
case SIGTERM:
if (MSNet::getInstance()->isInterrupted()) {
std::cout << TL("Another interrupt signal received, hard exit.") << std::endl;
exit(signum);
}
std::cout << TL("Interrupt signal received, trying to exit gracefully.") << std::endl;
MSNet::getInstance()->interrupt();
break;
#ifndef WIN32
case SIGUSR1:
std::cout << "Step #" << SIMSTEP << std::endl;
std::cout << MSNet::getInstance()->generateStatistics(string2time(OptionsCont::getOptions().getString("begin")),
SysUtils::getCurrentMillis()) << std::endl;
break;
case SIGUSR2:
break;
#endif
default:
break;
}
}
}
int
main(int argc, char** argv) {
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
#ifndef WIN32
signal(SIGUSR1, signalHandler);
signal(SIGUSR2, signalHandler);
#endif
OptionsCont& oc = OptionsCont::getOptions();
oc.setApplicationDescription(TL("A microscopic, multi-modal traffic simulation."));
oc.setApplicationName("sumo", "Eclipse SUMO sumo " VERSION_STRING);
gSimulation = true;
int ret = 0;
MSNet* net = nullptr;
try {
XMLSubSys::init();
OptionsIO::setArgs(argc, argv);
MSNet::SimulationState state = MSNet::SIMSTATE_LOADING;
while (state == MSNet::SIMSTATE_LOADING) {
net = NLBuilder::init();
if (net != nullptr) {
state = net->simulate(string2time(oc.getString("begin")), string2time(oc.getString("end")));
delete net;
} else {
break;
}
MsgHandler::getWarningInstance()->clear();
OutputDevice::closeAll();
MsgHandler::cleanupOnEnd();
}
} catch (const ProcessError& e) {
if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
WRITE_ERROR(e.what());
}
MsgHandler::getErrorInstance()->inform(TL("Quitting (on error)."), false);
delete net;
ret = 1;
#ifndef _DEBUG
} catch (const std::exception& e) {
if (std::string(e.what()) != std::string("")) {
WRITE_ERROR(e.what());
}
MsgHandler::getErrorInstance()->inform(TL("Quitting (on error)."), false);
ret = 1;
} catch (...) {
MsgHandler::getErrorInstance()->inform(TL("Quitting (on unknown error)."), false);
ret = 1;
#endif
}
TraCIServer::close();
SystemFrame::close();
return ret;
}