2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Class describing a basic acknowledgement frame
|
2014-04-29 21:51:33 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @copyright 2014 Copernica BV
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set up namespace
|
|
|
|
|
*/
|
|
|
|
|
namespace AMQP {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class defintion
|
|
|
|
|
*/
|
|
|
|
|
class BasicAckFrame : public BasicFrame {
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* server-assigned and channel specific delivery tag
|
|
|
|
|
* @var uint64_t
|
|
|
|
|
*/
|
|
|
|
|
uint64_t _deliveryTag;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* if set, tag is treated as "up to and including", so client can acknowledge multiple messages with a single method
|
|
|
|
|
* if not set, refers to single message
|
|
|
|
|
* @var BooleanSet
|
|
|
|
|
*/
|
|
|
|
|
BooleanSet _multiple;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* Encode a frame on a string buffer
|
|
|
|
|
*
|
|
|
|
|
* @param buffer buffer to write frame to
|
|
|
|
|
* @return pointer to object to allow for chaining
|
|
|
|
|
*/
|
|
|
|
|
virtual void fill(OutBuffer& buffer) const override
|
|
|
|
|
{
|
|
|
|
|
// call base
|
|
|
|
|
BasicFrame::fill(buffer);
|
2014-04-29 21:51:33 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
// add the delivery tag
|
|
|
|
|
buffer.add(_deliveryTag);
|
2014-04-29 21:51:33 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
// add the booleans
|
|
|
|
|
_multiple.fill(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Construct a basic acknowledgement frame
|
|
|
|
|
*
|
|
|
|
|
* @param channel Channel identifier
|
|
|
|
|
* @param deliveryTag server-assigned and channel specific delivery tag
|
|
|
|
|
* @param multiple acknowledge mutiple messages
|
|
|
|
|
*/
|
2014-04-29 21:51:33 +08:00
|
|
|
BasicAckFrame(uint16_t channel, uint64_t deliveryTag, bool multiple = false) :
|
2014-01-04 19:45:04 +08:00
|
|
|
BasicFrame(channel, 9),
|
|
|
|
|
_deliveryTag(deliveryTag),
|
|
|
|
|
_multiple(multiple) {}
|
2014-04-29 21:51:33 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Construct based on received frame
|
|
|
|
|
* @param frame
|
|
|
|
|
*/
|
2014-04-29 21:51:33 +08:00
|
|
|
BasicAckFrame(ReceivedFrame &frame) :
|
2014-01-04 19:45:04 +08:00
|
|
|
BasicFrame(frame),
|
|
|
|
|
_deliveryTag(frame.nextUint64()),
|
|
|
|
|
_multiple(frame) {}
|
2014-04-29 21:51:33 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Destructor
|
|
|
|
|
*/
|
|
|
|
|
virtual ~BasicAckFrame() {}
|
|
|
|
|
|
2014-04-29 21:51:33 +08:00
|
|
|
/**
|
|
|
|
|
* Is this a synchronous frame?
|
|
|
|
|
*
|
|
|
|
|
* After a synchronous frame no more frames may be
|
|
|
|
|
* sent until the accompanying -ok frame arrives
|
|
|
|
|
*/
|
|
|
|
|
virtual bool synchronous() const override
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Return the method ID
|
|
|
|
|
* @return uint16_t
|
|
|
|
|
*/
|
|
|
|
|
virtual uint16_t methodID() const override
|
|
|
|
|
{
|
|
|
|
|
return 80;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the server-assigned and channel specific delivery tag
|
|
|
|
|
* @return uint64_t
|
|
|
|
|
*/
|
|
|
|
|
uint64_t deliveryTag() const
|
|
|
|
|
{
|
|
|
|
|
return _deliveryTag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-04-30 20:18:18 +08:00
|
|
|
* Return whether to acknowledge multiple messages
|
2014-01-04 19:45:04 +08:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2015-04-30 20:18:18 +08:00
|
|
|
bool multiple() const
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
|
|
|
|
return _multiple.get(0);
|
|
|
|
|
}
|
2017-06-09 04:57:29 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process the frame
|
|
|
|
|
* @param connection The connection over which it was received
|
|
|
|
|
* @return bool Was it succesfully processed?
|
|
|
|
|
*/
|
|
|
|
|
virtual bool process(ConnectionImpl *connection) override
|
|
|
|
|
{
|
|
|
|
|
// we need the appropriate channel
|
|
|
|
|
auto channel = connection->channel(this->channel());
|
|
|
|
|
|
|
|
|
|
// channel does not exist
|
|
|
|
|
if(!channel) return false;
|
|
|
|
|
|
|
|
|
|
// start message counter
|
|
|
|
|
channel->reportAck(deliveryTag(), multiple());
|
|
|
|
|
|
|
|
|
|
// done
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-01-04 19:45:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* end namespace
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|