HiveMind
TCPServer.h
Go to the documentation of this file.
1 #ifndef __TCPSERVER_H__
2 #define __TCPSERVER_H__
3 
4 #include "bsp/ICommInterface.h"
5 #include <BaseTask.h>
6 #include <condition_variable>
7 #include <logger/ILogger.h>
8 #include <mutex>
9 #include <netinet/in.h>
10 #include <optional>
11 
12 class TCPServer : public ICommInterface {
13  public:
14  TCPServer(ILogger& logger);
15  ~TCPServer() override;
16 
20  bool openSocket(int port);
21 
22  bool send(const uint8_t* buffer, uint16_t length) override;
23 
24  bool receive(uint8_t* buffer, uint16_t length) override;
25 
26  bool isConnected() const override;
27 
28  void close();
29 
30  ConnectionType getType() const override;
31 
32  private:
33  void closeClient();
34 
37 
38  BaseTask<configMINIMAL_STACK_SIZE * 2> m_listenTask;
39 
41  std::optional<int> m_clientFd;
43  struct sockaddr_in m_address {};
44 
45  void waitForClient();
46  static void listenTask(void* param);
47 };
48 
49 #endif // __TCPSERVER_H__
TCPServer::getType
ConnectionType getType() const override
Tells the type of the connection interface.
Definition: TCPServer.cpp:93
TCPServer::m_address
Definition: TCPServer.h:43
ConnectionType
ConnectionType
Definition: ICommInterface.h:6
TCPServer::closeClient
void closeClient()
Definition: TCPServer.cpp:116
TCPServer::m_addressLength
int m_addressLength
Definition: TCPServer.h:42
ICommInterface.h
TCPServer::receive
bool receive(uint8_t *buffer, uint16_t length) override
Definition: TCPServer.cpp:71
TCPServer::send
bool send(const uint8_t *buffer, uint16_t length) override
Definition: TCPServer.cpp:61
TCPServer::m_port
int m_port
Definition: TCPServer.h:40
TCPServer::isConnected
bool isConnected() const override
Tells if interface is connected and functionning.
Definition: TCPServer.cpp:82
TCPServer::m_connected
bool m_connected
Definition: TCPServer.h:36
ILogger
A logger class with basic logging capabilities.
Definition: ILogger.h:35
ICommInterface
Definition: ICommInterface.h:8
TCPServer
Definition: TCPServer.h:12
TCPServer::listenTask
static void listenTask(void *param)
Definition: TCPServer.cpp:7
TCPServer::close
void close()
Definition: TCPServer.cpp:84
TCPServer::m_logger
ILogger & m_logger
Definition: TCPServer.h:35
TCPServer::waitForClient
void waitForClient()
Definition: TCPServer.cpp:95
TCPServer::m_serverFd
int m_serverFd
Definition: TCPServer.h:40
TCPServer::openSocket
bool openSocket(int port)
opens the socket on a certain port
Definition: TCPServer.cpp:20
TCPServer::m_listenTask
BaseTask< configMINIMAL_STACK_SIZE *2 > m_listenTask
Definition: TCPServer.h:38
TCPServer::~TCPServer
~TCPServer() override
Definition: TCPServer.cpp:18
ILogger.h
TCPServer::m_clientFd
std::optional< int > m_clientFd
Definition: TCPServer.h:41
TCPServer::TCPServer
TCPServer(ILogger &logger)
Definition: TCPServer.cpp:12