mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-11-30 10:13:04 +05:00
refactor: define OTA upgrade flag and MQTT mutex inline
This commit is contained in:
1 parent
aa7385c70f
commit
cc6131eac9
7 files changed
+22
-27
No files matched your search
+13
-13
@@ -236,15 +236,15 @@ static void restApi() {
|
||||
return false;
|
||||
}
|
||||
// UpgradeHandler invokes this callback for every upload chunk.
|
||||
if (vars.states.upgrading) {
|
||||
if (upgrading) {
|
||||
return true;
|
||||
}
|
||||
|
||||
vars.states.upgrading = true;
|
||||
upgrading = true;
|
||||
coreTaskManager.pause();
|
||||
// Core owns MQTT; finish its current callback before stopping the client.
|
||||
if (!coreTaskManager.waitForPaused(5000)) {
|
||||
vars.states.upgrading = false;
|
||||
upgrading = false;
|
||||
if (!restartTask.scheduled() && !restartTask.active()) {
|
||||
coreTaskManager.resume();
|
||||
}
|
||||
@@ -256,14 +256,14 @@ static void restApi() {
|
||||
|
||||
// An MQTT command already in flight may have scheduled a restart before end().
|
||||
if (restartTask.scheduled() || restartTask.active()) {
|
||||
vars.states.upgrading = false;
|
||||
upgrading = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
sensorsTaskManager.pause();
|
||||
if (!sensorsTaskManager.waitForPaused(5000)) {
|
||||
requestReconfigureMqtt();
|
||||
vars.states.upgrading = false;
|
||||
upgrading = false;
|
||||
if (!restartTask.scheduled() && !restartTask.active()) {
|
||||
coreTaskManager.resume();
|
||||
sensorsTaskManager.resume();
|
||||
@@ -275,7 +275,7 @@ static void restApi() {
|
||||
openthermTaskManager.pause();
|
||||
if (!openthermTaskManager.waitForPaused(5000)) {
|
||||
requestReconfigureMqtt();
|
||||
vars.states.upgrading = false;
|
||||
upgrading = false;
|
||||
if (!restartTask.scheduled() && !restartTask.active()) {
|
||||
coreTaskManager.resume();
|
||||
sensorsTaskManager.resume();
|
||||
@@ -302,7 +302,7 @@ static void restApi() {
|
||||
requestReconfigureMqtt();
|
||||
}
|
||||
|
||||
vars.states.upgrading = false;
|
||||
upgrading = false;
|
||||
if (status != 202 && !restartTask.scheduled() && !restartTask.active()) {
|
||||
coreTaskManager.resume();
|
||||
sensorsTaskManager.resume();
|
||||
@@ -374,7 +374,7 @@ static void restApi() {
|
||||
|
||||
// restart
|
||||
webServer->on("/api/restart", HTTP_POST, [](AsyncWebServerRequest *request) {
|
||||
if (vars.states.upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
if (upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
return request->send(503);
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ static void restApi() {
|
||||
}).addMiddleware(&authMiddleware);
|
||||
|
||||
auto& nsHandler = webServer->on("/api/network/settings", HTTP_POST, [](AsyncWebServerRequest *request, JsonVariant &requestDoc) {
|
||||
if (vars.states.upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
if (upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
return request->send(503);
|
||||
}
|
||||
|
||||
@@ -532,7 +532,7 @@ static void restApi() {
|
||||
}).addMiddleware(&authMiddleware);
|
||||
|
||||
auto& settingsHandler = webServer->on(AsyncURIMatcher::prefix("/api/settings/"), HTTP_POST, [](AsyncWebServerRequest *request, JsonVariant &requestDoc) {
|
||||
if (vars.states.upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
if (upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
request->send(503);
|
||||
return;
|
||||
}
|
||||
@@ -712,7 +712,7 @@ static void restApi() {
|
||||
}).addMiddleware(&authMiddleware);
|
||||
|
||||
auto& ssHandler = webServer->on(AsyncURIMatcher::exact("/api/sensor"), HTTP_POST, [](AsyncWebServerRequest *request, JsonVariant &requestDoc) {
|
||||
if (vars.states.upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
if (upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
return request->send(503);
|
||||
}
|
||||
|
||||
@@ -818,7 +818,7 @@ static void restApi() {
|
||||
}).addMiddleware(&authMiddleware);
|
||||
|
||||
auto& sensorValueHandler = webServer->on(AsyncURIMatcher::exact("/api/sensor/value"), HTTP_POST, [](AsyncWebServerRequest *request, JsonVariant &requestDoc) {
|
||||
if (vars.states.upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
if (upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
return request->send(503);
|
||||
}
|
||||
|
||||
@@ -881,7 +881,7 @@ static void restApi() {
|
||||
});
|
||||
|
||||
auto& vHandler = webServer->on("/api/vars", HTTP_POST, [](AsyncWebServerRequest *request, JsonVariant &requestDoc) {
|
||||
if (vars.states.upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
if (upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
return request->send(503);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user