BAOS SDK v2  1.0.1
An SDK providing access to IP-BAOS devices through BAOS binary protocol version 2.x
TcpIO Class Reference

Base class for a TCP input output connection. More...

#include <baos/ip/TcpIO.h>

Public Types

using UPtr = std::unique_ptr< TcpIO >
 Alias for a std::unique_ptr to this class.
 
using UniqueLock = std::unique_lock< std::mutex >
 Alias for unique lock used by this class.
 

Public Member Functions

 TcpIO (BaosMsgQueue &msgQueue, wzcpp::ExecutorBase &executor)
 Construct a new TcpIO object with a given message queue and executor. More...
 
void send (const Buffer &buf)
 Send a byte list out. More...
 
void open (const std::string &ip4Address, std::uint16_t port)
 Open the TCP connection to the remote device. More...
 
void close ()
 Close the TCP connection.
 
void waitForFinished ()
 Wait till the worker of this class has finished.
 
bool isOpen ()
 Get the open state of the TCP connection. More...
 

Protected Attributes

std::unique_ptr< Ip4Driver > driver_
 The driver to use for actual sending and receiving.
 
std::atomic< bool > rxShouldStop_ {false}
 Flag to indicate that the receiver worker should stop.
 
std::condition_variable cvFinished_
 Condition variable which is set when the receiver worker has stopped.
 
std::mutex cvFinished_mut_
 The correponding mutex for the cvFinished_ condition variable.
 
std::atomic< bool > stopped_ {false}
 
std::atomic< bool > isOpen_ {false}
 Flag to show if the TCP connection is open or not.
 
PacketizerBase::UPtr packetizer_
 TCP stream packetizer used by this class.
 
BaosMsgQueuemsgQueue_
 Reference to the message queue in which events will be posted by this class.
 
wzcpp::ExecutorBase & executor_
 Reference to the executor to use for running the receive(RX) worker.
 

Static Protected Attributes

static std::atomic< std::uint64_t > msgId
 Used to generate a continuous unique message id.
 

Detailed Description

Base class for a TCP input output connection.

This establishes a TCP connection to the BAOS devices. It sends and receives raw bytes.

Constructor & Destructor Documentation

◆ TcpIO()

TcpIO ( BaosMsgQueue msgQueue,
wzcpp::ExecutorBase &  executor 
)

Construct a new TcpIO object with a given message queue and executor.

Parameters
msgQueueAn external message queue to post events into
executorAn external executor to run this class worker in

Member Function Documentation

◆ send()

void send ( const Buffer buf)

Send a byte list out.

Parameters
bufThe bytes to send

◆ open()

void open ( const std::string &  ip4Address,
std::uint16_t  port 
)

Open the TCP connection to the remote device.

Parameters
ip4AddressThe IPv4 Address as string in the form "xxx.xxx.xxx.xxx"
portThe tcp port of the remote device

◆ isOpen()

bool isOpen ( )
inline

Get the open state of the TCP connection.

Returns
true if the TCP connection is established false otherwise

Member Data Documentation

◆ stopped_

std::atomic<bool> stopped_ {false}
protected

Flag to show the actual state of the receive worker. Because condition variables may suffer from spurious wakeups.


The documentation for this class was generated from the following file: