-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpilotlistcontroller.cpp
More file actions
32 lines (26 loc) · 911 Bytes
/
Copy pathpilotlistcontroller.cpp
File metadata and controls
32 lines (26 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "pilotlistcontroller.h"
PilotListController::PilotListController(QObject *parent, MemoryHandler *mH)
: HttpRequestHandler(parent), mH(mH)
{
}
void PilotListController::service(HttpRequest &request, HttpResponse &response)
{
response.setHeader("Content-Type","application/json; charset=UTF-8");
QJsonObject json;
QJsonArray pilots;
QMapIterator<int,QString> it(mH->getPilotList());
while(it.hasNext()){
it.next();
QString pilotName = it.value();
qDebug() << "found pilot: " << pilotName;
QJsonObject pilot;
pilot["name"] = pilotName;
pilot["status"] = mH->getPilotStatus(it.key());
pilots.append(pilot);
}
json["pilotsOnline"] = (int)mH->getPilotsOnline();
json["pilots"] = pilots;
QJsonDocument doc(json);
qDebug() << doc.toJson();
response.write(doc.toJson(QJsonDocument::Indented),true);
}