mirror of https://github.com/arendst/Tasmota.git
Refactor backlog from LinkedList to TasmotaLList
This commit is contained in:
parent
9006386cf2
commit
1ffbbc914d
|
@ -145,14 +145,13 @@ void LList<T>::reset(void) {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T * LList<T>::removeHead(void) {
|
T * LList<T>::removeHead(void) {
|
||||||
if (_head) {
|
if (_head) {
|
||||||
T & orginal_head = _head.val;
|
T * orginal_head = &_head->_val;
|
||||||
LList_elt<T> * next = _head->next();
|
LList_elt<T> * next = _head->next();
|
||||||
delete _head;
|
delete _head;
|
||||||
_head = next;
|
_head = next;
|
||||||
return orginal_head;
|
return orginal_head;
|
||||||
} else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -434,9 +434,8 @@ struct TasmotaGlobal_t {
|
||||||
|
|
||||||
TSettings* Settings = nullptr;
|
TSettings* Settings = nullptr;
|
||||||
|
|
||||||
#include <LinkedList.h>
|
LList<char*> backlog; // Command backlog implemented with TasmotaLList
|
||||||
LinkedList<char*> backlog; // Command backlog implemented with LinkedList
|
#define BACKLOG_EMPTY (backlog.isEmpty())
|
||||||
#define BACKLOG_EMPTY (backlog.size() == 0)
|
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Main
|
* Main
|
||||||
|
@ -782,7 +781,12 @@ void BacklogLoop(void) {
|
||||||
TasmotaGlobal.backlog_mutex = true;
|
TasmotaGlobal.backlog_mutex = true;
|
||||||
bool nodelay = false;
|
bool nodelay = false;
|
||||||
do {
|
do {
|
||||||
char* cmd = backlog.shift();
|
char* cmd = *backlog.head();
|
||||||
|
backlog.removeHead();
|
||||||
|
/*
|
||||||
|
// This adds 32 bytes
|
||||||
|
char* cmd = *backlog.removeHead();
|
||||||
|
*/
|
||||||
if (!strncasecmp_P(cmd, PSTR(D_CMND_NODELAY), strlen(D_CMND_NODELAY))) {
|
if (!strncasecmp_P(cmd, PSTR(D_CMND_NODELAY), strlen(D_CMND_NODELAY))) {
|
||||||
free(cmd);
|
free(cmd);
|
||||||
nodelay = true;
|
nodelay = true;
|
||||||
|
@ -795,6 +799,23 @@ void BacklogLoop(void) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (!BACKLOG_EMPTY);
|
} while (!BACKLOG_EMPTY);
|
||||||
|
/*
|
||||||
|
// This adds 96 bytes
|
||||||
|
for (auto &cmd : backlog) {
|
||||||
|
backlog.remove(&cmd);
|
||||||
|
if (!strncasecmp_P(cmd, PSTR(D_CMND_NODELAY), strlen(D_CMND_NODELAY))) {
|
||||||
|
free(cmd);
|
||||||
|
nodelay = true;
|
||||||
|
} else {
|
||||||
|
ExecuteCommand(cmd, SRC_BACKLOG);
|
||||||
|
free(cmd);
|
||||||
|
if (nodelay || TasmotaGlobal.backlog_nodelay) {
|
||||||
|
TasmotaGlobal.backlog_timer = millis(); // Reset backlog_timer which has been set by ExecuteCommand (CommandHandler)
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
TasmotaGlobal.backlog_mutex = false;
|
TasmotaGlobal.backlog_mutex = false;
|
||||||
}
|
}
|
||||||
if (BACKLOG_EMPTY) {
|
if (BACKLOG_EMPTY) {
|
||||||
|
|
|
@ -523,7 +523,8 @@ void CmndBacklog(void) {
|
||||||
char* temp = (char*)malloc(strlen(blcommand)+1);
|
char* temp = (char*)malloc(strlen(blcommand)+1);
|
||||||
if (temp != nullptr) {
|
if (temp != nullptr) {
|
||||||
strcpy(temp, blcommand);
|
strcpy(temp, blcommand);
|
||||||
backlog.add(temp);
|
char* &elem = backlog.addToLast();
|
||||||
|
elem = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blcommand = strtok(nullptr, ";");
|
blcommand = strtok(nullptr, ";");
|
||||||
|
@ -533,8 +534,9 @@ void CmndBacklog(void) {
|
||||||
TasmotaGlobal.backlog_timer = millis();
|
TasmotaGlobal.backlog_timer = millis();
|
||||||
} else {
|
} else {
|
||||||
bool blflag = BACKLOG_EMPTY;
|
bool blflag = BACKLOG_EMPTY;
|
||||||
while (backlog.size()) {
|
for (auto &elem : backlog) {
|
||||||
free(backlog.pop());
|
free(elem);
|
||||||
|
backlog.remove(&elem);
|
||||||
}
|
}
|
||||||
ResponseCmndChar(blflag ? PSTR(D_JSON_EMPTY) : PSTR(D_JSON_ABORTED));
|
ResponseCmndChar(blflag ? PSTR(D_JSON_EMPTY) : PSTR(D_JSON_ABORTED));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2069,7 +2069,8 @@ void ExecuteCommandBlock(const char * commands, int len)
|
||||||
char* temp = (char*)malloc(strlen(blcommand)+1);
|
char* temp = (char*)malloc(strlen(blcommand)+1);
|
||||||
if (temp != nullptr) {
|
if (temp != nullptr) {
|
||||||
strcpy(temp, blcommand);
|
strcpy(temp, blcommand);
|
||||||
backlog.add(insertPosition, temp);
|
char* &elem = backlog.insertAt(insertPosition);
|
||||||
|
elem = temp;
|
||||||
}
|
}
|
||||||
insertPosition++;
|
insertPosition++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue