2020-07-08 01:33:33 +00:00
# pragma once
# include "StreamAPI.h"
# include <WiFi.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 ) .
*/
class WiFiServerAPI : public StreamAPI
{
private :
WiFiClient client ;
public :
WiFiServerAPI ( WiFiClient & _client ) ;
virtual ~ WiFiServerAPI ( ) ;
2020-12-31 01:52:08 +00:00
/// override close to also shutdown the TCP link
virtual void close ( ) ;
2020-07-08 01:33:33 +00:00
protected :
2021-03-24 22:15:15 +00:00
2021-05-24 01:42:21 +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)
virtual void onConnectionChanged ( bool connected ) { }
2021-03-24 22:15:15 +00:00
virtual int32_t runOnce ( ) ; // Check for dropped client connections
2021-05-03 06:46:30 +00:00
/// Check the current underlying physical link to see if the client is currently connected
virtual bool checkIsConnected ( ) ;
2020-07-08 01:33:33 +00:00
} ;
/**
* Listens for incoming connections and does accepts and creates instances of WiFiServerAPI as needed
*/
2020-10-10 01:57:57 +00:00
class WiFiServerPort : public WiFiServer , private concurrency : : OSThread
2020-07-08 01:33:33 +00:00
{
2020-09-25 23:18:30 +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 .
*/
WiFiServerAPI * openAPI = NULL ;
2020-07-08 01:33:33 +00:00
public :
WiFiServerPort ( ) ;
void init ( ) ;
2020-10-10 01:57:57 +00:00
int32_t runOnce ( ) ;
2020-07-08 01:33:33 +00:00
} ;
2021-02-07 01:17:46 +00:00
void initApiServer ( ) ;