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-02-15 18:44:04 -05:00
|
|
|
bool generateDataStoreOptions(const int argc, const char *argv[], storage::DataPaths &paths)
|
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");
|
|
|
|
config_options.add_options()(
|
|
|
|
"hsgrdata", boost::program_options::value<boost::filesystem::path>(&paths["hsgrdata"]),
|
|
|
|
".hsgr file")("nodesdata",
|
|
|
|
boost::program_options::value<boost::filesystem::path>(&paths["nodesdata"]),
|
|
|
|
".nodes file")(
|
|
|
|
"edgesdata", boost::program_options::value<boost::filesystem::path>(&paths["edgesdata"]),
|
|
|
|
".edges file")("geometry",
|
|
|
|
boost::program_options::value<boost::filesystem::path>(&paths["geometry"]),
|
|
|
|
".geometry file")(
|
|
|
|
"ramindex", boost::program_options::value<boost::filesystem::path>(&paths["ramindex"]),
|
|
|
|
".ramIndex file")(
|
|
|
|
"fileindex", boost::program_options::value<boost::filesystem::path>(&paths["fileindex"]),
|
2015-09-08 19:57:29 -04:00
|
|
|
".fileIndex file")("core",
|
|
|
|
boost::program_options::value<boost::filesystem::path>(&paths["core"]),
|
|
|
|
".core file")(
|
2015-01-27 11:44:46 -05:00
|
|
|
"namesdata", boost::program_options::value<boost::filesystem::path>(&paths["namesdata"]),
|
|
|
|
".names file")("timestamp",
|
|
|
|
boost::program_options::value<boost::filesystem::path>(&paths["timestamp"]),
|
|
|
|
".timestamp file");
|
|
|
|
|
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()(
|
|
|
|
"base,b", boost::program_options::value<boost::filesystem::path>(&paths["base"]),
|
|
|
|
"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);
|
|
|
|
|
2016-02-12 20:11:35 -05:00
|
|
|
auto path_iterator = paths.find("base");
|
|
|
|
BOOST_ASSERT(paths.end() != path_iterator);
|
|
|
|
std::string base_string = path_iterator->second.string();
|
|
|
|
|
|
|
|
path_iterator = paths.find("hsgrdata");
|
|
|
|
if (path_iterator != paths.end())
|
2015-01-27 11:44:46 -05:00
|
|
|
{
|
2016-02-12 20:11:35 -05:00
|
|
|
path_iterator->second = base_string + ".hsgr";
|
2015-01-27 11:44:46 -05:00
|
|
|
}
|
|
|
|
|
2016-02-12 20:11:35 -05:00
|
|
|
path_iterator = paths.find("nodesdata");
|
|
|
|
if (path_iterator != paths.end())
|
2015-01-27 11:44:46 -05:00
|
|
|
{
|
2016-02-12 20:11:35 -05:00
|
|
|
path_iterator->second = base_string + ".nodes";
|
2015-01-27 11:44:46 -05:00
|
|
|
}
|
2016-02-12 20:11:35 -05:00
|
|
|
|
|
|
|
path_iterator = paths.find("edgesdata");
|
|
|
|
if (path_iterator != paths.end())
|
|
|
|
{
|
|
|
|
path_iterator->second = base_string + ".edges";
|
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("geometry");
|
|
|
|
if (path_iterator != paths.end())
|
|
|
|
{
|
|
|
|
path_iterator->second = base_string + ".geometry";
|
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("ramindex");
|
|
|
|
if (path_iterator != paths.end())
|
|
|
|
{
|
|
|
|
path_iterator->second = base_string + ".ramIndex";
|
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("fileindex");
|
|
|
|
if (path_iterator != paths.end())
|
|
|
|
{
|
|
|
|
path_iterator->second = base_string + ".fileIndex";
|
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("core");
|
|
|
|
if (path_iterator != paths.end())
|
|
|
|
{
|
|
|
|
path_iterator->second = base_string + ".core";
|
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("namesdata");
|
|
|
|
if (path_iterator != paths.end())
|
|
|
|
{
|
|
|
|
path_iterator->second = base_string + ".names";
|
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("timestamp");
|
|
|
|
if (path_iterator != paths.end())
|
2015-01-27 11:44:46 -05:00
|
|
|
{
|
2016-02-12 20:11:35 -05:00
|
|
|
path_iterator->second = base_string + ".timestamp";
|
2015-01-27 11:44:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("hsgrdata");
|
2015-09-08 19:57:29 -04:00
|
|
|
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
|
|
|
!boost::filesystem::is_regular_file(path_iterator->second))
|
2015-01-27 11:44:46 -05:00
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
throw util::exception("valid .hsgr file must be specified");
|
2015-01-27 11:44:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("nodesdata");
|
2015-09-08 19:57:29 -04:00
|
|
|
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
|
|
|
!boost::filesystem::is_regular_file(path_iterator->second))
|
2015-01-27 11:44:46 -05:00
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
throw util::exception("valid .nodes file must be specified");
|
2015-01-27 11:44:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("edgesdata");
|
2015-09-08 19:57:29 -04:00
|
|
|
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
|
|
|
!boost::filesystem::is_regular_file(path_iterator->second))
|
2015-01-27 11:44:46 -05:00
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
throw util::exception("valid .edges file must be specified");
|
2015-01-27 11:44:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("geometry");
|
2015-09-08 19:57:29 -04:00
|
|
|
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
|
|
|
!boost::filesystem::is_regular_file(path_iterator->second))
|
2015-01-27 11:44:46 -05:00
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
throw util::exception("valid .geometry file must be specified");
|
2015-01-27 11:44:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("ramindex");
|
2015-09-08 19:57:29 -04:00
|
|
|
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
|
|
|
!boost::filesystem::is_regular_file(path_iterator->second))
|
2015-01-27 11:44:46 -05:00
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
throw util::exception("valid .ramindex file must be specified");
|
2015-01-27 11:44:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("fileindex");
|
2015-09-08 19:57:29 -04:00
|
|
|
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
|
|
|
!boost::filesystem::is_regular_file(path_iterator->second))
|
2015-01-27 11:44:46 -05:00
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
throw util::exception("valid .fileindex file must be specified");
|
2015-01-27 11:44:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("namesdata");
|
2015-09-08 19:57:29 -04:00
|
|
|
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
|
|
|
!boost::filesystem::is_regular_file(path_iterator->second))
|
2015-01-27 11:44:46 -05:00
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
throw util::exception("valid .names file must be specified");
|
2015-01-27 11:44:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
path_iterator = paths.find("timestamp");
|
2015-09-08 19:57:29 -04:00
|
|
|
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
|
|
|
!boost::filesystem::is_regular_file(path_iterator->second))
|
2015-01-27 11:44:46 -05:00
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
throw util::exception("valid .timestamp file must be specified");
|
2015-01-27 11:44:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-01-07 13:19:55 -05:00
|
|
|
|
|
|
|
int main(const int argc, const char *argv[]) try
|
|
|
|
{
|
|
|
|
util::LogPolicy::GetInstance().Unmute();
|
|
|
|
|
|
|
|
storage::DataPaths paths;
|
|
|
|
if (!generateDataStoreOptions(argc, argv, paths))
|
|
|
|
{
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
storage::Storage storage(paths);
|
|
|
|
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
|
|
|
}
|