migrate Library dir to C++11, use fwd decls
This commit is contained in:
parent
abd20776a2
commit
e3244dd649
@ -28,22 +28,25 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#ifndef OSRM_H
|
#ifndef OSRM_H
|
||||||
#define OSRM_H
|
#define OSRM_H
|
||||||
|
|
||||||
#include <osrm/Reply.h>
|
#include <ServerPaths.h>
|
||||||
#include <osrm/RouteParameters.h>
|
|
||||||
#include <osrm/ServerPaths.h>
|
|
||||||
|
|
||||||
class OSRM_impl;
|
class OSRM_impl;
|
||||||
|
struct RouteParameters;
|
||||||
|
|
||||||
class OSRM {
|
namespace http
|
||||||
private:
|
{
|
||||||
OSRM_impl * OSRM_pimpl_;
|
class Reply;
|
||||||
public:
|
}
|
||||||
explicit OSRM(
|
|
||||||
const ServerPaths & paths,
|
class OSRM
|
||||||
const bool use_shared_memory = false
|
{
|
||||||
);
|
private:
|
||||||
|
OSRM_impl *OSRM_pimpl_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit OSRM(const ServerPaths &paths, const bool use_shared_memory = false);
|
||||||
~OSRM();
|
~OSRM();
|
||||||
void RunQuery(RouteParameters & route_parameters, http::Reply & reply);
|
void RunQuery(RouteParameters &route_parameters, http::Reply &reply);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // OSRM_H
|
#endif // OSRM_H
|
||||||
|
@ -41,82 +41,65 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
OSRM_impl::OSRM_impl( const ServerPaths & server_paths, const bool use_shared_memory )
|
OSRM_impl::OSRM_impl(const ServerPaths &server_paths, const bool use_shared_memory)
|
||||||
:
|
: use_shared_memory(use_shared_memory)
|
||||||
use_shared_memory(use_shared_memory)
|
|
||||||
{
|
{
|
||||||
if (use_shared_memory)
|
if (use_shared_memory)
|
||||||
{
|
{
|
||||||
barrier = new SharedBarriers();
|
barrier = new SharedBarriers();
|
||||||
query_data_facade = new SharedDataFacade<QueryEdge::EdgeData>( );
|
query_data_facade = new SharedDataFacade<QueryEdge::EdgeData>();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
query_data_facade = new InternalDataFacade<QueryEdge::EdgeData>(
|
query_data_facade = new InternalDataFacade<QueryEdge::EdgeData>(server_paths);
|
||||||
server_paths
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//The following plugins handle all requests.
|
// The following plugins handle all requests.
|
||||||
RegisterPlugin(
|
RegisterPlugin(new HelloWorldPlugin());
|
||||||
new HelloWorldPlugin()
|
RegisterPlugin(new LocatePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
|
||||||
);
|
RegisterPlugin(new NearestPlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
|
||||||
RegisterPlugin(
|
RegisterPlugin(new TimestampPlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
|
||||||
new LocatePlugin<BaseDataFacade<QueryEdge::EdgeData> >(
|
RegisterPlugin(new ViaRoutePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
|
||||||
query_data_facade
|
|
||||||
)
|
|
||||||
);
|
|
||||||
RegisterPlugin(
|
|
||||||
new NearestPlugin<BaseDataFacade<QueryEdge::EdgeData> >(
|
|
||||||
query_data_facade
|
|
||||||
)
|
|
||||||
);
|
|
||||||
RegisterPlugin(
|
|
||||||
new TimestampPlugin<BaseDataFacade<QueryEdge::EdgeData> >(
|
|
||||||
query_data_facade
|
|
||||||
)
|
|
||||||
);
|
|
||||||
RegisterPlugin(
|
|
||||||
new ViaRoutePlugin<BaseDataFacade<QueryEdge::EdgeData> >(
|
|
||||||
query_data_facade
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OSRM_impl::~OSRM_impl() {
|
OSRM_impl::~OSRM_impl()
|
||||||
BOOST_FOREACH(PluginMap::value_type & plugin_pointer, plugin_map) {
|
{
|
||||||
|
for (PluginMap::value_type &plugin_pointer : plugin_map)
|
||||||
|
{
|
||||||
delete plugin_pointer.second;
|
delete plugin_pointer.second;
|
||||||
}
|
}
|
||||||
if( use_shared_memory ) {
|
if (use_shared_memory)
|
||||||
|
{
|
||||||
delete barrier;
|
delete barrier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSRM_impl::RegisterPlugin(BasePlugin * plugin) {
|
void OSRM_impl::RegisterPlugin(BasePlugin *plugin)
|
||||||
SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor();
|
{
|
||||||
if( plugin_map.find(plugin->GetDescriptor()) != plugin_map.end() ) {
|
SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor();
|
||||||
|
if (plugin_map.find(plugin->GetDescriptor()) != plugin_map.end())
|
||||||
|
{
|
||||||
delete plugin_map.find(plugin->GetDescriptor())->second;
|
delete plugin_map.find(plugin->GetDescriptor())->second;
|
||||||
}
|
}
|
||||||
plugin_map.emplace(plugin->GetDescriptor(), plugin);
|
plugin_map.emplace(plugin->GetDescriptor(), plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSRM_impl::RunQuery(RouteParameters & route_parameters, http::Reply & reply) {
|
void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
|
||||||
const PluginMap::const_iterator & iter = plugin_map.find(
|
{
|
||||||
route_parameters.service
|
const PluginMap::const_iterator &iter = plugin_map.find(route_parameters.service);
|
||||||
);
|
|
||||||
|
|
||||||
if(plugin_map.end() != iter) {
|
if (plugin_map.end() != iter)
|
||||||
|
{
|
||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
if( use_shared_memory ) {
|
if (use_shared_memory)
|
||||||
|
{
|
||||||
// lock update pending
|
// lock update pending
|
||||||
boost::interprocess::scoped_lock<
|
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> pending_lock(
|
||||||
boost::interprocess::named_mutex
|
barrier->pending_update_mutex);
|
||||||
> pending_lock(barrier->pending_update_mutex);
|
|
||||||
|
|
||||||
// lock query
|
// lock query
|
||||||
boost::interprocess::scoped_lock<
|
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> query_lock(
|
||||||
boost::interprocess::named_mutex
|
barrier->query_mutex);
|
||||||
> query_lock(barrier->query_mutex);
|
|
||||||
|
|
||||||
// unlock update pending
|
// unlock update pending
|
||||||
pending_lock.unlock();
|
pending_lock.unlock();
|
||||||
@ -124,44 +107,44 @@ void OSRM_impl::RunQuery(RouteParameters & route_parameters, http::Reply & reply
|
|||||||
// increment query count
|
// increment query count
|
||||||
++(barrier->number_of_queries);
|
++(barrier->number_of_queries);
|
||||||
|
|
||||||
(static_cast<SharedDataFacade<QueryEdge::EdgeData>* >(query_data_facade))->CheckAndReloadFacade();
|
(static_cast<SharedDataFacade<QueryEdge::EdgeData> *>(query_data_facade))
|
||||||
|
->CheckAndReloadFacade();
|
||||||
}
|
}
|
||||||
|
|
||||||
iter->second->HandleRequest(route_parameters, reply );
|
iter->second->HandleRequest(route_parameters, reply);
|
||||||
if( use_shared_memory ) {
|
if (use_shared_memory)
|
||||||
|
{
|
||||||
// lock query
|
// lock query
|
||||||
boost::interprocess::scoped_lock<
|
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> query_lock(
|
||||||
boost::interprocess::named_mutex
|
barrier->query_mutex);
|
||||||
> query_lock(barrier->query_mutex);
|
|
||||||
|
|
||||||
// decrement query count
|
// decrement query count
|
||||||
--(barrier->number_of_queries);
|
--(barrier->number_of_queries);
|
||||||
BOOST_ASSERT_MSG(
|
BOOST_ASSERT_MSG(0 <= barrier->number_of_queries, "invalid number of queries");
|
||||||
0 <= barrier->number_of_queries,
|
|
||||||
"invalid number of queries"
|
|
||||||
);
|
|
||||||
|
|
||||||
// notify all processes that were waiting for this condition
|
// notify all processes that were waiting for this condition
|
||||||
if (0 == barrier->number_of_queries) {
|
if (0 == barrier->number_of_queries)
|
||||||
|
{
|
||||||
barrier->no_running_queries_condition.notify_all();
|
barrier->no_running_queries_condition.notify_all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// proxy code for compilation firewall
|
// proxy code for compilation firewall
|
||||||
|
|
||||||
OSRM::OSRM(
|
OSRM::OSRM(const ServerPaths &paths, const bool use_shared_memory)
|
||||||
const ServerPaths & paths,
|
: OSRM_pimpl_(new OSRM_impl(paths, use_shared_memory))
|
||||||
const bool use_shared_memory
|
{
|
||||||
) : OSRM_pimpl_(new OSRM_impl(paths, use_shared_memory)) { }
|
|
||||||
|
|
||||||
OSRM::~OSRM() {
|
|
||||||
delete OSRM_pimpl_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSRM::RunQuery(RouteParameters & route_parameters, http::Reply & reply) {
|
OSRM::~OSRM() { delete OSRM_pimpl_; }
|
||||||
|
|
||||||
|
void OSRM::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
|
||||||
|
{
|
||||||
OSRM_pimpl_->RunQuery(route_parameters, reply);
|
OSRM_pimpl_->RunQuery(route_parameters, reply);
|
||||||
}
|
}
|
||||||
|
@ -39,27 +39,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
|
|
||||||
struct SharedBarriers;
|
struct SharedBarriers;
|
||||||
template<class EdgeDataT>
|
template <class EdgeDataT> class BaseDataFacade;
|
||||||
class BaseDataFacade;
|
|
||||||
|
|
||||||
class OSRM_impl : boost::noncopyable {
|
class OSRM_impl
|
||||||
private:
|
{
|
||||||
|
private:
|
||||||
typedef boost::unordered_map<std::string, BasePlugin *> PluginMap;
|
typedef boost::unordered_map<std::string, BasePlugin *> PluginMap;
|
||||||
public:
|
|
||||||
OSRM_impl(
|
|
||||||
const ServerPaths & paths,
|
|
||||||
const bool use_shared_memory
|
|
||||||
);
|
|
||||||
virtual ~OSRM_impl();
|
|
||||||
void RunQuery(RouteParameters & route_parameters, http::Reply & reply);
|
|
||||||
|
|
||||||
private:
|
public:
|
||||||
void RegisterPlugin(BasePlugin * plugin);
|
OSRM_impl(const ServerPaths &paths, const bool use_shared_memory);
|
||||||
|
OSRM_impl(const OSRM_impl &) = delete;
|
||||||
|
virtual ~OSRM_impl();
|
||||||
|
void RunQuery(RouteParameters &route_parameters, http::Reply &reply);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void RegisterPlugin(BasePlugin *plugin);
|
||||||
PluginMap plugin_map;
|
PluginMap plugin_map;
|
||||||
bool use_shared_memory;
|
bool use_shared_memory;
|
||||||
SharedBarriers * barrier;
|
SharedBarriers *barrier;
|
||||||
//base class pointer to the objects
|
// base class pointer to the objects
|
||||||
BaseDataFacade<QueryEdge::EdgeData> * query_data_facade;
|
BaseDataFacade<QueryEdge::EdgeData> *query_data_facade;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //OSRM_IMPL_H
|
#endif // OSRM_IMPL_H
|
||||||
|
@ -30,7 +30,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "../Util/ProgramOptions.h"
|
#include "../Util/ProgramOptions.h"
|
||||||
#include "../Util/SimpleLogger.h"
|
#include "../Util/SimpleLogger.h"
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <Reply.h>
|
||||||
|
#include <RouteParameters.h>
|
||||||
|
#include <ServerPaths.h>
|
||||||
|
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include <boost/property_tree/json_parser.hpp>
|
#include <boost/property_tree/json_parser.hpp>
|
||||||
|
|
||||||
@ -107,7 +110,7 @@ int main (int argc, const char * argv[]) {
|
|||||||
//attention: super-inefficient hack below:
|
//attention: super-inefficient hack below:
|
||||||
|
|
||||||
std::stringstream my_stream;
|
std::stringstream my_stream;
|
||||||
BOOST_FOREACH(const std::string & line, osrm_reply.content)
|
for (const std::string & line : osrm_reply.content)
|
||||||
{
|
{
|
||||||
std::cout << line;
|
std::cout << line;
|
||||||
my_stream << line;
|
my_stream << line;
|
||||||
|
Loading…
Reference in New Issue
Block a user