2010-02-11 09:46:40 +01:00
|
|
|
#include "userinterface.hh"
|
|
|
|
#include "configuration.hh"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
|
|
|
|
using namespace std ;
|
|
|
|
namespace po = boost::program_options ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Default value definitions *** */
|
|
|
|
|
|
|
|
#define DEFAULT_CONFIG_FILE_NAME "cfg/owlps-positioning.cfg"
|
|
|
|
#define DEFAULT_LISTENING_PORT 9902
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Constructors *** */
|
|
|
|
|
|
|
|
|
2010-03-05 17:24:18 +01:00
|
|
|
/**
|
|
|
|
* \em argc and \em argv are (normally) the ones passed to the main()
|
|
|
|
* function.
|
|
|
|
* @param argc Number of arguments passed to the program.
|
|
|
|
* @param argv Values of the arguments.
|
|
|
|
*/
|
2010-02-11 09:46:40 +01:00
|
|
|
UserInterface::UserInterface(const int argc, char **argv)
|
|
|
|
{
|
2010-03-05 17:24:18 +01:00
|
|
|
assert(argv) ;
|
2010-02-11 09:46:40 +01:00
|
|
|
cli_argument_values = argv ;
|
2010-03-05 17:24:18 +01:00
|
|
|
cli_argument_count = argc ;
|
2010-02-11 09:46:40 +01:00
|
|
|
|
2010-02-26 13:09:45 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cli_options = new po::options_description("General options") ;
|
|
|
|
file_options = new po::options_description("Parameters") ;
|
|
|
|
}
|
|
|
|
catch (bad_alloc e)
|
|
|
|
{
|
|
|
|
throw ;
|
|
|
|
}
|
|
|
|
|
2010-02-11 09:46:40 +01:00
|
|
|
fill_options() ;
|
|
|
|
parse_options() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UserInterface::~UserInterface()
|
|
|
|
{
|
|
|
|
delete cli_options ;
|
|
|
|
delete file_options ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
|
|
|
|
|
|
void UserInterface::fill_options()
|
|
|
|
{
|
|
|
|
fill_cli_options() ;
|
|
|
|
fill_file_options() ;
|
|
|
|
|
|
|
|
// File options are also accepted on the command line
|
|
|
|
cli_options->add(*file_options) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UserInterface::fill_cli_options()
|
|
|
|
{
|
|
|
|
cli_options->add_options()
|
|
|
|
("help,h", "Print help")
|
2010-03-08 11:38:25 +01:00
|
|
|
("config-file,f", po::value<string>()
|
|
|
|
->default_value(DEFAULT_CONFIG_FILE_NAME),
|
2010-02-11 09:46:40 +01:00
|
|
|
"Alternative configuration file")
|
2010-03-05 17:24:18 +01:00
|
|
|
; // End of options
|
2010-02-11 09:46:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UserInterface::fill_file_options()
|
|
|
|
{
|
2010-03-23 14:53:37 +01:00
|
|
|
fill_server_options() ;
|
2010-04-02 15:49:22 +02:00
|
|
|
fill_data_input_options() ;
|
2010-03-23 14:53:37 +01:00
|
|
|
fill_input_options() ;
|
|
|
|
fill_log_options() ;
|
|
|
|
fill_positioning_options() ;
|
|
|
|
fill_output_options() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UserInterface::fill_server_options()
|
|
|
|
{
|
|
|
|
po::options_description options("Server options") ;
|
2010-03-05 17:24:18 +01:00
|
|
|
|
2010-03-23 14:53:37 +01:00
|
|
|
options.add_options()
|
2010-02-11 09:46:40 +01:00
|
|
|
("server.port,l", po::value<int>()
|
|
|
|
->default_value(DEFAULT_LISTENING_PORT),
|
2010-02-16 16:19:39 +01:00
|
|
|
"Server listening port.")
|
2010-03-23 14:53:37 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
file_options->add(options) ;
|
|
|
|
}
|
|
|
|
|
2010-03-05 17:24:18 +01:00
|
|
|
|
2010-04-02 15:49:22 +02:00
|
|
|
void UserInterface::fill_data_input_options()
|
|
|
|
{
|
|
|
|
po::options_description options("Data input options") ;
|
|
|
|
|
|
|
|
options.add_options()
|
2010-06-23 17:50:44 +02:00
|
|
|
("data-input.ap-medium", po::value< vector<string> >()
|
|
|
|
->composing(),
|
|
|
|
"Medium from which access points are read. You can specify this \
|
|
|
|
option more than once. Allowed: CSV.")
|
|
|
|
("data-input.ap-csv-file", po::value<string>(),
|
|
|
|
"CSV file to use for access points input (when \
|
|
|
|
data-input.ap-medium = CSV).")
|
2010-04-02 15:49:22 +02:00
|
|
|
("data-input.topology-medium,T", po::value< vector<string> >()
|
|
|
|
->composing(),
|
|
|
|
"Medium from which topology (buildings, areas and waypoints) is \
|
|
|
|
read. You can specify this option more than once. Allowed: CSV.")
|
|
|
|
("data-input.areas-csv-file,A", po::value<string>(),
|
|
|
|
"CSV file to use for topology input (when \
|
|
|
|
data-input.topology-medium = CSV).")
|
|
|
|
("data-input.waypoints-csv-file,W", po::value<string>(),
|
|
|
|
"CSV file to use for waypoints input (when \
|
|
|
|
data-input.topology-medium = CSV).")
|
2010-04-20 16:18:27 +02:00
|
|
|
("data-input.reference-points-medium,R", po::value< vector<string> >()
|
|
|
|
->composing(),
|
|
|
|
"Medium from which reference points are read. You can specify this \
|
|
|
|
option more than once. Allowed: CSV.")
|
|
|
|
("data-input.reference-points-csv-file", po::value<string>(),
|
|
|
|
"CSV file to use for reference points input (when \
|
|
|
|
data-input.reference-points-medium = CSV).")
|
2010-04-02 15:49:22 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
file_options->add(options) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 14:53:37 +01:00
|
|
|
void UserInterface::fill_input_options()
|
|
|
|
{
|
|
|
|
po::options_description options("Input options") ;
|
|
|
|
|
|
|
|
options.add_options()
|
2010-02-11 17:24:21 +01:00
|
|
|
("input.medium,I", po::value<string>(),
|
2011-03-18 10:37:06 +01:00
|
|
|
"Medium from which requests are read. Allowed: CSV, UDP.")
|
2010-02-11 17:24:21 +01:00
|
|
|
("input.csv-file,C", po::value<string>(),
|
2010-02-16 16:19:39 +01:00
|
|
|
"CSV file to use for input (when input.medium = CSV).")
|
2011-03-18 10:37:06 +01:00
|
|
|
("input.udp-port,p", po::value<int>(),
|
|
|
|
"Port on which the UDP socket listens (when input.medium = UDP).")
|
2010-03-23 14:53:37 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
file_options->add(options) ;
|
|
|
|
}
|
|
|
|
|
2010-03-05 17:24:18 +01:00
|
|
|
|
2010-03-23 14:53:37 +01:00
|
|
|
void UserInterface::fill_log_options()
|
|
|
|
{
|
|
|
|
po::options_description options("Log options") ;
|
|
|
|
|
|
|
|
options.add_options()
|
2010-02-16 16:19:39 +01:00
|
|
|
("log.medium,L", po::value< vector<string> >()->composing(),
|
|
|
|
"Medium to which the requests will be logged. You can specify \
|
|
|
|
this option more than once. Allowed: none, CSV. The `none` value \
|
|
|
|
completely disables logging.")
|
|
|
|
("log.csv-file", po::value<string>(),
|
|
|
|
"CSV file to use for logging (when log.medium = CSV).")
|
2010-03-23 14:53:37 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
file_options->add(options) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UserInterface::fill_positioning_options()
|
|
|
|
{
|
|
|
|
po::options_description options("Positioning options") ;
|
2010-03-05 17:24:18 +01:00
|
|
|
|
2010-03-23 14:53:37 +01:00
|
|
|
options.add_options()
|
2010-04-16 09:32:12 +02:00
|
|
|
("positioning.algorithm,a", po::value< vector<string> >()->composing(),
|
2010-03-04 17:51:44 +01:00
|
|
|
"Algorithms used to compute positions. You can specify \
|
2010-06-10 15:57:03 +02:00
|
|
|
this option more than once (but at least once). Allowed: Real, FBCM, \
|
2010-06-14 17:15:48 +02:00
|
|
|
FRBHMBasic, InterlinkNetworks, RADAR.")
|
2010-03-23 14:53:37 +01:00
|
|
|
;
|
2010-03-05 17:24:18 +01:00
|
|
|
|
2010-03-23 14:53:37 +01:00
|
|
|
file_options->add(options) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UserInterface::fill_output_options()
|
|
|
|
{
|
|
|
|
po::options_description options("Output options") ;
|
|
|
|
|
|
|
|
options.add_options()
|
2010-03-04 11:59:17 +01:00
|
|
|
("output.medium,O", po::value< vector<string> >()->composing(),
|
|
|
|
"Medium to which the results will be wrote. You can specify \
|
2010-03-08 17:36:16 +01:00
|
|
|
this option more than once. Allowed: Terminal, CSV. \
|
|
|
|
If this option is absent, results will be printed on the terminal.")
|
|
|
|
("output.csv-file", po::value<string>(),
|
|
|
|
"CSV file to use for output (when output.medium = CSV).")
|
2010-03-23 14:53:37 +01:00
|
|
|
;
|
2010-03-05 17:24:18 +01:00
|
|
|
|
2010-03-23 14:53:37 +01:00
|
|
|
file_options->add(options) ;
|
2010-02-11 09:46:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UserInterface::parse_options()
|
|
|
|
{
|
|
|
|
parse_command_line() ;
|
|
|
|
print_usage_and_exit_if_requested() ;
|
|
|
|
|
|
|
|
parse_file() ;
|
|
|
|
|
|
|
|
po::notify(Configuration::getw_configuration()) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UserInterface::parse_command_line() const
|
|
|
|
{
|
|
|
|
po::store(po::parse_command_line(cli_argument_count,
|
|
|
|
cli_argument_values,
|
|
|
|
*cli_options),
|
|
|
|
Configuration::getw_configuration()) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UserInterface::print_usage_and_exit_if_requested() const
|
|
|
|
{
|
|
|
|
if (Configuration::is_configured("help"))
|
|
|
|
{
|
|
|
|
cout << *cli_options ;
|
|
|
|
exit(0) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UserInterface::parse_file() const
|
|
|
|
{
|
2010-03-08 11:38:25 +01:00
|
|
|
string config_file_name = Configuration::string_value("config-file") ;
|
2010-02-11 09:46:40 +01:00
|
|
|
ifstream config_file(config_file_name.c_str()) ;
|
|
|
|
|
|
|
|
if (! config_file)
|
|
|
|
{
|
|
|
|
cerr
|
|
|
|
<< "Warning! Error opening input configuration file « "
|
|
|
|
<< config_file_name
|
|
|
|
<< " »! Using command line and default values…"
|
|
|
|
<< endl ;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
po::store(po::parse_config_file(config_file, *file_options),
|
|
|
|
Configuration::getw_configuration()) ;
|
|
|
|
}
|