/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2011-2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * \file server_main.cpp * * This file strongly follows the Serialization example from the boost::asio * library (see server.cpp) * * Created on: Oct 21, 2011 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif // boost asio needs specific operator new #include #include "CodePatterns/MemDebug.hpp" #include #include #include "CodePatterns/Info.hpp" #include "CodePatterns/Log.hpp" #include "atexit.hpp" #include "FragmentScheduler.hpp" #include "Jobs/SystemCommandJob.hpp" #include "ServerOptions.hpp" #include "SignalHandler.hpp" int server_main(int argc, char* argv[]) { // from this moment on, we need to be sure to deinitialize in the correct order // this is handled by the cleanup function atexit(cleanUp); ServerOptions ServerOpts; // Declare the supported options. boost::program_options::options_description desc("Allowed options"); desc.add_options() ("help,h", "produce help message") ("verbosity,v", boost::program_options::value(), "set verbosity level") ("signal", boost::program_options::value< std::vector >(), "set signal to catch (can be given multiple times)") ("workerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting workers") ("controllerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting controller") ; boost::program_options::variables_map vm; boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); boost::program_options::notify(vm); int status = 0; status = ServerOpts.parseHelp(vm, desc); if (status) return status; status = ServerOpts.parseVerbosity(vm); if (status) return status; status = ServerOpts.parseWorkerPort(vm); if (status) return status; status = ServerOpts.parseControllerPort(vm); if (status) return status; status = ServerOpts.parseSignals(vm); if (status) return status; size_t Exitflag = 0; try { boost::asio::io_service io_service; FragmentScheduler Server(io_service, ServerOpts.workerport, ServerOpts.controllerport); // catch ctrl-c and shutdown worker properly boost::function shutdownfunction = boost::bind(&FragmentScheduler::shutdown, boost::ref(Server), _1); SignalHandler signalhandler(shutdownfunction, ServerOpts.signals); { Info info("io_service"); io_service.run(); } Exitflag = Server.getExitflag(); } catch (std::exception& e) { std::cerr << e.what() << std::endl; } return Exitflag; }