From a37c354beab3274e132e18f81155b2fcab5fc488 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Thu, 23 Feb 2023 11:06:15 +0100 Subject: [PATCH] {auto} when wrapping a tagger around a channel that already has an error-callback installed, we should preserve the old callback --- include/amqpcpp/channelimpl.h | 8 ++++++++ src/tagger.cpp | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/amqpcpp/channelimpl.h b/include/amqpcpp/channelimpl.h index ef42922..9371aa3 100644 --- a/include/amqpcpp/channelimpl.h +++ b/include/amqpcpp/channelimpl.h @@ -207,6 +207,14 @@ public: // connection is gone _connection = nullptr; } + + /** + * Expose the currently installed callbacks + * @return ErrorCallback + */ + const ErrorCallback &onError() const { return _errorCallback; } + const SuccessCallback &onReady() const { return _readyCallback; } + /** * Callback that is called when the channel was succesfully created. diff --git a/src/tagger.cpp b/src/tagger.cpp index c96a503..d85da09 100644 --- a/src/tagger.cpp +++ b/src/tagger.cpp @@ -4,7 +4,7 @@ * Implementation for Tagger class. * * @author Michael van der Werve - * @copyright 2020 Copernica BV + * @copyright 2020 - 2023 Copernica BV */ /** @@ -34,6 +34,9 @@ Tagger::Tagger(Channel &channel) : _implementation(channel._implementation) // we might have failed, in which case we throw if (!deferred) throw std::runtime_error("could not enable publisher confirms"); + // remember the original callback + _errorCallback = _implementation->onError(); + // we wrap a handling error callback that calls our member function _implementation->onError([this](const char *message) { reportError(message); }); }