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
|
||||
#define OSRM_H
|
||||
|
||||
#include <osrm/Reply.h>
|
||||
#include <osrm/RouteParameters.h>
|
||||
#include <osrm/ServerPaths.h>
|
||||
#include <ServerPaths.h>
|
||||
|
||||
class OSRM_impl;
|
||||
struct RouteParameters;
|
||||
|
||||
class OSRM {
|
||||
private:
|
||||
OSRM_impl * OSRM_pimpl_;
|
||||
public:
|
||||
explicit OSRM(
|
||||
const ServerPaths & paths,
|
||||
const bool use_shared_memory = false
|
||||
);
|
||||
namespace http
|
||||
{
|
||||
class Reply;
|
||||
}
|
||||
|
||||
class OSRM
|
||||
{
|
||||
private:
|
||||
OSRM_impl *OSRM_pimpl_;
|
||||
|
||||
public:
|
||||
explicit OSRM(const ServerPaths &paths, const bool use_shared_memory = false);
|
||||
~OSRM();
|
||||
void RunQuery(RouteParameters & route_parameters, http::Reply & reply);
|
||||
void RunQuery(RouteParameters &route_parameters, http::Reply &reply);
|
||||
};
|
||||
|
||||
#endif // OSRM_H
|
||||
|
@ -41,82 +41,65 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
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 &server_paths, const bool use_shared_memory)
|
||||
: use_shared_memory(use_shared_memory)
|
||||
{
|
||||
if (use_shared_memory)
|
||||
{
|
||||
barrier = new SharedBarriers();
|
||||
query_data_facade = new SharedDataFacade<QueryEdge::EdgeData>( );
|
||||
query_data_facade = new SharedDataFacade<QueryEdge::EdgeData>();
|
||||
}
|
||||
else
|
||||
{
|
||||
query_data_facade = new InternalDataFacade<QueryEdge::EdgeData>(
|
||||
server_paths
|
||||
);
|
||||
query_data_facade = new InternalDataFacade<QueryEdge::EdgeData>(server_paths);
|
||||
}
|
||||
|
||||
//The following plugins handle all requests.
|
||||
RegisterPlugin(
|
||||
new HelloWorldPlugin()
|
||||
);
|
||||
RegisterPlugin(
|
||||
new LocatePlugin<BaseDataFacade<QueryEdge::EdgeData> >(
|
||||
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
|
||||
)
|
||||
);
|
||||
// The following plugins handle all requests.
|
||||
RegisterPlugin(new HelloWorldPlugin());
|
||||
RegisterPlugin(new LocatePlugin<BaseDataFacade<QueryEdge::EdgeData>>(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() {
|
||||
BOOST_FOREACH(PluginMap::value_type & plugin_pointer, plugin_map) {
|
||||
OSRM_impl::~OSRM_impl()
|
||||
{
|
||||
for (PluginMap::value_type &plugin_pointer : plugin_map)
|
||||
{
|
||||
delete plugin_pointer.second;
|
||||
}
|
||||
if( use_shared_memory ) {
|
||||
if (use_shared_memory)
|
||||
{
|
||||
delete barrier;
|
||||
}
|
||||
}
|
||||
|
||||
void OSRM_impl::RegisterPlugin(BasePlugin * plugin) {
|
||||
SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor();
|
||||
if( plugin_map.find(plugin->GetDescriptor()) != plugin_map.end() ) {
|
||||
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);
|
||||
}
|
||||
|
||||
void OSRM_impl::RunQuery(RouteParameters & route_parameters, http::Reply & reply) {
|
||||
const PluginMap::const_iterator & iter = plugin_map.find(
|
||||
route_parameters.service
|
||||
);
|
||||
void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
|
||||
{
|
||||
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;
|
||||
if( use_shared_memory ) {
|
||||
if (use_shared_memory)
|
||||
{
|
||||
// lock update pending
|
||||
boost::interprocess::scoped_lock<
|
||||
boost::interprocess::named_mutex
|
||||
> pending_lock(barrier->pending_update_mutex);
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> pending_lock(
|
||||
barrier->pending_update_mutex);
|
||||
|
||||
// lock query
|
||||
boost::interprocess::scoped_lock<
|
||||
boost::interprocess::named_mutex
|
||||
> query_lock(barrier->query_mutex);
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> query_lock(
|
||||
barrier->query_mutex);
|
||||
|
||||
// unlock update pending
|
||||
pending_lock.unlock();
|
||||
@ -124,44 +107,44 @@ void OSRM_impl::RunQuery(RouteParameters & route_parameters, http::Reply & reply
|
||||
// increment query count
|
||||
++(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 );
|
||||
if( use_shared_memory ) {
|
||||
iter->second->HandleRequest(route_parameters, reply);
|
||||
if (use_shared_memory)
|
||||
{
|
||||
// lock query
|
||||
boost::interprocess::scoped_lock<
|
||||
boost::interprocess::named_mutex
|
||||
> query_lock(barrier->query_mutex);
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> query_lock(
|
||||
barrier->query_mutex);
|
||||
|
||||
// decrement query count
|
||||
--(barrier->number_of_queries);
|
||||
BOOST_ASSERT_MSG(
|
||||
0 <= barrier->number_of_queries,
|
||||
"invalid number of queries"
|
||||
);
|
||||
BOOST_ASSERT_MSG(0 <= barrier->number_of_queries, "invalid number of queries");
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
}
|
||||
}
|
||||
|
||||
// proxy code for compilation firewall
|
||||
|
||||
OSRM::OSRM(
|
||||
const ServerPaths & paths,
|
||||
const bool use_shared_memory
|
||||
) : OSRM_pimpl_(new OSRM_impl(paths, use_shared_memory)) { }
|
||||
|
||||
OSRM::~OSRM() {
|
||||
delete OSRM_pimpl_;
|
||||
OSRM::OSRM(const ServerPaths &paths, const bool use_shared_memory)
|
||||
: OSRM_pimpl_(new OSRM_impl(paths, use_shared_memory))
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -39,27 +39,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
struct SharedBarriers;
|
||||
template<class EdgeDataT>
|
||||
class BaseDataFacade;
|
||||
template <class EdgeDataT> class BaseDataFacade;
|
||||
|
||||
class OSRM_impl : boost::noncopyable {
|
||||
private:
|
||||
class OSRM_impl
|
||||
{
|
||||
private:
|
||||
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:
|
||||
void RegisterPlugin(BasePlugin * plugin);
|
||||
public:
|
||||
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;
|
||||
bool use_shared_memory;
|
||||
SharedBarriers * barrier;
|
||||
//base class pointer to the objects
|
||||
BaseDataFacade<QueryEdge::EdgeData> * query_data_facade;
|
||||
SharedBarriers *barrier;
|
||||
// base class pointer to the objects
|
||||
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/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/json_parser.hpp>
|
||||
|
||||
@ -107,7 +110,7 @@ int main (int argc, const char * argv[]) {
|
||||
//attention: super-inefficient hack below:
|
||||
|
||||
std::stringstream my_stream;
|
||||
BOOST_FOREACH(const std::string & line, osrm_reply.content)
|
||||
for (const std::string & line : osrm_reply.content)
|
||||
{
|
||||
std::cout << line;
|
||||
my_stream << line;
|
||||
|
Loading…
Reference in New Issue
Block a user