BAOS SDK v2  1.0.1
An SDK providing access to IP-BAOS devices through BAOS binary protocol version 2.x
BaosTcpConnection.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2002-2023 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"
18 
24 namespace wz::baos::ip
25 {
26 
27 /**********************************************************
28  * BaosTcpConnection
29  ***********************************************************/
30 
34 class BAOSLIB_EXPORT BaosTcpConnection : public BaosConnection
35 {
36 public:
37  using UPtr = std::unique_ptr<BaosTcpConnection>;
39 
41 
43 
49  BaosTcpConnection(std::unique_ptr<Ip4Driver>& driver);
51 
52  virtual ~BaosTcpConnection();
53 
60  void open(const std::string& ip4Address, std::uint16_t port = 12004);
61  void reopen() override;
62 
63 protected:
64  bool isOpenImpl() override
65  {
66  return tcpTransport_.isOpen();
67  };
68 
76 
78  void startImpl() override;
79 
83  void eventHandler();
84 
91  void handleRxTcp(IOEvent&& event);
92 
97  void handleTxTcp(IOEvent&& event);
98 
100  void onStateChange(State oldState, State newState) override;
101 
102 private:
103  TcpIO tcpTransport_;
104  ip::Ip4SocketAddress socketAddress_;
105  WZLOGGER("BaosTcpConnection", LVL_DEBUG);
106  std::uint64_t msgId_{0};
107 };
108 
109 } // namespace wz::baos::ip
110 
111 #endif // __BAOSLIB_TCPCONNECTION_H__
Code regarding a connection to a physical BAOS device.
Represents a connection to a BAOS device.
Definition: BaosConnection.h:69
State
Represents the internal state of this connection.
Definition: BaosConnection.h:359
std::unique_ptr< BaosConnection > UPtr
An alias for an unqiue pointer to this class.
Definition: BaosConnection.h:74
Buffer BaosFrame
An alias for the container type to store frame/packets/telegrams in.
Definition: BaosConnection.h:72
Represents an IOEvent.
Definition: IOEvent.h:42
A specialization for connection to the BAOS device via a TCP connection.
Definition: BaosTcpConnection.h:35
void eventHandler()
Handles the incoming IOEvents.
Buffer TcpTransportFrame
Alias on how a TcpTransportFrame is represented.
Definition: BaosTcpConnection.h:38
void onStateChange(State oldState, State newState) override
Invoked if the internal connection state should be changed.
protocol::ResponseFuture closeImplAsync() override
The implementation function for closing a connection.
TcpTransportFrame wrapKNXnetIp(BaosFrame &&frame)
Wrap a baos frame into a KnxNet/Ip frame.
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.
Definition: BaosTcpConnection.h:64
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 TCP input output connection.
Definition: TcpIO.h:114
Global types and configuration for the whole SDK.
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:64
Represent the pair of IP address as string in the form "10.0.0.1020" and a port.
Definition: IpGeneral.h:34