Cleanup library setup

This commit is contained in:
Patrick Niklaus 2015-12-14 22:00:20 +01:00
parent 5a9bee0527
commit 6daa3290d4
7 changed files with 30 additions and 97 deletions

View File

@ -25,33 +25,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SERVER_CONFIG_HPP
#define SERVER_CONFIG_HPP
#ifndef LIBOSRM_CONFIG_HPP
#define LIBOSRM_CONFIG_HPP
#include <osrm/server_paths.hpp>
#include <boost/filesystem/path.hpp>
struct libosrm_config
#include <unordered_map>
#include <string>
struct LibOSRMConfig
{
libosrm_config(const libosrm_config &) = delete;
libosrm_config()
: max_locations_distance_table(100), max_locations_map_matching(-1),
use_shared_memory(true)
{
}
libosrm_config(ServerPaths paths,
const bool sharedmemory_flag,
const int max_table,
const int max_matching)
: server_paths(std::move(paths)), max_locations_distance_table(max_table),
max_locations_map_matching(max_matching), use_shared_memory(sharedmemory_flag)
{
}
ServerPaths server_paths;
int max_locations_distance_table;
int max_locations_map_matching;
bool use_shared_memory;
std::unordered_map<std::string, boost::filesystem::path> server_paths;
int max_locations_distance_table = -1;
int max_locations_map_matching = -1;
bool use_shared_memory = true;
};
#endif // SERVER_CONFIG_HPP

View File

@ -1,38 +0,0 @@
/*
Copyright (c) 2013, Project OSRM contributors
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_PATH_H
#define SERVER_PATH_H
#include <boost/filesystem.hpp>
#include <unordered_map>
#include <string>
using ServerPaths = std::unordered_map<std::string, boost::filesystem::path>;
#endif // SERVER_PATH_H

View File

@ -49,9 +49,9 @@ class OSRM
std::unique_ptr<OSRM_impl> OSRM_pimpl_;
public:
explicit OSRM(libosrm_config &lib_config);
explicit OSRM(LibOSRMConfig lib_config);
~OSRM();
int RunQuery(RouteParameters &route_parameters, osrm::json::Object &json_result);
int RunQuery(const RouteParameters &route_parameters, osrm::json::Object &json_result);
};
#endif // OSRM_HPP

View File

@ -62,7 +62,7 @@ class named_mutex;
#include <utility>
#include <vector>
OSRM_impl::OSRM_impl(libosrm_config &lib_config)
OSRM_impl::OSRM_impl(LibOSRMConfig lib_config)
{
if (lib_config.use_shared_memory)
{
@ -88,26 +88,14 @@ OSRM_impl::OSRM_impl(libosrm_config &lib_config)
RegisterPlugin(new RoundTripPlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
}
OSRM_impl::~OSRM_impl()
void OSRM_impl::RegisterPlugin(BasePlugin *raw_plugin_ptr)
{
delete query_data_facade;
for (PluginMap::value_type &plugin_pointer : plugin_map)
{
delete plugin_pointer.second;
}
std::unique_ptr<BasePlugin> plugin_ptr(raw_plugin_ptr);
SimpleLogger().Write() << "loaded plugin: " << plugin_ptr->GetDescriptor();
plugin_map[plugin_ptr->GetDescriptor()] = std::move(plugin_ptr);
}
void OSRM_impl::RegisterPlugin(BasePlugin *plugin)
{
SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor();
if (plugin_map.find(plugin->GetDescriptor()) != plugin_map.end())
{
delete plugin_map.find(plugin->GetDescriptor())->second;
}
plugin_map.emplace(plugin->GetDescriptor(), plugin);
}
int OSRM_impl::RunQuery(RouteParameters &route_parameters, osrm::json::Object &json_result)
int OSRM_impl::RunQuery(const RouteParameters &route_parameters, osrm::json::Object &json_result)
{
const auto &plugin_iterator = plugin_map.find(route_parameters.service);
@ -171,11 +159,11 @@ void OSRM_impl::increase_concurrent_query_count()
}
// proxy code for compilation firewall
OSRM::OSRM(libosrm_config &lib_config) : OSRM_pimpl_(osrm::make_unique<OSRM_impl>(lib_config)) {}
OSRM::OSRM(LibOSRMConfig lib_config) : OSRM_pimpl_(osrm::make_unique<OSRM_impl>(std::move(lib_config))) {}
OSRM::~OSRM() { OSRM_pimpl_.reset(); }
int OSRM::RunQuery(RouteParameters &route_parameters, osrm::json::Object &json_result)
int OSRM::RunQuery(const RouteParameters &route_parameters, osrm::json::Object &json_result)
{
return OSRM_pimpl_->RunQuery(route_parameters, json_result);
}

View File

@ -43,16 +43,15 @@ struct RouteParameters;
struct SharedBarriers;
template <class EdgeDataT> class BaseDataFacade;
class OSRM_impl
class OSRM_impl final
{
private:
using PluginMap = std::unordered_map<std::string, BasePlugin *>;
using PluginMap = std::unordered_map<std::string, std::unique_ptr<BasePlugin>>;
public:
OSRM_impl(libosrm_config &lib_config);
OSRM_impl(LibOSRMConfig lib_config);
OSRM_impl(const OSRM_impl &) = delete;
virtual ~OSRM_impl();
int RunQuery(RouteParameters &route_parameters, osrm::json::Object &json_result);
int RunQuery(const RouteParameters &route_parameters, osrm::json::Object &json_result);
private:
void RegisterPlugin(BasePlugin *plugin);

View File

@ -72,10 +72,7 @@ int main(int argc, const char *argv[]) try
std::string ip_address;
int ip_port, requested_thread_num;
libosrm_config lib_config;
// make the behaviour of routed backward compatible
lib_config.use_shared_memory = false;
LibOSRMConfig lib_config;
const unsigned init_result = GenerateServerProgramOptions(
argc, argv, lib_config.server_paths, ip_address, ip_port, requested_thread_num,
lib_config.use_shared_memory, trial_run, lib_config.max_locations_distance_table,

View File

@ -182,13 +182,13 @@ inline unsigned GenerateServerProgramOptions(const int argc,
"threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8),
"Number of threads to use")(
"shared-memory,s",
boost::program_options::value<bool>(&use_shared_memory)->implicit_value(true),
boost::program_options::value<bool>(&use_shared_memory)->implicit_value(false),
"Load data from shared memory")(
"max-table-size",
boost::program_options::value<int>(&max_locations_distance_table)->default_value(100),
"Max. locations supported in distance table query")(
"max-matching-size",
boost::program_options::value<int>(&max_locations_map_matching)->default_value(2),
boost::program_options::value<int>(&max_locations_map_matching)->default_value(100),
"Max. locations supported in map matching query");
// hidden options, will be allowed both on command line and in config
@ -262,9 +262,9 @@ inline unsigned GenerateServerProgramOptions(const int argc,
{
return INIT_OK_START_ENGINE;
}
if (1 > max_locations_distance_table)
if (2 > max_locations_distance_table)
{
throw osrm::exception("Max location for distance table must be a positive number");
throw osrm::exception("Max location for distance table must be at least two");
}
if (2 > max_locations_map_matching)
{