-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbmsrequestcontroller.cpp
More file actions
34 lines (31 loc) · 1.44 KB
/
bmsrequestcontroller.cpp
File metadata and controls
34 lines (31 loc) · 1.44 KB
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
33
34
#include "bmsrequestcontroller.h"
BMSRequestController::BMSRequestController(QObject *parent, MemoryHandler *mH)
: HttpRequestHandler(parent), mH(mH), pLController(this,mH), pSController(this,mH)
{
}
void BMSRequestController::service(HttpRequest &request, HttpResponse &response){
QByteArray path = request.getPath();
if(!mH->isSharedMemoryMapped || !mH->isBMSRunning()){
response.setHeader("Content-Type","application/json; charset=UTF-8");
QJsonObject json;
json["error"] = "Falcon BMS Server is down";
QJsonDocument doc(json);
qDebug() << doc.toJson();
response.write(doc.toJson(QJsonDocument::Indented),true);
} else {
if(path == "/" || QString(path).startsWith("/pilotlist",Qt::CaseInsensitive)) {
pLController.service(request,response);
} else if(QString(path).startsWith("/pilotstatus/",Qt::CaseInsensitive)) {
pSController.service(request,response);
}else if(QString(path).startsWith("/currenttime",Qt::CaseInsensitive)){
response.setHeader("Content-Type","application/json; charset=UTF-8");
QJsonObject json;
json["currentTime"] = mH->getCurrentTime();
QJsonDocument doc(json);
response.write(doc.toJson(QJsonDocument::Indented),true);
} else {
response.setStatus(404,"Not found");
response.write("The supplied URL could not be found.");
}
}
}