| 59 | // ---------------------------------------------------------------------------------------- |
| 60 | |
| 61 | int main(int argc, char** argv) |
| 62 | { |
| 63 | try |
| 64 | { |
| 65 | // Use the dlib command_line_parser to parse the command line. See the |
| 66 | // compress_stream_ex.cpp example program for an introduction to the command line |
| 67 | // parser. |
| 68 | command_line_parser parser; |
| 69 | parser.add_option("h","Display this help message."); |
| 70 | parser.add_option("l","Run as a listening BSP node.",1); |
| 71 | parser.parse(argc, argv); |
| 72 | parser.check_option_arg_range("l", 1, 65535); |
| 73 | |
| 74 | |
| 75 | // Print a help message if the user gives -h on the command line. |
| 76 | if (parser.option("h")) |
| 77 | { |
| 78 | // display all the command line options |
| 79 | cout << "Usage: bsp_ex (-l port | <list of hosts>)\n"; |
| 80 | parser.print_options(); |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | // If the command line contained -l |
| 86 | if (parser.option("l")) |
| 87 | { |
| 88 | // Get the argument to -l |
| 89 | const unsigned short listening_port = get_option(parser, "l", 0); |
| 90 | cout << "Listening on port " << listening_port << endl; |
| 91 | |
| 92 | const long grid_resolution = 100; |
| 93 | |
| 94 | // bsp_listen() starts a listening BSP job. This means that it will wait until |
| 95 | // someone calls bsp_connect() and connects to it before it starts running. |
| 96 | // However, once it starts it will call bsp_job_other_nodes() which will then |
| 97 | // do all the real work. |
| 98 | // |
| 99 | // The first argument is the port to listen on. The second argument is the |
| 100 | // function which it should run to do all the work. The other arguments are |
| 101 | // optional and allow you to pass values into the bsp_job_other_nodes() |
| 102 | // routine. In this case, we are passing the grid_resolution to |
| 103 | // bsp_job_other_nodes(). |
| 104 | bsp_listen(listening_port, bsp_job_other_nodes, grid_resolution); |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | if (parser.number_of_arguments() == 0) |
| 109 | { |
| 110 | cout << "You must give some listening BSP nodes as arguments to this program!" << endl; |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | // Take the hostname:port strings from the command line and put them into the |
| 115 | // vector of hosts. |
| 116 | std::vector<network_address> hosts; |
| 117 | for (unsigned long i = 0; i < parser.number_of_arguments(); ++i) |
| 118 | hosts.push_back(parser[i]); |
nothing calls this directly
no test coverage detected