Rewiring query plugins
This commit is contained in:
parent
01d2d91ecc
commit
7599124aa0
@ -26,19 +26,23 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "../Server/DataStructures/QueryObjectsStorage.h"
|
#include "../Server/DataStructures/QueryObjectsStorage.h"
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
|
|
||||||
/*
|
//locates the nearest node in the road network for a given coordinate.
|
||||||
* This Plugin locates the nearest node in the road network for a given coordinate.
|
|
||||||
*/
|
|
||||||
//TODO: Rework data access to go through facade
|
//TODO: Rework data access to go through facade
|
||||||
|
|
||||||
template<class DataFacadeT>
|
template<class DataFacadeT>
|
||||||
class LocatePlugin : public BasePlugin {
|
class LocatePlugin : public BasePlugin {
|
||||||
public:
|
public:
|
||||||
LocatePlugin(DataFacadeT * objects) : descriptor_string("locate") {
|
LocatePlugin(DataFacadeT * facade)
|
||||||
nodeHelpDesk = objects->nodeHelpDesk;
|
:
|
||||||
}
|
descriptor_string("locate"),
|
||||||
|
facade(facade)
|
||||||
|
{ }
|
||||||
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);
|
||||||
@ -54,7 +58,6 @@ public:
|
|||||||
std::string tmp;
|
std::string tmp;
|
||||||
//json
|
//json
|
||||||
|
|
||||||
// JSONParameter = routeParameters.options.Find("jsonp");
|
|
||||||
if(!routeParameters.jsonpParameter.empty()) {
|
if(!routeParameters.jsonpParameter.empty()) {
|
||||||
reply.content += routeParameters.jsonpParameter;
|
reply.content += routeParameters.jsonpParameter;
|
||||||
reply.content += "(";
|
reply.content += "(";
|
||||||
@ -62,7 +65,7 @@ public:
|
|||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
reply.content += ("{");
|
reply.content += ("{");
|
||||||
reply.content += ("\"version\":0.3,");
|
reply.content += ("\"version\":0.3,");
|
||||||
if(!nodeHelpDesk->LocateClosestEndPointForCoordinate(routeParameters.coordinates[0], result)) {
|
if(!facade->LocateClosestEndPointForCoordinate(routeParameters.coordinates[0], result)) {
|
||||||
reply.content += ("\"status\":207,");
|
reply.content += ("\"status\":207,");
|
||||||
reply.content += ("\"mapped_coordinate\":[]");
|
reply.content += ("\"mapped_coordinate\":[]");
|
||||||
} else {
|
} else {
|
||||||
@ -100,8 +103,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NodeInformationHelpDesk * nodeHelpDesk;
|
|
||||||
std::string descriptor_string;
|
std::string descriptor_string;
|
||||||
|
DataFacadeT * facade;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* LOCATEPLUGIN_H_ */
|
#endif /* LOCATEPLUGIN_H_ */
|
||||||
|
@ -30,14 +30,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//TODO: Rework data access to go through facade
|
|
||||||
|
|
||||||
template<class DataFacadeT>
|
template<class DataFacadeT>
|
||||||
class NearestPlugin : public BasePlugin {
|
class NearestPlugin : public BasePlugin {
|
||||||
public:
|
public:
|
||||||
NearestPlugin(DataFacadeT * objects )
|
NearestPlugin(DataFacadeT * facade )
|
||||||
:
|
:
|
||||||
m_query_objects(objects),
|
facade(facade),
|
||||||
descriptor_string("nearest")
|
descriptor_string("nearest")
|
||||||
{
|
{
|
||||||
descriptorTable.insert(std::make_pair("" , 0)); //default descriptor
|
descriptorTable.insert(std::make_pair("" , 0)); //default descriptor
|
||||||
@ -50,14 +48,13 @@ public:
|
|||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(false == checkCoord(routeParameters.coordinates[0])) {
|
if( !checkCoord(routeParameters.coordinates[0]) ) {
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NodeInformationHelpDesk * nodeHelpDesk = m_query_objects->nodeHelpDesk;
|
|
||||||
//query to helpdesk
|
|
||||||
PhantomNode result;
|
PhantomNode result;
|
||||||
nodeHelpDesk->FindPhantomNodeForCoordinate(
|
facade->FindPhantomNodeForCoordinate(
|
||||||
routeParameters.coordinates[0],
|
routeParameters.coordinates[0],
|
||||||
result,
|
result,
|
||||||
routeParameters.zoomLevel
|
routeParameters.zoomLevel
|
||||||
@ -92,14 +89,14 @@ public:
|
|||||||
reply.content += "],";
|
reply.content += "],";
|
||||||
reply.content += "\"name\":\"";
|
reply.content += "\"name\":\"";
|
||||||
if(UINT_MAX != result.edgeBasedNode) {
|
if(UINT_MAX != result.edgeBasedNode) {
|
||||||
m_query_objects->GetName(result.nodeBasedEdgeNameID, temp_string);
|
facade->GetName(result.nodeBasedEdgeNameID, temp_string);
|
||||||
reply.content += temp_string;
|
reply.content += temp_string;
|
||||||
}
|
}
|
||||||
reply.content += "\"";
|
reply.content += "\"";
|
||||||
reply.content += ",\"transactionId\":\"OSRM Routing Engine JSON Nearest (v0.3)\"";
|
reply.content += ",\"transactionId\":\"OSRM Routing Engine JSON Nearest (v0.3)\"";
|
||||||
reply.content += ("}");
|
reply.content += ("}");
|
||||||
reply.headers.resize(3);
|
reply.headers.resize(3);
|
||||||
if("" != routeParameters.jsonpParameter) {
|
if( !routeParameters.jsonpParameter.empty() ) {
|
||||||
reply.content += ")";
|
reply.content += ")";
|
||||||
reply.headers[1].name = "Content-Type";
|
reply.headers[1].name = "Content-Type";
|
||||||
reply.headers[1].value = "text/javascript";
|
reply.headers[1].value = "text/javascript";
|
||||||
@ -117,7 +114,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DataFacadeT * m_query_objects;
|
DataFacadeT * facade;
|
||||||
HashTable<std::string, unsigned> descriptorTable;
|
HashTable<std::string, unsigned> descriptorTable;
|
||||||
std::string descriptor_string;
|
std::string descriptor_string;
|
||||||
};
|
};
|
||||||
|
@ -27,8 +27,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
template<class DataFacadeT>
|
template<class DataFacadeT>
|
||||||
class TimestampPlugin : public BasePlugin {
|
class TimestampPlugin : public BasePlugin {
|
||||||
public:
|
public:
|
||||||
TimestampPlugin(DataFacadeT * o)
|
TimestampPlugin(const DataFacadeT * facade)
|
||||||
: objects(o), descriptor_string("timestamp")
|
: facade(facade), descriptor_string("timestamp")
|
||||||
{ }
|
{ }
|
||||||
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) {
|
||||||
@ -46,7 +46,7 @@ public:
|
|||||||
reply.content += ("\"status\":");
|
reply.content += ("\"status\":");
|
||||||
reply.content += "0,";
|
reply.content += "0,";
|
||||||
reply.content += ("\"timestamp\":\"");
|
reply.content += ("\"timestamp\":\"");
|
||||||
reply.content += objects->timestamp;
|
reply.content += facade->GetTimestamp();
|
||||||
reply.content += "\"";
|
reply.content += "\"";
|
||||||
reply.content += ",\"transactionId\":\"OSRM Routing Engine JSON timestamp (v0.3)\"";
|
reply.content += ",\"transactionId\":\"OSRM Routing Engine JSON timestamp (v0.3)\"";
|
||||||
reply.content += ("}");
|
reply.content += ("}");
|
||||||
@ -68,7 +68,7 @@ public:
|
|||||||
reply.headers[0].value = tmp;
|
reply.headers[0].value = tmp;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
DataFacadeT * objects;
|
const DataFacadeT * facade;
|
||||||
std::string descriptor_string;
|
std::string descriptor_string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,34 +44,32 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
template<class DataFacadeT>
|
template<class DataFacadeT>
|
||||||
class ViaRoutePlugin : public BasePlugin {
|
class ViaRoutePlugin : public BasePlugin {
|
||||||
private:
|
private:
|
||||||
NodeInformationHelpDesk * nodeHelpDesk;
|
boost::unordered_map<std::string, unsigned> descriptorTable;
|
||||||
StaticGraph<QueryEdge::EdgeData> * graph;
|
SearchEngine<DataFacadeT> * search_engine_ptr;
|
||||||
HashTable<std::string, unsigned> descriptorTable;
|
|
||||||
SearchEngine * searchEnginePtr;
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ViaRoutePlugin(DataFacadeT * objects)
|
ViaRoutePlugin(DataFacadeT * facade)
|
||||||
:
|
:
|
||||||
// objects(objects),
|
descriptor_string("viaroute"),
|
||||||
descriptor_string("viaroute")
|
facade(facade)
|
||||||
{
|
{
|
||||||
nodeHelpDesk = objects->nodeHelpDesk;
|
//TODO: set up an engine for each thread!!
|
||||||
graph = objects->graph;
|
search_engine_ptr = new SearchEngine<DataFacadeT>(facade);
|
||||||
|
|
||||||
searchEnginePtr = new SearchEngine(objects);
|
|
||||||
|
|
||||||
// descriptorTable.emplace("" , 0);
|
|
||||||
descriptorTable.emplace("json", 0);
|
descriptorTable.emplace("json", 0);
|
||||||
descriptorTable.emplace("gpx" , 1);
|
descriptorTable.emplace("gpx" , 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~ViaRoutePlugin() {
|
virtual ~ViaRoutePlugin() {
|
||||||
delete searchEnginePtr;
|
delete search_engine_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
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( 2 > routeParameters.coordinates.size() ) {
|
if( 2 > routeParameters.coordinates.size() ) {
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
@ -79,11 +77,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
RawRouteData rawRoute;
|
RawRouteData rawRoute;
|
||||||
rawRoute.checkSum = nodeHelpDesk->GetCheckSum();
|
rawRoute.checkSum = facade->GetCheckSum();
|
||||||
bool checksumOK = (routeParameters.checkSum == rawRoute.checkSum);
|
bool checksumOK = (routeParameters.checkSum == rawRoute.checkSum);
|
||||||
std::vector<std::string> textCoord;
|
std::vector<std::string> textCoord;
|
||||||
for(unsigned i = 0; i < routeParameters.coordinates.size(); ++i) {
|
for(unsigned i = 0; i < routeParameters.coordinates.size(); ++i) {
|
||||||
if(false == checkCoord(routeParameters.coordinates[i])) {
|
if( !checkCoord(routeParameters.coordinates[i]) ) {
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -94,13 +92,17 @@ public:
|
|||||||
if(checksumOK && i < routeParameters.hints.size() && "" != routeParameters.hints[i]) {
|
if(checksumOK && i < routeParameters.hints.size() && "" != routeParameters.hints[i]) {
|
||||||
// SimpleLogger().Write() <<"Decoding hint: " << routeParameters.hints[i] << " for location index " << i;
|
// SimpleLogger().Write() <<"Decoding hint: " << routeParameters.hints[i] << " for location index " << i;
|
||||||
DecodeObjectFromBase64(routeParameters.hints[i], phantomNodeVector[i]);
|
DecodeObjectFromBase64(routeParameters.hints[i], phantomNodeVector[i]);
|
||||||
if(phantomNodeVector[i].isValid(nodeHelpDesk->GetNumberOfNodes())) {
|
if(phantomNodeVector[i].isValid(facade->GetNumberOfNodes())) {
|
||||||
// SimpleLogger().Write() << "Decoded hint " << i << " successfully";
|
// SimpleLogger().Write() << "Decoded hint " << i << " successfully";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// SimpleLogger().Write() << "Brute force lookup of coordinate " << i;
|
// SimpleLogger().Write() << "Brute force lookup of coordinate " << i;
|
||||||
searchEnginePtr->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i], routeParameters.zoomLevel);
|
facade->FindPhantomNodeForCoordinate(
|
||||||
|
rawRoute.rawViaNodeCoordinates[i],
|
||||||
|
phantomNodeVector[i],
|
||||||
|
routeParameters.zoomLevel
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(unsigned i = 0; i < phantomNodeVector.size()-1; ++i) {
|
for(unsigned i = 0; i < phantomNodeVector.size()-1; ++i) {
|
||||||
@ -109,22 +111,29 @@ public:
|
|||||||
segmentPhantomNodes.targetPhantom = phantomNodeVector[i+1];
|
segmentPhantomNodes.targetPhantom = phantomNodeVector[i+1];
|
||||||
rawRoute.segmentEndCoordinates.push_back(segmentPhantomNodes);
|
rawRoute.segmentEndCoordinates.push_back(segmentPhantomNodes);
|
||||||
}
|
}
|
||||||
if( ( routeParameters.alternateRoute ) && (1 == rawRoute.segmentEndCoordinates.size()) ) {
|
if(
|
||||||
// SimpleLogger().Write() << "Checking for alternative paths";
|
( routeParameters.alternateRoute ) &&
|
||||||
searchEnginePtr->alternativePaths(rawRoute.segmentEndCoordinates[0], rawRoute);
|
(1 == rawRoute.segmentEndCoordinates.size())
|
||||||
|
) {
|
||||||
|
search_engine_ptr->alternativePaths(
|
||||||
|
rawRoute.segmentEndCoordinates[0],
|
||||||
|
rawRoute
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
searchEnginePtr->shortestPath(rawRoute.segmentEndCoordinates, rawRoute);
|
search_engine_ptr->shortestPath(
|
||||||
|
rawRoute.segmentEndCoordinates,
|
||||||
|
rawRoute
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(INT_MAX == rawRoute.lengthOfShortestPath ) {
|
if(INT_MAX == rawRoute.lengthOfShortestPath ) {
|
||||||
SimpleLogger().Write(logDEBUG) << "Error occurred, single path not found";
|
SimpleLogger().Write(logDEBUG) <<
|
||||||
|
"Error occurred, single path not found";
|
||||||
}
|
}
|
||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
|
|
||||||
//TODO: Move to member as smart pointer
|
//TODO: Move to member as smart pointer
|
||||||
BaseDescriptor * desc;
|
BaseDescriptor<DataFacadeT> * desc;
|
||||||
if("" != routeParameters.jsonpParameter) {
|
if("" != routeParameters.jsonpParameter) {
|
||||||
reply.content += routeParameters.jsonpParameter;
|
reply.content += routeParameters.jsonpParameter;
|
||||||
reply.content += "(";
|
reply.content += "(";
|
||||||
@ -143,15 +152,15 @@ public:
|
|||||||
|
|
||||||
switch(descriptorType){
|
switch(descriptorType){
|
||||||
case 0:
|
case 0:
|
||||||
desc = new JSONDescriptor();
|
desc = new JSONDescriptor<DataFacadeT>();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
desc = new GPXDescriptor();
|
desc = new GPXDescriptor<DataFacadeT>();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
desc = new JSONDescriptor();
|
desc = new JSONDescriptor<DataFacadeT>();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -164,7 +173,7 @@ public:
|
|||||||
// SimpleLogger().Write() << "Number of segments: " << rawRoute.segmentEndCoordinates.size();
|
// SimpleLogger().Write() << "Number of segments: " << rawRoute.segmentEndCoordinates.size();
|
||||||
desc->SetConfig(descriptorConfig);
|
desc->SetConfig(descriptorConfig);
|
||||||
|
|
||||||
desc->Run(reply, rawRoute, phantomNodes, *searchEnginePtr);
|
desc->Run(reply, rawRoute, phantomNodes, facade);
|
||||||
if("" != routeParameters.jsonpParameter) {
|
if("" != routeParameters.jsonpParameter) {
|
||||||
reply.content += ")\n";
|
reply.content += ")\n";
|
||||||
}
|
}
|
||||||
@ -175,7 +184,7 @@ public:
|
|||||||
reply.headers[0].value = tmp;
|
reply.headers[0].value = tmp;
|
||||||
switch(descriptorType){
|
switch(descriptorType){
|
||||||
case 0:
|
case 0:
|
||||||
if("" != routeParameters.jsonpParameter){
|
if( !routeParameters.jsonpParameter.empty() ){
|
||||||
reply.headers[1].name = "Content-Type";
|
reply.headers[1].name = "Content-Type";
|
||||||
reply.headers[1].value = "text/javascript";
|
reply.headers[1].value = "text/javascript";
|
||||||
reply.headers[2].name = "Content-Disposition";
|
reply.headers[2].name = "Content-Disposition";
|
||||||
@ -196,7 +205,7 @@ public:
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if("" != routeParameters.jsonpParameter){
|
if( !routeParameters.jsonpParameter.empty() ){
|
||||||
reply.headers[1].name = "Content-Type";
|
reply.headers[1].name = "Content-Type";
|
||||||
reply.headers[1].value = "text/javascript";
|
reply.headers[1].value = "text/javascript";
|
||||||
reply.headers[2].name = "Content-Disposition";
|
reply.headers[2].name = "Content-Disposition";
|
||||||
@ -215,6 +224,7 @@ public:
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::string descriptor_string;
|
std::string descriptor_string;
|
||||||
|
DataFacadeT * facade;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user