ARGoS  3
A parallel, multi-engine simulator for swarm robotics
core/simulator/main.cpp
Go to the documentation of this file.
00001 
00007 #include <argos3/core/simulator/simulator.h>
00008 #include <argos3/core/utility/plugins/dynamic_loading.h>
00009 #include <argos3/core/simulator/query_plugins.h>
00010 #include <argos3/core/simulator/argos_command_line_arg_parser.h>
00011 
00012 using namespace argos;
00013 
00025 int main(int n_argc, char** ppch_argv) {
00026    try {
00027       /* Create a new instance of the simulator */
00028       CSimulator& cSimulator = CSimulator::GetInstance();
00029       /* Configure the command line options */
00030       CARGoSCommandLineArgParser cACLAP;
00031       /* Parse command line */
00032       cACLAP.Parse(n_argc, ppch_argv);
00033       switch(cACLAP.GetAction()) {
00034          case CARGoSCommandLineArgParser::ACTION_RUN_EXPERIMENT:
00035             CDynamicLoading::LoadAllLibraries();
00036             cSimulator.SetExperimentFileName(cACLAP.GetExperimentConfigFile());
00037             cSimulator.LoadExperiment();
00038             cSimulator.Execute();
00039             break;
00040          case CARGoSCommandLineArgParser::ACTION_QUERY:
00041             CDynamicLoading::LoadAllLibraries();
00042             QueryPlugins(cACLAP.GetQuery());
00043             break;
00044          case CARGoSCommandLineArgParser::ACTION_SHOW_HELP:
00045             cACLAP.PrintUsage(LOG);
00046             break;
00047          case CARGoSCommandLineArgParser::ACTION_SHOW_VERSION:
00048             cACLAP.PrintVersion();
00049             break;
00050          case CARGoSCommandLineArgParser::ACTION_UNKNOWN:
00051             /* Should never get here */
00052             break;
00053       }
00054       /* Done, destroy stuff */
00055       cSimulator.Destroy();
00056       CDynamicLoading::UnloadAllLibraries();
00057    }
00058    catch(std::exception& ex) {
00059       /* A fatal error occurred: dispose of data, print error and exit */
00060       LOGERR << ex.what() << std::endl;
00061 #ifdef ARGOS_THREADSAFE_LOG
00062       LOG.Flush();
00063       LOGERR.Flush();
00064 #endif
00065       return 1;
00066    }
00067    /* Everything's ok, exit */
00068    return 0;
00069 }