/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * \file poolworker_main.cpp * * This file strongly follows the Serialization example from the boost::asio * library (see client.cpp) * * Created on: Feb 28, 2012 * 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 #include #include "CodePatterns/Info.hpp" #include "CodePatterns/Log.hpp" #include "atexit.hpp" #include "Pool/PoolWorker.hpp" #include "Jobs/SystemCommandJob.hpp" #include "SignalHandler.hpp" #include "WorkerOptions.hpp" int poolworker_main(int argc, char* argv[]) { // from this moment on, we need to be sure to deeinitialize in the correct order // this is handled by the cleanup function atexit(cleanUp); WorkerOptions WorkerOpts; boost::program_options::variables_map vm; // 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)") ("server", boost::program_options::value< std::string>(), "connect to server at this address (host:port)") ("listen", boost::program_options::value< std::string >(), "listen on this port") ("hostname", boost::program_options::value< std::string>(), "name of host on which this codes runs and which server can resolve") ; boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); boost::program_options::notify(vm); int status = 0; status = WorkerOpts.parseHelp(vm, desc); if (status) return status; status = WorkerOpts.parseVerbosity(vm); if (status) return status; status = WorkerOpts.parseServer(vm); if (status) return status; status = WorkerOpts.parseListenPort(vm); if (status) return status; status = WorkerOpts.parseLocalhost(vm); if (status) return status; status = WorkerOpts.parseSignals(vm); if (status) return status; size_t exitflag = 0; try { boost::asio::io_service io_service; PoolWorker client(io_service, WorkerOpts.server, WorkerOpts.serverport, WorkerOpts.hostname, WorkerOpts.listenport); // catch ctrl-c and shutdown worker properly boost::function shutdownfunction = boost::bind(&PoolWorker::shutdown, boost::ref(client), _1); SignalHandler signalhandler(shutdownfunction, WorkerOpts.signals); // process io requests { Info info("io_service"); io_service.run(); } exitflag = client.getFlag(); } catch (std::exception& e) { std::cerr << e.what() << std::endl; } return exitflag; }