replaced contigouos output data with collection of small'ish sub blocks. saves (re-)allocations. also removed a remaining stringstream
This commit is contained in:
parent
8b6fe691ed
commit
cabaad4b17
@ -29,7 +29,7 @@ add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.cpp UUID.cpp.alwaysbuild
|
|||||||
|
|
||||||
add_custom_target(UUIDConfigure DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.cpp )
|
add_custom_target(UUIDConfigure DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.cpp )
|
||||||
|
|
||||||
set(BOOST_COMPONENTS filesystem program_options regex system thread)
|
set(BOOST_COMPONENTS filesystem iostreams program_options regex system thread)
|
||||||
|
|
||||||
configure_file(Util/GitDescription.cpp.in ${CMAKE_SOURCE_DIR}/Util/GitDescription.cpp)
|
configure_file(Util/GitDescription.cpp.in ${CMAKE_SOURCE_DIR}/Util/GitDescription.cpp)
|
||||||
file(GLOB ExtractorGlob Extractor/*.cpp)
|
file(GLOB ExtractorGlob Extractor/*.cpp)
|
||||||
|
@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "../DataStructures/HashTable.h"
|
#include "../DataStructures/HashTable.h"
|
||||||
#include "../DataStructures/PhantomNodes.h"
|
#include "../DataStructures/PhantomNodes.h"
|
||||||
#include "../DataStructures/RawRouteData.h"
|
#include "../DataStructures/RawRouteData.h"
|
||||||
|
#include "../Server/Http/Reply.h"
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
@ -95,21 +95,31 @@ void DescriptionFactory::AppendSegment(
|
|||||||
|
|
||||||
void DescriptionFactory::AppendEncodedPolylineString(
|
void DescriptionFactory::AppendEncodedPolylineString(
|
||||||
const bool return_encoded,
|
const bool return_encoded,
|
||||||
std::string & output
|
std::vector<std::string> & output
|
||||||
) {
|
) {
|
||||||
|
std::string temp;
|
||||||
if(return_encoded) {
|
if(return_encoded) {
|
||||||
polyline_compressor.printEncodedString(pathDescription, output);
|
polyline_compressor.printEncodedString(pathDescription, temp);
|
||||||
} else {
|
} else {
|
||||||
polyline_compressor.printUnencodedString(pathDescription, output);
|
polyline_compressor.printUnencodedString(pathDescription, temp);
|
||||||
}
|
}
|
||||||
|
output.push_back(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptionFactory::AppendEncodedPolylineString(std::string &output) const {
|
void DescriptionFactory::AppendEncodedPolylineString(
|
||||||
polyline_compressor.printEncodedString(pathDescription, output);
|
std::vector<std::string> &output
|
||||||
|
) const {
|
||||||
|
std::string temp;
|
||||||
|
polyline_compressor.printEncodedString(pathDescription, temp);
|
||||||
|
output.push_back(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptionFactory::AppendUnencodedPolylineString(std::string &output) const {
|
void DescriptionFactory::AppendUnencodedPolylineString(
|
||||||
polyline_compressor.printUnencodedString(pathDescription, output);
|
std::vector<std::string>& output
|
||||||
|
) const {
|
||||||
|
std::string temp;
|
||||||
|
polyline_compressor.printUnencodedString(pathDescription, temp);
|
||||||
|
output.push_back(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLevel) {
|
// void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLevel) {
|
||||||
|
@ -82,15 +82,15 @@ public:
|
|||||||
DescriptionFactory();
|
DescriptionFactory();
|
||||||
virtual ~DescriptionFactory();
|
virtual ~DescriptionFactory();
|
||||||
double GetBearing(const FixedPointCoordinate& C, const FixedPointCoordinate& B) const;
|
double GetBearing(const FixedPointCoordinate& C, const FixedPointCoordinate& B) const;
|
||||||
void AppendEncodedPolylineString(std::string &output) const;
|
void AppendEncodedPolylineString(std::vector<std::string> &output) const;
|
||||||
void AppendUnencodedPolylineString(std::string &output) const;
|
void AppendUnencodedPolylineString(std::vector<std::string> &output) const;
|
||||||
void AppendSegment(const FixedPointCoordinate & coordinate, const _PathData & data);
|
void AppendSegment(const FixedPointCoordinate & coordinate, const _PathData & data);
|
||||||
void BuildRouteSummary(const double distance, const unsigned time);
|
void BuildRouteSummary(const double distance, const unsigned time);
|
||||||
void SetStartSegment(const PhantomNode & start_phantom);
|
void SetStartSegment(const PhantomNode & start_phantom);
|
||||||
void SetEndSegment(const PhantomNode & start_phantom);
|
void SetEndSegment(const PhantomNode & start_phantom);
|
||||||
void AppendEncodedPolylineString(
|
void AppendEncodedPolylineString(
|
||||||
const bool return_encoded,
|
const bool return_encoded,
|
||||||
std::string & output
|
std::vector<std::string> & output
|
||||||
);
|
);
|
||||||
|
|
||||||
template<class DataFacadeT>
|
template<class DataFacadeT>
|
||||||
|
@ -49,18 +49,18 @@ public:
|
|||||||
PhantomNodes &phantomNodes,
|
PhantomNodes &phantomNodes,
|
||||||
const DataFacadeT * facade
|
const DataFacadeT * facade
|
||||||
) {
|
) {
|
||||||
reply.content += ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
reply.content.push_back("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||||
reply.content +=
|
reply.content.push_back(
|
||||||
"<gpx creator=\"OSRM Routing Engine\" version=\"1.1\" "
|
"<gpx creator=\"OSRM Routing Engine\" version=\"1.1\" "
|
||||||
"xmlns=\"http://www.topografix.com/GPX/1/1\" "
|
"xmlns=\"http://www.topografix.com/GPX/1/1\" "
|
||||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
|
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
|
||||||
"xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 gpx.xsd"
|
"xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 gpx.xsd"
|
||||||
"\">";
|
"\">");
|
||||||
reply.content +=
|
reply.content.push_back(
|
||||||
"<metadata><copyright author=\"Project OSRM\"><license>Data (c)"
|
"<metadata><copyright author=\"Project OSRM\"><license>Data (c)"
|
||||||
" OpenStreetMap contributors (ODbL)</license></copyright>"
|
" OpenStreetMap contributors (ODbL)</license></copyright>"
|
||||||
"</metadata>";
|
"</metadata>");
|
||||||
reply.content += "<rte>";
|
reply.content.push_back("<rte>");
|
||||||
bool found_route = (rawRoute.lengthOfShortestPath != INT_MAX) &&
|
bool found_route = (rawRoute.lengthOfShortestPath != INT_MAX) &&
|
||||||
(rawRoute.computedShortestPath.size() );
|
(rawRoute.computedShortestPath.size() );
|
||||||
if( found_route ) {
|
if( found_route ) {
|
||||||
@ -68,12 +68,12 @@ public:
|
|||||||
phantomNodes.startPhantom.location.lat,
|
phantomNodes.startPhantom.location.lat,
|
||||||
tmp
|
tmp
|
||||||
);
|
);
|
||||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
reply.content.push_back("<rtept lat=\"" + tmp + "\" ");
|
||||||
convertInternalLatLonToString(
|
convertInternalLatLonToString(
|
||||||
phantomNodes.startPhantom.location.lon,
|
phantomNodes.startPhantom.location.lon,
|
||||||
tmp
|
tmp
|
||||||
);
|
);
|
||||||
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
reply.content.push_back("lon=\"" + tmp + "\"></rtept>");
|
||||||
|
|
||||||
BOOST_FOREACH(
|
BOOST_FOREACH(
|
||||||
const _PathData & pathData,
|
const _PathData & pathData,
|
||||||
@ -82,22 +82,22 @@ public:
|
|||||||
current = facade->GetCoordinateOfNode(pathData.node);
|
current = facade->GetCoordinateOfNode(pathData.node);
|
||||||
|
|
||||||
convertInternalLatLonToString(current.lat, tmp);
|
convertInternalLatLonToString(current.lat, tmp);
|
||||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
reply.content.push_back("<rtept lat=\"" + tmp + "\" ");
|
||||||
convertInternalLatLonToString(current.lon, tmp);
|
convertInternalLatLonToString(current.lon, tmp);
|
||||||
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
reply.content.push_back("lon=\"" + tmp + "\"></rtept>");
|
||||||
}
|
}
|
||||||
convertInternalLatLonToString(
|
convertInternalLatLonToString(
|
||||||
phantomNodes.targetPhantom.location.lat,
|
phantomNodes.targetPhantom.location.lat,
|
||||||
tmp
|
tmp
|
||||||
);
|
);
|
||||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
reply.content.push_back("<rtept lat=\"" + tmp + "\" ");
|
||||||
convertInternalLatLonToString(
|
convertInternalLatLonToString(
|
||||||
phantomNodes.targetPhantom.location.lon,
|
phantomNodes.targetPhantom.location.lon,
|
||||||
tmp
|
tmp
|
||||||
);
|
);
|
||||||
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
reply.content.push_back("lon=\"" + tmp + "\"></rtept>");
|
||||||
}
|
}
|
||||||
reply.content += "</rte></gpx>";
|
reply.content.push_back("</rte></gpx>");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif // GPX_DESCRIPTOR_H_
|
#endif // GPX_DESCRIPTOR_H_
|
||||||
|
@ -92,8 +92,8 @@ public:
|
|||||||
|
|
||||||
if(raw_route_information.lengthOfShortestPath != INT_MAX) {
|
if(raw_route_information.lengthOfShortestPath != INT_MAX) {
|
||||||
description_factory.SetStartSegment(phantom_nodes.startPhantom);
|
description_factory.SetStartSegment(phantom_nodes.startPhantom);
|
||||||
reply.content += "0,"
|
reply.content.push_back("0,"
|
||||||
"\"status_message\": \"Found route between points\",";
|
"\"status_message\": \"Found route between points\",");
|
||||||
|
|
||||||
//Get all the coordinates for the computed route
|
//Get all the coordinates for the computed route
|
||||||
BOOST_FOREACH(const _PathData & path_data, raw_route_information.computedShortestPath) {
|
BOOST_FOREACH(const _PathData & path_data, raw_route_information.computedShortestPath) {
|
||||||
@ -103,23 +103,23 @@ public:
|
|||||||
description_factory.SetEndSegment(phantom_nodes.targetPhantom);
|
description_factory.SetEndSegment(phantom_nodes.targetPhantom);
|
||||||
} else {
|
} else {
|
||||||
//We do not need to do much, if there is no route ;-)
|
//We do not need to do much, if there is no route ;-)
|
||||||
reply.content += "207,"
|
reply.content.push_back("207,"
|
||||||
"\"status_message\": \"Cannot find route between points\",";
|
"\"status_message\": \"Cannot find route between points\",");
|
||||||
}
|
}
|
||||||
|
|
||||||
description_factory.Run(facade, config.zoom_level);
|
description_factory.Run(facade, config.zoom_level);
|
||||||
reply.content += "\"route_geometry\": ";
|
reply.content.push_back("\"route_geometry\": ");
|
||||||
if(config.geometry) {
|
if(config.geometry) {
|
||||||
description_factory.AppendEncodedPolylineString(
|
description_factory.AppendEncodedPolylineString(
|
||||||
config.encode_geometry,
|
config.encode_geometry,
|
||||||
reply.content
|
reply.content
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
reply.content += "[]";
|
reply.content.push_back("[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
reply.content += ","
|
reply.content.push_back(","
|
||||||
"\"route_instructions\": [";
|
"\"route_instructions\": [");
|
||||||
entered_restricted_area_count = 0;
|
entered_restricted_area_count = 0;
|
||||||
if(config.instructions) {
|
if(config.instructions) {
|
||||||
BuildTextualDescription(
|
BuildTextualDescription(
|
||||||
@ -138,32 +138,32 @@ public:
|
|||||||
entered_restricted_area_count += (current_instruction != segment.turnInstruction);
|
entered_restricted_area_count += (current_instruction != segment.turnInstruction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reply.content += "],";
|
reply.content.push_back("],");
|
||||||
description_factory.BuildRouteSummary(
|
description_factory.BuildRouteSummary(
|
||||||
description_factory.entireLength,
|
description_factory.entireLength,
|
||||||
raw_route_information.lengthOfShortestPath - ( entered_restricted_area_count*TurnInstructions.AccessRestrictionPenalty)
|
raw_route_information.lengthOfShortestPath - ( entered_restricted_area_count*TurnInstructions.AccessRestrictionPenalty)
|
||||||
);
|
);
|
||||||
|
|
||||||
reply.content += "\"route_summary\":";
|
reply.content.push_back("\"route_summary\":");
|
||||||
reply.content += "{";
|
reply.content.push_back("{");
|
||||||
reply.content += "\"total_distance\":";
|
reply.content.push_back("\"total_distance\":");
|
||||||
reply.content += description_factory.summary.lengthString;
|
reply.content.push_back(description_factory.summary.lengthString);
|
||||||
reply.content += ","
|
reply.content.push_back(","
|
||||||
"\"total_time\":";
|
"\"total_time\":");
|
||||||
reply.content += description_factory.summary.durationString;
|
reply.content.push_back(description_factory.summary.durationString);
|
||||||
reply.content += ","
|
reply.content.push_back(","
|
||||||
"\"start_point\":\"";
|
"\"start_point\":\"");
|
||||||
reply.content += facade->GetEscapedNameForNameID(
|
reply.content.push_back(
|
||||||
description_factory.summary.startName
|
facade->GetEscapedNameForNameID(description_factory.summary.startName)
|
||||||
);
|
);
|
||||||
reply.content += "\","
|
reply.content.push_back("\","
|
||||||
"\"end_point\":\"";
|
"\"end_point\":\"");
|
||||||
reply.content += facade->GetEscapedNameForNameID(
|
reply.content.push_back(
|
||||||
description_factory.summary.destName
|
facade->GetEscapedNameForNameID(description_factory.summary.destName)
|
||||||
);
|
);
|
||||||
reply.content += "\"";
|
reply.content.push_back("\"");
|
||||||
reply.content += "}";
|
reply.content.push_back("}");
|
||||||
reply.content +=",";
|
reply.content.push_back(",");
|
||||||
|
|
||||||
//only one alternative route is computed at this time, so this is hardcoded
|
//only one alternative route is computed at this time, so this is hardcoded
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ public:
|
|||||||
alternateDescriptionFactory.Run(facade, config.zoom_level);
|
alternateDescriptionFactory.Run(facade, config.zoom_level);
|
||||||
|
|
||||||
//give an array of alternative routes
|
//give an array of alternative routes
|
||||||
reply.content += "\"alternative_geometries\": [";
|
reply.content.push_back("\"alternative_geometries\": [");
|
||||||
if(config.geometry && INT_MAX != raw_route_information.lengthOfAlternativePath) {
|
if(config.geometry && INT_MAX != raw_route_information.lengthOfAlternativePath) {
|
||||||
//Generate the linestrings for each alternative
|
//Generate the linestrings for each alternative
|
||||||
alternateDescriptionFactory.AppendEncodedPolylineString(
|
alternateDescriptionFactory.AppendEncodedPolylineString(
|
||||||
@ -187,11 +187,11 @@ public:
|
|||||||
reply.content
|
reply.content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
reply.content += "],";
|
reply.content.push_back("],");
|
||||||
reply.content += "\"alternative_instructions\":[";
|
reply.content.push_back("\"alternative_instructions\":[");
|
||||||
entered_restricted_area_count = 0;
|
entered_restricted_area_count = 0;
|
||||||
if(INT_MAX != raw_route_information.lengthOfAlternativePath) {
|
if(INT_MAX != raw_route_information.lengthOfAlternativePath) {
|
||||||
reply.content += "[";
|
reply.content.push_back("[");
|
||||||
//Generate instructions for each alternative
|
//Generate instructions for each alternative
|
||||||
if(config.instructions) {
|
if(config.instructions) {
|
||||||
BuildTextualDescription(
|
BuildTextualDescription(
|
||||||
@ -207,89 +207,89 @@ public:
|
|||||||
entered_restricted_area_count += (current_instruction != segment.turnInstruction);
|
entered_restricted_area_count += (current_instruction != segment.turnInstruction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reply.content += "]";
|
reply.content.push_back("]");
|
||||||
}
|
}
|
||||||
reply.content += "],";
|
reply.content.push_back("],");
|
||||||
reply.content += "\"alternative_summaries\":[";
|
reply.content.push_back("\"alternative_summaries\":[");
|
||||||
if(INT_MAX != raw_route_information.lengthOfAlternativePath) {
|
if(INT_MAX != raw_route_information.lengthOfAlternativePath) {
|
||||||
//Generate route summary (length, duration) for each alternative
|
//Generate route summary (length, duration) for each alternative
|
||||||
alternateDescriptionFactory.BuildRouteSummary(alternateDescriptionFactory.entireLength, raw_route_information.lengthOfAlternativePath - ( entered_restricted_area_count*TurnInstructions.AccessRestrictionPenalty));
|
alternateDescriptionFactory.BuildRouteSummary(alternateDescriptionFactory.entireLength, raw_route_information.lengthOfAlternativePath - ( entered_restricted_area_count*TurnInstructions.AccessRestrictionPenalty));
|
||||||
reply.content += "{";
|
reply.content.push_back("{");
|
||||||
reply.content += "\"total_distance\":";
|
reply.content.push_back("\"total_distance\":");
|
||||||
reply.content += alternateDescriptionFactory.summary.lengthString;
|
reply.content.push_back(alternateDescriptionFactory.summary.lengthString);
|
||||||
reply.content += ","
|
reply.content.push_back(","
|
||||||
"\"total_time\":";
|
"\"total_time\":");
|
||||||
reply.content += alternateDescriptionFactory.summary.durationString;
|
reply.content.push_back(alternateDescriptionFactory.summary.durationString);
|
||||||
reply.content += ","
|
reply.content.push_back(","
|
||||||
"\"start_point\":\"";
|
"\"start_point\":\"");
|
||||||
reply.content += facade->GetEscapedNameForNameID(description_factory.summary.startName);
|
reply.content.push_back(facade->GetEscapedNameForNameID(description_factory.summary.startName));
|
||||||
reply.content += "\","
|
reply.content.push_back("\","
|
||||||
"\"end_point\":\"";
|
"\"end_point\":\"");
|
||||||
reply.content += facade->GetEscapedNameForNameID(description_factory.summary.destName);
|
reply.content.push_back(facade->GetEscapedNameForNameID(description_factory.summary.destName));
|
||||||
reply.content += "\"";
|
reply.content.push_back("\"");
|
||||||
reply.content += "}";
|
reply.content.push_back("}");
|
||||||
}
|
}
|
||||||
reply.content += "],";
|
reply.content.push_back("],");
|
||||||
|
|
||||||
//Get Names for both routes
|
//Get Names for both routes
|
||||||
RouteNames routeNames;
|
RouteNames routeNames;
|
||||||
GetRouteNames(shortest_path_segments, alternative_path_segments, facade, routeNames);
|
GetRouteNames(shortest_path_segments, alternative_path_segments, facade, routeNames);
|
||||||
|
|
||||||
reply.content += "\"route_name\":[\"";
|
reply.content.push_back("\"route_name\":[\"");
|
||||||
reply.content += routeNames.shortestPathName1;
|
reply.content.push_back(routeNames.shortestPathName1);
|
||||||
reply.content += "\",\"";
|
reply.content.push_back("\",\"");
|
||||||
reply.content += routeNames.shortestPathName2;
|
reply.content.push_back(routeNames.shortestPathName2);
|
||||||
reply.content += "\"],"
|
reply.content.push_back("\"],"
|
||||||
"\"alternative_names\":[";
|
"\"alternative_names\":[");
|
||||||
reply.content += "[\"";
|
reply.content.push_back("[\"");
|
||||||
reply.content += routeNames.alternativePathName1;
|
reply.content.push_back(routeNames.alternativePathName1);
|
||||||
reply.content += "\",\"";
|
reply.content.push_back("\",\"");
|
||||||
reply.content += routeNames.alternativePathName2;
|
reply.content.push_back(routeNames.alternativePathName2);
|
||||||
reply.content += "\"]";
|
reply.content.push_back("\"]");
|
||||||
reply.content += "],";
|
reply.content.push_back("],");
|
||||||
//list all viapoints so that the client may display it
|
//list all viapoints so that the client may display it
|
||||||
reply.content += "\"via_points\":[";
|
reply.content.push_back("\"via_points\":[");
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
if(config.geometry && INT_MAX != raw_route_information.lengthOfShortestPath) {
|
if(config.geometry && INT_MAX != raw_route_information.lengthOfShortestPath) {
|
||||||
for(unsigned i = 0; i < raw_route_information.segmentEndCoordinates.size(); ++i) {
|
for(unsigned i = 0; i < raw_route_information.segmentEndCoordinates.size(); ++i) {
|
||||||
reply.content += "[";
|
reply.content.push_back("[");
|
||||||
if(raw_route_information.segmentEndCoordinates[i].startPhantom.location.isSet())
|
if(raw_route_information.segmentEndCoordinates[i].startPhantom.location.isSet())
|
||||||
convertInternalReversedCoordinateToString(raw_route_information.segmentEndCoordinates[i].startPhantom.location, tmp);
|
convertInternalReversedCoordinateToString(raw_route_information.segmentEndCoordinates[i].startPhantom.location, tmp);
|
||||||
else
|
else
|
||||||
convertInternalReversedCoordinateToString(raw_route_information.rawViaNodeCoordinates[i], tmp);
|
convertInternalReversedCoordinateToString(raw_route_information.rawViaNodeCoordinates[i], tmp);
|
||||||
|
|
||||||
reply.content += tmp;
|
reply.content.push_back(tmp);
|
||||||
reply.content += "],";
|
reply.content.push_back("],");
|
||||||
}
|
}
|
||||||
reply.content += "[";
|
reply.content.push_back("[");
|
||||||
if(raw_route_information.segmentEndCoordinates.back().startPhantom.location.isSet())
|
if(raw_route_information.segmentEndCoordinates.back().startPhantom.location.isSet())
|
||||||
convertInternalReversedCoordinateToString(raw_route_information.segmentEndCoordinates.back().targetPhantom.location, tmp);
|
convertInternalReversedCoordinateToString(raw_route_information.segmentEndCoordinates.back().targetPhantom.location, tmp);
|
||||||
else
|
else
|
||||||
convertInternalReversedCoordinateToString(raw_route_information.rawViaNodeCoordinates.back(), tmp);
|
convertInternalReversedCoordinateToString(raw_route_information.rawViaNodeCoordinates.back(), tmp);
|
||||||
reply.content += tmp;
|
reply.content.push_back(tmp);
|
||||||
reply.content += "]";
|
reply.content.push_back("]");
|
||||||
}
|
}
|
||||||
reply.content += "],";
|
reply.content.push_back("],");
|
||||||
reply.content += "\"hint_data\": {";
|
reply.content.push_back("\"hint_data\": {");
|
||||||
reply.content += "\"checksum\":";
|
reply.content.push_back("\"checksum\":");
|
||||||
intToString(raw_route_information.checkSum, tmp);
|
intToString(raw_route_information.checkSum, tmp);
|
||||||
reply.content += tmp;
|
reply.content.push_back(tmp);
|
||||||
reply.content += ", \"locations\": [";
|
reply.content.push_back(", \"locations\": [");
|
||||||
|
|
||||||
std::string hint;
|
std::string hint;
|
||||||
for(unsigned i = 0; i < raw_route_information.segmentEndCoordinates.size(); ++i) {
|
for(unsigned i = 0; i < raw_route_information.segmentEndCoordinates.size(); ++i) {
|
||||||
reply.content += "\"";
|
reply.content.push_back("\"");
|
||||||
EncodeObjectToBase64(raw_route_information.segmentEndCoordinates[i].startPhantom, hint);
|
EncodeObjectToBase64(raw_route_information.segmentEndCoordinates[i].startPhantom, hint);
|
||||||
reply.content += hint;
|
reply.content.push_back(hint);
|
||||||
reply.content += "\", ";
|
reply.content.push_back("\", ");
|
||||||
}
|
}
|
||||||
EncodeObjectToBase64(raw_route_information.segmentEndCoordinates.back().targetPhantom, hint);
|
EncodeObjectToBase64(raw_route_information.segmentEndCoordinates.back().targetPhantom, hint);
|
||||||
reply.content += "\"";
|
reply.content.push_back("\"");
|
||||||
reply.content += hint;
|
reply.content.push_back(hint);
|
||||||
reply.content += "\"]";
|
reply.content.push_back("\"]");
|
||||||
reply.content += "},";
|
reply.content.push_back("},");
|
||||||
reply.content += "\"transactionId\": \"OSRM Routing Engine JSON Descriptor (v0.3)\"";
|
reply.content.push_back("\"transactionId\": \"OSRM Routing Engine JSON Descriptor (v0.3)\"");
|
||||||
reply.content += "}";
|
reply.content.push_back("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// construct routes names
|
// construct routes names
|
||||||
@ -357,10 +357,12 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void WriteHeaderToOutput(std::string & output) {
|
inline void WriteHeaderToOutput(std::vector<std::string> & output) {
|
||||||
output += "{"
|
output.push_back(
|
||||||
"\"version\": 0.3,"
|
"{"
|
||||||
"\"status\":";
|
"\"version\": 0.3,"
|
||||||
|
"\"status\":"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: reorder parameters
|
//TODO: reorder parameters
|
||||||
@ -389,41 +391,41 @@ public:
|
|||||||
roundAbout.start_index = prefixSumOfNecessarySegments;
|
roundAbout.start_index = prefixSumOfNecessarySegments;
|
||||||
} else {
|
} else {
|
||||||
if(0 != prefixSumOfNecessarySegments){
|
if(0 != prefixSumOfNecessarySegments){
|
||||||
reply.content += ",";
|
reply.content.push_back(",");
|
||||||
}
|
}
|
||||||
reply.content += "[\"";
|
reply.content.push_back("[\"");
|
||||||
if(TurnInstructions.LeaveRoundAbout == current_instruction) {
|
if(TurnInstructions.LeaveRoundAbout == current_instruction) {
|
||||||
intToString(TurnInstructions.EnterRoundAbout, tmpInstruction);
|
intToString(TurnInstructions.EnterRoundAbout, tmpInstruction);
|
||||||
reply.content += tmpInstruction;
|
reply.content.push_back(tmpInstruction);
|
||||||
reply.content += "-";
|
reply.content.push_back("-");
|
||||||
intToString(roundAbout.leave_at_exit+1, tmpInstruction);
|
intToString(roundAbout.leave_at_exit+1, tmpInstruction);
|
||||||
reply.content += tmpInstruction;
|
reply.content.push_back(tmpInstruction);
|
||||||
roundAbout.leave_at_exit = 0;
|
roundAbout.leave_at_exit = 0;
|
||||||
} else {
|
} else {
|
||||||
intToString(current_instruction, tmpInstruction);
|
intToString(current_instruction, tmpInstruction);
|
||||||
reply.content += tmpInstruction;
|
reply.content.push_back(tmpInstruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
reply.content += "\",\"";
|
reply.content.push_back("\",\"");
|
||||||
reply.content += facade->GetEscapedNameForNameID(segment.nameID);
|
reply.content.push_back(facade->GetEscapedNameForNameID(segment.nameID));
|
||||||
reply.content += "\",";
|
reply.content.push_back("\",");
|
||||||
intToString(segment.length, tmpDist);
|
intToString(segment.length, tmpDist);
|
||||||
reply.content += tmpDist;
|
reply.content.push_back(tmpDist);
|
||||||
reply.content += ",";
|
reply.content.push_back(",");
|
||||||
intToString(prefixSumOfNecessarySegments, tmpLength);
|
intToString(prefixSumOfNecessarySegments, tmpLength);
|
||||||
reply.content += tmpLength;
|
reply.content.push_back(tmpLength);
|
||||||
reply.content += ",";
|
reply.content.push_back(",");
|
||||||
intToString(segment.duration/10, tmpDuration);
|
intToString(segment.duration/10, tmpDuration);
|
||||||
reply.content += tmpDuration;
|
reply.content.push_back(tmpDuration);
|
||||||
reply.content += ",\"";
|
reply.content.push_back(",\"");
|
||||||
intToString(segment.length, tmpLength);
|
intToString(segment.length, tmpLength);
|
||||||
reply.content += tmpLength;
|
reply.content.push_back(tmpLength);
|
||||||
reply.content += "m\",\"";
|
reply.content.push_back("m\",\"");
|
||||||
reply.content += Azimuth::Get(segment.bearing);
|
reply.content.push_back(Azimuth::Get(segment.bearing));
|
||||||
reply.content += "\",";
|
reply.content.push_back("\",");
|
||||||
intToString(round(segment.bearing), tmpBearing);
|
intToString(round(segment.bearing), tmpBearing);
|
||||||
reply.content += tmpBearing;
|
reply.content.push_back(tmpBearing);
|
||||||
reply.content += "]";
|
reply.content.push_back("]");
|
||||||
|
|
||||||
route_segments_list.push_back(
|
route_segments_list.push_back(
|
||||||
Segment(
|
Segment(
|
||||||
@ -440,23 +442,23 @@ public:
|
|||||||
++prefixSumOfNecessarySegments;
|
++prefixSumOfNecessarySegments;
|
||||||
}
|
}
|
||||||
if(INT_MAX != route_length) {
|
if(INT_MAX != route_length) {
|
||||||
reply.content += ",[\"";
|
reply.content.push_back(",[\"");
|
||||||
intToString(TurnInstructions.ReachedYourDestination, tmpInstruction);
|
intToString(TurnInstructions.ReachedYourDestination, tmpInstruction);
|
||||||
reply.content += tmpInstruction;
|
reply.content.push_back(tmpInstruction);
|
||||||
reply.content += "\",\"";
|
reply.content.push_back("\",\"");
|
||||||
reply.content += "\",";
|
reply.content.push_back("\",");
|
||||||
reply.content += "0";
|
reply.content.push_back("0");
|
||||||
reply.content += ",";
|
reply.content.push_back(",");
|
||||||
intToString(prefixSumOfNecessarySegments-1, tmpLength);
|
intToString(prefixSumOfNecessarySegments-1, tmpLength);
|
||||||
reply.content += tmpLength;
|
reply.content.push_back(tmpLength);
|
||||||
reply.content += ",";
|
reply.content.push_back(",");
|
||||||
reply.content += "0";
|
reply.content.push_back("0");
|
||||||
reply.content += ",\"";
|
reply.content.push_back(",\"");
|
||||||
reply.content += "\",\"";
|
reply.content.push_back("\",\"");
|
||||||
reply.content += Azimuth::Get(0.0);
|
reply.content.push_back(Azimuth::Get(0.0));
|
||||||
reply.content += "\",";
|
reply.content.push_back("\",");
|
||||||
reply.content += "0.0";
|
reply.content.push_back("0.0");
|
||||||
reply.content += "]";
|
reply.content.push_back("]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,10 +29,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#define HELLOWORLDPLUGIN_H_
|
#define HELLOWORLDPLUGIN_H_
|
||||||
|
|
||||||
#include "BasePlugin.h"
|
#include "BasePlugin.h"
|
||||||
|
#include "../Util/StringUtil.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <string>
|
||||||
|
|
||||||
class HelloWorldPlugin : public BasePlugin {
|
class HelloWorldPlugin : public BasePlugin {
|
||||||
|
private:
|
||||||
|
std::string temp_string;
|
||||||
public:
|
public:
|
||||||
HelloWorldPlugin() : descriptor_string("hello"){}
|
HelloWorldPlugin() : descriptor_string("hello"){}
|
||||||
virtual ~HelloWorldPlugin() { }
|
virtual ~HelloWorldPlugin() { }
|
||||||
@ -40,28 +43,56 @@ public:
|
|||||||
|
|
||||||
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
reply.content.append("<html><head><title>Hello World Demonstration Document</title></head><body><h1>Hello, World!</h1>");
|
reply.content.push_back("<html><head><title>Hello World Demonstration Document</title></head><body><h1>Hello, World!</h1>");
|
||||||
std::stringstream content;
|
reply.content.push_back("<pre>");
|
||||||
content << "<pre>";
|
reply.content.push_back("zoom level: ");
|
||||||
content << "zoom level: " << routeParameters.zoomLevel << "\n";
|
intToString(routeParameters.zoomLevel, temp_string);
|
||||||
content << "checksum: " << routeParameters.checkSum << "\n";
|
reply.content.push_back(temp_string);
|
||||||
content << "instructions: " << (routeParameters.printInstructions ? "yes" : "no") << "\n";
|
reply.content.push_back("\nchecksum: ");
|
||||||
content << "geometry: " << (routeParameters.geometry ? "yes" : "no") << "\n";
|
intToString(routeParameters.checkSum, temp_string);
|
||||||
content << "compression: " << (routeParameters.compression ? "yes" : "no") << "\n";
|
reply.content.push_back(temp_string);
|
||||||
content << "output format: " << routeParameters.outputFormat << "\n";
|
reply.content.push_back("\ninstructions: ");
|
||||||
content << "json parameter: " << routeParameters.jsonpParameter << "\n";
|
reply.content.push_back((routeParameters.printInstructions ? "yes" : "no"));
|
||||||
content << "language: " << routeParameters.language << "<br>";
|
reply.content.push_back(temp_string);
|
||||||
content << "Number of locations: " << routeParameters.coordinates.size() << "\n";
|
reply.content.push_back("\ngeometry: ");
|
||||||
|
reply.content.push_back((routeParameters.geometry ? "yes" : "no"));
|
||||||
|
reply.content.push_back("\ncompression: ");
|
||||||
|
reply.content.push_back((routeParameters.compression ? "yes" : "no"));
|
||||||
|
reply.content.push_back("\noutput format: ");
|
||||||
|
reply.content.push_back(routeParameters.outputFormat);
|
||||||
|
reply.content.push_back("\njson parameter: ");
|
||||||
|
reply.content.push_back(routeParameters.jsonpParameter);
|
||||||
|
reply.content.push_back("\nlanguage: ");
|
||||||
|
reply.content.push_back(routeParameters.language);
|
||||||
|
reply.content.push_back("\nNumber of locations: ");
|
||||||
|
intToString(routeParameters.coordinates.size(), temp_string);
|
||||||
|
reply.content.push_back(temp_string);
|
||||||
|
reply.content.push_back("\n");
|
||||||
for(unsigned i = 0; i < routeParameters.coordinates.size(); ++i) {
|
for(unsigned i = 0; i < routeParameters.coordinates.size(); ++i) {
|
||||||
content << " [" << i << "] " << routeParameters.coordinates[i].lat/COORDINATE_PRECISION << "," << routeParameters.coordinates[i].lon/COORDINATE_PRECISION << "\n";
|
reply.content.push_back( " [");
|
||||||
|
intToString(i, temp_string);
|
||||||
|
reply.content.push_back(temp_string);
|
||||||
|
reply.content.push_back("] ");
|
||||||
|
doubleToString(routeParameters.coordinates[i].lat/COORDINATE_PRECISION, temp_string);
|
||||||
|
reply.content.push_back(temp_string);
|
||||||
|
reply.content.push_back(",");
|
||||||
|
doubleToString(routeParameters.coordinates[i].lon/COORDINATE_PRECISION, temp_string);
|
||||||
|
reply.content.push_back(temp_string);
|
||||||
|
reply.content.push_back("\n");
|
||||||
}
|
}
|
||||||
content << "Number of hints: " << routeParameters.hints.size() << "\n";
|
reply.content.push_back( "Number of hints: ");
|
||||||
|
intToString(routeParameters.hints.size(), temp_string);
|
||||||
|
reply.content.push_back(temp_string);
|
||||||
|
reply.content.push_back("\n");
|
||||||
for(unsigned i = 0; i < routeParameters.hints.size(); ++i) {
|
for(unsigned i = 0; i < routeParameters.hints.size(); ++i) {
|
||||||
content << " [" << i << "] " << routeParameters.hints[i] << "\n";
|
reply.content.push_back( " [");
|
||||||
|
intToString(i, temp_string);
|
||||||
|
reply.content.push_back(temp_string);
|
||||||
|
reply.content.push_back("] ");
|
||||||
|
reply.content.push_back(routeParameters.hints[i]);
|
||||||
|
reply.content.push_back("\n");
|
||||||
}
|
}
|
||||||
content << "</pre>";
|
reply.content.push_back( "</pre></body></html>");
|
||||||
reply.content.append(content.str());
|
|
||||||
reply.content.append("</body></html>");
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::string descriptor_string;
|
std::string descriptor_string;
|
||||||
|
@ -63,38 +63,38 @@ public:
|
|||||||
//json
|
//json
|
||||||
|
|
||||||
if(!routeParameters.jsonpParameter.empty()) {
|
if(!routeParameters.jsonpParameter.empty()) {
|
||||||
reply.content += routeParameters.jsonpParameter;
|
reply.content.push_back(routeParameters.jsonpParameter);
|
||||||
reply.content += "(";
|
reply.content.push_back("(");
|
||||||
}
|
}
|
||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
reply.content += ("{");
|
reply.content.push_back ("{");
|
||||||
reply.content += ("\"version\":0.3,");
|
reply.content.push_back ("\"version\":0.3,");
|
||||||
if(
|
if(
|
||||||
!facade->LocateClosestEndPointForCoordinate(
|
!facade->LocateClosestEndPointForCoordinate(
|
||||||
routeParameters.coordinates[0],
|
routeParameters.coordinates[0],
|
||||||
result
|
result
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
reply.content += ("\"status\":207,");
|
reply.content.push_back ("\"status\":207,");
|
||||||
reply.content += ("\"mapped_coordinate\":[]");
|
reply.content.push_back ("\"mapped_coordinate\":[]");
|
||||||
} else {
|
} else {
|
||||||
//Write coordinate to stream
|
//Write coordinate to stream
|
||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
reply.content += ("\"status\":0,");
|
reply.content.push_back ("\"status\":0,");
|
||||||
reply.content += ("\"mapped_coordinate\":");
|
reply.content.push_back ("\"mapped_coordinate\":");
|
||||||
convertInternalLatLonToString(result.lat, tmp);
|
convertInternalLatLonToString(result.lat, tmp);
|
||||||
reply.content += "[";
|
reply.content.push_back("[");
|
||||||
reply.content += tmp;
|
reply.content.push_back(tmp);
|
||||||
convertInternalLatLonToString(result.lon, tmp);
|
convertInternalLatLonToString(result.lon, tmp);
|
||||||
reply.content += ",";
|
reply.content.push_back(",");
|
||||||
reply.content += tmp;
|
reply.content.push_back(tmp);
|
||||||
reply.content += "]";
|
reply.content.push_back("]");
|
||||||
}
|
}
|
||||||
reply.content += ",\"transactionId\": \"OSRM Routing Engine JSON Locate (v0.3)\"";
|
reply.content.push_back(",\"transactionId\": \"OSRM Routing Engine JSON Locate (v0.3)\"");
|
||||||
reply.content += ("}");
|
reply.content.push_back("}");
|
||||||
reply.headers.resize(3);
|
reply.headers.resize(3);
|
||||||
if(!routeParameters.jsonpParameter.empty()) {
|
if(!routeParameters.jsonpParameter.empty()) {
|
||||||
reply.content += ")";
|
reply.content.push_back( ")");
|
||||||
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";
|
||||||
|
@ -70,40 +70,40 @@ public:
|
|||||||
//json
|
//json
|
||||||
|
|
||||||
if("" != routeParameters.jsonpParameter) {
|
if("" != routeParameters.jsonpParameter) {
|
||||||
reply.content += routeParameters.jsonpParameter;
|
reply.content.push_back(routeParameters.jsonpParameter);
|
||||||
reply.content += "(";
|
reply.content.push_back("(");
|
||||||
}
|
}
|
||||||
|
|
||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
reply.content += ("{");
|
reply.content.push_back("{");
|
||||||
reply.content += ("\"version\":0.3,");
|
reply.content.push_back("\"version\":0.3,");
|
||||||
reply.content += ("\"status\":");
|
reply.content.push_back("\"status\":");
|
||||||
if(UINT_MAX != result.edgeBasedNode) {
|
if(UINT_MAX != result.edgeBasedNode) {
|
||||||
reply.content += "0,";
|
reply.content.push_back("0,");
|
||||||
} else {
|
} else {
|
||||||
reply.content += "207,";
|
reply.content.push_back("207,");
|
||||||
}
|
}
|
||||||
reply.content += ("\"mapped_coordinate\":");
|
reply.content.push_back("\"mapped_coordinate\":");
|
||||||
reply.content += "[";
|
reply.content.push_back("[");
|
||||||
if(UINT_MAX != result.edgeBasedNode) {
|
if(UINT_MAX != result.edgeBasedNode) {
|
||||||
convertInternalLatLonToString(result.location.lat, temp_string);
|
convertInternalLatLonToString(result.location.lat, temp_string);
|
||||||
reply.content += temp_string;
|
reply.content.push_back(temp_string);
|
||||||
convertInternalLatLonToString(result.location.lon, temp_string);
|
convertInternalLatLonToString(result.location.lon, temp_string);
|
||||||
reply.content += ",";
|
reply.content.push_back(",");
|
||||||
reply.content += temp_string;
|
reply.content.push_back(temp_string);
|
||||||
}
|
}
|
||||||
reply.content += "],";
|
reply.content.push_back("],");
|
||||||
reply.content += "\"name\":\"";
|
reply.content.push_back("\"name\":\"");
|
||||||
if(UINT_MAX != result.edgeBasedNode) {
|
if(UINT_MAX != result.edgeBasedNode) {
|
||||||
facade->GetName(result.nodeBasedEdgeNameID, temp_string);
|
facade->GetName(result.nodeBasedEdgeNameID, temp_string);
|
||||||
reply.content += temp_string;
|
reply.content.push_back(temp_string);
|
||||||
}
|
}
|
||||||
reply.content += "\"";
|
reply.content.push_back("\"");
|
||||||
reply.content += ",\"transactionId\":\"OSRM Routing Engine JSON Nearest (v0.3)\"";
|
reply.content.push_back(",\"transactionId\":\"OSRM Routing Engine JSON Nearest (v0.3)\"");
|
||||||
reply.content += ("}");
|
reply.content.push_back("}");
|
||||||
reply.headers.resize(3);
|
reply.headers.resize(3);
|
||||||
if( !routeParameters.jsonpParameter.empty() ) {
|
if( !routeParameters.jsonpParameter.empty() ) {
|
||||||
reply.content += ")";
|
reply.content.push_back(")");
|
||||||
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";
|
||||||
|
@ -42,23 +42,23 @@ public:
|
|||||||
|
|
||||||
//json
|
//json
|
||||||
if("" != routeParameters.jsonpParameter) {
|
if("" != routeParameters.jsonpParameter) {
|
||||||
reply.content += routeParameters.jsonpParameter;
|
reply.content.push_back(routeParameters.jsonpParameter);
|
||||||
reply.content += "(";
|
reply.content.push_back("(");
|
||||||
}
|
}
|
||||||
|
|
||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
reply.content += ("{");
|
reply.content.push_back("{");
|
||||||
reply.content += ("\"version\":0.3,");
|
reply.content.push_back("\"version\":0.3,");
|
||||||
reply.content += ("\"status\":");
|
reply.content.push_back("\"status\":");
|
||||||
reply.content += "0,";
|
reply.content.push_back("0,");
|
||||||
reply.content += ("\"timestamp\":\"");
|
reply.content.push_back("\"timestamp\":\"");
|
||||||
reply.content += facade->GetTimestamp();
|
reply.content.push_back(facade->GetTimestamp());
|
||||||
reply.content += "\"";
|
reply.content.push_back("\"");
|
||||||
reply.content += ",\"transactionId\":\"OSRM Routing Engine JSON timestamp (v0.3)\"";
|
reply.content.push_back(",\"transactionId\":\"OSRM Routing Engine JSON timestamp (v0.3)\"");
|
||||||
reply.content += ("}");
|
reply.content.push_back("}");
|
||||||
reply.headers.resize(3);
|
reply.headers.resize(3);
|
||||||
if("" != routeParameters.jsonpParameter) {
|
if("" != routeParameters.jsonpParameter) {
|
||||||
reply.content += ")";
|
reply.content.push_back(")");
|
||||||
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";
|
||||||
|
@ -140,8 +140,8 @@ public:
|
|||||||
//TODO: Move to member as smart pointer
|
//TODO: Move to member as smart pointer
|
||||||
BaseDescriptor<DataFacadeT> * desc;
|
BaseDescriptor<DataFacadeT> * desc;
|
||||||
if("" != routeParameters.jsonpParameter) {
|
if("" != routeParameters.jsonpParameter) {
|
||||||
reply.content += routeParameters.jsonpParameter;
|
reply.content.push_back(routeParameters.jsonpParameter);
|
||||||
reply.content += "(";
|
reply.content.push_back("(");
|
||||||
}
|
}
|
||||||
|
|
||||||
DescriptorConfig descriptorConfig;
|
DescriptorConfig descriptorConfig;
|
||||||
@ -172,15 +172,12 @@ public:
|
|||||||
|
|
||||||
PhantomNodes phantomNodes;
|
PhantomNodes phantomNodes;
|
||||||
phantomNodes.startPhantom = rawRoute.segmentEndCoordinates[0].startPhantom;
|
phantomNodes.startPhantom = rawRoute.segmentEndCoordinates[0].startPhantom;
|
||||||
// SimpleLogger().Write() << "Start location: " << phantomNodes.startPhantom.location;
|
|
||||||
phantomNodes.targetPhantom = rawRoute.segmentEndCoordinates[rawRoute.segmentEndCoordinates.size()-1].targetPhantom;
|
phantomNodes.targetPhantom = rawRoute.segmentEndCoordinates[rawRoute.segmentEndCoordinates.size()-1].targetPhantom;
|
||||||
// SimpleLogger().Write() << "TargetLocation: " << phantomNodes.targetPhantom.location;
|
|
||||||
// SimpleLogger().Write() << "Number of segments: " << rawRoute.segmentEndCoordinates.size();
|
|
||||||
desc->SetConfig(descriptorConfig);
|
desc->SetConfig(descriptorConfig);
|
||||||
|
|
||||||
desc->Run(reply, rawRoute, phantomNodes, facade);
|
desc->Run(reply, rawRoute, phantomNodes, facade);
|
||||||
if("" != routeParameters.jsonpParameter) {
|
if("" != routeParameters.jsonpParameter) {
|
||||||
reply.content += ")\n";
|
reply.content.push_back(")\n");
|
||||||
}
|
}
|
||||||
reply.headers.resize(3);
|
reply.headers.resize(3);
|
||||||
reply.headers[0].name = "Content-Length";
|
reply.headers[0].name = "Content-Length";
|
||||||
|
@ -37,11 +37,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/enable_shared_from_this.hpp>
|
#include <boost/enable_shared_from_this.hpp>
|
||||||
|
#include <boost/iostreams/filtering_stream.hpp>
|
||||||
|
#include <boost/iostreams/filter/gzip.hpp>
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include <zlib.h>
|
|
||||||
|
|
||||||
|
// #include <zlib.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace http {
|
namespace http {
|
||||||
@ -92,7 +96,7 @@ private:
|
|||||||
request_handler.handle_request(request, reply);
|
request_handler.handle_request(request, reply);
|
||||||
|
|
||||||
Header compression_header;
|
Header compression_header;
|
||||||
std::vector<unsigned char> compressed_output;
|
std::vector<char> compressed_output;
|
||||||
std::vector<boost::asio::const_buffer> output_buffer;
|
std::vector<boost::asio::const_buffer> output_buffer;
|
||||||
switch(compression_type) {
|
switch(compression_type) {
|
||||||
case deflateRFC1951:
|
case deflateRFC1951:
|
||||||
@ -102,11 +106,10 @@ private:
|
|||||||
reply.headers.begin(),
|
reply.headers.begin(),
|
||||||
compression_header
|
compression_header
|
||||||
);
|
);
|
||||||
compressCharArray(
|
compressBufferCollection(
|
||||||
reply.content.c_str(),
|
reply.content,
|
||||||
reply.content.length(),
|
compression_type,
|
||||||
compressed_output,
|
compressed_output
|
||||||
compression_type
|
|
||||||
);
|
);
|
||||||
reply.setSize(compressed_output.size());
|
reply.setSize(compressed_output.size());
|
||||||
output_buffer = reply.HeaderstoBuffers();
|
output_buffer = reply.HeaderstoBuffers();
|
||||||
@ -132,11 +135,10 @@ private:
|
|||||||
reply.headers.begin(),
|
reply.headers.begin(),
|
||||||
compression_header
|
compression_header
|
||||||
);
|
);
|
||||||
compressCharArray(
|
compressBufferCollection(
|
||||||
reply.content.c_str(),
|
reply.content,
|
||||||
reply.content.length(),
|
compression_type,
|
||||||
compressed_output,
|
compressed_output
|
||||||
compression_type
|
|
||||||
);
|
);
|
||||||
reply.setSize(compressed_output.size());
|
reply.setSize(compressed_output.size());
|
||||||
output_buffer = reply.HeaderstoBuffers();
|
output_buffer = reply.HeaderstoBuffers();
|
||||||
@ -210,71 +212,100 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void compressBufferCollection(
|
||||||
|
std::vector<std::string> uncompressed_data,
|
||||||
|
CompressionType compression_type,
|
||||||
|
std::vector<char> & compressed_data
|
||||||
|
) {
|
||||||
|
boost::iostreams::gzip_params compression_parameters;
|
||||||
|
|
||||||
|
compression_parameters.level = boost::iostreams::zlib::best_speed;
|
||||||
|
if ( deflateRFC1951 == compression_type ) {
|
||||||
|
compression_parameters.noheader = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_ASSERT( compressed_data.empty() );
|
||||||
|
boost::iostreams::filtering_ostream compressing_stream;
|
||||||
|
|
||||||
|
compressing_stream.push(
|
||||||
|
boost::iostreams::gzip_compressor(compression_parameters)
|
||||||
|
);
|
||||||
|
compressing_stream.push(
|
||||||
|
boost::iostreams::back_inserter(compressed_data)
|
||||||
|
);
|
||||||
|
|
||||||
|
BOOST_FOREACH( const std::string & line, uncompressed_data) {
|
||||||
|
compressing_stream << line;
|
||||||
|
}
|
||||||
|
|
||||||
|
compressing_stream.reset();
|
||||||
|
}
|
||||||
|
|
||||||
// Big thanks to deusty who explains how to use gzip compression by
|
// Big thanks to deusty who explains how to use gzip compression by
|
||||||
// the right call to deflateInit2():
|
// the right call to deflateInit2():
|
||||||
// http://deusty.blogspot.com/2007/07/gzip-compressiondecompression.html
|
// http://deusty.blogspot.com/2007/07/gzip-compressiondecompression.html
|
||||||
void compressCharArray(
|
// void compressCharArray(
|
||||||
const char * in_data,
|
// const char * in_data,
|
||||||
size_t in_data_size,
|
// size_t in_data_size,
|
||||||
std::vector<unsigned char> & buffer,
|
// std::vector<unsigned char> & buffer,
|
||||||
CompressionType type
|
// CompressionType type
|
||||||
) {
|
// ) {
|
||||||
const size_t BUFSIZE = 128 * 1024;
|
// const size_t BUFSIZE = 128 * 1024;
|
||||||
unsigned char temp_buffer[BUFSIZE];
|
// unsigned char temp_buffer[BUFSIZE];
|
||||||
|
|
||||||
z_stream strm;
|
// z_stream strm;
|
||||||
strm.zalloc = Z_NULL;
|
// strm.zalloc = Z_NULL;
|
||||||
strm.zfree = Z_NULL;
|
// strm.zfree = Z_NULL;
|
||||||
strm.opaque = Z_NULL;
|
// strm.opaque = Z_NULL;
|
||||||
strm.total_out = 0;
|
// strm.total_out = 0;
|
||||||
strm.next_in = (unsigned char *)(in_data);
|
// strm.next_in = (unsigned char *)(in_data);
|
||||||
strm.avail_in = in_data_size;
|
// strm.avail_in = in_data_size;
|
||||||
strm.next_out = temp_buffer;
|
// strm.next_out = temp_buffer;
|
||||||
strm.avail_out = BUFSIZE;
|
// strm.avail_out = BUFSIZE;
|
||||||
strm.data_type = Z_ASCII;
|
// strm.data_type = Z_ASCII;
|
||||||
|
|
||||||
switch(type){
|
// switch(type){
|
||||||
case deflateRFC1951:
|
// case deflateRFC1951:
|
||||||
deflateInit(&strm, Z_BEST_SPEED);
|
// deflateInit(&strm, Z_BEST_SPEED);
|
||||||
break;
|
// break;
|
||||||
case gzipRFC1952:
|
// case gzipRFC1952:
|
||||||
deflateInit2(
|
// deflateInit2(
|
||||||
&strm,
|
// &strm,
|
||||||
Z_DEFAULT_COMPRESSION,
|
// Z_DEFAULT_COMPRESSION,
|
||||||
Z_DEFLATED,
|
// Z_DEFLATED,
|
||||||
(15+16),
|
// (15+16),
|
||||||
9,
|
// 9,
|
||||||
Z_DEFAULT_STRATEGY
|
// Z_DEFAULT_STRATEGY
|
||||||
);
|
// );
|
||||||
break;
|
// break;
|
||||||
default:
|
// default:
|
||||||
BOOST_ASSERT_MSG(false, "should not happen");
|
// BOOST_ASSERT_MSG(false, "should not happen");
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
int deflate_res = Z_OK;
|
// int deflate_res = Z_OK;
|
||||||
do {
|
// do {
|
||||||
if ( 0 == strm.avail_out ) {
|
// if ( 0 == strm.avail_out ) {
|
||||||
buffer.insert(buffer.end(), temp_buffer, temp_buffer + BUFSIZE);
|
// buffer.insert(buffer.end(), temp_buffer, temp_buffer + BUFSIZE);
|
||||||
strm.next_out = temp_buffer;
|
// strm.next_out = temp_buffer;
|
||||||
strm.avail_out = BUFSIZE;
|
// strm.avail_out = BUFSIZE;
|
||||||
}
|
// }
|
||||||
deflate_res = deflate(&strm, Z_FINISH);
|
// deflate_res = deflate(&strm, Z_FINISH);
|
||||||
|
|
||||||
} while (deflate_res == Z_OK);
|
// } while (deflate_res == Z_OK);
|
||||||
|
|
||||||
BOOST_ASSERT_MSG(
|
// BOOST_ASSERT_MSG(
|
||||||
deflate_res == Z_STREAM_END,
|
// deflate_res == Z_STREAM_END,
|
||||||
"compression not properly finished"
|
// "compression not properly finished"
|
||||||
);
|
// );
|
||||||
|
|
||||||
buffer.insert(
|
// buffer.insert(
|
||||||
buffer.end(),
|
// buffer.end(),
|
||||||
temp_buffer,
|
// temp_buffer,
|
||||||
temp_buffer + BUFSIZE - strm.avail_out
|
// temp_buffer + BUFSIZE - strm.avail_out
|
||||||
);
|
// );
|
||||||
deflateEnd(&strm);
|
// deflateEnd(&strm);
|
||||||
}
|
// }
|
||||||
|
|
||||||
boost::asio::io_service::strand strand;
|
boost::asio::io_service::strand strand;
|
||||||
boost::asio::ip::tcp::socket TCP_socket;
|
boost::asio::ip::tcp::socket TCP_socket;
|
||||||
|
@ -41,15 +41,16 @@ void Reply::setSize(const unsigned size) {
|
|||||||
std::vector<boost::asio::const_buffer> Reply::toBuffers(){
|
std::vector<boost::asio::const_buffer> Reply::toBuffers(){
|
||||||
std::vector<boost::asio::const_buffer> buffers;
|
std::vector<boost::asio::const_buffer> buffers;
|
||||||
buffers.push_back(ToBuffer(status));
|
buffers.push_back(ToBuffer(status));
|
||||||
for (std::size_t i = 0; i < headers.size(); ++i) {
|
BOOST_FOREACH(const Header & h, headers) {
|
||||||
Header& h = headers[i];
|
|
||||||
buffers.push_back(boost::asio::buffer(h.name));
|
buffers.push_back(boost::asio::buffer(h.name));
|
||||||
buffers.push_back(boost::asio::buffer(seperators));
|
buffers.push_back(boost::asio::buffer(seperators));
|
||||||
buffers.push_back(boost::asio::buffer(h.value));
|
buffers.push_back(boost::asio::buffer(h.value));
|
||||||
buffers.push_back(boost::asio::buffer(crlf));
|
buffers.push_back(boost::asio::buffer(crlf));
|
||||||
}
|
}
|
||||||
buffers.push_back(boost::asio::buffer(crlf));
|
buffers.push_back(boost::asio::buffer(crlf));
|
||||||
buffers.push_back(boost::asio::buffer(content));
|
BOOST_FOREACH(const std::string & line, content) {
|
||||||
|
buffers.push_back(boost::asio::buffer(line));
|
||||||
|
}
|
||||||
return buffers;
|
return buffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +71,8 @@ std::vector<boost::asio::const_buffer> Reply::HeaderstoBuffers(){
|
|||||||
Reply Reply::StockReply(Reply::status_type status) {
|
Reply Reply::StockReply(Reply::status_type status) {
|
||||||
Reply rep;
|
Reply rep;
|
||||||
rep.status = status;
|
rep.status = status;
|
||||||
rep.content = ToString(status);
|
rep.content.clear();
|
||||||
|
rep.content.push_back( ToString(status) );
|
||||||
rep.headers.resize(3);
|
rep.headers.resize(3);
|
||||||
rep.headers[0].name = "Access-Control-Allow-Origin";
|
rep.headers[0].name = "Access-Control-Allow-Origin";
|
||||||
rep.headers[0].value = "*";
|
rep.headers[0].value = "*";
|
||||||
@ -85,7 +87,6 @@ Reply Reply::StockReply(Reply::status_type status) {
|
|||||||
return rep;
|
return rep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string Reply::ToString(Reply::status_type status) {
|
std::string Reply::ToString(Reply::status_type status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Reply::ok:
|
case Reply::ok:
|
||||||
@ -110,7 +111,7 @@ boost::asio::const_buffer Reply::ToBuffer(Reply::status_type status) {
|
|||||||
|
|
||||||
|
|
||||||
Reply::Reply() : status(ok) {
|
Reply::Reply() : status(ok) {
|
||||||
content.reserve(2 << 20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ const std::string internalServerErrorString = "HTTP/1.0 500 Internal Server Erro
|
|||||||
std::vector<Header> headers;
|
std::vector<Header> headers;
|
||||||
std::vector<boost::asio::const_buffer> toBuffers();
|
std::vector<boost::asio::const_buffer> toBuffers();
|
||||||
std::vector<boost::asio::const_buffer> HeaderstoBuffers();
|
std::vector<boost::asio::const_buffer> HeaderstoBuffers();
|
||||||
std::string content;
|
std::vector<std::string> content;
|
||||||
static Reply StockReply(status_type status);
|
static Reply StockReply(status_type status);
|
||||||
void setSize(const unsigned size);
|
void setSize(const unsigned size);
|
||||||
Reply();
|
Reply();
|
||||||
|
@ -85,16 +85,18 @@ public:
|
|||||||
const int position = std::distance(request.begin(), it);
|
const int position = std::distance(request.begin(), it);
|
||||||
std::string tmp_position_string;
|
std::string tmp_position_string;
|
||||||
intToString(position, tmp_position_string);
|
intToString(position, tmp_position_string);
|
||||||
rep.content += "Input seems to be malformed close to position ";
|
rep.content.push_back(
|
||||||
rep.content += "<br><pre>";
|
"Input seems to be malformed close to position "
|
||||||
rep.content += request;
|
"<br><pre>"
|
||||||
rep.content += tmp_position_string;
|
);
|
||||||
rep.content += "<br>";
|
rep.content.push_back( request );
|
||||||
|
rep.content.push_back(tmp_position_string);
|
||||||
|
rep.content.push_back("<br>");
|
||||||
const unsigned end = std::distance(request.begin(), it);
|
const unsigned end = std::distance(request.begin(), it);
|
||||||
for(unsigned i = 0; i < end; ++i) {
|
for(unsigned i = 0; i < end; ++i) {
|
||||||
rep.content += " ";
|
rep.content.push_back(" ");
|
||||||
}
|
}
|
||||||
rep.content += "^<br></pre>";
|
rep.content.push_back("^<br></pre>");
|
||||||
} else {
|
} else {
|
||||||
//parsing done, lets call the right plugin to handle the request
|
//parsing done, lets call the right plugin to handle the request
|
||||||
BOOST_ASSERT_MSG(
|
BOOST_ASSERT_MSG(
|
||||||
|
@ -42,10 +42,19 @@ public:
|
|||||||
RequestParser();
|
RequestParser();
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
boost::tuple<boost::tribool, char*> Parse(Request& req, char* begin, char* end, CompressionType * compressionType);
|
boost::tuple<boost::tribool, char*> Parse(
|
||||||
|
Request& req,
|
||||||
|
char* begin,
|
||||||
|
char* end,
|
||||||
|
CompressionType * compressionType
|
||||||
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::tribool consume(Request& req, char input, CompressionType * compressionType);
|
boost::tribool consume(
|
||||||
|
Request& req,
|
||||||
|
char input,
|
||||||
|
CompressionType * compressionType
|
||||||
|
);
|
||||||
|
|
||||||
inline bool isChar(int c);
|
inline bool isChar(int c);
|
||||||
|
|
||||||
|
@ -98,12 +98,14 @@ int main (int argc, const char * argv[]) {
|
|||||||
|
|
||||||
routing_machine.RunQuery(route_parameters, osrm_reply);
|
routing_machine.RunQuery(route_parameters, osrm_reply);
|
||||||
|
|
||||||
std::cout << osrm_reply.content << std::endl;
|
|
||||||
|
|
||||||
//attention: super-inefficient hack below:
|
//attention: super-inefficient hack below:
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << osrm_reply.content;
|
BOOST_FOREACH(const std::string & line, osrm_reply.content) {
|
||||||
|
std::cout << line;
|
||||||
|
ss << line;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
boost::property_tree::ptree pt;
|
boost::property_tree::ptree pt;
|
||||||
boost::property_tree::read_json(ss, pt);
|
boost::property_tree::read_json(ss, pt);
|
||||||
|
Loading…
Reference in New Issue
Block a user