From 8546f52cd0d0ccba9b2a8bd433c1bcba0947f87a Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sun, 28 Oct 2018 10:22:01 +0100 Subject: [PATCH] added onAttached() and onDetached() to the TcpHandler interface --- include/amqpcpp/linux_tcp/tcpconnection.h | 12 ++++++++++++ include/amqpcpp/linux_tcp/tcphandler.h | 24 +++++++++++++++++++++++ src/linux_tcp/tcpconnection.cpp | 20 +++++++++++++++++++ src/linux_tcp/tcpstate.h | 18 +++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/include/amqpcpp/linux_tcp/tcpconnection.h b/include/amqpcpp/linux_tcp/tcpconnection.h index 15709a0..9a7a1df 100644 --- a/include/amqpcpp/linux_tcp/tcpconnection.h +++ b/include/amqpcpp/linux_tcp/tcpconnection.h @@ -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. diff --git a/include/amqpcpp/linux_tcp/tcphandler.h b/include/amqpcpp/linux_tcp/tcphandler.h index 9b0c87d..6190e1e 100644 --- a/include/amqpcpp/linux_tcp/tcphandler.h +++ b/include/amqpcpp/linux_tcp/tcphandler.h @@ -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 diff --git a/src/linux_tcp/tcpconnection.cpp b/src/linux_tcp/tcpconnection.cpp index 80e2430..e23d34e 100644 --- a/src/linux_tcp/tcpconnection.cpp +++ b/src/linux_tcp/tcpconnection.cpp @@ -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 diff --git a/src/linux_tcp/tcpstate.h b/src/linux_tcp/tcpstate.h index c7660c9..d83edc0 100644 --- a/src/linux_tcp/tcpstate.h +++ b/src/linux_tcp/tcpstate.h @@ -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