firmware/src/mesh/api/ServerAPI.h

53 lines
1.6 KiB
C
Raw Normal View History

2020-07-08 01:33:33 +00:00
#pragma once
#include "StreamAPI.h"
/**
* Provides both debug printing and, if the client starts sending protobufs to us, switches to send/receive protobufs
* (and starts dropping debug printing - FIXME, eventually those prints should be encapsulated in protobufs).
*/
2023-01-21 13:34:29 +00:00
template <class T> class ServerAPI : public StreamAPI, private concurrency::OSThread
2020-07-08 01:33:33 +00:00
{
private:
T client;
2020-07-08 01:33:33 +00:00
public:
explicit ServerAPI(T &_client);
2020-07-08 01:33:33 +00:00
virtual ~ServerAPI();
2020-07-08 01:33:33 +00:00
/// override close to also shutdown the TCP link
virtual void close();
2020-07-08 01:33:33 +00:00
protected:
2021-08-18 16:25:17 +00:00
/// We override this method to prevent publishing EVENT_SERIAL_CONNECTED/DISCONNECTED for wifi links (we want the board to
/// stay in the POWERED state to prevent disabling wifi)
2022-01-24 17:24:40 +00:00
virtual void onConnectionChanged(bool connected) override {}
2022-01-24 17:24:40 +00:00
virtual int32_t runOnce() override; // Check for dropped client connections
/// Check the current underlying physical link to see if the client is currently connected
2022-01-24 17:24:40 +00:00
virtual bool checkIsConnected() override;
2020-07-08 01:33:33 +00:00
};
/**
* Listens for incoming connections and does accepts and creates instances of WiFiServerAPI as needed
*/
2023-01-21 13:34:29 +00:00
template <class T, class U> class APIServerPort : public U, private concurrency::OSThread
2020-07-08 01:33:33 +00:00
{
/** The currently open port
*
* FIXME: We currently only allow one open TCP connection at a time, because we depend on the loop() call in this class to
* delegate to the worker. Once coroutines are implemented we can relax this restriction.
*/
T *openAPI = NULL;
2020-07-08 01:33:33 +00:00
public:
explicit APIServerPort(int port);
2020-07-08 01:33:33 +00:00
void init();
2021-08-18 16:25:17 +00:00
protected:
2022-01-24 17:24:40 +00:00
int32_t runOnce() override;
2020-07-08 01:33:33 +00:00
};