2016-01-07 13:19:55 -05:00
|
|
|
#include "storage/storage.hpp"
|
2016-01-28 08:27:05 -05:00
|
|
|
#include "util/exception.hpp"
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "util/simple_logger.hpp"
|
2016-01-07 13:19:55 -05:00
|
|
|
#include "util/typedefs.hpp"
|
|
|
|
#include "util/version.hpp"
|
2015-01-27 11:44:46 -05:00
|
|
|
|
2016-02-12 20:11:35 -05:00
|
|
|
#include <boost/filesystem.hpp>
|
2015-01-27 11:44:46 -05:00
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
using namespace osrm;
|
2016-01-05 10:51:13 -05:00
|
|
|
|
2015-01-27 11:44:46 -05:00
|
|
|
// generate boost::program_options object for the routing part
|
2016-03-22 14:30:18 -04:00
|
|
|
bool generateDataStoreOptions(const int argc, const char *argv[], boost::filesystem::path& base_path)
|
2015-01-27 11:44:46 -05:00
|
|
|
{
|
|
|
|
// declare a group of options that will be allowed only on command line
|
|
|
|
boost::program_options::options_description generic_options("Options");
|
|
|
|
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
|
2016-02-12 20:11:35 -05:00
|
|
|
"springclean,s", "Remove all regions in shared memory");
|
2015-01-27 11:44:46 -05:00
|
|
|
|
|
|
|
// declare a group of options that will be allowed both on command line
|
|
|
|
// as well as in a config file
|
|
|
|
boost::program_options::options_description config_options("Configuration");
|
|
|
|
|
2016-02-12 20:11:35 -05:00
|
|
|
// hidden options, will be allowed on command line but will not be shown to the user
|
2015-01-27 11:44:46 -05:00
|
|
|
boost::program_options::options_description hidden_options("Hidden options");
|
|
|
|
hidden_options.add_options()(
|
2016-03-22 14:30:18 -04:00
|
|
|
"base,b", boost::program_options::value<boost::filesystem::path>(&base_path),
|
2015-01-27 11:44:46 -05:00
|
|
|
"base path to .osrm file");
|
|
|
|
|
|
|
|
// positional option
|
|
|
|
boost::program_options::positional_options_description positional_options;
|
|
|
|
positional_options.add("base", 1);
|
|
|
|
|
|
|
|
// combine above options for parsing
|
|
|
|
boost::program_options::options_description cmdline_options;
|
|
|
|
cmdline_options.add(generic_options).add(config_options).add(hidden_options);
|
|
|
|
|
|
|
|
boost::program_options::options_description visible_options(
|
|
|
|
boost::filesystem::basename(argv[0]) + " [<options>] <configuration>");
|
|
|
|
visible_options.add(generic_options).add(config_options);
|
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
// print help options if no infile is specified
|
|
|
|
if (argc < 2)
|
|
|
|
{
|
|
|
|
util::SimpleLogger().Write() << visible_options;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-27 11:44:46 -05:00
|
|
|
// parse command line options
|
|
|
|
boost::program_options::variables_map option_variables;
|
|
|
|
boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
|
|
|
|
.options(cmdline_options)
|
|
|
|
.positional(positional_options)
|
|
|
|
.run(),
|
|
|
|
option_variables);
|
|
|
|
|
|
|
|
if (option_variables.count("version"))
|
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
util::SimpleLogger().Write() << OSRM_VERSION;
|
2015-01-27 11:44:46 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option_variables.count("help"))
|
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
util::SimpleLogger().Write() << visible_options;
|
2015-01-27 11:44:46 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::program_options::notify(option_variables);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-01-07 13:19:55 -05:00
|
|
|
|
|
|
|
int main(const int argc, const char *argv[]) try
|
|
|
|
{
|
|
|
|
util::LogPolicy::GetInstance().Unmute();
|
|
|
|
|
2016-03-22 14:30:18 -04:00
|
|
|
boost::filesystem::path base_path;
|
|
|
|
if (!generateDataStoreOptions(argc, argv, base_path))
|
2016-01-07 13:19:55 -05:00
|
|
|
{
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2016-03-22 14:30:18 -04:00
|
|
|
storage::StorageConfig config(base_path);
|
|
|
|
if (!config.IsValid())
|
|
|
|
{
|
|
|
|
util::SimpleLogger().Write(logWARNING) << "Invalid file path given!";
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
storage::Storage storage(std::move(config));
|
2016-01-07 13:19:55 -05:00
|
|
|
return storage.Run();
|
2016-01-05 10:51:13 -05:00
|
|
|
}
|
2016-01-07 13:19:55 -05:00
|
|
|
catch (const std::bad_alloc &e)
|
|
|
|
{
|
|
|
|
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
|
|
|
util::SimpleLogger().Write(logWARNING)
|
|
|
|
<< "Please provide more memory or disable locking the virtual "
|
|
|
|
"address space (note: this makes OSRM swap, i.e. slow)";
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
util::SimpleLogger().Write(logWARNING) << "caught exception: " << e.what();
|
|
|
|
return EXIT_FAILURE;
|
2016-01-05 10:51:13 -05:00
|
|
|
}
|