TSDuck v3.45-4766
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches

Exchanging TLV messages over a stream device. More...

#include <tsTLVStream.h>

Inheritance diagram for ts::TLVStream:
Collaboration diagram for ts::TLVStream:

Public Member Functions

 TLVStream (tlv::Logger &logger, const tlv::Protocol &protocol, StreamInterface &stream, bool auto_error_response=true, size_t max_invalid_msg=0)
 Constructor.
 
bool getAutoErrorResponse () const
 Get invalid incoming messages processing.
 
size_t getMaxInvalidMessages () const
 Get invalid message threshold.
 
bool receiveMessage (tlv::MessagePtr &msg, const AbortInterface *abort=nullptr)
 Receive a TLV message.
 
bool sendMessage (const tlv::Message &msg)
 Serialize and send a TLV message.
 
void setAutoErrorResponse (bool on)
 Set invalid incoming messages processing.
 
void setMaxInvalidMessages (size_t n)
 Set invalid message threshold.
 
StreamInterfacestream ()
 Get a reference to the associated stream device.
 

Protected Member Functions

virtual void handleSocketCloseComplete (Socket &sock, bool silent, bool success)
 Called after a socket is closed.
 
virtual void handleSocketCloseStart (Socket &sock, bool silent)
 Called when a socket is about to be closed.
 
virtual void handleSocketConnected (TCPConnection &sock) override
 Called when a TCP socket is successfully connected.
 
virtual void handleSocketDisconnected (TCPConnection &sock, bool silent)
 Called when a TCP socket is disconnected.
 
virtual void handleSocketOpenComplete (Socket &sock, bool success)
 Called after a socket is opened (or failed to open).
 
virtual void handleSocketOpenStart (Socket &sock)
 Called when a socket is about to be opened.
 

Detailed Description

Exchanging TLV messages over a stream device.

Constructor & Destructor Documentation

◆ TLVStream()

ts::TLVStream::TLVStream ( tlv::Logger logger,
const tlv::Protocol protocol,
StreamInterface stream,
bool  auto_error_response = true,
size_t  max_invalid_msg = 0 
)

Constructor.

Parameters
[in,out]loggerWhere to report errors and messages. 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]streamAssociated stream device. The device 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. This applies only when a stream object is a subclass of TCPConnection.

Member Function Documentation

◆ stream()

StreamInterface & ts::TLVStream::stream ( )
inline

Get a reference to the associated stream device.

Returns
A reference to the associated stream device.

◆ sendMessage()

bool ts::TLVStream::sendMessage ( const tlv::Message msg)

Serialize and send a TLV message.

Parameters
[in]msgThe message to send.
Returns
True on success, false on error.

◆ receiveMessage()

bool ts::TLVStream::receiveMessage ( tlv::MessagePtr msg,
const AbortInterface abort = nullptr 
)

Receive a TLV message.

Wait for the message, deserialize it and validate it. Process invalid messages and loop until a valid message is received.

Parameters
[out]msgA safe pointer to the received message.
[in]abortIf non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry).
Returns
True on success, false on error.

◆ getAutoErrorResponse()

bool ts::TLVStream::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::TLVStream::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::TLVStream::getMaxInvalidMessages ( ) const
inline

Get invalid message threshold.

This applies only when a stream object is a subclass of TCPConnection.

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

◆ setMaxInvalidMessages()

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

Set invalid message threshold.

This applies only when a stream object is a subclass of TCPConnection.

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

◆ handleSocketConnected()

virtual void ts::TLVStream::handleSocketConnected ( TCPConnection sock)
overrideprotectedvirtual

Called when a TCP socket is successfully connected.

Parameters
[in,out]sockSocket for which the handler is invoked.

Reimplemented from ts::SocketHandlerInterface.

◆ handleSocketOpenStart()

virtual void ts::SocketHandlerInterface::handleSocketOpenStart ( Socket sock)
virtualinherited

Called when a socket is about to be opened.

Never called when the application tries to open a socket which is already open.

Parameters
[in,out]sockSocket for which the handler is invoked.

◆ handleSocketOpenComplete()

virtual void ts::SocketHandlerInterface::handleSocketOpenComplete ( Socket sock,
bool  success 
)
virtualinherited

Called after a socket is opened (or failed to open).

Parameters
[in,out]sockSocket for which the handler is invoked.
[in]successTrue if the open was successful, false if the open failed. In case of error, the socket shall be considered as closed.

◆ handleSocketDisconnected()

virtual void ts::SocketHandlerInterface::handleSocketDisconnected ( TCPConnection sock,
bool  silent 
)
virtualinherited

Called when a TCP socket is disconnected.

Parameters
[in,out]sockSocket for which the handler is invoked.
[in]silentSame value as passed to disconnect() or close().

◆ handleSocketCloseStart()

virtual void ts::SocketHandlerInterface::handleSocketCloseStart ( Socket sock,
bool  silent 
)
virtualinherited

Called when a socket is about to be closed.

Never called when the application tries to close a socket which is not open.

Parameters
[in,out]sockSocket for which the handler is invoked.
[in]silentSame value as passed to close().

◆ handleSocketCloseComplete()

virtual void ts::SocketHandlerInterface::handleSocketCloseComplete ( Socket sock,
bool  silent,
bool  success 
)
virtualinherited

Called after a socket is closed.

Parameters
[in,out]sockSocket for which the handler is invoked.
[in]silentSame value as passed to close().
[in]successTrue if the close was successful, false if there was an error during the close. The socket shall be considered as closed on all cases, regardless of success.

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