[6c52d2] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 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 | * WorkerOptions.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: 01.06.2012
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 21 |
|
---|
| 22 | #include "WorkerOptions.hpp"
|
---|
| 23 |
|
---|
| 24 | #include <unistd.h>
|
---|
| 25 |
|
---|
| 26 | #include "CodePatterns/Log.hpp"
|
---|
| 27 |
|
---|
| 28 | int WorkerOptions::parseServer(boost::program_options::variables_map &vm) {
|
---|
| 29 | if (vm.count("server")) {
|
---|
| 30 | server = vm["server"].as< std::string >();
|
---|
| 31 | serverport = server.substr(server.find_last_of(':')+1, std::string::npos);
|
---|
| 32 | server = server.substr(0, server.find_last_of(':'));
|
---|
| 33 | try {
|
---|
| 34 | boost::lexical_cast<size_t>(serverport);
|
---|
| 35 | } catch (boost::bad_lexical_cast) {
|
---|
| 36 | ELOG(1, "Could not interpret " << serverport << " as server:port.");
|
---|
| 37 | return 255;
|
---|
| 38 | }
|
---|
| 39 | LOG(1, "INFO: Using " << server << ":" << serverport << " as server's address.");
|
---|
| 40 | } else {
|
---|
| 41 | ELOG(1, "Requiring server's address (host:port) to connect to.");
|
---|
| 42 | return 255;
|
---|
| 43 | }
|
---|
| 44 | return 0;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | int WorkerOptions::parseLocalhost(boost::program_options::variables_map &vm) {
|
---|
| 48 | if (vm.count("hostname")) {
|
---|
| 49 | hostname = vm["hostname"].as< std::string >();
|
---|
| 50 | LOG(1, "INFO: Using " << hostname << " as host's name.");
|
---|
| 51 | } else {
|
---|
| 52 | char name[1024];
|
---|
| 53 | if (gethostname(name, 1023) == 0) {
|
---|
| 54 | hostname = name;
|
---|
| 55 | LOG(1, "INFO: Using obtained hostname " << hostname << ".");
|
---|
| 56 | } else {
|
---|
| 57 | ELOG(1, "No hostname given and failed to determine automatically.");
|
---|
| 58 | return 255;
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | return 0;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | int WorkerOptions::parseListenPort(boost::program_options::variables_map &vm) {
|
---|
| 65 | if (vm.count("listen")) {
|
---|
| 66 | try {
|
---|
| 67 | listenport = vm["listen"].as< std::string >();
|
---|
| 68 | } catch (boost::bad_lexical_cast) {
|
---|
| 69 | ELOG(1, "Could not read " << vm["listen"].as< std::string >() << " as digits.");
|
---|
| 70 | return 255;
|
---|
| 71 | }
|
---|
| 72 | LOG(1, "INFO: Using port " << listenport << " to listen to server connects.");
|
---|
| 73 | } else {
|
---|
| 74 | ELOG(1, "Requiring port to listen on .");
|
---|
| 75 | return 255;
|
---|
| 76 | }
|
---|
| 77 | return 0;
|
---|
| 78 | }
|
---|