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>;
59 : startPattern_{startPattern},
60 sizePosition_{sizePosition},
74 std::uint16_t bufferSize,
76 std::uint16_t& length) = 0;
80 const std::int32_t sizePosition_{-1};
81 const std::uint16_t sizeBytes_{0};
90 using UPtr = std::unique_ptr<KnxNetIPPacketizer>;
100 bool packetize(
const Buffer& buf, std::uint16_t bufferSize, std::int32_t& offset, std::uint16_t& length)
override;
116 using UPtr = std::unique_ptr<TcpIO>;
135 TcpIO(
BaosMsgQueue& msgQueue, std::unique_ptr<Ip4Driver>& driver, wzcpp::ExecutorBase& executor);
142 Ip4Driver& getDriver()
163 void open(
const std::string& ip4Address, std::uint16_t port);
190 static std::atomic<std::uint64_t>
msgId;
192 std::atomic<bool> rxShouldStop_{
false};
195 std::atomic<bool> stopped_{
false};
198 std::atomic<bool> isOpen_{
false};
Code regarding Input/Output Events.
Specializaton for a Packetizer which detects KnxNet/Ip packets.
Definition: TcpIO.h:88
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.
Definition: TcpIO.h:96
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:79
PacketizerBase(const Buffer &startPattern, std::uint16_t sizePosition, std::uint16_t sizeBytes)
Construct a new Packetizer Base object from a given pattern.
Definition: TcpIO.h:58
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:114
bool isOpen()
Get the open state of the TCP connection.
Definition: TcpIO.h:180
void close()
Close the TCP connection.
std::unique_lock< std::mutex > UniqueLock
Alias for unique lock used by this class.
Definition: TcpIO.h:117
BaosMsgQueue & msgQueue_
Reference to the message queue in which events will be posted by this class.
Definition: TcpIO.h:200
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:193
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:116
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:194
std::unique_ptr< Ip4Driver > driver_
The driver to use for actual sending and receiving.
Definition: TcpIO.h:191
wzcpp::ExecutorBase & executor_
Reference to the executor to use for running the receive(RX) worker.
Definition: TcpIO.h:201
static std::atomic< std::uint64_t > msgId
Used to generate a continuous unique message id.
Definition: TcpIO.h:190
PacketizerBase::UPtr packetizer_
TCP stream packetizer used by this class.
Definition: TcpIO.h:199
Global types and configuration for the whole SDK.
std::vector< std::uint8_t > Buffer
An alias type for a byte buffer.
Definition: config.h:64
wzcpp::ConcurrentDeque< IOEvent > BaosMsgQueue
Alias for a concurrent queue with IOEvents.
Definition: IOEvent.h:117