Add generation of history JSON.

Add support for URL handlers that match a path prefix.

(cherry picked from commit 38faa510cb881cbf9d2a0a85bbde61130b5259e7)
This commit is contained in:
Oliver Jowett 2015-01-15 20:55:55 +00:00
parent b1bfb4d520
commit 1db63ebc65
3 changed files with 53 additions and 7 deletions

View file

@ -680,7 +680,8 @@ static void display_stats(void) {
//
void backgroundTasks(void) {
static time_t next_stats;
static time_t next_json;
static time_t next_json, next_history;
time_t now = time(NULL);
if (Modes.net) {
@ -709,6 +710,20 @@ void backgroundTasks(void) {
writeJsonToFile("aircraft.json", generateAircraftJson);
next_json = now + Modes.json_interval;
}
if ((Modes.json_dir || Modes.net_http_port) && now >= next_history) {
char filebuf[PATH_MAX];
free(Modes.json_aircraft_history[Modes.json_aircraft_history_next].content); // might be NULL, that's OK.
Modes.json_aircraft_history[Modes.json_aircraft_history_next].content =
generateAircraftJson("/data/aircraft.json", &Modes.json_aircraft_history[Modes.json_aircraft_history_next].clen);
snprintf(filebuf, PATH_MAX, "history_%d.json", Modes.json_aircraft_history_next);
writeJsonToFile(filebuf, generateHistoryJson);
Modes.json_aircraft_history_next = (Modes.json_aircraft_history_next+1) % HISTORY_SIZE;
next_history = now + HISTORY_INTERVAL;
}
}
//