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
+2
-2
@@ -3606,7 +3606,7 @@ static SettingResult applyAction(Variables& dst, std::string_view action, bool v
|
||||
}
|
||||
|
||||
bool applyAction(std::string_view action, bool value) {
|
||||
if (vars.states.upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
if (upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3617,7 +3617,7 @@ SettingResult fromJson(const JsonVariantConst src, Variables& dst) {
|
||||
SettingResult result;
|
||||
|
||||
// Admit the whole request before one of its actions schedules a restart.
|
||||
if (vars.states.upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
if (upgrading || restartTask.scheduled() || restartTask.active()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -18,8 +18,6 @@
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
std::mutex mqttMutex;
|
||||
|
||||
static std::unique_ptr<MQTT> mqttClient;
|
||||
|
||||
// Keep the applied prefix separate from settings until MQTT is reconfigured.
|
||||
@@ -55,7 +53,7 @@ static bool isSensorReconfigurationPending(uint8_t sensorId) {
|
||||
}
|
||||
|
||||
static bool isMqttBlocked() {
|
||||
return vars.states.upgrading || restartTask.scheduled() || restartTask.active();
|
||||
return upgrading || restartTask.scheduled() || restartTask.active();
|
||||
}
|
||||
|
||||
static bool isMqttReady() {
|
||||
@@ -1154,7 +1152,7 @@ Task mqttConfigureTask("Configure MQTT", Task::Type::ONCE, [](void*) {
|
||||
void initMqtt() {
|
||||
// Keep only the configuration dispatcher when MQTT publications are disabled.
|
||||
mqttConfigureTask.pause().setEnabledWhen([] {
|
||||
return !vars.states.upgrading && !restartTask.scheduled() && !restartTask.active();
|
||||
return !upgrading && !restartTask.scheduled() && !restartTask.active();
|
||||
});
|
||||
|
||||
coreTaskManager.addTask(mqttConfigureTask);
|
||||
|
||||
+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);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -770,7 +770,7 @@ static void updateConnectionStatus() {
|
||||
}
|
||||
|
||||
static bool canRunSensors() {
|
||||
return !vars.states.upgrading && !restartTask.scheduled() && !restartTask.active();
|
||||
return !upgrading && !restartTask.scheduled() && !restartTask.active();
|
||||
}
|
||||
|
||||
static Task readDallasSensorsTask("Read Dallas sensors", [](void*) {
|
||||
|
||||
+1
-1
@@ -94,7 +94,7 @@ static Task heapTask("Heap monitoring", [](void*) {
|
||||
unsigned int maxFreeBlockHeap = memory.heap.largest_free_block;
|
||||
|
||||
/*if (freeHeap < 2048 || maxFreeBlockHeap < 2048) {
|
||||
if (!vars.states.upgrading) {
|
||||
if (!upgrading) {
|
||||
esp_system_abort("OTGateway: low internal heap");
|
||||
}
|
||||
}*/
|
||||
|
||||
Reference in new issue
Block a user