From: Torsten Dreyer Date: Tue, 3 Mar 2015 16:10:16 +0000 (+0100) Subject: Use the pagedPathForHistory in the FlightHistoryUriHandler X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0f72564140d0a8398d5874a814fdc93aa5d64381;p=flightgear.git Use the pagedPathForHistory in the FlightHistoryUriHandler --- diff --git a/src/Network/http/FlightHistoryUriHandler.cxx b/src/Network/http/FlightHistoryUriHandler.cxx index c4654ee88..615b04996 100644 --- a/src/Network/http/FlightHistoryUriHandler.cxx +++ b/src/Network/http/FlightHistoryUriHandler.cxx @@ -25,6 +25,7 @@ #include #include
#include +#include using std::string; using std::stringstream; @@ -45,7 +46,17 @@ namespace http { } */ -static string FlightHistoryToJson(const SGGeodVec & history) { +static const char * errorPage = + "Flight History" + "

Flight History

" + "Supported formats:" + "" + ""; + +static string FlightHistoryToJson(const SGGeodVec & history, size_t last_seen ) { cJSON * feature = cJSON_CreateObject(); cJSON_AddItemToObject(feature, "type", cJSON_CreateString("Feature")); @@ -54,6 +65,8 @@ static string FlightHistoryToJson(const SGGeodVec & history) { cJSON * properties = cJSON_CreateObject(); cJSON_AddItemToObject(feature, "properties", properties ); + cJSON_AddItemToObject(properties, "type", cJSON_CreateString("FlightHistory")); + cJSON_AddItemToObject(properties, "last", cJSON_CreateNumber(last_seen)); cJSON_AddItemToObject(lineString, "type", cJSON_CreateString("LineString")); cJSON * coordinates = cJSON_CreateArray(); @@ -272,14 +285,26 @@ bool FlightHistoryUriHandler::handleRequest(const HTTPRequest & request, history->pathForHistory(minEdgeLengthM), request); } else if (requestPath == "track.json") { + size_t count = -1; + try { + count = boost::lexical_cast(request.RequestVariables.get("count")); + } + catch( ... ) { + } + size_t last = 0; + try { + last = boost::lexical_cast(request.RequestVariables.get("last")); + } + catch( ... ) { + } + response.Header["Content-Type"] = "application/json; charset=UTF-8"; - response.Content = FlightHistoryToJson( - history->pathForHistory(minEdgeLengthM)); + PagedPathForHistory_ptr h = history->pagedPathForHistory( count, last ); + response.Content = FlightHistoryToJson( h->path, h->last_seen ); } else { response.Header["Content-Type"] = "text/html"; - response.StatusCode = 404; - response.Content = "Not found!404"; + response.Content = errorPage; } return true;