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>
|
||||
T * LList<T>::removeHead(void) {
|
||||
if (_head) {
|
||||
T & orginal_head = _head.val;
|
||||
T * orginal_head = &_head->_val;
|
||||
LList_elt<T> * next = _head->next();
|
||||
delete _head;
|
||||
_head = next;
|
||||
return orginal_head;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -434,9 +434,8 @@ struct TasmotaGlobal_t {
|
|||
|
||||
TSettings* Settings = nullptr;
|
||||
|
||||
#include <LinkedList.h>
|
||||
LinkedList<char*> backlog; // Command backlog implemented with LinkedList
|
||||
#define BACKLOG_EMPTY (backlog.size() == 0)
|
||||
LList<char*> backlog; // Command backlog implemented with TasmotaLList
|
||||
#define BACKLOG_EMPTY (backlog.isEmpty())
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Main
|
||||
|
@ -782,7 +781,12 @@ void BacklogLoop(void) {
|
|||
TasmotaGlobal.backlog_mutex = true;
|
||||
bool nodelay = false;
|
||||
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))) {
|
||||
free(cmd);
|
||||
nodelay = true;
|
||||
|
@ -795,6 +799,23 @@ void BacklogLoop(void) {
|
|||
break;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
if (BACKLOG_EMPTY) {
|
||||
|
|
|
@ -523,7 +523,8 @@ void CmndBacklog(void) {
|
|||
char* temp = (char*)malloc(strlen(blcommand)+1);
|
||||
if (temp != nullptr) {
|
||||
strcpy(temp, blcommand);
|
||||
backlog.add(temp);
|
||||
char* &elem = backlog.addToLast();
|
||||
elem = temp;
|
||||
}
|
||||
}
|
||||
blcommand = strtok(nullptr, ";");
|
||||
|
@ -533,8 +534,9 @@ void CmndBacklog(void) {
|
|||
TasmotaGlobal.backlog_timer = millis();
|
||||
} else {
|
||||
bool blflag = BACKLOG_EMPTY;
|
||||
while (backlog.size()) {
|
||||
free(backlog.pop());
|
||||
for (auto &elem : backlog) {
|
||||
free(elem);
|
||||
backlog.remove(&elem);
|
||||
}
|
||||
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);
|
||||
if (temp != nullptr) {
|
||||
strcpy(temp, blcommand);
|
||||
backlog.add(insertPosition, temp);
|
||||
char* &elem = backlog.insertAt(insertPosition);
|
||||
elem = temp;
|
||||
}
|
||||
insertPosition++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue