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