added onAttached() and onDetached() to the TcpHandler interface

This commit is contained in:
Emiel Bruijntjes 2018-10-28 10:22:01 +01:00
parent c52e8ff0b2
commit 8546f52cd0
4 changed files with 74 additions and 0 deletions

View File

@ -43,6 +43,18 @@ private:
* @var Connection
*/
Connection _connection;
/**
* Method that is called after the connection was constructed
* @param connection The connection that was attached to the handler
*/
virtual void onAttached(Connection *connection) override;
/**
* Method that is called when the connection is destructed
* @param connection The connection that was detached from the handler
*/
virtual void onDetached(Connection *connection) override;
/**
* Method that is called when the heartbeat frequency is negotiated.

View File

@ -40,6 +40,30 @@ public:
*/
virtual ~TcpHandler() = default;
/**
* Method that is called immediately after a connection has been constructed.
* @param connection The connection object that was just constructed
*
* @see ConnectionHandler::onAttached
*/
virtual void onAttached(TcpConnection *connection)
{
// make sure compilers dont complain about unused parameters
(void) connection;
}
/**
* Method that is called right before a connection object is destructed.
* @param connection The connection that is being destructed
*
* @see ConnectionHandler::onDetached
*/
virtual void onDetached(TcpConnection *connection)
{
// make sure compilers dont complain about unused parameters
(void) connection;
}
/**
* Method that is called after a TCP connection has been set up and the initial
* TLS handshake is finished too, but right before the AMQP login handshake is

View File

@ -116,6 +116,26 @@ void TcpConnection::flush()
}
}
/**
* Method that is called after the connection was constructed
* @param connection The connection that was attached to the handler
*/
void TcpConnection::onAttached(Connection *connection)
{
// pass on to the state
_state->reportAttached();
}
/**
* Method that is called when the connection is destructed
* @param connection The connection that was detached from the handler
*/
void TcpConnection::onDetached(Connection *connection)
{
// pass on to the state
_state->reportDetached();
}
/**
* Method that is called when the heartbeat frequency is negotiated.
* @param connection The connection that suggested a heartbeat interval

View File

@ -116,6 +116,24 @@ public:
*/
virtual TcpState *flush(const Monitor &monitor) { return this; }
/**
* Report to the handler that the connection was constructed
*/
virtual void reportAttached()
{
// pass to the handler
_handler->onAttached(_connection);
}
/**
* Report to the handler that the connection was destructed
*/
virtual void reportDetached()
{
// pass to the handler
_handler->onDetached(_connection);
}
/**
* Report to the handler that heartbeat negotiation is going on
* @param heartbeat suggested heartbeat