#include "ServerAPI.h" #include "configuration.h" #include template ServerAPI::ServerAPI(T &_client) : StreamAPI(&client), concurrency::OSThread("ServerAPI"), client(_client) { LOG_INFO("Incoming wifi connection\n"); } template ServerAPI::~ServerAPI() { client.stop(); } template void ServerAPI::close() { client.stop(); // drop tcp connection StreamAPI::close(); } /// Check the current underlying physical link to see if the client is currently connected template bool ServerAPI::checkIsConnected() { return client.connected(); } template int32_t ServerAPI::runOnce() { if (client.connected()) { return StreamAPI::runOncePart(); } else { LOG_INFO("Client dropped connection, suspending API service\n"); enabled = false; // we no longer need to run return 0; } } template APIServerPort::APIServerPort(int port) : U(port), concurrency::OSThread("ApiServer") {} template void APIServerPort::init() { U::begin(); } template int32_t APIServerPort::runOnce() { auto client = U::available(); if (client) { // Close any previous connection (see FIXME in header file) if (openAPI) { LOG_INFO("Force closing previous TCP connection\n"); delete openAPI; } openAPI = new T(client); } return 100; // only check occasionally for incoming connections }