This commit is contained in:
parent
45a4fe44f7
commit
7794cd6274
@ -34,8 +34,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "../Plugins/TimestampPlugin.h"
|
#include "../Plugins/TimestampPlugin.h"
|
||||||
#include "../Plugins/ViaRoutePlugin.h"
|
#include "../Plugins/ViaRoutePlugin.h"
|
||||||
|
|
||||||
|
#include "../Server/DataStructures/BaseDataFacade.h"
|
||||||
#include "../Server/DataStructures/InternalDataFacade.h"
|
#include "../Server/DataStructures/InternalDataFacade.h"
|
||||||
|
#include "../Server/DataStructures/SharedBarriers.h"
|
||||||
#include "../Server/DataStructures/SharedDataFacade.h"
|
#include "../Server/DataStructures/SharedDataFacade.h"
|
||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
@ -49,6 +50,7 @@ OSRM_impl::OSRM_impl( const ServerPaths & server_paths, const bool use_shared_me
|
|||||||
server_paths
|
server_paths
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
barrier = new SharedBarriers();
|
||||||
query_data_facade = new SharedDataFacade<QueryEdge::EdgeData>( );
|
query_data_facade = new SharedDataFacade<QueryEdge::EdgeData>( );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +84,9 @@ OSRM_impl::~OSRM_impl() {
|
|||||||
BOOST_FOREACH(PluginMap::value_type & plugin_pointer, plugin_map) {
|
BOOST_FOREACH(PluginMap::value_type & plugin_pointer, plugin_map) {
|
||||||
delete plugin_pointer.second;
|
delete plugin_pointer.second;
|
||||||
}
|
}
|
||||||
|
if( use_shared_memory ) {
|
||||||
|
delete barrier;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSRM_impl::RegisterPlugin(BasePlugin * plugin) {
|
void OSRM_impl::RegisterPlugin(BasePlugin * plugin) {
|
||||||
@ -103,18 +108,18 @@ void OSRM_impl::RunQuery(RouteParameters & route_parameters, http::Reply & reply
|
|||||||
// lock update pending
|
// lock update pending
|
||||||
boost::interprocess::scoped_lock<
|
boost::interprocess::scoped_lock<
|
||||||
boost::interprocess::named_mutex
|
boost::interprocess::named_mutex
|
||||||
> pending_lock(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
|
boost::interprocess::named_mutex
|
||||||
> query_lock(barrier.query_mutex);
|
> query_lock(barrier->query_mutex);
|
||||||
|
|
||||||
// unlock update pending
|
// unlock update pending
|
||||||
pending_lock.unlock();
|
pending_lock.unlock();
|
||||||
|
|
||||||
// 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();
|
||||||
}
|
}
|
||||||
@ -124,18 +129,18 @@ void OSRM_impl::RunQuery(RouteParameters & route_parameters, http::Reply & reply
|
|||||||
// lock query
|
// lock query
|
||||||
boost::interprocess::scoped_lock<
|
boost::interprocess::scoped_lock<
|
||||||
boost::interprocess::named_mutex
|
boost::interprocess::named_mutex
|
||||||
> query_lock(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,
|
0 <= barrier->number_of_queries,
|
||||||
"invalid 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 {
|
||||||
|
@ -34,12 +34,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include "../DataStructures/QueryEdge.h"
|
#include "../DataStructures/QueryEdge.h"
|
||||||
#include "../Plugins/BasePlugin.h"
|
#include "../Plugins/BasePlugin.h"
|
||||||
#include "../Server/DataStructures/SharedBarriers.h"
|
|
||||||
#include "../Server/DataStructures/BaseDataFacade.h"
|
|
||||||
#include "../Util/ProgramOptions.h"
|
#include "../Util/ProgramOptions.h"
|
||||||
|
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
|
|
||||||
|
struct SharedBarriers;
|
||||||
|
template<class EdgeDataT>
|
||||||
|
class BaseDataFacade;
|
||||||
|
|
||||||
class OSRM_impl : boost::noncopyable {
|
class OSRM_impl : boost::noncopyable {
|
||||||
private:
|
private:
|
||||||
typedef boost::unordered_map<std::string, BasePlugin *> PluginMap;
|
typedef boost::unordered_map<std::string, BasePlugin *> PluginMap;
|
||||||
@ -55,7 +57,7 @@ private:
|
|||||||
void RegisterPlugin(BasePlugin * plugin);
|
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;
|
||||||
};
|
};
|
||||||
|
@ -25,13 +25,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NearestPlugin_H_
|
#ifndef NEAREST_PLUGIN_H
|
||||||
#define NearestPlugin_H_
|
#define NEAREST_PLUGIN_H
|
||||||
|
|
||||||
#include "BasePlugin.h"
|
#include "BasePlugin.h"
|
||||||
#include "../DataStructures/PhantomNodes.h"
|
#include "../DataStructures/PhantomNodes.h"
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
|
|
||||||
|
#include <boost/unordered_map.hpp>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This Plugin locates the nearest point on a street in the road network for a given coordinate.
|
* This Plugin locates the nearest point on a street in the road network for a given coordinate.
|
||||||
*/
|
*/
|
||||||
@ -44,11 +46,15 @@ public:
|
|||||||
facade(facade),
|
facade(facade),
|
||||||
descriptor_string("nearest")
|
descriptor_string("nearest")
|
||||||
{
|
{
|
||||||
descriptorTable.insert(std::make_pair("" , 0)); //default descriptor
|
descriptorTable.emplace("", 0); //default descriptor
|
||||||
descriptorTable.insert(std::make_pair("json", 1));
|
descriptorTable.emplace("json", 1);
|
||||||
}
|
}
|
||||||
const std::string & GetDescriptor() const { return descriptor_string; }
|
const std::string & GetDescriptor() const { return descriptor_string; }
|
||||||
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
|
||||||
|
void HandleRequest(
|
||||||
|
const RouteParameters & routeParameters,
|
||||||
|
http::Reply& reply
|
||||||
|
) {
|
||||||
//check number of parameters
|
//check number of parameters
|
||||||
if(!routeParameters.coordinates.size()) {
|
if(!routeParameters.coordinates.size()) {
|
||||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||||
@ -119,8 +125,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
DataFacadeT * facade;
|
DataFacadeT * facade;
|
||||||
HashTable<std::string, unsigned> descriptorTable;
|
boost::unordered_map<std::string, unsigned> descriptorTable;
|
||||||
std::string descriptor_string;
|
std::string descriptor_string;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* NearestPlugin_H_ */
|
#endif /* NEAREST_PLUGIN_H */
|
||||||
|
@ -1,3 +1,33 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright (c) 2013, 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 SHARED_BARRIER_H
|
||||||
|
#define SHARED_BARRIER_H
|
||||||
|
|
||||||
#include <boost/interprocess/sync/named_mutex.hpp>
|
#include <boost/interprocess/sync/named_mutex.hpp>
|
||||||
#include <boost/interprocess/sync/named_condition.hpp>
|
#include <boost/interprocess/sync/named_condition.hpp>
|
||||||
|
|
||||||
@ -38,3 +68,5 @@ struct SharedBarriers {
|
|||||||
// Is there any query?
|
// Is there any query?
|
||||||
int number_of_queries;
|
int number_of_queries;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif //SHARED_BARRIER_H
|
||||||
|
Loading…
Reference in New Issue
Block a user