From ec31f5ad1192a3ba01e028ed27cdd21cb4cdbbf6 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sun, 25 Nov 2018 12:46:12 +0100 Subject: [PATCH] added Channel implementation file (fixes #267) --- src/channel.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/channel.cpp diff --git a/src/channel.cpp b/src/channel.cpp new file mode 100644 index 0000000..e19cb2f --- /dev/null +++ b/src/channel.cpp @@ -0,0 +1,49 @@ +/** + * Channel.cpp + * + * Implementation file for the Channel class + * + * @author Emiel Bruijntjes + * @copyright 2018 Copernica BV + */ + +/** + * Dependencies + */ +#include "includes.h" + +/** + * Begin of namespace + */ +namespace AMQP { + +/** + * Construct a channel object + * + * The passed in connection pointer must remain valid for the + * lifetime of the channel. Watch out: this method throws an error + * if the channel could not be constructed (for example because the + * max number of AMQP channels has been reached) + * + * @param connection + * @throws std::runtime_error + */ +Channel::Channel(Connection *connection) : _implementation(new ChannelImpl()) +{ + // check if the connection is indeed usable + if (!connection->usable()) throw std::runtime_error("failed to open channel: connection is not active"); + + // attach to the connection + if (_implementation->attach(connection)) return; + + // this failed, max number of channels has been reached + throw std::runtime_error("failed to open channel: max number of channels has been reached"); +} + +/** + * End of namespace + */ +} + + + \ No newline at end of file