diff --git a/include/channelimpl.h b/include/channelimpl.h index 6326693..6c02163 100644 --- a/include/channelimpl.h +++ b/include/channelimpl.h @@ -213,26 +213,7 @@ public: * * @param callback the callback to execute */ - void onError(const ErrorCallback &callback) - { - // store callback - _errorCallback = callback; - - // if the channel is connected, all is ok - if (connected()) return; - - // is the channel closing down? - if (_state == state_closing) return callback("Channel is closing down"); - - // the channel is closed, but what is the connection doing? - if (_connection == nullptr) return callback("Channel is not linked to a connection"); - - // if the connection is valid, this is a pure channel error - if (_connection->connected()) return callback("Channel is in an error state, but the connection is valid"); - - // direct call if channel is already in error state - callback("Channel is in error state because no AMQP connection is available"); - } + void onError(const ErrorCallback &callback); /** * Pause deliveries on a channel diff --git a/src/channelimpl.cpp b/src/channelimpl.cpp index 6a6904b..2b771e6 100644 --- a/src/channelimpl.cpp +++ b/src/channelimpl.cpp @@ -60,6 +60,35 @@ ChannelImpl::~ChannelImpl() if (_connection) _connection->remove(this); } +/** + * Callback that is called when an error occurs. + * + * Only one error callback can be registered. Calling this function + * multiple times will remove the old callback. + * + * @param callback the callback to execute + */ +void ChannelImpl::onError(const ErrorCallback &callback) +{ + // store callback + _errorCallback = callback; + + // if the channel is connected, all is ok + if (connected()) return; + + // is the channel closing down? + if (_state == state_closing) return callback("Channel is closing down"); + + // the channel is closed, but what is the connection doing? + if (_connection == nullptr) return callback("Channel is not linked to a connection"); + + // if the connection is valid, this is a pure channel error + if (_connection->connected()) return callback("Channel is in an error state, but the connection is valid"); + + // direct call if channel is already in error state + callback("Channel is in error state because no AMQP connection is available"); +} + /** * Initialize the object with an connection * @param connection