diff --git a/amqpcpp.h b/amqpcpp.h index b267dff..de21bf9 100644 --- a/amqpcpp.h +++ b/amqpcpp.h @@ -67,7 +67,9 @@ #include #include #include +#include #include #include #include - +#include +#include diff --git a/include/channel.h b/include/channel.h index dae6d52..1597f23 100644 --- a/include/channel.h +++ b/include/channel.h @@ -1,15 +1,24 @@ -#pragma once /** * Class describing a (mid-level) AMQP channel implementation * * @copyright 2014 Copernica BV */ +/** + * Include guard + */ +#pragma once + /** * Set up namespace */ namespace AMQP { +/** + * Forward declarations + */ +class TcpConnection; + /** * Class definition */ @@ -32,7 +41,17 @@ public: // attach the connection to the channel _implementation->attach(connection); } - + + /** + * Construct a channel around a wrapped-connection + * @param connection + */ + Channel(TcpConnection *connection) : _implementation(new ChannelImpl()) + { + // attach the connection to the channel + _implementation->attach(connection); + } + /** * Copy'ing of channel objects is not supported * @param channel diff --git a/include/channelimpl.h b/include/channelimpl.h index 6261827..e7444a0 100644 --- a/include/channelimpl.h +++ b/include/channelimpl.h @@ -18,6 +18,7 @@ namespace AMQP { * Forward declarations */ class ConsumedMessage; +class TcpConnection; /** * Class definition @@ -109,6 +110,12 @@ private: */ void attach(Connection *connection); + /** + * Attach the connection + * @param connection + */ + void attach(TcpConnection *connection); + /** * Push a deferred result * @param result The deferred result diff --git a/include/tcpconnection.h b/include/tcpconnection.h index bd063b5..3422407 100644 --- a/include/tcpconnection.h +++ b/include/tcpconnection.h @@ -26,17 +26,22 @@ class TcpState; /** * Class definition */ -class TcpConnection : public Connection, private ConnectionHandler +class TcpConnection : private ConnectionHandler { private: /** * The state of the TCP connection - this state objecs changes based on * the state of the connection (resolving, connected or closed) - * * @var TcpState */ TcpState *_state = nullptr; + /** + * The underlying AMQP connection + * @var Connection + */ + Connection _connection; + /** * Method that is called by the connection when data needs to be sent over the network @@ -65,6 +70,22 @@ private: */ virtual void onClosed(Connection *connection) override; + /** + * Parse a buffer that was received + * @param buffer + */ + uint64_t parse(const Buffer &buffer) + { + // pass to the AMQP connection + return _connection.parse(buffer); + } + + /** + * Classes that have access to private data + */ + friend class TcpConnected; + friend class ChannelImpl; + public: /** diff --git a/src/channelimpl.cpp b/src/channelimpl.cpp index e285385..1fdbd4d 100644 --- a/src/channelimpl.cpp +++ b/src/channelimpl.cpp @@ -90,6 +90,16 @@ void ChannelImpl::attach(Connection *connection) } } +/** + * Initialize the object with an connection + * @param connection + */ +void ChannelImpl::attach(TcpConnection *connection) +{ + // pass to the other attach() method + attach(&connection->_connection); +} + /** * Push a deferred result * @param result The deferred object to push diff --git a/src/tcpconnection.cpp b/src/tcpconnection.cpp index f90f0b6..8c92865 100644 --- a/src/tcpconnection.cpp +++ b/src/tcpconnection.cpp @@ -21,12 +21,12 @@ namespace AMQP { /** * Constructor * @param handler User implemented handler object - * @param address AMQP address object + * @param hostname The address to connect to */ -TcpConnection::TcpConnection(TcpHandler *handler, const Address &address) : - Connection(this, address.login(), address.vhost()), - _state(new TcpResolver(this, address.hostname(), address.port(), handler)) {} - +TcpConnection::TcpConnection(TcpHandler *handler, const Address &address) : + _state(new TcpResolver(this, address.hostname(), address.port(), handler)), + _connection(this, address.login(), address.vhost()) {} + /** * Destructor */