Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
psen_scan_v2_standalone::communication_layer::UdpClientImpl Class Reference

Helper for asynchronously sending and receiving data via UDP. More...

#include <udp_client.h>

Classes

class  CloseConnectionFailure
 Exception thrown if the UDP socket cannot be closed. More...
 
class  OpenConnectionFailure
 Exception thrown if the UDP socket cannot be opened. More...
 

Public Member Functions

void close ()
 Closes the UDP connection and stops all pending asynchronous operation. More...
 
boost::asio::ip::address_v4 hostIp ()
 Returns local ip address of current socket connection. More...
 
void startAsyncReceiving (const ReceiveMode &modi=ReceiveMode::continuous)
 Starts an asynchronous process listing to (a) new message(s) from the other endpoint. If the function continuously listens to new messages or only listens for one message is specified by the receive modi specified. More...
 
void stop ()
 Stops the underlying io_service so that no messages are received anymore. More...
 
 UdpClientImpl (const NewMessageCallback &msg_callback, const ErrorCallback &error_callback, const unsigned short &host_port, const unsigned int &endpoint_ip, const unsigned short &endpoint_port)
 Opens an UDP connection. More...
 
void write (const data_conversion_layer::RawData &data)
 Asynchronously sends the specified data to the other endpoint. More...
 
 ~UdpClientImpl ()
 Closes the UDP connection and stops all pending asynchronous operation. More...
 

Private Member Functions

void asyncReceive (const ReceiveMode &modi)
 
void sendCompleteHandler (const boost::system::error_code &error, std::size_t bytes_transferred)
 

Private Attributes

boost::asio::ip::udp::endpoint endpoint_
 
ErrorCallback error_callback_
 
boost::asio::io_service io_service_
 
std::thread io_service_thread_
 
NewMessageCallback message_callback_
 
data_conversion_layer::RawDataPtr received_data_
 
boost::asio::ip::udp::socket socket_
 
boost::asio::io_service::work work_ { io_service_ }
 

Detailed Description

Helper for asynchronously sending and receiving data via UDP.

This class provides methods for opening and closing the UDP connection, writing and receiving data via UDP. The data is represented by data_conversion_layer::RawData. Upon receiving data a NewMessageCallback is invoked. When something goes wrong an ErrorCallback is invoked.

The ScannerV2 constructs two UDP clients, which are then used by the scanner_protocol::ScannerProtocolDef.

Definition at line 74 of file udp_client.h.

Constructor & Destructor Documentation

◆ UdpClientImpl()

psen_scan_v2_standalone::communication_layer::UdpClientImpl::UdpClientImpl ( const NewMessageCallback msg_callback,
const ErrorCallback error_callback,
const unsigned short &  host_port,
const unsigned int &  endpoint_ip,
const unsigned short &  endpoint_port 
)
inline

Opens an UDP connection.

Note
The client does not start listing for new messages until explicitly triggered via startAsyncReceiving().
Parameters
msg_callbackCallback called whenever new messages are received.
error_callbackHandler called whenever something wents wrong while receiving data.
host_portPort from which data are sent and received.
endpoint_ipIP address of the endpoint from which data are received and sent too.
endpoint_portPort on which the other endpoint is sending and receiving data.

Definition at line 175 of file udp_client.h.

◆ ~UdpClientImpl()

psen_scan_v2_standalone::communication_layer::UdpClientImpl::~UdpClientImpl ( )
inline

Closes the UDP connection and stops all pending asynchronous operation.

Definition at line 247 of file udp_client.h.

Member Function Documentation

◆ asyncReceive()

void psen_scan_v2_standalone::communication_layer::UdpClientImpl::asyncReceive ( const ReceiveMode modi)
inlineprivate

Definition at line 300 of file udp_client.h.

◆ close()

void psen_scan_v2_standalone::communication_layer::UdpClientImpl::close ( )
inline

Closes the UDP connection and stops all pending asynchronous operation.

Definition at line 217 of file udp_client.h.

◆ hostIp()

boost::asio::ip::address_v4 psen_scan_v2_standalone::communication_layer::UdpClientImpl::hostIp ( )
inline

Returns local ip address of current socket connection.

Definition at line 242 of file udp_client.h.

◆ sendCompleteHandler()

void psen_scan_v2_standalone::communication_layer::UdpClientImpl::sendCompleteHandler ( const boost::system::error_code &  error,
std::size_t  bytes_transferred 
)
inlineprivate

Definition at line 262 of file udp_client.h.

◆ startAsyncReceiving()

void psen_scan_v2_standalone::communication_layer::UdpClientImpl::startAsyncReceiving ( const ReceiveMode modi = ReceiveMode::continuous)
inline

Starts an asynchronous process listing to (a) new message(s) from the other endpoint. If the function continuously listens to new messages or only listens for one message is specified by the receive modi specified.

  • If a new message is received, the message callback is called.
  • If an error occurs while receiving data, the error callback is called.
Parameters
modiSpecifies if the function continuously listens to new messages or or not.

Definition at line 286 of file udp_client.h.

◆ stop()

void psen_scan_v2_standalone::communication_layer::UdpClientImpl::stop ( )
inline

Stops the underlying io_service so that no messages are received anymore.

Note: In contrary to close() this is non-blocking but note that after calling stop() calls to the msg_callback are still possible due to pending messages.

Definition at line 212 of file udp_client.h.

◆ write()

void psen_scan_v2_standalone::communication_layer::UdpClientImpl::write ( const data_conversion_layer::RawData data)
inline

Asynchronously sends the specified data to the other endpoint.

Parameters
dataData which have to be send to the other endpoint.

Definition at line 275 of file udp_client.h.

Member Data Documentation

◆ endpoint_

boost::asio::ip::udp::endpoint psen_scan_v2_standalone::communication_layer::UdpClientImpl::endpoint_
private

Definition at line 172 of file udp_client.h.

◆ error_callback_

ErrorCallback psen_scan_v2_standalone::communication_layer::UdpClientImpl::error_callback_
private

Definition at line 169 of file udp_client.h.

◆ io_service_

boost::asio::io_service psen_scan_v2_standalone::communication_layer::UdpClientImpl::io_service_
private

Definition at line 161 of file udp_client.h.

◆ io_service_thread_

std::thread psen_scan_v2_standalone::communication_layer::UdpClientImpl::io_service_thread_
private

Definition at line 164 of file udp_client.h.

◆ message_callback_

NewMessageCallback psen_scan_v2_standalone::communication_layer::UdpClientImpl::message_callback_
private

Definition at line 168 of file udp_client.h.

◆ received_data_

data_conversion_layer::RawDataPtr psen_scan_v2_standalone::communication_layer::UdpClientImpl::received_data_
private

Definition at line 166 of file udp_client.h.

◆ socket_

boost::asio::ip::udp::socket psen_scan_v2_standalone::communication_layer::UdpClientImpl::socket_
private

Definition at line 171 of file udp_client.h.

◆ work_

boost::asio::io_service::work psen_scan_v2_standalone::communication_layer::UdpClientImpl::work_ { io_service_ }
private

Definition at line 163 of file udp_client.h.


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


psen_scan_v2
Author(s): Pilz GmbH + Co. KG
autogenerated on Sat Nov 5 2022 02:13:36