From e2605c2838ad937030da50f828b9ba114a8c75f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Thu, 27 Nov 2014 12:09:07 +0100 Subject: [PATCH 1/7] Add a commande line option to osrm-routed for max locations supported in distance table query --- Library/OSRM.h | 2 +- Library/OSRM_impl.cpp | 8 ++++---- Library/OSRM_impl.h | 2 +- Util/ProgramOptions.h | 13 +++++++++++-- plugins/distance_table.hpp | 9 ++++++--- routed.cpp | 7 ++++--- tools/simpleclient.cpp | 5 +++-- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Library/OSRM.h b/Library/OSRM.h index 372e82c3919..6bfa845a66e 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -46,7 +46,7 @@ class OSRM std::unique_ptr OSRM_pimpl_; public: - explicit OSRM(ServerPaths paths, const bool use_shared_memory = false); + explicit OSRM(ServerPaths paths, const bool use_shared_memory = false, const int max_locations_distance_table = 100); ~OSRM(); void RunQuery(RouteParameters &route_parameters, http::Reply &reply); }; diff --git a/Library/OSRM_impl.cpp b/Library/OSRM_impl.cpp index 40fef682ce9..b0e7f013dbe 100644 --- a/Library/OSRM_impl.cpp +++ b/Library/OSRM_impl.cpp @@ -57,7 +57,7 @@ namespace boost { namespace interprocess { class named_mutex; } } #include #include -OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory) +OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory, const int max_locations_distance_table) { if (use_shared_memory) { @@ -72,7 +72,7 @@ OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory) } // The following plugins handle all requests. - RegisterPlugin(new DistanceTablePlugin>(query_data_facade)); + RegisterPlugin(new DistanceTablePlugin>(query_data_facade, max_locations_distance_table)); RegisterPlugin(new HelloWorldPlugin()); RegisterPlugin(new LocatePlugin>(query_data_facade)); RegisterPlugin(new NearestPlugin>(query_data_facade)); @@ -152,8 +152,8 @@ void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply) // proxy code for compilation firewall -OSRM::OSRM(ServerPaths paths, const bool use_shared_memory) - : OSRM_pimpl_(osrm::make_unique(paths, use_shared_memory)) +OSRM::OSRM(ServerPaths paths, const bool use_shared_memory, const int max_locations_distance_table) + : OSRM_pimpl_(osrm::make_unique(paths, use_shared_memory, max_locations_distance_table)) { } diff --git a/Library/OSRM_impl.h b/Library/OSRM_impl.h index e8b47df56c8..56dc137d952 100644 --- a/Library/OSRM_impl.h +++ b/Library/OSRM_impl.h @@ -49,7 +49,7 @@ class OSRM_impl using PluginMap = std::unordered_map; public: - OSRM_impl(ServerPaths paths, const bool use_shared_memory); + OSRM_impl(ServerPaths paths, const bool use_shared_memory, const int max_locations_distance_table); OSRM_impl(const OSRM_impl &) = delete; virtual ~OSRM_impl(); void RunQuery(RouteParameters &route_parameters, http::Reply &reply); diff --git a/Util/ProgramOptions.h b/Util/ProgramOptions.h index 3329b3108de..1f9a2404bdf 100644 --- a/Util/ProgramOptions.h +++ b/Util/ProgramOptions.h @@ -151,7 +151,8 @@ inline unsigned GenerateServerProgramOptions(const int argc, int &ip_port, int &requested_num_threads, bool &use_shared_memory, - bool &trial) + bool &trial, + int &max_locations_distance_table) { // declare a group of options that will be allowed only on command line boost::program_options::options_description generic_options("Options"); @@ -198,7 +199,10 @@ inline unsigned GenerateServerProgramOptions(const int argc, "Number of threads to use")( "sharedmemory,s", boost::program_options::value(&use_shared_memory)->implicit_value(true), - "Load data from shared memory"); + "Load data from shared memory")( + "max_locations_distance_table", + boost::program_options::value(&max_locations_distance_table)->default_value(100), + "Max locations supported in distance table query"); // hidden options, will be allowed both on command line and in config // file, but will not be shown to the user @@ -272,6 +276,11 @@ inline unsigned GenerateServerProgramOptions(const int argc, { return INIT_OK_START_ENGINE; } + if (1 > max_locations_distance_table) + { + throw OSRMException("Max location for distance table must be a positive number"); + } + SimpleLogger().Write() << visible_options; return INIT_OK_DO_NOT_START_ENGINE; } diff --git a/plugins/distance_table.hpp b/plugins/distance_table.hpp index 6ef90a5b830..33dd7cb0b9c 100644 --- a/plugins/distance_table.hpp +++ b/plugins/distance_table.hpp @@ -52,9 +52,11 @@ template class DistanceTablePlugin final : public BasePlugin { private: std::unique_ptr> search_engine_ptr; + int max_locations_distance_table; public: - explicit DistanceTablePlugin(DataFacadeT *facade) : descriptor_string("table"), facade(facade) + explicit DistanceTablePlugin(DataFacadeT *facade, const int max_locations_distance_table) : + max_locations_distance_table(max_locations_distance_table), descriptor_string("table"), facade(facade) { search_engine_ptr = osrm::make_unique>(facade); } @@ -72,8 +74,9 @@ template class DistanceTablePlugin final : public BasePlugin } const bool checksum_OK = (route_parameters.check_sum == facade->GetCheckSum()); - unsigned max_locations = - std::min(100u, static_cast(route_parameters.coordinates.size())); + unsigned max_locations = std::min(static_cast(max_locations_distance_table), + static_cast(route_parameters.coordinates.size())); + PhantomNodeArray phantom_node_vector(max_locations); for (const auto i : osrm::irange(0u, max_locations)) { diff --git a/routed.cpp b/routed.cpp index 1be6dd80534..26a39ef1251 100644 --- a/routed.cpp +++ b/routed.cpp @@ -71,7 +71,7 @@ int main(int argc, const char *argv[]) bool use_shared_memory = false, trial_run = false; std::string ip_address; - int ip_port, requested_thread_num; + int ip_port, requested_thread_num, max_locations_distance_table; ServerPaths server_paths; @@ -82,7 +82,8 @@ int main(int argc, const char *argv[]) ip_port, requested_thread_num, use_shared_memory, - trial_run); + trial_run, + max_locations_distance_table); if (init_result == INIT_OK_DO_NOT_START_ENGINE) { return 0; @@ -117,7 +118,7 @@ int main(int argc, const char *argv[]) pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); #endif - OSRM osrm_lib(server_paths, use_shared_memory); + OSRM osrm_lib(server_paths, use_shared_memory, max_locations_distance_table); auto routing_server = Server::CreateServer(ip_address, ip_port, requested_thread_num); diff --git a/tools/simpleclient.cpp b/tools/simpleclient.cpp index d9c8217b92e..fb26d4ba953 100644 --- a/tools/simpleclient.cpp +++ b/tools/simpleclient.cpp @@ -65,7 +65,7 @@ int main(int argc, const char *argv[]) try { std::string ip_address; - int ip_port, requested_thread_num; + int ip_port, requested_thread_num, max_locations_distance_table; bool use_shared_memory = false, trial_run = false; ServerPaths server_paths; @@ -76,7 +76,8 @@ int main(int argc, const char *argv[]) ip_port, requested_thread_num, use_shared_memory, - trial_run); + trial_run, + max_locations_distance_table); if (init_result == INIT_FAILED) { From 7075a8a8ef66f0dd8ec0f0b3f7aab701e3232354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Tue, 23 Dec 2014 15:33:53 +0100 Subject: [PATCH 2/7] Fix tests for new option --max_locations_distance_table --- features/options/routed/help.feature | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/features/options/routed/help.feature b/features/options/routed/help.feature index 9603c40dde5..f11787d6cd2 100644 --- a/features/options/routed/help.feature +++ b/features/options/routed/help.feature @@ -25,7 +25,8 @@ Feature: osrm-routed command line options: help And stdout should contain "--port" And stdout should contain "--threads" And stdout should contain "--sharedmemory" - And stdout should contain 22 lines + And stdout should contain "--max_locations_distance_table" + And stdout should contain 25 lines And it should exit with code 0 Scenario: osrm-routed - Help, short @@ -49,7 +50,8 @@ Feature: osrm-routed command line options: help And stdout should contain "--port" And stdout should contain "--threads" And stdout should contain "--sharedmemory" - And stdout should contain 22 lines + And stdout should contain "--max_locations_distance_table" + And stdout should contain 25 lines And it should exit with code 0 Scenario: osrm-routed - Help, long @@ -73,5 +75,6 @@ Feature: osrm-routed command line options: help And stdout should contain "--port" And stdout should contain "--threads" And stdout should contain "--sharedmemory" - And stdout should contain 22 lines + And stdout should contain "--max_locations_distance_table" + And stdout should contain 25 lines And it should exit with code 0 From ced64d7a0986fb45493d6ce20f9e61d8025c0750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Tue, 23 Dec 2014 15:34:54 +0100 Subject: [PATCH 3/7] Move server configuration from method parameter to a struct --- Include/osrm/ServerConfig.h | 48 +++++++++++++++++++++++++++++++ Library/OSRM.h | 4 +-- Library/OSRM_impl.cpp | 17 +++++------ Library/OSRM_impl.h | 5 ++-- data_structures/server_config.hpp | 39 +++++++++++++++++++++++++ routed.cpp | 6 +++- 6 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 Include/osrm/ServerConfig.h create mode 100644 data_structures/server_config.hpp diff --git a/Include/osrm/ServerConfig.h b/Include/osrm/ServerConfig.h new file mode 100644 index 00000000000..4c6b52a1dda --- /dev/null +++ b/Include/osrm/ServerConfig.h @@ -0,0 +1,48 @@ +/* + +Copyright (c) 2014, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef SERVER_CONFIG_H +#define SERVER_CONFIG_H + +#include + +struct ServerConfig +{ + ServerConfig(); + + void setServerPaths(const ServerPaths paths); + + void setUseSharedMemory(const bool use_shared_memory); + + void setMaxLocationsDistanceTable(const int max_locations_distance_table); + + ServerPaths server_paths; + bool use_shared_memory; + int max_locations_distance_table; +}; + +#endif // SERVER_CONFIG_H diff --git a/Library/OSRM.h b/Library/OSRM.h index 6bfa845a66e..3c9c4d5e589 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef OSRM_H #define OSRM_H -#include +#include #include @@ -46,7 +46,7 @@ class OSRM std::unique_ptr OSRM_pimpl_; public: - explicit OSRM(ServerPaths paths, const bool use_shared_memory = false, const int max_locations_distance_table = 100); + explicit OSRM(ServerConfig serverConfig); ~OSRM(); void RunQuery(RouteParameters &route_parameters, http::Reply &reply); }; diff --git a/Library/OSRM_impl.cpp b/Library/OSRM_impl.cpp index b0e7f013dbe..8604878aef6 100644 --- a/Library/OSRM_impl.cpp +++ b/Library/OSRM_impl.cpp @@ -32,7 +32,7 @@ namespace boost { namespace interprocess { class named_mutex; } } #include #include -#include +#include #include "../plugins/distance_table.hpp" #include "../plugins/hello_world.hpp" @@ -57,9 +57,9 @@ namespace boost { namespace interprocess { class named_mutex; } } #include #include -OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory, const int max_locations_distance_table) +OSRM_impl::OSRM_impl(ServerConfig serverConfig) { - if (use_shared_memory) + if (serverConfig.use_shared_memory) { barrier = osrm::make_unique(); query_data_facade = new SharedDataFacade(); @@ -67,12 +67,13 @@ OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory, con else { // populate base path - populate_base_path(server_paths); - query_data_facade = new InternalDataFacade(server_paths); + populate_base_path(serverConfig.server_paths); + query_data_facade = new InternalDataFacade(serverConfig.server_paths); } // The following plugins handle all requests. - RegisterPlugin(new DistanceTablePlugin>(query_data_facade, max_locations_distance_table)); + RegisterPlugin(new DistanceTablePlugin>(query_data_facade, + serverConfig.max_locations_distance_table)); RegisterPlugin(new HelloWorldPlugin()); RegisterPlugin(new LocatePlugin>(query_data_facade)); RegisterPlugin(new NearestPlugin>(query_data_facade)); @@ -152,8 +153,8 @@ void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply) // proxy code for compilation firewall -OSRM::OSRM(ServerPaths paths, const bool use_shared_memory, const int max_locations_distance_table) - : OSRM_pimpl_(osrm::make_unique(paths, use_shared_memory, max_locations_distance_table)) +OSRM::OSRM(ServerConfig server_config) + : OSRM_pimpl_(osrm::make_unique(server_config)) { } diff --git a/Library/OSRM_impl.h b/Library/OSRM_impl.h index 56dc137d952..2b9639fb8da 100644 --- a/Library/OSRM_impl.h +++ b/Library/OSRM_impl.h @@ -32,8 +32,9 @@ class BasePlugin; namespace http { class Reply; } struct RouteParameters; -#include +#include +#include "../data_structures/server_config.hpp" #include "../data_structures/query_edge.hpp" #include @@ -49,7 +50,7 @@ class OSRM_impl using PluginMap = std::unordered_map; public: - OSRM_impl(ServerPaths paths, const bool use_shared_memory, const int max_locations_distance_table); + OSRM_impl(ServerConfig serverConfig); OSRM_impl(const OSRM_impl &) = delete; virtual ~OSRM_impl(); void RunQuery(RouteParameters &route_parameters, http::Reply &reply); diff --git a/data_structures/server_config.hpp b/data_structures/server_config.hpp new file mode 100644 index 00000000000..7adbd56942d --- /dev/null +++ b/data_structures/server_config.hpp @@ -0,0 +1,39 @@ +/* + +Copyright (c) 2014, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include + +ServerConfig::ServerConfig() + : use_shared_memory(false), max_locations_distance_table(100) +{ +} + +void ServerConfig::setServerPaths(const ServerPaths object) { server_paths = object; } + +void ServerConfig::setUseSharedMemory(const bool flag) { use_shared_memory = flag; } + +void ServerConfig::setMaxLocationsDistanceTable(const int max) { max_locations_distance_table = max; } diff --git a/routed.cpp b/routed.cpp index 26a39ef1251..6133577fc87 100644 --- a/routed.cpp +++ b/routed.cpp @@ -118,7 +118,11 @@ int main(int argc, const char *argv[]) pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); #endif - OSRM osrm_lib(server_paths, use_shared_memory, max_locations_distance_table); + ServerConfig server_config; + server_config.setServerPaths(server_paths); + server_config.setUseSharedMemory(use_shared_memory); + server_config.setMaxLocationsDistanceTable(max_locations_distance_table); + OSRM osrm_lib(server_config); auto routing_server = Server::CreateServer(ip_address, ip_port, requested_thread_num); From 598f5519d109903861d234f94e4a2484e4aedc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Mon, 5 Jan 2015 15:48:24 +0100 Subject: [PATCH 4/7] Remove setters from structures server_config --- Include/osrm/ServerConfig.h | 17 ++++++++------ Library/OSRM_impl.h | 1 - data_structures/server_config.hpp | 39 ------------------------------- routed.cpp | 5 +--- 4 files changed, 11 insertions(+), 51 deletions(-) delete mode 100644 data_structures/server_config.hpp diff --git a/Include/osrm/ServerConfig.h b/Include/osrm/ServerConfig.h index 4c6b52a1dda..a3ffb11e21c 100644 --- a/Include/osrm/ServerConfig.h +++ b/Include/osrm/ServerConfig.h @@ -32,13 +32,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. struct ServerConfig { - ServerConfig(); - - void setServerPaths(const ServerPaths paths); - - void setUseSharedMemory(const bool use_shared_memory); - - void setMaxLocationsDistanceTable(const int max_locations_distance_table); + ServerConfig() + : use_shared_memory(false) + , max_locations_distance_table(100) + {} + + ServerConfig(const ServerPaths paths, const bool flag, const int max) + : server_paths(paths) + , use_shared_memory(flag) + , max_locations_distance_table(max) + {} ServerPaths server_paths; bool use_shared_memory; diff --git a/Library/OSRM_impl.h b/Library/OSRM_impl.h index 2b9639fb8da..bf28c8bf9e4 100644 --- a/Library/OSRM_impl.h +++ b/Library/OSRM_impl.h @@ -34,7 +34,6 @@ struct RouteParameters; #include -#include "../data_structures/server_config.hpp" #include "../data_structures/query_edge.hpp" #include diff --git a/data_structures/server_config.hpp b/data_structures/server_config.hpp deleted file mode 100644 index 7adbd56942d..00000000000 --- a/data_structures/server_config.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - -Copyright (c) 2014, Project OSRM, Dennis Luxen, others -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this list -of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this -list of conditions and the following disclaimer in the documentation and/or -other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ - -#include - -ServerConfig::ServerConfig() - : use_shared_memory(false), max_locations_distance_table(100) -{ -} - -void ServerConfig::setServerPaths(const ServerPaths object) { server_paths = object; } - -void ServerConfig::setUseSharedMemory(const bool flag) { use_shared_memory = flag; } - -void ServerConfig::setMaxLocationsDistanceTable(const int max) { max_locations_distance_table = max; } diff --git a/routed.cpp b/routed.cpp index 6133577fc87..8224c2e7b57 100644 --- a/routed.cpp +++ b/routed.cpp @@ -118,10 +118,7 @@ int main(int argc, const char *argv[]) pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); #endif - ServerConfig server_config; - server_config.setServerPaths(server_paths); - server_config.setUseSharedMemory(use_shared_memory); - server_config.setMaxLocationsDistanceTable(max_locations_distance_table); + ServerConfig server_config(server_paths, use_shared_memory, max_locations_distance_table); OSRM osrm_lib(server_config); auto routing_server = Server::CreateServer(ip_address, ip_port, requested_thread_num); From 12f2acc9ff917d60af23fe1786c0bce8c402a305 Mon Sep 17 00:00:00 2001 From: Frederic Rodrigo Date: Tue, 6 Jan 2015 15:33:57 +0000 Subject: [PATCH 5/7] Order ServerPaths members by memory size, pass ServerPaths by ref --- Include/osrm/ServerConfig.h | 12 ++++++------ Library/OSRM_impl.cpp | 2 +- Library/OSRM_impl.h | 2 +- Util/ProgramOptions.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Include/osrm/ServerConfig.h b/Include/osrm/ServerConfig.h index a3ffb11e21c..3c48f3c5617 100644 --- a/Include/osrm/ServerConfig.h +++ b/Include/osrm/ServerConfig.h @@ -1,6 +1,6 @@ /* -Copyright (c) 2014, Project OSRM, Dennis Luxen, others +Copyright (c) 2015, Project OSRM, Dennis Luxen, others All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -33,19 +33,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. struct ServerConfig { ServerConfig() - : use_shared_memory(false) - , max_locations_distance_table(100) + : max_locations_distance_table(100) + , use_shared_memory(false) {} - ServerConfig(const ServerPaths paths, const bool flag, const int max) + ServerConfig(const ServerPaths &paths, const bool flag, const int max) : server_paths(paths) - , use_shared_memory(flag) , max_locations_distance_table(max) + , use_shared_memory(flag) {} ServerPaths server_paths; - bool use_shared_memory; int max_locations_distance_table; + bool use_shared_memory; }; #endif // SERVER_CONFIG_H diff --git a/Library/OSRM_impl.cpp b/Library/OSRM_impl.cpp index 8604878aef6..6b3a2e11f3a 100644 --- a/Library/OSRM_impl.cpp +++ b/Library/OSRM_impl.cpp @@ -57,7 +57,7 @@ namespace boost { namespace interprocess { class named_mutex; } } #include #include -OSRM_impl::OSRM_impl(ServerConfig serverConfig) +OSRM_impl::OSRM_impl(ServerConfig &serverConfig) { if (serverConfig.use_shared_memory) { diff --git a/Library/OSRM_impl.h b/Library/OSRM_impl.h index bf28c8bf9e4..94aa123a954 100644 --- a/Library/OSRM_impl.h +++ b/Library/OSRM_impl.h @@ -49,7 +49,7 @@ class OSRM_impl using PluginMap = std::unordered_map; public: - OSRM_impl(ServerConfig serverConfig); + OSRM_impl(ServerConfig &serverConfig); OSRM_impl(const OSRM_impl &) = delete; virtual ~OSRM_impl(); void RunQuery(RouteParameters &route_parameters, http::Reply &reply); diff --git a/Util/ProgramOptions.h b/Util/ProgramOptions.h index 1f9a2404bdf..ae50cd97f9f 100644 --- a/Util/ProgramOptions.h +++ b/Util/ProgramOptions.h @@ -278,7 +278,7 @@ inline unsigned GenerateServerProgramOptions(const int argc, } if (1 > max_locations_distance_table) { - throw OSRMException("Max location for distance table must be a positive number"); + throw osrm::exception("Max location for distance table must be a positive number"); } SimpleLogger().Write() << visible_options; From c6bb7c5993fcd3c525f29b1d8b0689c2e5997212 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 Jan 2015 15:05:54 +0100 Subject: [PATCH 6/7] renamed: Include/osrm/ServerConfig.h -> Include/osrm/libosrm_config.hpp pass lib config object by reference --- .../osrm/{ServerConfig.h => libosrm_config.hpp} | 7 ++++--- Library/OSRM.h | 4 ++-- Library/OSRM_impl.cpp | 14 +++++++------- Library/OSRM_impl.h | 4 ++-- routed.cpp | 17 ++++++++--------- tools/simpleclient.cpp | 12 ++++++------ 6 files changed, 29 insertions(+), 29 deletions(-) rename Include/osrm/{ServerConfig.h => libosrm_config.hpp} (90%) diff --git a/Include/osrm/ServerConfig.h b/Include/osrm/libosrm_config.hpp similarity index 90% rename from Include/osrm/ServerConfig.h rename to Include/osrm/libosrm_config.hpp index bcd561d6916..078c28f8f8a 100644 --- a/Include/osrm/ServerConfig.h +++ b/Include/osrm/libosrm_config.hpp @@ -30,14 +30,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -struct ServerConfig +struct libosrm_config { - ServerConfig() + libosrm_config(const libosrm_config&) = delete; + libosrm_config() : max_locations_distance_table(100) , use_shared_memory(false) {} - ServerConfig(const ServerPaths &paths, const bool flag, const int max) + libosrm_config(const ServerPaths &paths, const bool flag, const int max) : server_paths(paths) , max_locations_distance_table(max) , use_shared_memory(flag) diff --git a/Library/OSRM.h b/Library/OSRM.h index 1f35ec27258..d51f8dcee1a 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef OSRM_H #define OSRM_H -#include +#include #include @@ -46,7 +46,7 @@ class OSRM std::unique_ptr OSRM_pimpl_; public: - explicit OSRM(ServerConfig serverConfig); + explicit OSRM(libosrm_config &lib_config); ~OSRM(); int RunQuery(RouteParameters &route_parameters, JSON::Object &json_result); }; diff --git a/Library/OSRM_impl.cpp b/Library/OSRM_impl.cpp index a557aa66a7c..38f5fd1d9b6 100644 --- a/Library/OSRM_impl.cpp +++ b/Library/OSRM_impl.cpp @@ -55,9 +55,9 @@ namespace boost { namespace interprocess { class named_mutex; } } #include #include -OSRM_impl::OSRM_impl(ServerConfig &serverConfig) +OSRM_impl::OSRM_impl(libosrm_config &lib_config) { - if (serverConfig.use_shared_memory) + if (lib_config.use_shared_memory) { barrier = osrm::make_unique(); query_data_facade = new SharedDataFacade(); @@ -65,13 +65,13 @@ OSRM_impl::OSRM_impl(ServerConfig &serverConfig) else { // populate base path - populate_base_path(serverConfig.server_paths); - query_data_facade = new InternalDataFacade(serverConfig.server_paths); + populate_base_path(lib_config.server_paths); + query_data_facade = new InternalDataFacade(lib_config.server_paths); } // The following plugins handle all requests. RegisterPlugin(new DistanceTablePlugin>(query_data_facade, - serverConfig.max_locations_distance_table)); + lib_config.max_locations_distance_table)); RegisterPlugin(new HelloWorldPlugin()); RegisterPlugin(new LocatePlugin>(query_data_facade)); RegisterPlugin(new NearestPlugin>(query_data_facade)); @@ -151,8 +151,8 @@ int OSRM_impl::RunQuery(RouteParameters &route_parameters, JSON::Object &json_re // proxy code for compilation firewall -OSRM::OSRM(ServerConfig server_config) - : OSRM_pimpl_(osrm::make_unique(server_config)) +OSRM::OSRM(libosrm_config &lib_config) + : OSRM_pimpl_(osrm::make_unique(lib_config)) { } diff --git a/Library/OSRM_impl.h b/Library/OSRM_impl.h index 51968627760..176ede68888 100644 --- a/Library/OSRM_impl.h +++ b/Library/OSRM_impl.h @@ -35,7 +35,7 @@ struct RouteParameters; #include "../data_structures/query_edge.hpp" #include -#include +#include #include #include @@ -50,7 +50,7 @@ class OSRM_impl using PluginMap = std::unordered_map; public: - OSRM_impl(ServerConfig &serverConfig); + OSRM_impl(libosrm_config &lib_config); OSRM_impl(const OSRM_impl &) = delete; virtual ~OSRM_impl(); int RunQuery(RouteParameters &route_parameters, JSON::Object &json_result); diff --git a/routed.cpp b/routed.cpp index 8224c2e7b57..a0caac1f460 100644 --- a/routed.cpp +++ b/routed.cpp @@ -69,21 +69,21 @@ int main(int argc, const char *argv[]) { LogPolicy::GetInstance().Unmute(); - bool use_shared_memory = false, trial_run = false; + bool trial_run = false; std::string ip_address; - int ip_port, requested_thread_num, max_locations_distance_table; + int ip_port, requested_thread_num; - ServerPaths server_paths; + libosrm_config lib_config; const unsigned init_result = GenerateServerProgramOptions(argc, argv, - server_paths, + lib_config.server_paths, ip_address, ip_port, requested_thread_num, - use_shared_memory, + lib_config.use_shared_memory, trial_run, - max_locations_distance_table); + lib_config.max_locations_distance_table); if (init_result == INIT_OK_DO_NOT_START_ENGINE) { return 0; @@ -102,7 +102,7 @@ int main(int argc, const char *argv[]) #endif SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION; - if (use_shared_memory) + if (lib_config.use_shared_memory) { SimpleLogger().Write(logDEBUG) << "Loading from shared memory"; } @@ -118,8 +118,7 @@ int main(int argc, const char *argv[]) pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); #endif - ServerConfig server_config(server_paths, use_shared_memory, max_locations_distance_table); - OSRM osrm_lib(server_config); + OSRM osrm_lib(lib_config); auto routing_server = Server::CreateServer(ip_address, ip_port, requested_thread_num); diff --git a/tools/simpleclient.cpp b/tools/simpleclient.cpp index 0a736d8b769..0bb47599bed 100644 --- a/tools/simpleclient.cpp +++ b/tools/simpleclient.cpp @@ -32,8 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Util/simple_logger.hpp" #include +#include #include -#include #include @@ -45,16 +45,16 @@ int main(int argc, const char *argv[]) std::string ip_address; int ip_port, requested_thread_num; bool trial_run = false; - ServerConfig server_config; + libosrm_config lib_config; const unsigned init_result = GenerateServerProgramOptions(argc, argv, - server_config.server_paths, + lib_config.server_paths, ip_address, ip_port, requested_thread_num, - server_config.use_shared_memory, + lib_config.use_shared_memory, trial_run, - server_config.max_locations_distance_table); + lib_config.max_locations_distance_table); if (init_result == INIT_OK_DO_NOT_START_ENGINE) { @@ -66,7 +66,7 @@ int main(int argc, const char *argv[]) } SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION; - OSRM routing_machine(server_config); + OSRM routing_machine(lib_config); RouteParameters route_parameters; route_parameters.zoom_level = 18; // no generalization From 91a89399f8d28b2687c4f4d2372f6393087e058c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 Jan 2015 15:07:01 +0100 Subject: [PATCH 7/7] fix copyright year --- Library/OSRM.h | 2 +- Library/OSRM_impl.cpp | 2 +- Library/OSRM_impl.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/OSRM.h b/Library/OSRM.h index d51f8dcee1a..1f0acebfade 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -1,6 +1,6 @@ /* -Copyright (c) 2013, Project OSRM, Dennis Luxen, others +Copyright (c) 2015, Project OSRM, Dennis Luxen, others All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/Library/OSRM_impl.cpp b/Library/OSRM_impl.cpp index 38f5fd1d9b6..6b67a675df0 100644 --- a/Library/OSRM_impl.cpp +++ b/Library/OSRM_impl.cpp @@ -1,6 +1,6 @@ /* -Copyright (c) 2014, Project OSRM, Dennis Luxen, others +Copyright (c) 2015, Project OSRM, Dennis Luxen, others All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/Library/OSRM_impl.h b/Library/OSRM_impl.h index 176ede68888..625fc19caa0 100644 --- a/Library/OSRM_impl.h +++ b/Library/OSRM_impl.h @@ -1,6 +1,6 @@ /* -Copyright (c) 2013, Project OSRM, Dennis Luxen, others +Copyright (c) 2015, Project OSRM, Dennis Luxen, others All rights reserved. Redistribution and use in source and binary forms, with or without modification,