Only allow to specify the common base path
This commit is contained in:
+132
-5
@@ -1,10 +1,14 @@
|
||||
#include "server/server.hpp"
|
||||
#include "util/routed_options.hpp"
|
||||
#include "util/make_unique.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/version.hpp"
|
||||
|
||||
#include "osrm/osrm.hpp"
|
||||
#include "osrm/engine_config.hpp"
|
||||
#include "osrm/storage_config.hpp"
|
||||
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/mman.h>
|
||||
@@ -19,6 +23,7 @@
|
||||
#include <iostream>
|
||||
#include <new>
|
||||
#include <thread>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
boost::function0<void> console_ctrl_function;
|
||||
@@ -41,6 +46,111 @@ BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
|
||||
|
||||
using namespace osrm;
|
||||
|
||||
const static unsigned INIT_OK_START_ENGINE = 0;
|
||||
const static unsigned INIT_OK_DO_NOT_START_ENGINE = 1;
|
||||
const static unsigned INIT_FAILED = -1;
|
||||
|
||||
// generate boost::program_options object for the routing part
|
||||
inline unsigned
|
||||
generateServerProgramOptions(const int argc,
|
||||
const char *argv[],
|
||||
boost::filesystem::path &base_path,
|
||||
std::string &ip_address,
|
||||
int &ip_port,
|
||||
int &requested_num_threads,
|
||||
bool &use_shared_memory,
|
||||
bool &trial,
|
||||
int &max_locations_trip,
|
||||
int &max_locations_viaroute,
|
||||
int &max_locations_distance_table,
|
||||
int &max_locations_map_matching)
|
||||
{
|
||||
using boost::program_options::value;
|
||||
using boost::filesystem::path;
|
||||
|
||||
// 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") //
|
||||
("trial", value<bool>(&trial)->implicit_value(true), "Quit after initialization");
|
||||
|
||||
// declare a group of options that will be allowed on command line
|
||||
boost::program_options::options_description config_options("Configuration");
|
||||
config_options.add_options() //
|
||||
("ip,i", value<std::string>(&ip_address)->default_value("0.0.0.0"),
|
||||
"IP address") //
|
||||
("port,p", value<int>(&ip_port)->default_value(5000),
|
||||
"TCP/IP port") //
|
||||
("threads,t", value<int>(&requested_num_threads)->default_value(8),
|
||||
"Number of threads to use") //
|
||||
("shared-memory,s",
|
||||
value<bool>(&use_shared_memory)->implicit_value(true)->default_value(false),
|
||||
"Load data from shared memory") //
|
||||
("max-viaroute-size", value<int>(&max_locations_viaroute)->default_value(500),
|
||||
"Max. locations supported in viaroute query") //
|
||||
("max-trip-size", value<int>(&max_locations_trip)->default_value(100),
|
||||
"Max. locations supported in trip query") //
|
||||
("max-table-size", value<int>(&max_locations_distance_table)->default_value(100),
|
||||
"Max. locations supported in distance table query") //
|
||||
("max-matching-size", value<int>(&max_locations_map_matching)->default_value(100),
|
||||
"Max. locations supported in map matching query");
|
||||
|
||||
// hidden options, will be allowed on command line, but will not be shown to the user
|
||||
boost::program_options::options_description hidden_options("Hidden options");
|
||||
hidden_options.add_options()("base,b", value<boost::filesystem::path>(&base_path),
|
||||
"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::path(argv[0]).stem().string() + " <base.osrm> [<options>]");
|
||||
visible_options.add(generic_options).add(config_options);
|
||||
|
||||
// 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"))
|
||||
{
|
||||
util::SimpleLogger().Write() << OSRM_VERSION;
|
||||
return INIT_OK_DO_NOT_START_ENGINE;
|
||||
}
|
||||
|
||||
if (option_variables.count("help"))
|
||||
{
|
||||
util::SimpleLogger().Write() << visible_options;
|
||||
return INIT_OK_DO_NOT_START_ENGINE;
|
||||
}
|
||||
|
||||
boost::program_options::notify(option_variables);
|
||||
|
||||
if (!use_shared_memory && option_variables.count("base"))
|
||||
{
|
||||
return INIT_OK_START_ENGINE;
|
||||
}
|
||||
else if (use_shared_memory && !option_variables.count("base"))
|
||||
{
|
||||
return INIT_OK_START_ENGINE;
|
||||
}
|
||||
else if (use_shared_memory && option_variables.count("base"))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << "Shared memory settings conflict with path settings.";
|
||||
}
|
||||
|
||||
util::SimpleLogger().Write() << visible_options;
|
||||
return INIT_OK_DO_NOT_START_ENGINE;
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) try
|
||||
{
|
||||
util::LogPolicy::GetInstance().Unmute();
|
||||
@@ -50,19 +160,36 @@ int main(int argc, const char *argv[]) try
|
||||
int ip_port, requested_thread_num;
|
||||
|
||||
EngineConfig config;
|
||||
const unsigned init_result = util::GenerateServerProgramOptions(
|
||||
argc, argv, config.server_paths, ip_address, ip_port, requested_thread_num,
|
||||
boost::filesystem::path base_path;
|
||||
const unsigned init_result = generateServerProgramOptions(
|
||||
argc, argv, base_path, ip_address, ip_port, requested_thread_num,
|
||||
config.use_shared_memory, trial_run, config.max_locations_trip,
|
||||
config.max_locations_viaroute, config.max_locations_distance_table,
|
||||
config.max_locations_map_matching);
|
||||
if (init_result == util::INIT_OK_DO_NOT_START_ENGINE)
|
||||
if (init_result == INIT_OK_DO_NOT_START_ENGINE)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (init_result == util::INIT_FAILED)
|
||||
if (init_result == INIT_FAILED)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (!base_path.empty())
|
||||
{
|
||||
config.storage_config = storage::StorageConfig(base_path);
|
||||
}
|
||||
if(!config.IsValid())
|
||||
{
|
||||
if (base_path.empty() != config.use_shared_memory)
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << "Path settings and shared memory conflicts.";
|
||||
}
|
||||
else
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << "Invalid config options.";
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
struct MemoryLocker final
|
||||
|
||||
+11
-172
@@ -10,7 +10,7 @@
|
||||
using namespace osrm;
|
||||
|
||||
// generate boost::program_options object for the routing part
|
||||
bool generateDataStoreOptions(const int argc, const char *argv[], storage::DataPaths &paths)
|
||||
bool generateDataStoreOptions(const int argc, const char *argv[], boost::filesystem::path& base_path)
|
||||
{
|
||||
// declare a group of options that will be allowed only on command line
|
||||
boost::program_options::options_description generic_options("Options");
|
||||
@@ -20,38 +20,11 @@ bool generateDataStoreOptions(const int argc, const char *argv[], storage::DataP
|
||||
// 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"]),
|
||||
".fileIndex file")("core",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["core"]),
|
||||
".core file")(
|
||||
"namesdata", boost::program_options::value<boost::filesystem::path>(&paths["namesdata"]),
|
||||
".names file")("timestamp",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["timestamp"]),
|
||||
".timestamp file")(
|
||||
"datasource_names",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["datasource_names"]),
|
||||
".datasource_names file")(
|
||||
"datasource_indexes",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["datasource_indexes"]),
|
||||
".datasource_indexes file")(
|
||||
"properties", boost::program_options::value<boost::filesystem::path>(&paths["properties"]),
|
||||
".properties file");
|
||||
|
||||
// hidden options, will be allowed on command line but will not be shown to the user
|
||||
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,b", boost::program_options::value<boost::filesystem::path>(&base_path),
|
||||
"base path to .osrm file");
|
||||
|
||||
// positional option
|
||||
@@ -95,145 +68,6 @@ bool generateDataStoreOptions(const int argc, const char *argv[], storage::DataP
|
||||
|
||||
boost::program_options::notify(option_variables);
|
||||
|
||||
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())
|
||||
{
|
||||
path_iterator->second = base_string + ".hsgr";
|
||||
}
|
||||
|
||||
path_iterator = paths.find("nodesdata");
|
||||
if (path_iterator != paths.end())
|
||||
{
|
||||
path_iterator->second = base_string + ".nodes";
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
path_iterator->second = base_string + ".timestamp";
|
||||
}
|
||||
|
||||
path_iterator = paths.find("properties");
|
||||
if (path_iterator != paths.end())
|
||||
{
|
||||
path_iterator->second = base_string + ".properties";
|
||||
}
|
||||
|
||||
path_iterator = paths.find("datasource_indexes");
|
||||
if (path_iterator != paths.end())
|
||||
{
|
||||
path_iterator->second = base_string + ".datasource_indexes";
|
||||
}
|
||||
|
||||
path_iterator = paths.find("datasource_names");
|
||||
if (path_iterator != paths.end())
|
||||
{
|
||||
path_iterator->second = base_string + ".datasource_names";
|
||||
}
|
||||
|
||||
path_iterator = paths.find("hsgrdata");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw util::exception("valid .hsgr file must be specified");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("nodesdata");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw util::exception("valid .nodes file must be specified");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("edgesdata");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw util::exception("valid .edges file must be specified");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("geometry");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw util::exception("valid .geometry file must be specified");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("ramindex");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw util::exception("valid .ramindex file must be specified");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("fileindex");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw util::exception("valid .fileindex file must be specified");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("namesdata");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw util::exception("valid .names file must be specified");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("timestamp");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw util::exception("valid .timestamp file must be specified");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("properties");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw util::exception("valid .properties file must be specified");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -241,13 +75,18 @@ int main(const int argc, const char *argv[]) try
|
||||
{
|
||||
util::LogPolicy::GetInstance().Unmute();
|
||||
|
||||
storage::DataPaths paths;
|
||||
if (!generateDataStoreOptions(argc, argv, paths))
|
||||
boost::filesystem::path base_path;
|
||||
if (!generateDataStoreOptions(argc, argv, base_path))
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
storage::Storage storage(paths);
|
||||
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));
|
||||
return storage.Run();
|
||||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
|
||||
Reference in New Issue
Block a user