Public Member Functions | Protected Member Functions | Private Attributes | List of all members
urcl::comm::URStream< T > Class Template Reference

The stream is an abstraction of the TCPSocket that offers reading a full UR data package out of the socket. This means, it has to have some knowledge about the package structure to peek at the field defining the package length. This is why it is templated with the package header type. More...

#include <stream.h>

Inheritance diagram for urcl::comm::URStream< T >:
Inheritance graph
[legend]

Public Member Functions

bool closed ()
 Returns whether the underlying socket is currently closed. More...
 
bool connect ()
 Connects to the configured socket. More...
 
void disconnect ()
 Disconnects from the configured socket. More...
 
bool read (uint8_t *buf, const size_t buf_len, size_t &read)
 Reads a full UR package out of a socket. For this, it looks into the package and reads the byte length from the socket directly. It returns as soon as all bytes for the package are read from the socket. More...
 
 URStream (const std::string &host, int port)
 Creates a new URStream object. Note, that this does not immediately open the socket, that has to be done separately by calling the connect() function. More...
 
bool write (const uint8_t *buf, const size_t buf_len, size_t &written)
 Writes directly to the underlying socket (with a mutex guard) More...
 
- Public Member Functions inherited from urcl::comm::TCPSocket
void close ()
 Closes the connection to the socket. More...
 
std::string getIP () const
 Determines the local IP address of the currently configured socket. More...
 
int getSocketFD ()
 Getter for the file descriptor of the socket. More...
 
SocketState getState ()
 Getter for the state of the socket. More...
 
bool read (char *character)
 Reads one byte from the socket. More...
 
bool read (uint8_t *buf, const size_t buf_len, size_t &read)
 Reads data from the socket. More...
 
void setReceiveTimeout (const timeval &timeout)
 Setup Receive timeout used for this socket. More...
 
 TCPSocket ()
 Creates a TCPSocket object. More...
 
bool write (const uint8_t *buf, const size_t buf_len, size_t &written)
 Writes to the socket. More...
 
virtual ~TCPSocket ()
 

Protected Member Functions

virtual bool open (int socket_fd, struct sockaddr *address, size_t address_len)
 
- Protected Member Functions inherited from urcl::comm::TCPSocket
virtual void setOptions (int socket_fd)
 
bool setup (std::string &host, int port)
 

Private Attributes

std::string host_
 
int port_
 
std::mutex read_mutex_
 
std::mutex write_mutex_
 

Additional Inherited Members

- Protected Attributes inherited from urcl::comm::TCPSocket
std::unique_ptr< timeval > recv_timeout_
 

Detailed Description

template<typename T>
class urcl::comm::URStream< T >

The stream is an abstraction of the TCPSocket that offers reading a full UR data package out of the socket. This means, it has to have some knowledge about the package structure to peek at the field defining the package length. This is why it is templated with the package header type.

Definition at line 42 of file stream.h.

Constructor & Destructor Documentation

template<typename T>
urcl::comm::URStream< T >::URStream ( const std::string &  host,
int  port 
)
inline

Creates a new URStream object. Note, that this does not immediately open the socket, that has to be done separately by calling the connect() function.

Parameters
hostIP address of the remote host
portPort on which the socket shall be connected

Definition at line 52 of file stream.h.

Member Function Documentation

template<typename T>
bool urcl::comm::URStream< T >::closed ( )
inline

Returns whether the underlying socket is currently closed.

Definition at line 78 of file stream.h.

template<typename T>
bool urcl::comm::URStream< T >::connect ( )
inline

Connects to the configured socket.

Returns
True on success, false if connection could not be established

Definition at line 61 of file stream.h.

template<typename T>
void urcl::comm::URStream< T >::disconnect ( )
inline

Disconnects from the configured socket.

Definition at line 69 of file stream.h.

template<typename T>
virtual bool urcl::comm::URStream< T >::open ( int  socket_fd,
struct sockaddr *  address,
size_t  address_len 
)
inlineprotectedvirtual

Reimplemented from urcl::comm::TCPSocket.

Definition at line 108 of file stream.h.

template<typename T >
bool urcl::comm::URStream< T >::read ( uint8_t *  buf,
const size_t  buf_len,
size_t &  read 
)

Reads a full UR package out of a socket. For this, it looks into the package and reads the byte length from the socket directly. It returns as soon as all bytes for the package are read from the socket.

Parameters
[out]bufThe byte buffer where the content shall be stored
[in]buf_lenNumber of bytes allocated for the buffer
[out]readNumber of bytes actually read from the socket
Returns
True on success, false on error, e.g. the buffer is smaller than the package size

Definition at line 127 of file stream.h.

template<typename T >
bool urcl::comm::URStream< T >::write ( const uint8_t *  buf,
const size_t  buf_len,
size_t &  written 
)

Writes directly to the underlying socket (with a mutex guard)

Parameters
[in]bufByte stream that should be sent
[in]buf_lenNumber of bytes in buffer
[out]writtenNumber of bytes actually written to the socket
Returns
False if sending went wrong

Definition at line 120 of file stream.h.

Member Data Documentation

template<typename T>
std::string urcl::comm::URStream< T >::host_
private

Definition at line 114 of file stream.h.

template<typename T>
int urcl::comm::URStream< T >::port_
private

Definition at line 115 of file stream.h.

template<typename T>
std::mutex urcl::comm::URStream< T >::read_mutex_
private

Definition at line 116 of file stream.h.

template<typename T>
std::mutex urcl::comm::URStream< T >::write_mutex_
private

Definition at line 116 of file stream.h.


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


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Sun May 9 2021 02:16:26