13 #ifndef __BAOSLIB_TCP_IO_H__
14 #define __BAOSLIB_TCP_IO_H__
16 #include "baos/BaosLib_export.h"
20 #include "wzcpp/features/concurrent/executor.h"
35 namespace wz::baos::ip
48 using UPtr = std::unique_ptr<PacketizerBase>;
70 std::uint16_t bufferSize,
72 std::uint16_t& length) = 0;
76 const std::int32_t sizePosition_{-1};
77 const std::uint16_t sizeBytes_{0};
86 using UPtr = std::unique_ptr<KnxNetIPPacketizer>;
94 bool packetize(
const Buffer& buf, std::uint16_t bufferSize, std::int32_t& offset, std::uint16_t& length)
override;
96 void setAcceptedProtocolVersions(
const std::vector<std::uint8_t>& versions);
99 constexpr
static std::uint8_t HEADER_SIZE{6};
100 constexpr
static std::uint8_t PROTOCOL_VERSION_POSITION{1};
101 std::vector<std::uint8_t> acceptedProtocolVersions_{0x10,0x20};
117 using UPtr = std::unique_ptr<TcpIO>;
136 TcpIO(
BaosMsgQueue& msgQueue, std::unique_ptr<Ip4Driver>& driver, wzcpp::ExecutorBase& executor);
143 Ip4Driver& getDriver();
161 void open(
const std::string& ip4Address, std::uint16_t port);
184 static std::atomic<std::uint64_t>
msgId;
185 std::atomic<bool> rxShouldStop_{
false};
188 bool stopped_{
false};
191 std::atomic<bool> isOpen_{
false};
Code regarding Input/Output Events.
Specializaton for a Packetizer which detects KnxNet/Ip packets.
Definition: TcpIO.h:84
bool packetize(const Buffer &buf, std::uint16_t bufferSize, std::int32_t &offset, std::uint16_t &length) override
KnxNetIPPacketizer()
Construct a new Knx Net IP Packetizer object with given pattern. size position and length.
To find packets in the TCP byte stream a pattern and the following toatl packet length are used.
Definition: TcpIO.h:46
const Buffer startPattern_
The pattern which marks the beginning of a packet in the byte stream.
Definition: TcpIO.h:75
PacketizerBase(const Buffer &startPattern, std::uint16_t sizePosition, std::uint16_t sizeBytes)
Construct a new Packetizer Base object from a given pattern.
virtual bool packetize(const Buffer &buf, std::uint16_t bufferSize, std::int32_t &offset, std::uint16_t &length)=0
std::unique_ptr< PacketizerBase > UPtr
Alias for a std::unique_ptr to this class.
Definition: TcpIO.h:48
Base class for a TCP input output connection.
Definition: TcpIO.h:115
bool isOpen()
Get the open state of the TCP connection.
void close()
Close the TCP connection.
std::unique_lock< std::mutex > UniqueLock
Alias for unique lock used by this class.
Definition: TcpIO.h:118
BaosMsgQueue & msgQueue_
Reference to the message queue in which events will be posted by this class.
Definition: TcpIO.h:192
void open(const std::string &ip4Address, std::uint16_t port)
Open the TCP connection to the remote device.
TcpIO(BaosMsgQueue &msgQueue, wzcpp::ExecutorBase &executor)
Construct a new TcpIO object with a given message queue and executor.
std::condition_variable cvFinished_
Condition variable which is set when the receiver worker has stopped.
Definition: TcpIO.h:186
void waitForFinished()
Wait till the worker of this class has finished.
std::unique_ptr< TcpIO > UPtr
Alias for a std::unique_ptr to this class.
Definition: TcpIO.h:117
void send(const Buffer &buf)
Send a byte list out.
std::mutex cvFinished_mut_
The correponding mutex for the cvFinished_ condition variable.
Definition: TcpIO.h:187
std::unique_ptr< Ip4Driver > driver_
The driver to use for actual sending and receiving.
Definition: TcpIO.h:194
wzcpp::ExecutorBase & executor_
Reference to the executor to use for running the receive(RX) worker.
Definition: TcpIO.h:193
static std::atomic< std::uint64_t > msgId
Used to generate a continuous unique message id.
Definition: TcpIO.h:184
PacketizerBase::UPtr packetizer_
TCP stream packetizer used by this class.
Definition: TcpIO.h:195
Global types and configuration for the whole SDK.
std::vector< std::uint8_t > Buffer
An alias type for a byte buffer.
Definition: config.h:71
wzcpp::ConcurrentDeque< IOEvent > BaosMsgQueue
Alias for a concurrent queue with IOEvents.
Definition: IOEvent.h:96