2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Class describing a mid-level Amqp connection
|
|
|
|
|
*
|
|
|
|
|
* @copyright 2014 Copernica BV
|
|
|
|
|
*/
|
|
|
|
|
|
2015-11-01 17:48:13 +08:00
|
|
|
/**
|
|
|
|
|
* Include guard
|
|
|
|
|
*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Set up namespace
|
|
|
|
|
*/
|
|
|
|
|
namespace AMQP {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class definition
|
|
|
|
|
*/
|
|
|
|
|
class Connection
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* The actual implementation
|
|
|
|
|
* @var ConnectionImpl
|
|
|
|
|
*/
|
|
|
|
|
ConnectionImpl _implementation;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Construct an AMQP object based on full login data
|
|
|
|
|
*
|
|
|
|
|
* The first parameter is a handler object. This handler class is
|
|
|
|
|
* an interface that should be implemented by the caller.
|
|
|
|
|
*
|
|
|
|
|
* @param handler Connection handler
|
|
|
|
|
* @param login Login data
|
2014-01-04 21:11:06 +08:00
|
|
|
* @param vhost Vhost to use
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-01-04 21:11:06 +08:00
|
|
|
Connection(ConnectionHandler *handler, const Login &login, const std::string &vhost) : _implementation(this, handler, login, vhost) {}
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
2014-01-04 21:11:06 +08:00
|
|
|
* Construct with default vhost
|
|
|
|
|
* @param handler Connection handler
|
|
|
|
|
* @param login Login data
|
|
|
|
|
*/
|
|
|
|
|
Connection(ConnectionHandler *handler, const Login &login) : _implementation(this, handler, login, "/") {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct an AMQP object with default login data and default vhost
|
|
|
|
|
* @param handler Connection handler
|
|
|
|
|
*/
|
|
|
|
|
Connection(ConnectionHandler *handler, const std::string &vhost) : _implementation(this, handler, Login(), vhost) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct an AMQP object with default login data and default vhost
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param handler Connection handler
|
|
|
|
|
*/
|
2014-01-04 21:11:06 +08:00
|
|
|
Connection(ConnectionHandler *handler) : _implementation(this, handler, Login(), "/") {}
|
2014-01-04 19:45:04 +08:00
|
|
|
|
2014-08-29 19:17:17 +08:00
|
|
|
/**
|
|
|
|
|
* No copy'ing, we do not support having two identical connection objects
|
|
|
|
|
* @param connection
|
|
|
|
|
*/
|
|
|
|
|
Connection(const Connection &connection) = delete;
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Destructor
|
|
|
|
|
*/
|
|
|
|
|
virtual ~Connection() {}
|
2014-08-29 19:24:24 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* No assignments of other connections
|
|
|
|
|
* @param connection
|
|
|
|
|
* @return Connection
|
|
|
|
|
*/
|
|
|
|
|
Connection &operator=(const Connection &connection) = delete;
|
2014-08-19 20:54:30 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the login data
|
|
|
|
|
* @return Login
|
|
|
|
|
*/
|
|
|
|
|
const Login &login() const
|
|
|
|
|
{
|
|
|
|
|
return _implementation.login();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the vhost
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
const std::string &vhost() const
|
|
|
|
|
{
|
2014-08-19 21:00:20 +08:00
|
|
|
return _implementation.vhost();
|
2014-08-19 20:54:30 +08:00
|
|
|
}
|
2014-01-04 19:45:04 +08:00
|
|
|
|
2017-06-16 17:14:42 +08:00
|
|
|
/**
|
|
|
|
|
* Send a ping/heartbeat to the channel to keep it alive
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool ping()
|
|
|
|
|
{
|
|
|
|
|
return _implementation.ping();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
2014-01-04 21:11:06 +08:00
|
|
|
* Parse data that was recevied from RabbitMQ
|
2014-01-04 19:45:04 +08:00
|
|
|
*
|
2014-01-04 21:11:06 +08:00
|
|
|
* Every time that data comes in from RabbitMQ, you should call this method to parse
|
2014-01-04 19:45:04 +08:00
|
|
|
* the incoming data, and let it handle by the AMQP library. This method returns the number
|
|
|
|
|
* of bytes that were processed.
|
|
|
|
|
*
|
|
|
|
|
* If not all bytes could be processed because it only contained a partial frame, you should
|
|
|
|
|
* call this same method later on when more data is available. The AMQP library does not do
|
|
|
|
|
* any buffering, so it is up to the caller to ensure that the old data is also passed in that
|
|
|
|
|
* later call.
|
|
|
|
|
*
|
|
|
|
|
* @param buffer buffer to decode
|
|
|
|
|
* @param size size of the buffer to decode
|
|
|
|
|
* @return number of bytes that were processed
|
|
|
|
|
*/
|
2015-04-24 16:46:44 +08:00
|
|
|
uint64_t parse(const char *buffer, size_t size)
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
2014-08-13 19:01:27 +08:00
|
|
|
return _implementation.parse(ByteBuffer(buffer, size));
|
2014-01-04 19:45:04 +08:00
|
|
|
}
|
2014-08-01 17:55:07 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parse data that was recevied from RabbitMQ
|
|
|
|
|
*
|
|
|
|
|
* Every time that data comes in from RabbitMQ, you should call this method to parse
|
|
|
|
|
* the incoming data, and let it handle by the AMQP library. This method returns the number
|
|
|
|
|
* of bytes that were processed.
|
|
|
|
|
*
|
|
|
|
|
* If not all bytes could be processed because it only contained a partial frame, you should
|
|
|
|
|
* call this same method later on when more data is available. The AMQP library does not do
|
|
|
|
|
* any buffering, so it is up to the caller to ensure that the old data is also passed in that
|
|
|
|
|
* later call.
|
|
|
|
|
*
|
|
|
|
|
* This method accepts a buffer object. This is an interface that is defined by the AMQP
|
|
|
|
|
* library, that can be implemented by you to allow faster access to a buffer.
|
|
|
|
|
*
|
|
|
|
|
* @param buffer buffer to decode
|
|
|
|
|
* @return number of bytes that were processed
|
|
|
|
|
*/
|
2015-04-24 16:46:44 +08:00
|
|
|
uint64_t parse(const Buffer &buffer)
|
2014-08-13 19:01:27 +08:00
|
|
|
{
|
|
|
|
|
return _implementation.parse(buffer);
|
|
|
|
|
}
|
2016-06-15 16:57:46 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Max frame size
|
|
|
|
|
*
|
|
|
|
|
* If you allocate memory to receive data that you are going to pass to the parse() method,
|
|
|
|
|
* it might be useful to have an insight in the max frame size. The parse() method process
|
|
|
|
|
* one frame at a time, so you must at least be able to read in buffers of this specific
|
|
|
|
|
* frame size.
|
|
|
|
|
*
|
|
|
|
|
* @return size_t
|
|
|
|
|
*/
|
|
|
|
|
uint32_t maxFrame() const
|
|
|
|
|
{
|
|
|
|
|
return _implementation.maxFrame();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Expected number of bytes for the next parse() call.
|
|
|
|
|
*
|
|
|
|
|
* This method returns the number of bytes that the next call to parse() at least expects to
|
|
|
|
|
* do something meaningful with it.
|
|
|
|
|
*
|
|
|
|
|
* @return size_t
|
|
|
|
|
*/
|
|
|
|
|
uint32_t expected() const
|
|
|
|
|
{
|
|
|
|
|
return _implementation.expected();
|
|
|
|
|
}
|
2014-08-14 21:19:08 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Close the connection
|
|
|
|
|
* This will close all channels
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool close()
|
|
|
|
|
{
|
|
|
|
|
return _implementation.close();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-10 20:33:25 +08:00
|
|
|
/**
|
2015-11-01 01:26:52 +08:00
|
|
|
* Retrieve the number of channels that are active for this connection
|
2015-09-10 20:33:25 +08:00
|
|
|
* @return std::size_t
|
|
|
|
|
*/
|
|
|
|
|
std::size_t channels() const
|
|
|
|
|
{
|
|
|
|
|
return _implementation.channels();
|
|
|
|
|
}
|
2015-11-01 01:26:52 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is the connection busy waiting for an answer from the server? (in the
|
|
|
|
|
* meantime you can already send more instructions over it)
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2016-07-03 21:35:44 +08:00
|
|
|
bool waiting() const
|
2015-11-01 01:26:52 +08:00
|
|
|
{
|
|
|
|
|
return _implementation.waiting();
|
|
|
|
|
}
|
2015-09-10 20:33:25 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Some classes have access to private properties
|
|
|
|
|
*/
|
|
|
|
|
friend class ChannelImpl;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* End of namespace
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|