Cleanup library setup
This commit is contained in:
parent
5a9bee0527
commit
6daa3290d4
@ -25,33 +25,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SERVER_CONFIG_HPP
|
#ifndef LIBOSRM_CONFIG_HPP
|
||||||
#define SERVER_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;
|
std::unordered_map<std::string, boost::filesystem::path> server_paths;
|
||||||
libosrm_config()
|
int max_locations_distance_table = -1;
|
||||||
: max_locations_distance_table(100), max_locations_map_matching(-1),
|
int max_locations_map_matching = -1;
|
||||||
use_shared_memory(true)
|
bool 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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SERVER_CONFIG_HPP
|
#endif // SERVER_CONFIG_HPP
|
||||||
|
@ -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
|
|
@ -49,9 +49,9 @@ class OSRM
|
|||||||
std::unique_ptr<OSRM_impl> OSRM_pimpl_;
|
std::unique_ptr<OSRM_impl> OSRM_pimpl_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit OSRM(libosrm_config &lib_config);
|
explicit OSRM(LibOSRMConfig lib_config);
|
||||||
~OSRM();
|
~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
|
#endif // OSRM_HPP
|
||||||
|
@ -62,7 +62,7 @@ class named_mutex;
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
OSRM_impl::OSRM_impl(libosrm_config &lib_config)
|
OSRM_impl::OSRM_impl(LibOSRMConfig lib_config)
|
||||||
{
|
{
|
||||||
if (lib_config.use_shared_memory)
|
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));
|
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;
|
std::unique_ptr<BasePlugin> plugin_ptr(raw_plugin_ptr);
|
||||||
for (PluginMap::value_type &plugin_pointer : plugin_map)
|
SimpleLogger().Write() << "loaded plugin: " << plugin_ptr->GetDescriptor();
|
||||||
{
|
plugin_map[plugin_ptr->GetDescriptor()] = std::move(plugin_ptr);
|
||||||
delete plugin_pointer.second;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSRM_impl::RegisterPlugin(BasePlugin *plugin)
|
int OSRM_impl::RunQuery(const RouteParameters &route_parameters, osrm::json::Object &json_result)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
const auto &plugin_iterator = plugin_map.find(route_parameters.service);
|
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
|
// 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(); }
|
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);
|
return OSRM_pimpl_->RunQuery(route_parameters, json_result);
|
||||||
}
|
}
|
||||||
|
@ -43,16 +43,15 @@ struct RouteParameters;
|
|||||||
struct SharedBarriers;
|
struct SharedBarriers;
|
||||||
template <class EdgeDataT> class BaseDataFacade;
|
template <class EdgeDataT> class BaseDataFacade;
|
||||||
|
|
||||||
class OSRM_impl
|
class OSRM_impl final
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
using PluginMap = std::unordered_map<std::string, BasePlugin *>;
|
using PluginMap = std::unordered_map<std::string, std::unique_ptr<BasePlugin>>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OSRM_impl(libosrm_config &lib_config);
|
OSRM_impl(LibOSRMConfig lib_config);
|
||||||
OSRM_impl(const OSRM_impl &) = delete;
|
OSRM_impl(const OSRM_impl &) = delete;
|
||||||
virtual ~OSRM_impl();
|
int RunQuery(const RouteParameters &route_parameters, osrm::json::Object &json_result);
|
||||||
int RunQuery(RouteParameters &route_parameters, osrm::json::Object &json_result);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RegisterPlugin(BasePlugin *plugin);
|
void RegisterPlugin(BasePlugin *plugin);
|
||||||
|
@ -72,10 +72,7 @@ int main(int argc, const char *argv[]) try
|
|||||||
std::string ip_address;
|
std::string ip_address;
|
||||||
int ip_port, requested_thread_num;
|
int ip_port, requested_thread_num;
|
||||||
|
|
||||||
libosrm_config lib_config;
|
LibOSRMConfig lib_config;
|
||||||
// make the behaviour of routed backward compatible
|
|
||||||
lib_config.use_shared_memory = false;
|
|
||||||
|
|
||||||
const unsigned init_result = GenerateServerProgramOptions(
|
const unsigned init_result = GenerateServerProgramOptions(
|
||||||
argc, argv, lib_config.server_paths, ip_address, ip_port, requested_thread_num,
|
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,
|
lib_config.use_shared_memory, trial_run, lib_config.max_locations_distance_table,
|
||||||
|
@ -182,13 +182,13 @@ inline unsigned GenerateServerProgramOptions(const int argc,
|
|||||||
"threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8),
|
"threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8),
|
||||||
"Number of threads to use")(
|
"Number of threads to use")(
|
||||||
"shared-memory,s",
|
"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")(
|
"Load data from shared memory")(
|
||||||
"max-table-size",
|
"max-table-size",
|
||||||
boost::program_options::value<int>(&max_locations_distance_table)->default_value(100),
|
boost::program_options::value<int>(&max_locations_distance_table)->default_value(100),
|
||||||
"Max. locations supported in distance table query")(
|
"Max. locations supported in distance table query")(
|
||||||
"max-matching-size",
|
"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");
|
"Max. locations supported in map matching query");
|
||||||
|
|
||||||
// hidden options, will be allowed both on command line and in config
|
// 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;
|
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)
|
if (2 > max_locations_map_matching)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user