BAOS SDK v2  1.2.1
An SDK providing access to IP-BAOS devices through BAOS binary protocol version 2.x
Loading...
Searching...
No Matches
BaosTcpConnection.h
Go to the documentation of this file.
1//
2// Copyright (c) 2002-2026 WEINZIERL ENGINEERING GmbH
3// All rights reserved.
4//
5// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
8// SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
9// WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
10// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
11//
12
13#ifndef __BAOSLIB_TCPCONNECTION_H__
14#define __BAOSLIB_TCPCONNECTION_H__
15
16#include "baos/config.h"
19
24namespace wz::baos::transport
25{
26class ProtocolStack;
27}
28
29namespace wz::baos::ip
30{
31
32/**********************************************************
33 * Base BaosTcpConnection
34 ***********************************************************/
35
36namespace base
37{
42{
43public:
44 using UPtr = std::unique_ptr<BaosTcpConnection>;
46
48
50
56 BaosTcpConnection(std::unique_ptr<ip::Ip4Driver>& driver);
58
59 virtual ~BaosTcpConnection();
60
68
74
81 void open(const std::string& ip4Address, std::uint16_t port = 12004);
82 void reopen() override;
83
84protected:
85 virtual void postOpen(protocol::ResponsePromise&& prom);
86
87 bool isOpenImpl() override;
88
90 void startImpl() override;
91
96
104
110
113
114 void resolveMsgQPromises(std::exception_ptr eptr) noexcept;
115
116 transport::TransportTcpIO& getTransportIO();
117
118protected:
120 ip::Ip4SocketAddress socketAddress_;
121 std::uint64_t msgId_{0};
122 bool ensureAutoConnect_{true};
123 bool verifyProtocolVersion_{true};
124};
125
126} // namespace base
127
128/***************************************************************
129 * BaosConLessTcpConnection
130 ***************************************************************/
131
145{
146public:
147 using UPtr = std::unique_ptr<BaosConLessTcpConnection>;
148
150 BaosConLessTcpConnection(std::unique_ptr<ip::Ip4Driver>& driver);
151
153
154};
155
169
170/***************************************************************
171 * BaosConOrientedTcpConnection
172 ***************************************************************/
173
182{
183public:
184 using UPtr = std::unique_ptr<BaosConOrientedTcpConnection>;
185
187 BaosConOrientedTcpConnection(std::unique_ptr<ip::Ip4Driver>& driver);
188
190
191};
192
193/***************************************************************
194 * BaosSecureTcpConnection
195 ***************************************************************/
196
205{
206public:
207 using UPtr = std::unique_ptr<BaosSecureTcpConnection>;
208 using PasswordHash = std::array<std::uint8_t, 16>;
209 using AuthenticationCode = std::array<std::uint8_t, 16>;
210
212 BaosSecureTcpConnection(std::unique_ptr<ip::Ip4Driver>& driver);
213
214 virtual ~BaosSecureTcpConnection();
215
216 void open(const std::string& ip4Address,
217 const PasswordHash& passwordHash,
218 std::uint16_t port = 12004);
219
220 void open(const std::string& ip4Address,
221 const PasswordHash& passwordHash, const AuthenticationCode& authenticationCode,
222 std::uint16_t port = 12004);
223
224 static PasswordHash calculatePasswordHash(const std::string& password);
225 static AuthenticationCode calculateDeviceAuthenticationCode(const std::string& secret);
226
227protected:
228 void postOpen(protocol::ResponsePromise&& prom) override;
229
230private:
231 PasswordHash passwordHash_;
232 std::optional<AuthenticationCode> authenticationCode_;
233
234};
235
236} // namespace wz::baos::ip
237
238#endif // __BAOSLIB_TCPCONNECTION_H__
Code regarding a connection to a physical BAOS device.
Base class for the transport protocol io used by BaosConnections.
Represents a connection to a BAOS device.
Definition BaosConnection.h:67
State
Represents the internal state of this connection.
Definition BaosConnection.h:355
Buffer BaosFrame
An alias for the container type to store frame/packets/telegrams in.
Definition BaosConnection.h:70
Represents an IOEvent.
Definition IOEvent.h:44
A specialization for (connection-less) connection to the BAOS device via a TCP connection.
Definition BaosTcpConnection.h:145
std::unique_ptr< BaosConLessTcpConnection > UPtr
Alias for a std::unique_ptr to this class.
Definition BaosTcpConnection.h:147
A specialization for (connection oriented) connection to the BAOS device via a TCP connection.
Definition BaosTcpConnection.h:182
std::unique_ptr< BaosConOrientedTcpConnection > UPtr
Alias for a std::unique_ptr to this class.
Definition BaosTcpConnection.h:184
A specialization for secure connection to the BAOS device via a TCP connection.
Definition BaosTcpConnection.h:205
std::unique_ptr< BaosSecureTcpConnection > UPtr
Alias for a std::unique_ptr to this class.
Definition BaosTcpConnection.h:207
Base class for connections to the BAOS device via a TCP connection.
Definition BaosTcpConnection.h:42
void eventHandler()
Handles the incoming IOEvents.
Buffer TcpTransportFrame
Alias on how a TcpTransportFrame is represented.
Definition BaosTcpConnection.h:45
void onStateChange(State oldState, State newState) override
Invoked if the internal connection state should be changed.
std::unique_ptr< BaosTcpConnection > UPtr
Alias for a std::unique_ptr to this class.
Definition BaosTcpConnection.h:44
void enableVerifyProtocolVersion(bool enable)
Enables the option for verify the BAOS binary protocol version. The default value is true (enabled).
protocol::ResponseFuture closeImplAsync() override
The implementation function for closing a connection.
void reopen() override
Reopens the underlying connection, has to be implemented by derived classes.
bool isOpenImpl() override
The implementation function for getting the opened state of the connection.
void enableEnsureAutoConnect(bool enable)
Enables the option for ensure auto connect in legacy mode (e.g. 774.1 with auto connect mode)....
protocol::ResponseFuture sendImpl(BaosFrame &&frame) override
The implementation function for sending bytes to the connected device.
void open(const std::string &ip4Address, std::uint16_t port=12004)
Open a connection to physical BAOS device.
void handleTxTcp(IOEvent &&event)
Called for every Tx IOEvent (outgoing, send, transmit)
void handleRxTcp(IOEvent &&event)
Called for every Rx IOEvent (incoming, received)
void startImpl() override
The implementation function for starting the connection class.
Base class for a Transport input output connection.
Definition TransportTcpIO.h:54
std::unique_ptr< TransportTcpIO > UPtr
Alias for a std::unique_ptr to this class.
Definition TransportTcpIO.h:56
Global types and configuration for the whole SDK.
std::promise< BaseResponse::SPtr > ResponsePromise
Definition Response.h:95
std::future< BaseResponse::SPtr > ResponseFuture
Definition Response.h:97
std::vector< std::uint8_t > Buffer
An alias type for a byte buffer.
Definition config.h:71
Represent the pair of IP address as string in the form "10.0.0.1020" and a port.
Definition IpGeneral.h:34