TraveSim Adapters
0.1
Protobuf adapters for TraveSim project
|
Receiver class using UDP. More...
#include "receiver.hpp"
Public Member Functions | |
Receiver (const std::string receiver_address, const short receiver_port) | |
Construct a new Receiver object. More... | |
virtual | ~Receiver () |
Destroy the Receiver object. More... | |
size_t | receive (char *buffer, const size_t buffer_size) |
Receive data using UDP. More... | |
size_t | receive_latest (char *buffer, const size_t buffer_size) |
Receive the latest data using UDP. More... | |
void | force_specific_source (bool specific_source) |
Set wheter to enable any source or source specific. True for specific source, false for any source, default is false. More... | |
void | set_receiver_endpoint (const std::string receiver_address, const short receiver_port) |
Set the receiver endpoint. More... | |
void | reset (void) |
Reset the receiver. More... | |
Protected Member Functions | |
virtual void | open_socket ()=0 |
Open the socket with the desired options. More... | |
virtual void | close_socket () |
Close the socket. More... | |
Protected Attributes | |
boost::asio::ip::udp::socket * | socket |
boost::asio::ip::udp::endpoint | receiver_endpoint |
Private Member Functions | |
void | validate_sender_endpoint (boost::asio::ip::udp::endpoint current_sender_endpoint) |
Validate whether the current sender endpoint matches the first sender endpoint when using specific source. More... | |
Private Attributes | |
boost::asio::io_context | io_context |
boost::asio::ip::udp::endpoint | sender_endpoint |
bool | specific_source |
Receiver class using UDP.
Definition at line 25 of file receiver.hpp.
travesim::udp::Receiver::Receiver | ( | const std::string | receiver_address, |
const short | receiver_port | ||
) |
Construct a new Receiver object.
receiver_address | Address where to send data |
receiver_port | Port where to send data |
Definition at line 32 of file receiver.cpp.
References force_specific_source(), io_context, set_receiver_endpoint(), and socket.
|
virtual |
Destroy the Receiver object.
Definition at line 40 of file receiver.cpp.
References socket.
|
protectedvirtual |
Close the socket.
Reimplemented in travesim::udp::MulticastReceiver.
Definition at line 128 of file receiver.cpp.
References socket.
void travesim::udp::Receiver::force_specific_source | ( | bool | specific_source | ) |
Set wheter to enable any source or source specific. True for specific source, false for any source, default is false.
specific_source | Whether to enable source specific or not. |
Definition at line 108 of file receiver.cpp.
References specific_source.
|
protectedpure virtual |
Open the socket with the desired options.
Implemented in travesim::udp::MulticastReceiver, and travesim::udp::UnicastReceiver.
size_t travesim::udp::Receiver::receive | ( | char * | buffer, |
const size_t | buffer_size | ||
) |
Receive data using UDP.
buffer | Buffet to store data |
buffer_size | Size of the buffer where to store data |
Definition at line 44 of file receiver.cpp.
References NO_FLAGS, socket, and validate_sender_endpoint().
size_t travesim::udp::Receiver::receive_latest | ( | char * | buffer, |
const size_t | buffer_size | ||
) |
Receive the latest data using UDP.
buffer | Buffet to store data |
buffer_size | Size of the buffer where to store data |
Definition at line 75 of file receiver.cpp.
References NO_FLAGS, socket, and validate_sender_endpoint().
void travesim::udp::Receiver::reset | ( | void | ) |
Reset the receiver.
Definition at line 117 of file receiver.cpp.
References close_socket(), INVALID_ENDPOINT, open_socket(), and sender_endpoint.
void travesim::udp::Receiver::set_receiver_endpoint | ( | const std::string | receiver_address, |
const short | receiver_port | ||
) |
Set the receiver endpoint.
receiver_address | Address where to send data |
receiver_port | Port where to send data |
Definition at line 112 of file receiver.cpp.
References receiver_endpoint.
|
inlineprivate |
Validate whether the current sender endpoint matches the first sender endpoint when using specific source.
current_sender_endpoint | The endpoint from where the last data came from |
std::runtime_error | When messages from multiple senders are received and any-source is not enabled. |
Definition at line 138 of file receiver.cpp.
References INVALID_ENDPOINT, sender_endpoint, and specific_source.
|
private |
boost/asio I/O execution context
Definition at line 119 of file receiver.hpp.
|
protected |
Receiver address and port pair
Definition at line 89 of file receiver.hpp.
|
private |
Sender address and port pair
Definition at line 121 of file receiver.hpp.
|
protected |
Network socket
Definition at line 88 of file receiver.hpp.
|
private |
True for specific source, false for any source, default is false
Definition at line 123 of file receiver.hpp.