LCOV - code coverage report
Current view: top level - src - sumo_main.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 76.1 % 46 35
Test Date: 2024-11-20 15:55:46 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    sumo_main.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Axel Wegener
      18              : /// @author  Thimor Bohn
      19              : /// @author  Michael Behrisch
      20              : /// @date    Tue, 20 Nov 2001
      21              : ///
      22              : // Main for SUMO
      23              : /****************************************************************************/
      24              : #include <config.h>
      25              : 
      26              : #ifdef HAVE_VERSION_H
      27              : #include <version.h>
      28              : #endif
      29              : 
      30              : #include <csignal>
      31              : #include <netload/NLBuilder.h>
      32              : #include <utils/common/MsgHandler.h>
      33              : #include <utils/common/SystemFrame.h>
      34              : #include <utils/options/OptionsIO.h>
      35              : #include <utils/xml/XMLSubSys.h>
      36              : #include <traci-server/TraCIServer.h>
      37              : 
      38              : 
      39              : // ===========================================================================
      40              : // functions
      41              : // ===========================================================================
      42              : void
      43           15 : signalHandler(int signum) {
      44           15 :     if (MSNet::hasInstance()) {
      45           15 :         switch (signum) {
      46           15 :             case SIGINT:
      47              :             case SIGTERM:
      48           15 :                 if (MSNet::getInstance()->isInterrupted()) {
      49            0 :                     std::cout << TL("Another interrupt signal received, hard exit.") << std::endl;
      50            0 :                     exit(signum);
      51              :                 }
      52           15 :                 std::cout << TL("Interrupt signal received, trying to exit gracefully.") << std::endl;
      53           15 :                 MSNet::getInstance()->interrupt();
      54              :                 break;
      55              : #ifndef WIN32
      56              :             case SIGUSR1:
      57            0 :                 std::cout << "Step #" << SIMSTEP << std::endl;
      58            0 :                 std::cout << MSNet::getInstance()->generateStatistics(string2time(OptionsCont::getOptions().getString("begin")),
      59              :                           SysUtils::getCurrentMillis()) << std::endl;
      60            0 :                 break;
      61              :             case SIGUSR2:
      62              :                 //TODO reload sim
      63              :                 break;
      64              : #endif
      65              :             default:
      66              :                 break;
      67              :         }
      68              :     }
      69           15 : }
      70              : 
      71              : 
      72              : /* -------------------------------------------------------------------------
      73              :  * main
      74              :  * ----------------------------------------------------------------------- */
      75              : int
      76        35298 : main(int argc, char** argv) {
      77        35298 :     signal(SIGINT, signalHandler);
      78        35298 :     signal(SIGTERM, signalHandler);
      79              : #ifndef WIN32
      80        35298 :     signal(SIGUSR1, signalHandler);
      81        35298 :     signal(SIGUSR2, signalHandler);
      82              : #endif
      83              : 
      84        35298 :     OptionsCont& oc = OptionsCont::getOptions();
      85              :     // give some application descriptions
      86        35298 :     oc.setApplicationDescription(TL("A microscopic, multi-modal traffic simulation."));
      87        70596 :     oc.setApplicationName("sumo", "Eclipse SUMO sumo Version " VERSION_STRING);
      88        35298 :     gSimulation = true;
      89              :     int ret = 0;
      90              :     MSNet* net = nullptr;
      91              :     try {
      92              :         // initialise subsystems
      93        35298 :         XMLSubSys::init();
      94        35298 :         OptionsIO::setArgs(argc, argv);
      95              :         // load the net
      96              :         MSNet::SimulationState state = MSNet::SIMSTATE_LOADING;
      97        65997 :         while (state == MSNet::SIMSTATE_LOADING) {
      98        35311 :             net = NLBuilder::init();
      99        31265 :             if (net != nullptr) {
     100        62032 :                 state = net->simulate(string2time(oc.getString("begin")), string2time(oc.getString("end")));
     101        30699 :                 delete net;
     102              :             } else {
     103              :                 break;
     104              :             }
     105              :             // flush warnings and prepare reinit of all outputs
     106        30699 :             MsgHandler::getWarningInstance()->clear();
     107        30699 :             OutputDevice::closeAll();
     108        30699 :             MsgHandler::cleanupOnEnd();
     109              :         }
     110         4363 :     } catch (const ProcessError& e) {
     111        10677 :         if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
     112         6272 :             WRITE_ERROR(e.what());
     113              :         }
     114         4363 :         MsgHandler::getErrorInstance()->inform(TL("Quitting (on error)."), false);
     115              :         // we need to delete the network explicitly to trigger the cleanup in the correct order
     116         4363 :         delete net;
     117              :         ret = 1;
     118              : #ifndef _DEBUG
     119         4363 :     } catch (const std::exception& e) {
     120            0 :         if (std::string(e.what()) != std::string("")) {
     121            0 :             WRITE_ERROR(e.what());
     122              :         }
     123            0 :         MsgHandler::getErrorInstance()->inform(TL("Quitting (on error)."), false);
     124              :         ret = 1;
     125            0 :     } catch (...) {
     126            0 :         MsgHandler::getErrorInstance()->inform(TL("Quitting (on unknown error)."), false);
     127              :         ret = 1;
     128              : #endif
     129            0 :     }
     130        35298 :     TraCIServer::close();
     131        35298 :     SystemFrame::close();
     132              :     return ret;
     133              : }
     134              : 
     135              : 
     136              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1