[f7f995] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2011-2012 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * \file Server.cpp
|
---|
| 10 | *
|
---|
| 11 | * This file strongly follows the Serialization example from the boost::asio
|
---|
| 12 | * library (see server.cpp)
|
---|
| 13 | *
|
---|
| 14 | * Created on: Oct 21, 2011
|
---|
| 15 | * Author: heber
|
---|
| 16 | */
|
---|
| 17 |
|
---|
| 18 | // include config.h
|
---|
| 19 | #ifdef HAVE_CONFIG_H
|
---|
| 20 | #include <config.h>
|
---|
| 21 | #endif
|
---|
| 22 |
|
---|
| 23 | // boost asio needs specific operator new
|
---|
| 24 | #include <boost/asio.hpp>
|
---|
| 25 |
|
---|
| 26 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 27 |
|
---|
| 28 | #include <boost/lexical_cast.hpp>
|
---|
[684bc1] | 29 | #include <boost/program_options.hpp>
|
---|
[f7f995] | 30 | #include <iostream>
|
---|
| 31 |
|
---|
| 32 | #include "atexit.hpp"
|
---|
| 33 | #include "CodePatterns/Info.hpp"
|
---|
[630a6e] | 34 | #include "CodePatterns/Log.hpp"
|
---|
[f7f995] | 35 | #include "FragmentScheduler.hpp"
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | int main(int argc, char* argv[])
|
---|
| 39 | {
|
---|
| 40 | // from this moment on, we need to be sure to deinitialize in the correct order
|
---|
| 41 | // this is handled by the cleanup function
|
---|
| 42 | atexit(cleanUp);
|
---|
| 43 |
|
---|
[684bc1] | 44 | // Declare the supported options.
|
---|
| 45 | boost::program_options::options_description desc("Allowed options");
|
---|
| 46 | desc.add_options()
|
---|
| 47 | ("help,h", "produce help message")
|
---|
| 48 | ("verbosity,v", boost::program_options::value<size_t>(), "set verbosity level")
|
---|
| 49 | ("workerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting workers")
|
---|
| 50 | ("controllerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting controller")
|
---|
| 51 | ;
|
---|
| 52 |
|
---|
| 53 | boost::program_options::variables_map vm;
|
---|
| 54 | boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
|
---|
| 55 | boost::program_options::notify(vm);
|
---|
| 56 |
|
---|
| 57 | if (vm.count("help")) {
|
---|
| 58 | std::cout << desc << "\n";
|
---|
| 59 | return 1;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | if (vm.count("verbosity")) {
|
---|
| 63 | LOG(0, "STATUS: Verbosity level was set to " << vm["verbosity"].as<size_t>() << ".");
|
---|
| 64 | setVerbosity(vm["verbosity"].as<size_t>());
|
---|
| 65 | } else {
|
---|
| 66 | LOG(0, "STATUS: Verbosity level was not set, defaulting to 3.");
|
---|
| 67 | setVerbosity(3);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | unsigned short workerport;
|
---|
| 71 | if (vm.count("workerport")) {
|
---|
| 72 | try {
|
---|
| 73 | workerport = vm["workerport"].as< unsigned short >();
|
---|
| 74 | } catch (boost::bad_lexical_cast) {
|
---|
| 75 | ELOG(1, "Could not read " << workerport << " as digits.");
|
---|
| 76 | return 255;
|
---|
| 77 | }
|
---|
| 78 | LOG(1, "INFO: Using " << workerport << " as listen port for worker.");
|
---|
| 79 | } else {
|
---|
| 80 | ELOG(1, "Requiring listen port for worker.");
|
---|
| 81 | return 255;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | unsigned short controllerport;
|
---|
| 85 | if (vm.count("controllerport")) {
|
---|
| 86 | try {
|
---|
| 87 | controllerport = vm["controllerport"].as< unsigned short >();
|
---|
| 88 | } catch (boost::bad_lexical_cast) {
|
---|
| 89 | ELOG(1, "Could not read " << controllerport << " as digits.");
|
---|
| 90 | return 255;
|
---|
| 91 | }
|
---|
| 92 | LOG(1, "INFO: Using " << controllerport << " as listen port for controller.");
|
---|
| 93 | } else {
|
---|
| 94 | ELOG(1, "Requiring listen port for controller.");
|
---|
| 95 | return 255;
|
---|
| 96 | }
|
---|
[630a6e] | 97 |
|
---|
[db03d9] | 98 | size_t Exitflag = 0;
|
---|
[f7f995] | 99 | try
|
---|
| 100 | {
|
---|
| 101 | boost::asio::io_service io_service;
|
---|
[db03d9] | 102 | FragmentScheduler Server(io_service, workerport, controllerport);
|
---|
[f7f995] | 103 | {
|
---|
| 104 | Info info("io_service");
|
---|
| 105 | io_service.run();
|
---|
| 106 | }
|
---|
[db03d9] | 107 | Exitflag = Server.getExitflag();
|
---|
[f7f995] | 108 | }
|
---|
| 109 | catch (std::exception& e)
|
---|
| 110 | {
|
---|
| 111 | std::cerr << e.what() << std::endl;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[db03d9] | 114 | return Exitflag;
|
---|
[f7f995] | 115 | }
|
---|