Webserver addition and TactilityC symbols (#451)

This commit is contained in:
Shadowtrance
2026-01-22 06:47:59 +10:00
committed by GitHub
parent c98cb2bf10
commit 01ffe420eb
22 changed files with 5006 additions and 21 deletions
+27 -7
View File
@@ -9,39 +9,58 @@ namespace tt::network {
static const auto LOGGER = Logger("HttpServer");
static constexpr size_t INTERNAL_URI_HANDLER_COUNT = 2;
bool HttpServer::startInternal() {
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
config.stack_size = stackSize;
config.server_port = port;
config.uri_match_fn = matchUri;
config.max_uri_handlers = handlers.size() + INTERNAL_URI_HANDLER_COUNT;
if (httpd_start(&server, &config) != ESP_OK) {
LOGGER.error("Failed to start http server on port {}", port);
return false;
}
bool allRegistered = true;
for (std::vector<httpd_uri_t>::reference handler : handlers) {
httpd_register_uri_handler(server, &handler);
if (httpd_register_uri_handler(server, &handler) != ESP_OK) {
LOGGER.error("Failed to register URI handler: {}", handler.uri);
allRegistered = false;
}
}
if (!allRegistered) {
httpd_stop(server);
server = nullptr;
return false;
}
LOGGER.info("Started on port {}", config.server_port);
return true;
}
void HttpServer::stopInternal() {
LOGGER.info("Stopping server");
if (server != nullptr && httpd_stop(server) != ESP_OK) {
LOGGER.warn("Error while stopping");
server = nullptr;
if (server != nullptr) {
if (httpd_stop(server) == ESP_OK) {
server = nullptr;
} else {
LOGGER.warn("Error while stopping");
}
}
}
void HttpServer::start() {
bool HttpServer::start() {
auto lock = mutex.asScopedLock();
lock.lock();
startInternal();
if (isStarted()) {
LOGGER.warn("Already started");
return true;
}
return startInternal();
}
void HttpServer::stop() {
@@ -50,6 +69,7 @@ void HttpServer::stop() {
if (!isStarted()) {
LOGGER.warn("Not started");
return;
}
stopInternal();