HiveMind
TCPClient.h
Go to the documentation of this file.
1 #ifndef __TCPCLIENT_H_
2 #define __TCPCLIENT_H_
3 
4 #include "bsp/ICommInterface.h"
5 #include <condition_variable>
6 #include <logger/ILogger.h>
7 #include <mutex>
8 #include <netinet/in.h>
9 #include <optional>
10 #include <thread>
11 
12 class TCPClient : public ICommInterface {
13  public:
14  TCPClient(int socket, sockaddr_in address, ILogger& logger);
15 
16  ~TCPClient() override = default;
17 
18  bool receive(uint8_t* data, uint16_t length) override;
19 
20  bool send(const uint8_t* data, uint16_t length) override;
21 
22  bool isConnected() const override;
23 
24  bool close();
25 
26  ConnectionType getType() const override;
27 
28  friend void rxThread(TCPClient* context);
29 
30  private:
32  const int m_socketFd{};
33  const sockaddr_in m_address{};
35 };
36 
37 #endif // __TCPCLIENT_H_
TCPClient::isConnected
bool isConnected() const override
Tells if interface is connected and functionning.
Definition: TCPClient.cpp:21
TCPClient::receive
bool receive(uint8_t *data, uint16_t length) override
Definition: TCPClient.cpp:9
TCPClient::m_address
const sockaddr_in m_address
Definition: TCPClient.h:33
ConnectionType
ConnectionType
Definition: ICommInterface.h:6
TCPClient::m_logger
ILogger & m_logger
Definition: TCPClient.h:31
TCPClient::~TCPClient
~TCPClient() override=default
ICommInterface.h
TCPClient
Definition: TCPClient.h:12
TCPClient::m_socketFd
const int m_socketFd
Definition: TCPClient.h:32
TCPClient::rxThread
friend void rxThread(TCPClient *context)
TCPClient::send
bool send(const uint8_t *data, uint16_t length) override
Definition: TCPClient.cpp:15
ILogger
A logger class with basic logging capabilities.
Definition: ILogger.h:35
TCPClient::close
bool close()
Definition: TCPClient.cpp:23
ICommInterface
Definition: ICommInterface.h:8
TCPClient::TCPClient
TCPClient(int socket, sockaddr_in address, ILogger &logger)
Definition: TCPClient.cpp:6
TCPClient::getType
ConnectionType getType() const override
Tells the type of the connection interface.
Definition: TCPClient.cpp:30
TCPClient::m_connected
bool m_connected
Definition: TCPClient.h:34
ILogger.h