| 14 | TaskHandle_t WebClients::_background_task_handle = nullptr; |
| 15 | |
| 16 | void WebClients::background_task(void* pvParameters) { |
| 17 | std::string cmd; |
| 18 | while (true) { |
| 19 | WebClient* webClient; |
| 20 | if (xQueueReceive(_background_task_queue, &webClient, portMAX_DELAY) == pdTRUE) { |
| 21 | webClient->xBufferLock.lock(); |
| 22 | if (webClient->cmds.size() > 0) { |
| 23 | cmd = webClient->cmds.front(); |
| 24 | webClient->cmds.pop_front(); |
| 25 | webClient->xBufferLock.unlock(); |
| 26 | // TODO: check error result and see if we can do anything... |
| 27 | settings_execute_line(cmd.c_str(), *webClient, AuthenticationLevel::LEVEL_ADMIN); |
| 28 | // Should not call detach, since we still need to send the remaining buffer, so we should not free and clear yet. |
| 29 | webClient->xBufferLock.lock(); |
| 30 | webClient->done = true; |
| 31 | webClient->xBufferLock.unlock(); |
| 32 | } else { |
| 33 | webClient->xBufferLock.unlock(); |
| 34 | } |
| 35 | } else |
| 36 | delay(1); // This should never happen if portMAX_DELAY is trully infinite |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | WebClient::WebClient() : Channel("webclient") { |
| 41 | if (WebClients::_background_task_queue == nullptr) // If we are the first instanciation ever, create the event queue |