From b9e1d3116c4f1d524f6fa1c95d4fa984c599eb83 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 8 Oct 2014 17:01:53 +0200 Subject: [PATCH] implements and fixes #997 - ServerPaths object can be populated by passing base path to OSRM - reduces code/functionality duplication in node-OSRM --- Library/OSRM_impl.cpp | 7 +- Library/OSRM_impl.h | 1 + Util/ProgramOptions.h | 191 +++++++++++++++++++++++------------------- routed.cpp | 18 +--- 4 files changed, 113 insertions(+), 104 deletions(-) diff --git a/Library/OSRM_impl.cpp b/Library/OSRM_impl.cpp index f18c812ef..0bbdc7da7 100644 --- a/Library/OSRM_impl.cpp +++ b/Library/OSRM_impl.cpp @@ -46,6 +46,7 @@ namespace boost { namespace interprocess { class named_mutex; } } #include "../Server/DataStructures/SharedBarriers.h" #include "../Server/DataStructures/SharedDataFacade.h" #include "../Util/make_unique.hpp" +#include "../Util/ProgramOptions.h" #include "../Util/SimpleLogger.h" #include @@ -57,8 +58,8 @@ namespace boost { namespace interprocess { class named_mutex; } } #include #include -OSRM_impl::OSRM_impl(const ServerPaths &server_paths, const bool use_shared_memory) - : use_shared_memory(use_shared_memory) +OSRM_impl::OSRM_impl(const ServerPaths &paths, const bool use_shared_memory) + : server_paths(paths) { if (use_shared_memory) { @@ -67,6 +68,8 @@ OSRM_impl::OSRM_impl(const ServerPaths &server_paths, const bool use_shared_memo } else { + // populate base path + populate_base_path(server_paths); query_data_facade = new InternalDataFacade(server_paths); } diff --git a/Library/OSRM_impl.h b/Library/OSRM_impl.h index e518036e9..38b919a8d 100644 --- a/Library/OSRM_impl.h +++ b/Library/OSRM_impl.h @@ -56,6 +56,7 @@ class OSRM_impl private: void RegisterPlugin(BasePlugin *plugin); PluginMap plugin_map; + ServerPaths server_paths; bool use_shared_memory; SharedBarriers *barrier; // base class pointer to the objects diff --git a/Util/ProgramOptions.h b/Util/ProgramOptions.h index c6e5448a6..d36bcfd8e 100644 --- a/Util/ProgramOptions.h +++ b/Util/ProgramOptions.h @@ -45,6 +45,109 @@ const static unsigned INIT_OK_START_ENGINE = 0; const static unsigned INIT_OK_DO_NOT_START_ENGINE = 1; const static unsigned INIT_FAILED = -1; +inline void populate_base_path(ServerPaths & server_paths) +{ + // populate the server_path object + auto path_iterator = server_paths.find("base"); + BOOST_ASSERT(server_paths.end() != path_iterator); + std::string base_string = path_iterator->second.string(); + SimpleLogger().Write() << "populating base path: " << base_string; + + path_iterator = server_paths.find("hsgrdata"); + if (path_iterator != server_paths.end() && + !boost::filesystem::is_regular_file(path_iterator->second)) + { + path_iterator->second = base_string + ".hsgr"; + } + else + { + throw OSRMException(base_string + ".hsgr not found"); + } + + path_iterator = server_paths.find("nodesdata"); + if (path_iterator != server_paths.end() && + !boost::filesystem::is_regular_file(path_iterator->second)) + { + path_iterator->second = base_string + ".nodes"; + } + else + { + throw OSRMException(base_string + ".nodes not found"); + } + + path_iterator = server_paths.find("edgesdata"); + if (path_iterator != server_paths.end() && + !boost::filesystem::is_regular_file(path_iterator->second)) + { + path_iterator->second = base_string + ".edges"; + } + else + { + throw OSRMException(base_string + ".edges not found"); + } + + path_iterator = server_paths.find("geometries"); + if (path_iterator != server_paths.end() && + !boost::filesystem::is_regular_file(path_iterator->second)) + { + path_iterator->second = base_string + ".geometry"; + } + else + { + throw OSRMException(base_string + ".geometry not found"); + } + + path_iterator = server_paths.find("ramindex"); + if (path_iterator != server_paths.end() && + !boost::filesystem::is_regular_file(path_iterator->second)) + { + path_iterator->second = base_string + ".ramIndex"; + } + else + { + throw OSRMException(base_string + ".ramIndex not found"); + } + + path_iterator = server_paths.find("fileindex"); + if (path_iterator != server_paths.end() && + !boost::filesystem::is_regular_file(path_iterator->second)) + { + path_iterator->second = base_string + ".fileIndex"; + } + else + { + throw OSRMException(base_string + ".fileIndex not found"); + } + + path_iterator = server_paths.find("namesdata"); + if (path_iterator != server_paths.end() && + !boost::filesystem::is_regular_file(path_iterator->second)) + { + path_iterator->second = base_string + ".names"; + } + else + { + throw OSRMException(base_string + ".namesIndex not found"); + } + + path_iterator = server_paths.find("timestamp"); + if (path_iterator != server_paths.end() && + !boost::filesystem::is_regular_file(path_iterator->second)) + { + path_iterator->second = base_string + ".timestamp"; + } + + SimpleLogger().Write() << "HSGR file:\t" << server_paths["hsgrdata"]; + SimpleLogger().Write(logDEBUG) << "Nodes file:\t" << server_paths["nodesdata"]; + SimpleLogger().Write(logDEBUG) << "Edges file:\t" << server_paths["edgesdata"]; + SimpleLogger().Write(logDEBUG) << "Geometry file:\t" << server_paths["geometries"]; + SimpleLogger().Write(logDEBUG) << "RAM file:\t" << server_paths["ramindex"]; + SimpleLogger().Write(logDEBUG) << "Index file:\t" << server_paths["fileindex"]; + SimpleLogger().Write(logDEBUG) << "Names file:\t" << server_paths["namesdata"]; + SimpleLogger().Write(logDEBUG) << "Timestamp file:\t" << server_paths["timestamp"]; +} + + // generate boost::program_options object for the routing part inline unsigned GenerateServerProgramOptions(const int argc, const char *argv[], @@ -169,94 +272,6 @@ inline unsigned GenerateServerProgramOptions(const int argc, if (!use_shared_memory && option_variables.count("base")) { - 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() && - !boost::filesystem::is_regular_file(path_iterator->second)) - { - path_iterator->second = base_string + ".hsgr"; - } - else - { - throw OSRMException(base_string + ".hsgr not found"); - } - - path_iterator = paths.find("nodesdata"); - if (path_iterator != paths.end() && - !boost::filesystem::is_regular_file(path_iterator->second)) - { - path_iterator->second = base_string + ".nodes"; - } - else - { - throw OSRMException(base_string + ".nodes not found"); - } - - path_iterator = paths.find("edgesdata"); - if (path_iterator != paths.end() && - !boost::filesystem::is_regular_file(path_iterator->second)) - { - path_iterator->second = base_string + ".edges"; - } - else - { - throw OSRMException(base_string + ".edges not found"); - } - - path_iterator = paths.find("geometries"); - if (path_iterator != paths.end() && - !boost::filesystem::is_regular_file(path_iterator->second)) - { - path_iterator->second = base_string + ".geometry"; - } - else - { - throw OSRMException(base_string + ".geometry not found"); - } - - path_iterator = paths.find("ramindex"); - if (path_iterator != paths.end() && - !boost::filesystem::is_regular_file(path_iterator->second)) - { - path_iterator->second = base_string + ".ramIndex"; - } - else - { - throw OSRMException(base_string + ".ramIndex not found"); - } - - path_iterator = paths.find("fileindex"); - if (path_iterator != paths.end() && - !boost::filesystem::is_regular_file(path_iterator->second)) - { - path_iterator->second = base_string + ".fileIndex"; - } - else - { - throw OSRMException(base_string + ".fileIndex not found"); - } - - path_iterator = paths.find("namesdata"); - if (path_iterator != paths.end() && - !boost::filesystem::is_regular_file(path_iterator->second)) - { - path_iterator->second = base_string + ".names"; - } - else - { - throw OSRMException(base_string + ".namesIndex not found"); - } - - path_iterator = paths.find("timestamp"); - if (path_iterator != paths.end() && - !boost::filesystem::is_regular_file(path_iterator->second)) - { - path_iterator->second = base_string + ".timestamp"; - } - return INIT_OK_START_ENGINE; } if (use_shared_memory && !option_variables.count("base")) diff --git a/routed.cpp b/routed.cpp index e317797c5..ca64671a5 100644 --- a/routed.cpp +++ b/routed.cpp @@ -108,20 +108,10 @@ int main(int argc, const char *argv[]) { SimpleLogger().Write(logDEBUG) << "Loading from shared memory"; } - else - { - SimpleLogger().Write() << "HSGR file:\t" << server_paths["hsgrdata"]; - SimpleLogger().Write(logDEBUG) << "Nodes file:\t" << server_paths["nodesdata"]; - SimpleLogger().Write(logDEBUG) << "Edges file:\t" << server_paths["edgesdata"]; - SimpleLogger().Write(logDEBUG) << "Geometry file:\t" << server_paths["geometries"]; - SimpleLogger().Write(logDEBUG) << "RAM file:\t" << server_paths["ramindex"]; - SimpleLogger().Write(logDEBUG) << "Index file:\t" << server_paths["fileindex"]; - SimpleLogger().Write(logDEBUG) << "Names file:\t" << server_paths["namesdata"]; - SimpleLogger().Write(logDEBUG) << "Timestamp file:\t" << server_paths["timestamp"]; - SimpleLogger().Write(logDEBUG) << "Threads:\t" << requested_thread_num; - SimpleLogger().Write(logDEBUG) << "IP address:\t" << ip_address; - SimpleLogger().Write(logDEBUG) << "IP port:\t" << ip_port; - } + + SimpleLogger().Write(logDEBUG) << "Threads:\t" << requested_thread_num; + SimpleLogger().Write(logDEBUG) << "IP address:\t" << ip_address; + SimpleLogger().Write(logDEBUG) << "IP port:\t" << ip_port; #ifndef _WIN32 int sig = 0; sigset_t new_mask;