TSDuck v3.45-4725
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::ReactiveTLVConnection Class Reference

TLV-messages connection for use in a Reactor environment. More...

#include <tsReactiveTLVConnection.h>

Inheritance diagram for ts::ReactiveTLVConnection:
Collaboration diagram for ts::ReactiveTLVConnection:

Public Member Functions

 ReactiveTLVConnection (tlv::Logger &logger, const tlv::Protocol &protocol, ReactiveTCPConnection &socket, bool auto_error_response=true, size_t max_invalid_msg=0, Object *owner=nullptr)
 Constructor.
 
virtual ~ReactiveTLVConnection () override
 Destructor.
 
bool getAutoErrorResponse () const
 Get invalid incoming messages processing.
 
size_t getMaxInvalidMessages () const
 Get invalid message threshold.
 
bool isOwned ()
 Check if the object is owned.
 
template<class OBJECT >
requires std::derived_from<OBJECT, ts::Object>
bool isOwned ()
 Check if the object is owned by an object of a given type.
 
Objectowner ()
 Get the address of the optional "owner" object which was specified in the constructor.
 
template<class OBJECT >
requires std::derived_from<OBJECT, ts::Object>
OBJECT * owner ()
 Get the address of the "owner" object which was specified in the constructor.
 
void setAutoErrorResponse (bool on)
 Set invalid incoming messages processing.
 
void setMaxInvalidMessages (size_t n)
 Set invalid message threshold.
 
ReactiveTCPConnectionsocket ()
 Get a reference to the associated socket.
 
bool startReceive (ReactiveTLVConnectionHandlerInterface *handler, size_t buffer_size=ReactiveTCPConnection::DEFAULT_RECEIVE_BUFFER_SIZE)
 Start the operation of receiving messages from the socket.
 
bool startSendMessage (const tlv::Message &msg)
 Start the operation of sending a message over the TCP connection.
 

Detailed Description

TLV-messages connection for use in a Reactor environment.

The class ReactiveTLVConnection is a wrapper around ReactiveTCPConnection to handle reactive I/O.

Constructor & Destructor Documentation

◆ ReactiveTLVConnection()

ts::ReactiveTLVConnection::ReactiveTLVConnection ( tlv::Logger logger,
const tlv::Protocol protocol,
ReactiveTCPConnection socket,
bool  auto_error_response = true,
size_t  max_invalid_msg = 0,
Object owner = nullptr 
)

Constructor.

Parameters
[in,out]loggerWhere to report errors and messages. An internal reference is kept. The logger object must remain valid as long as this object exists.
[in]protocolThe incoming messages are interpreted according to this protocol. The reference is kept in this object.
[in,out]socketAssociated reactive TCP socket. The socket object must remain valid as long as this object is valid.
[in]auto_error_responseWhen an invalid message is received, the corresponding error message is automatically sent back to the sender when auto_error_response is true.
[in]max_invalid_msgWhen non-zero, the connection is automatically disconnected when the number of consecutive invalid messages has reached this value.
[in]ownerOptional address of an "owner" object, typically an instance of class containing this object.

Member Function Documentation

◆ socket()

ReactiveTCPConnection & ts::ReactiveTLVConnection::socket ( )
inline

Get a reference to the associated socket.

Returns
A reference to the associated socket.

◆ startSendMessage()

bool ts::ReactiveTLVConnection::startSendMessage ( const tlv::Message msg)

Start the operation of sending a message over the TCP connection.

There is no completion handler because the serialized data to send is kept in a dedicated buffer.

Parameters
[in]msgThe message to send.
Returns
True on success, false on error. Success means that the I/O was successfully started.

◆ startReceive()

bool ts::ReactiveTLVConnection::startReceive ( ReactiveTLVConnectionHandlerInterface handler,
size_t  buffer_size = ReactiveTCPConnection::DEFAULT_RECEIVE_BUFFER_SIZE 
)

Start the operation of receiving messages from the socket.

Parameters
[in]handlerHandler class to call each time a message is received. Cannot be null. If a previous receive handler was registered, it is replaced.
[in]buffer_sizeSize of input buffers to receive data. This is a tuning parameter only. It is automatically increased when necessary.
Returns
True on success, false on error. Success means that the I/O was successfully started. The final status of the I/O will be transmitted in the handler.

◆ getAutoErrorResponse()

bool ts::ReactiveTLVConnection::getAutoErrorResponse ( ) const
inline

Get invalid incoming messages processing.

Returns
True if, when an invalid message is received, the corresponding error message is automatically sent back to the sender.

◆ setAutoErrorResponse()

void ts::ReactiveTLVConnection::setAutoErrorResponse ( bool  on)
inline

Set invalid incoming messages processing.

Parameters
[in]onWhen an invalid message is received, the corresponding error message is automatically sent back to the sender when on is true.

◆ getMaxInvalidMessages()

size_t ts::ReactiveTLVConnection::getMaxInvalidMessages ( ) const
inline

Get invalid message threshold.

Returns
When non-zero, the connection is automatically disconnected when the number of consecutive invalid messages has reached this value.

◆ setMaxInvalidMessages()

void ts::ReactiveTLVConnection::setMaxInvalidMessages ( size_t  n)
inline

Set invalid message threshold.

Parameters
[in]nWhen non-zero, the connection is automatically disconnected when the number of consecutive invalid messages has reached this value.

◆ owner() [1/2]

Object * ts::OwnedObject::owner ( )
inlineinherited

Get the address of the optional "owner" object which was specified in the constructor.

Returns
Address of the "owner" object or a null pointer if there was none.

◆ owner() [2/2]

template<class OBJECT >
requires std::derived_from<OBJECT, ts::Object>
OBJECT * ts::OwnedObject::owner ( )
inherited

Get the address of the "owner" object which was specified in the constructor.

This template version requires that the owner objet is set and of type OBJECT, or some subclass of it. If there is no owner object or if it is not compatible with the template class OBJECT, this is a fatal error and the application is terminated.

Template Parameters
OBJECTA subclass of Object
Returns
Address of the "owner" object or a null pointer if there was none.

◆ isOwned() [1/2]

bool ts::OwnedObject::isOwned ( )
inlineinherited

Check if the object is owned.

Returns
True if this object has an owner, false otherwise.

◆ isOwned() [2/2]

template<class OBJECT >
requires std::derived_from<OBJECT, ts::Object>
bool ts::OwnedObject::isOwned ( )
inlineinherited

Check if the object is owned by an object of a given type.

Template Parameters
OBJECTA subclass of Object
Returns
True if this object has an owner by an object of type OBJECT, false otherwise.

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