clean up QAmqpFrame paths
- opt for QDataStream overloads instead of read ctor and toStream methods - removed some unneccesary prefixes to Type and MethodClass enums - removed documentation from header (this is coming back!) - cleaned up some confusing code paths, removed unneccessary methods (like readHeader/writeHeader)
This commit is contained in:
parent
10ab1423c2
commit
7242a64a2f
|
|
@ -38,7 +38,7 @@ bool QAmqpChannelPrivate::_q_method(const QAmqpMethodFrame &frame)
|
|||
if (frame.channel() != channelNumber)
|
||||
return true;
|
||||
|
||||
if (frame.methodClass() == QAmqpFrame::fcBasic) {
|
||||
if (frame.methodClass() == QAmqpFrame::Basic) {
|
||||
if (frame.id() == bmQosOk) {
|
||||
qosOk(frame);
|
||||
return true;
|
||||
|
|
@ -47,7 +47,7 @@ bool QAmqpChannelPrivate::_q_method(const QAmqpMethodFrame &frame)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (frame.methodClass() != QAmqpFrame::fcChannel)
|
||||
if (frame.methodClass() != QAmqpFrame::Channel)
|
||||
return false;
|
||||
|
||||
qAmqpDebug("Channel#%d:", channelNumber);
|
||||
|
|
@ -97,7 +97,7 @@ void QAmqpChannelPrivate::open()
|
|||
return;
|
||||
|
||||
qAmqpDebug("Open channel #%d", channelNumber);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcChannel, miOpen);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Channel, miOpen);
|
||||
frame.setChannel(channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -114,7 +114,7 @@ void QAmqpChannelPrivate::flow(bool active)
|
|||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortShortUint, (active ? 1 : 0));
|
||||
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcChannel, miFlow);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Channel, miFlow);
|
||||
frame.setChannel(channelNumber);
|
||||
frame.setArguments(arguments);
|
||||
sendFrame(frame);
|
||||
|
|
@ -162,7 +162,7 @@ void QAmqpChannelPrivate::close(int code, const QString &text, int classId, int
|
|||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortUint, classId);
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortUint, methodId);
|
||||
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcChannel, miClose);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Channel, miClose);
|
||||
frame.setChannel(channelNumber);
|
||||
frame.setArguments(arguments);
|
||||
sendFrame(frame);
|
||||
|
|
@ -196,7 +196,7 @@ void QAmqpChannelPrivate::close(const QAmqpMethodFrame &frame)
|
|||
Q_EMIT q->closed();
|
||||
|
||||
// complete handshake
|
||||
QAmqpMethodFrame closeOkFrame(QAmqpFrame::fcChannel, miCloseOk);
|
||||
QAmqpMethodFrame closeOkFrame(QAmqpFrame::Channel, miCloseOk);
|
||||
closeOkFrame.setChannel(channelNumber);
|
||||
sendFrame(closeOkFrame);
|
||||
}
|
||||
|
|
@ -289,7 +289,7 @@ bool QAmqpChannel::isOpened() const
|
|||
void QAmqpChannel::qos(qint16 prefetchCount, qint32 prefetchSize)
|
||||
{
|
||||
Q_D(QAmqpChannel);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpChannelPrivate::bmQos);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Basic, QAmqpChannelPrivate::bmQos);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
|
|||
|
|
@ -207,16 +207,18 @@ void QAmqpClientPrivate::_q_readyRead()
|
|||
}
|
||||
|
||||
QDataStream streamB(&buffer, QIODevice::ReadOnly);
|
||||
switch(QAmqpFrame::Type(type)) {
|
||||
case QAmqpFrame::ftMethod:
|
||||
switch (static_cast<QAmqpFrame::FrameType>(type)) {
|
||||
case QAmqpFrame::Method:
|
||||
{
|
||||
QAmqpMethodFrame frame(streamB);
|
||||
QAmqpMethodFrame frame;
|
||||
streamB >> frame;
|
||||
|
||||
if (frame.size() > frameMax) {
|
||||
close(QAMQP::FrameError, "frame size too large");
|
||||
return;
|
||||
}
|
||||
|
||||
if (frame.methodClass() == QAmqpFrame::fcConnection) {
|
||||
if (frame.methodClass() == QAmqpFrame::Connection) {
|
||||
_q_method(frame);
|
||||
} else {
|
||||
foreach (QAmqpMethodFrameHandler *methodHandler, methodHandlersByChannel[frame.channel()])
|
||||
|
|
@ -224,9 +226,11 @@ void QAmqpClientPrivate::_q_readyRead()
|
|||
}
|
||||
}
|
||||
break;
|
||||
case QAmqpFrame::ftHeader:
|
||||
case QAmqpFrame::Header:
|
||||
{
|
||||
QAmqpContentFrame frame(streamB);
|
||||
QAmqpContentFrame frame;
|
||||
streamB >> frame;
|
||||
|
||||
if (frame.size() > frameMax) {
|
||||
close(QAMQP::FrameError, "frame size too large");
|
||||
return;
|
||||
|
|
@ -239,9 +243,11 @@ void QAmqpClientPrivate::_q_readyRead()
|
|||
methodHandler->_q_content(frame);
|
||||
}
|
||||
break;
|
||||
case QAmqpFrame::ftBody:
|
||||
case QAmqpFrame::Body:
|
||||
{
|
||||
QAmqpContentBodyFrame frame(streamB);
|
||||
QAmqpContentBodyFrame frame;
|
||||
streamB >> frame;
|
||||
|
||||
if (frame.size() > frameMax) {
|
||||
close(QAMQP::FrameError, "frame size too large");
|
||||
return;
|
||||
|
|
@ -254,9 +260,11 @@ void QAmqpClientPrivate::_q_readyRead()
|
|||
methodHandler->_q_body(frame);
|
||||
}
|
||||
break;
|
||||
case QAmqpFrame::ftHeartbeat:
|
||||
case QAmqpFrame::Heartbeat:
|
||||
{
|
||||
QAmqpMethodFrame frame(streamB);
|
||||
QAmqpMethodFrame frame;
|
||||
streamB >> frame;
|
||||
|
||||
if (frame.channel() != 0) {
|
||||
close(QAMQP::FrameError, "heartbeat must have channel id zero");
|
||||
return;
|
||||
|
|
@ -281,13 +289,13 @@ void QAmqpClientPrivate::sendFrame(const QAmqpFrame &frame)
|
|||
}
|
||||
|
||||
QDataStream stream(socket);
|
||||
frame.toStream(stream);
|
||||
stream << frame;
|
||||
}
|
||||
|
||||
bool QAmqpClientPrivate::_q_method(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_ASSERT(frame.methodClass() == QAmqpFrame::fcConnection);
|
||||
if (frame.methodClass() != QAmqpFrame::fcConnection)
|
||||
Q_ASSERT(frame.methodClass() == QAmqpFrame::Connection);
|
||||
if (frame.methodClass() != QAmqpFrame::Connection)
|
||||
return false;
|
||||
|
||||
qAmqpDebug() << "Connection:";
|
||||
|
|
@ -448,13 +456,13 @@ void QAmqpClientPrivate::close(const QAmqpMethodFrame &frame)
|
|||
Q_EMIT q->disconnected();
|
||||
|
||||
// complete handshake
|
||||
QAmqpMethodFrame closeOkFrame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miCloseOk);
|
||||
QAmqpMethodFrame closeOkFrame(QAmqpFrame::Connection, QAmqpClientPrivate::miCloseOk);
|
||||
sendFrame(closeOkFrame);
|
||||
}
|
||||
|
||||
void QAmqpClientPrivate::startOk()
|
||||
{
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miStartOk);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Connection, QAmqpClientPrivate::miStartOk);
|
||||
QByteArray arguments;
|
||||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
|
|
@ -479,7 +487,7 @@ void QAmqpClientPrivate::secureOk()
|
|||
|
||||
void QAmqpClientPrivate::tuneOk()
|
||||
{
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miTuneOk);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Connection, QAmqpClientPrivate::miTuneOk);
|
||||
QByteArray arguments;
|
||||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
|
|
@ -493,7 +501,7 @@ void QAmqpClientPrivate::tuneOk()
|
|||
|
||||
void QAmqpClientPrivate::open()
|
||||
{
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miOpen);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Connection, QAmqpClientPrivate::miOpen);
|
||||
QByteArray arguments;
|
||||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
|
|
@ -515,7 +523,7 @@ void QAmqpClientPrivate::close(int code, const QString &text, int classId, int m
|
|||
stream << qint16(classId);
|
||||
stream << qint16(methodId);
|
||||
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miClose);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Connection, QAmqpClientPrivate::miClose);
|
||||
frame.setArguments(arguments);
|
||||
sendFrame(frame);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ void QAmqpExchangePrivate::declare()
|
|||
return;
|
||||
}
|
||||
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcExchange, QAmqpExchangePrivate::miDeclare);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Exchange, QAmqpExchangePrivate::miDeclare);
|
||||
frame.setChannel(channelNumber);
|
||||
|
||||
QByteArray args;
|
||||
|
|
@ -61,7 +61,7 @@ bool QAmqpExchangePrivate::_q_method(const QAmqpMethodFrame &frame)
|
|||
if (QAmqpChannelPrivate::_q_method(frame))
|
||||
return true;
|
||||
|
||||
if (frame.methodClass() == QAmqpFrame::fcExchange) {
|
||||
if (frame.methodClass() == QAmqpFrame::Exchange) {
|
||||
switch (frame.id()) {
|
||||
case miDeclareOk:
|
||||
declareOk(frame);
|
||||
|
|
@ -76,7 +76,7 @@ bool QAmqpExchangePrivate::_q_method(const QAmqpMethodFrame &frame)
|
|||
}
|
||||
|
||||
return true;
|
||||
} else if (frame.methodClass() == QAmqpFrame::fcBasic) {
|
||||
} else if (frame.methodClass() == QAmqpFrame::Basic) {
|
||||
switch (frame.id()) {
|
||||
case bmReturn:
|
||||
basicReturn(frame);
|
||||
|
|
@ -198,7 +198,7 @@ void QAmqpExchange::declare(const QString &type, ExchangeOptions options, const
|
|||
void QAmqpExchange::remove(int options)
|
||||
{
|
||||
Q_D(QAmqpExchange);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcExchange, QAmqpExchangePrivate::miDelete);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Exchange, QAmqpExchangePrivate::miDelete);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -231,7 +231,7 @@ void QAmqpExchange::publish(const QByteArray &message, const QString &routingKey
|
|||
const QAmqpMessage::PropertyHash &properties, int publishOptions)
|
||||
{
|
||||
Q_D(QAmqpExchange);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpExchangePrivate::bmPublish);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Basic, QAmqpExchangePrivate::bmPublish);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -245,7 +245,7 @@ void QAmqpExchange::publish(const QByteArray &message, const QString &routingKey
|
|||
frame.setArguments(arguments);
|
||||
d->sendFrame(frame);
|
||||
|
||||
QAmqpContentFrame content(QAmqpFrame::fcBasic);
|
||||
QAmqpContentFrame content(QAmqpFrame::Basic);
|
||||
content.setChannel(d->channelNumber);
|
||||
content.setProperty(QAmqpMessage::ContentType, mimeType);
|
||||
content.setProperty(QAmqpMessage::ContentEncoding, "utf-8");
|
||||
|
|
|
|||
|
|
@ -6,21 +6,16 @@
|
|||
#include "qamqpglobal.h"
|
||||
#include "qamqpframe_p.h"
|
||||
|
||||
QAmqpFrame::QAmqpFrame(Type type)
|
||||
QAmqpFrame::QAmqpFrame(FrameType type)
|
||||
: size_(0),
|
||||
type_(type),
|
||||
channel_(0)
|
||||
{
|
||||
}
|
||||
|
||||
QAmqpFrame::QAmqpFrame(QDataStream &raw)
|
||||
QAmqpFrame::FrameType QAmqpFrame::type() const
|
||||
{
|
||||
readHeader(raw);
|
||||
}
|
||||
|
||||
QAmqpFrame::Type QAmqpFrame::type() const
|
||||
{
|
||||
return Type(type_);
|
||||
return static_cast<QAmqpFrame::FrameType>(type_);
|
||||
}
|
||||
|
||||
QAmqpFrame::~QAmqpFrame()
|
||||
|
|
@ -42,26 +37,6 @@ qint32 QAmqpFrame::size() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
void QAmqpFrame::writeHeader(QDataStream &stream) const
|
||||
{
|
||||
stream << type_;
|
||||
stream << channel_;
|
||||
stream << qint32(size());
|
||||
}
|
||||
|
||||
void QAmqpFrame::writeEnd(QDataStream &stream) const
|
||||
{
|
||||
stream << qint8(FRAME_END);
|
||||
stream.device()->waitForBytesWritten(1000);
|
||||
}
|
||||
|
||||
void QAmqpFrame::readHeader(QDataStream &stream)
|
||||
{
|
||||
stream >> type_;
|
||||
stream >> channel_;
|
||||
stream >> size_;
|
||||
}
|
||||
|
||||
/*
|
||||
void QAmqpFrame::readEnd(QDataStream &stream)
|
||||
{
|
||||
|
|
@ -72,26 +47,44 @@ void QAmqpFrame::readEnd(QDataStream &stream)
|
|||
}
|
||||
*/
|
||||
|
||||
void QAmqpFrame::toStream(QDataStream &stream) const
|
||||
QDataStream &operator<<(QDataStream &stream, const QAmqpFrame &frame)
|
||||
{
|
||||
writeHeader(stream);
|
||||
writePayload(stream);
|
||||
writeEnd(stream);
|
||||
// write header
|
||||
stream << frame.type_;
|
||||
stream << frame.channel_;
|
||||
stream << frame.size();
|
||||
|
||||
frame.writePayload(stream);
|
||||
|
||||
// write end
|
||||
stream << qint8(QAmqpFrame::FRAME_END);
|
||||
stream.device()->waitForBytesWritten(1000);
|
||||
return stream;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &stream, QAmqpFrame &frame)
|
||||
{
|
||||
stream >> frame.type_;
|
||||
stream >> frame.channel_;
|
||||
stream >> frame.size_;
|
||||
frame.readPayload(stream);
|
||||
return stream;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
QAmqpMethodFrame::QAmqpMethodFrame(MethodClass methodClass, qint16 id)
|
||||
: QAmqpFrame(QAmqpFrame::ftMethod),
|
||||
methodClass_(methodClass),
|
||||
id_(id)
|
||||
QAmqpMethodFrame::QAmqpMethodFrame()
|
||||
: QAmqpFrame(QAmqpFrame::Method),
|
||||
methodClass_(0),
|
||||
id_(0)
|
||||
{
|
||||
}
|
||||
|
||||
QAmqpMethodFrame::QAmqpMethodFrame(QDataStream &raw)
|
||||
: QAmqpFrame(raw)
|
||||
QAmqpMethodFrame::QAmqpMethodFrame(MethodClass methodClass, qint16 id)
|
||||
: QAmqpFrame(QAmqpFrame::Method),
|
||||
methodClass_(methodClass),
|
||||
id_(id)
|
||||
{
|
||||
readPayload(raw);
|
||||
}
|
||||
|
||||
QAmqpFrame::MethodClass QAmqpMethodFrame::methodClass() const
|
||||
|
|
@ -264,22 +257,16 @@ void QAmqpFrame::writeAmqpField(QDataStream &s, QAmqpMetaType::ValueType type, c
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
QAmqpContentFrame::QAmqpContentFrame()
|
||||
: QAmqpFrame(QAmqpFrame::ftHeader)
|
||||
: QAmqpFrame(QAmqpFrame::Header)
|
||||
{
|
||||
}
|
||||
|
||||
QAmqpContentFrame::QAmqpContentFrame(QAmqpFrame::MethodClass methodClass)
|
||||
: QAmqpFrame(QAmqpFrame::ftHeader)
|
||||
: QAmqpFrame(QAmqpFrame::Header)
|
||||
{
|
||||
methodClass_ = methodClass;
|
||||
}
|
||||
|
||||
QAmqpContentFrame::QAmqpContentFrame(QDataStream &raw)
|
||||
: QAmqpFrame(raw)
|
||||
{
|
||||
readPayload(raw);
|
||||
}
|
||||
|
||||
QAmqpFrame::MethodClass QAmqpContentFrame::methodClass() const
|
||||
{
|
||||
return MethodClass(methodClass_);
|
||||
|
|
@ -421,16 +408,10 @@ void QAmqpContentFrame::readPayload(QDataStream &in)
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
QAmqpContentBodyFrame::QAmqpContentBodyFrame()
|
||||
: QAmqpFrame(QAmqpFrame::ftBody)
|
||||
: QAmqpFrame(QAmqpFrame::Body)
|
||||
{
|
||||
}
|
||||
|
||||
QAmqpContentBodyFrame::QAmqpContentBodyFrame(QDataStream &raw)
|
||||
: QAmqpFrame(raw)
|
||||
{
|
||||
readPayload(raw);
|
||||
}
|
||||
|
||||
void QAmqpContentBodyFrame::setBody(const QByteArray &data)
|
||||
{
|
||||
body_ = data;
|
||||
|
|
@ -460,7 +441,7 @@ qint32 QAmqpContentBodyFrame::size() const
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
QAmqpHeartbeatFrame::QAmqpHeartbeatFrame()
|
||||
: QAmqpFrame(QAmqpFrame::ftHeartbeat)
|
||||
: QAmqpFrame(QAmqpFrame::Heartbeat)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,128 +8,47 @@
|
|||
#include "qamqpglobal.h"
|
||||
#include "qamqpmessage.h"
|
||||
|
||||
class QAmqpQueuePrivate;
|
||||
|
||||
/**
|
||||
* Library namespace
|
||||
* @namespace QAMQP
|
||||
*/
|
||||
|
||||
class QAmqpFramePrivate;
|
||||
class QAmqpFrame
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* @brief Header size in bytes
|
||||
*/
|
||||
static const qint64 HEADER_SIZE = 7;
|
||||
|
||||
/*
|
||||
* @brief Frame end indicator size in bytes
|
||||
*/
|
||||
static const qint64 FRAME_END_SIZE = 1;
|
||||
|
||||
/*
|
||||
* @brief Frame end marker
|
||||
*/
|
||||
static const quint8 FRAME_END = 0xCE;
|
||||
|
||||
/*
|
||||
* @brief Frame type
|
||||
*/
|
||||
enum Type
|
||||
enum FrameType
|
||||
{
|
||||
ftMethod = 1, /*!< Used define method frame */
|
||||
ftHeader = 2, /*!< Used define content header frame */
|
||||
ftBody = 3, /*!< Used define content body frame */
|
||||
ftHeartbeat = 8 /*!< Used define heartbeat frame */
|
||||
Method = 1,
|
||||
Header = 2,
|
||||
Body = 3,
|
||||
Heartbeat = 8
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief Frame method class
|
||||
* @enum MethodClass
|
||||
*/
|
||||
enum MethodClass
|
||||
{
|
||||
fcConnection = 10, // Define class of methods related to connection
|
||||
fcChannel = 20, // Define class of methods related to channel
|
||||
fcExchange = 40, // Define class of methods related to exchange
|
||||
fcQueue = 50, // Define class of methods related to queue
|
||||
fcBasic = 60, // Define class of methods related to basic command
|
||||
fcTx = 90,
|
||||
Connection = 10,
|
||||
Channel = 20,
|
||||
Exchange = 40,
|
||||
Queue = 50,
|
||||
Basic = 60,
|
||||
Tx = 90,
|
||||
};
|
||||
|
||||
virtual ~QAmqpFrame();
|
||||
|
||||
FrameType type() const;
|
||||
|
||||
qint16 channel() const;
|
||||
void setChannel(qint16 channel);
|
||||
|
||||
virtual qint32 size() const;
|
||||
|
||||
static QVariant readAmqpField(QDataStream &s, QAmqpMetaType::ValueType type);
|
||||
static void writeAmqpField(QDataStream &s, QAmqpMetaType::ValueType type, const QVariant &value);
|
||||
|
||||
/*
|
||||
* @brief Base class for any frames.
|
||||
* @detailed Implement main methods for serialize and deserialize raw frame data.
|
||||
* All frames start with a 7-octet header composed of a type field (octet), a channel field (short integer) and a
|
||||
* size field (long integer):
|
||||
* @code Frame struct
|
||||
* 0 1 3 7 size+7 size+8
|
||||
* +------+---------+---------+ +-------------+ +-----------+
|
||||
* | type | channel | size | | payload | | frame-end |
|
||||
* +------+---------+---------+ +-------------+ +-----------+
|
||||
* @endcode
|
||||
* octet short long 'size' octets octet
|
||||
*/
|
||||
|
||||
/*
|
||||
* Base class constructor.
|
||||
* @detailed Construct frame class for sending.
|
||||
* @param type Define type of constructed frame.
|
||||
*/
|
||||
QAmqpFrame(Type type);
|
||||
|
||||
/*
|
||||
* Base class constructor.
|
||||
* @detailed Construct frame class from received raw data.
|
||||
* @param raw Data stream for reading source data.
|
||||
*/
|
||||
QAmqpFrame(QDataStream &raw);
|
||||
|
||||
/*
|
||||
* Base class virtual destructor
|
||||
*/
|
||||
virtual ~QAmqpFrame();
|
||||
|
||||
/*
|
||||
* Frame type
|
||||
* @detailed Return type of current frame.
|
||||
*/
|
||||
Type type() const;
|
||||
|
||||
/*
|
||||
* Set number of associated channel.
|
||||
* @param channel Number of channel.
|
||||
* @sa channel()
|
||||
*/
|
||||
void setChannel(qint16 channel);
|
||||
|
||||
/*
|
||||
* Return number of associated channel.
|
||||
* @sa setChannel()
|
||||
*/
|
||||
qint16 channel() const;
|
||||
|
||||
/*
|
||||
* Return size of frame.
|
||||
*/
|
||||
virtual qint32 size() const;
|
||||
|
||||
/*
|
||||
* Output frame to stream.
|
||||
* @param stream Stream for serilize frame.
|
||||
*/
|
||||
void toStream(QDataStream &stream) const;
|
||||
|
||||
protected:
|
||||
void writeHeader(QDataStream &stream) const;
|
||||
explicit QAmqpFrame(FrameType type);
|
||||
virtual void writePayload(QDataStream &stream) const = 0;
|
||||
void writeEnd(QDataStream &stream) const;
|
||||
|
||||
void readHeader(QDataStream &stream);
|
||||
virtual void readPayload(QDataStream &stream) = 0;
|
||||
|
||||
qint32 size_;
|
||||
|
|
@ -138,212 +57,104 @@ private:
|
|||
qint8 type_;
|
||||
qint16 channel_;
|
||||
|
||||
friend QDataStream &operator<<(QDataStream &stream, const QAmqpFrame &frame);
|
||||
friend QDataStream &operator>>(QDataStream &stream, QAmqpFrame &frame);
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief Class for working with method frames.
|
||||
* @detailed Implement main methods for serialize and deserialize raw method frame data.
|
||||
* Method frame bodies consist of an invariant list of data fields, called "arguments". All method bodies start
|
||||
* with identifier numbers for the class and method:
|
||||
* @code Frame struct
|
||||
* 0 2 4
|
||||
* +----------+-----------+-------------- - -
|
||||
* | class-id | method-id | arguments...
|
||||
* +----------+-----------+-------------- - -
|
||||
* short short ...
|
||||
* @endcode
|
||||
*/
|
||||
QDataStream &operator<<(QDataStream &, const QAmqpFrame &frame);
|
||||
QDataStream &operator>>(QDataStream &, QAmqpFrame &frame);
|
||||
|
||||
class QAMQP_EXPORT QAmqpMethodFrame : public QAmqpFrame
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Method class constructor.
|
||||
* @detailed Construct frame class for sending.
|
||||
* @param methodClass Define method class id of constructed frame.
|
||||
* @param id Define method id of constructed frame.
|
||||
*/
|
||||
explicit QAmqpMethodFrame(MethodClass methodClass, qint16 id);
|
||||
QAmqpMethodFrame();
|
||||
QAmqpMethodFrame(MethodClass methodClass, qint16 id);
|
||||
|
||||
/*
|
||||
* Method class constructor.
|
||||
* @detailed Construct frame class from received raw data.
|
||||
* @param raw Data stream for reading source data.
|
||||
*/
|
||||
explicit QAmqpMethodFrame(QDataStream &raw);
|
||||
|
||||
/*
|
||||
* Method class type.
|
||||
*/
|
||||
qint16 id() const;
|
||||
MethodClass methodClass() const;
|
||||
|
||||
/*
|
||||
* Method id.
|
||||
*/
|
||||
qint16 id() const;
|
||||
qint32 size() const;
|
||||
virtual qint32 size() const;
|
||||
|
||||
/*
|
||||
* Set arguments for method.
|
||||
* @param data Serialized method arguments.
|
||||
* @sa arguments
|
||||
*/
|
||||
QByteArray arguments() const;
|
||||
void setArguments(const QByteArray &data);
|
||||
|
||||
/*
|
||||
* Return arguments for method.
|
||||
* @sa setArguments
|
||||
*/
|
||||
QByteArray arguments() const;
|
||||
|
||||
protected:
|
||||
private:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
|
||||
short methodClass_;
|
||||
qint16 id_;
|
||||
QByteArray arguments_;
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief Class for working with content frames.
|
||||
* @detailed Implement main methods for serialize and deserialize raw content frame data.
|
||||
* A content header payload has this format:
|
||||
* @code Frame struct
|
||||
* +----------+--------+-----------+----------------+------------- - -
|
||||
* | class-id | weight | body size | property flags | property list...
|
||||
* +----------+--------+-----------+----------------+------------- - -
|
||||
* short short long long short remainder...
|
||||
* @endcode
|
||||
*
|
||||
* | Property | Description |
|
||||
* | ---------------- | -------------------------------------- |
|
||||
* | ContentType | MIME content type |
|
||||
* | ContentEncoding | MIME content encoding |
|
||||
* | Headers | message header field table |
|
||||
* | DeliveryMode | nonpersistent (1) or persistent (2) |
|
||||
* | Priority | message priority, 0 to 9 |
|
||||
* | CorrelationId | application correlation identifier |
|
||||
* | ReplyTo | address to reply to |
|
||||
* | Expiration | message expiration specification |
|
||||
* | MessageId | application message identifier |
|
||||
* | Timestamp | message timestamp |
|
||||
* | Type | message type name |
|
||||
* | UserId | creating user id |
|
||||
* | AppId | creating application id |
|
||||
* | ClusterID | cluster ID |
|
||||
*
|
||||
* Default property:
|
||||
* @sa setProperty
|
||||
* @sa property
|
||||
*/
|
||||
class QAMQP_EXPORT QAmqpContentFrame : public QAmqpFrame
|
||||
class QAmqpContentFrame : public QAmqpFrame
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Content class constructor.
|
||||
* @detailed Construct frame content header class for sending.
|
||||
*/
|
||||
QAmqpContentFrame();
|
||||
|
||||
/*
|
||||
* Content class constructor.
|
||||
* @detailed Construct frame content header class for sending.
|
||||
* @param methodClass Define method class id of constructed frame.
|
||||
*/
|
||||
QAmqpContentFrame(MethodClass methodClass);
|
||||
|
||||
/*
|
||||
* Content class constructor.
|
||||
* @detailed Construct frame content header class for sending.
|
||||
* @param raw Data stream for reading source data.
|
||||
*/
|
||||
QAmqpContentFrame(QDataStream &raw);
|
||||
|
||||
/*
|
||||
* Method class type.
|
||||
*/
|
||||
MethodClass methodClass() const;
|
||||
qint32 size() const;
|
||||
|
||||
/*
|
||||
* Set default content header property
|
||||
* @param prop Any default content header property
|
||||
* @param value Associated data
|
||||
*/
|
||||
void setProperty(QAmqpMessage::Property prop, const QVariant &value);
|
||||
virtual qint32 size() const;
|
||||
|
||||
/*
|
||||
* Return associated with property value
|
||||
* @param prop Any default content header property
|
||||
*/
|
||||
QVariant property(QAmqpMessage::Property prop) const;
|
||||
void setProperty(QAmqpMessage::Property prop, const QVariant &value);
|
||||
|
||||
qlonglong bodySize() const;
|
||||
void setBodySize(qlonglong size);
|
||||
|
||||
protected:
|
||||
private:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
friend class QAmqpQueuePrivate;
|
||||
|
||||
short methodClass_;
|
||||
qint16 id_;
|
||||
mutable QByteArray buffer_;
|
||||
QAmqpMessage::PropertyHash properties_;
|
||||
qlonglong bodySize_;
|
||||
|
||||
private:
|
||||
friend class QAmqpQueuePrivate;
|
||||
|
||||
};
|
||||
|
||||
class QAMQP_EXPORT QAmqpContentBodyFrame : public QAmqpFrame
|
||||
class QAmqpContentBodyFrame : public QAmqpFrame
|
||||
{
|
||||
public:
|
||||
QAmqpContentBodyFrame();
|
||||
QAmqpContentBodyFrame(QDataStream &raw);
|
||||
|
||||
void setBody(const QByteArray &data);
|
||||
QByteArray body() const;
|
||||
|
||||
qint32 size() const;
|
||||
protected:
|
||||
virtual qint32 size() const;
|
||||
|
||||
private:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
|
||||
private:
|
||||
QByteArray body_;
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief Class for working with heartbeat frames.
|
||||
* @detailed Implement frame for heartbeat send.
|
||||
*/
|
||||
class QAMQP_EXPORT QAmqpHeartbeatFrame : public QAmqpFrame
|
||||
class QAmqpHeartbeatFrame : public QAmqpFrame
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Heartbeat class constructor.
|
||||
* @detailed Construct frame class for sending.
|
||||
*/
|
||||
QAmqpHeartbeatFrame();
|
||||
|
||||
protected:
|
||||
private:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
};
|
||||
|
||||
class QAMQP_EXPORT QAmqpMethodFrameHandler
|
||||
class QAmqpMethodFrameHandler
|
||||
{
|
||||
public:
|
||||
virtual bool _q_method(const QAmqpMethodFrame &frame) = 0;
|
||||
};
|
||||
|
||||
class QAMQP_EXPORT QAmqpContentFrameHandler
|
||||
class QAmqpContentFrameHandler
|
||||
{
|
||||
public:
|
||||
virtual void _q_content(const QAmqpContentFrame &frame) = 0;
|
||||
};
|
||||
|
||||
class QAMQP_EXPORT QAmqpContentBodyFrameHandler
|
||||
class QAmqpContentBodyFrameHandler
|
||||
{
|
||||
public:
|
||||
virtual void _q_body(const QAmqpContentBodyFrame &frame) = 0;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ bool QAmqpQueuePrivate::_q_method(const QAmqpMethodFrame &frame)
|
|||
if (QAmqpChannelPrivate::_q_method(frame))
|
||||
return true;
|
||||
|
||||
if (frame.methodClass() == QAmqpFrame::fcQueue) {
|
||||
if (frame.methodClass() == QAmqpFrame::Queue) {
|
||||
switch (frame.id()) {
|
||||
case miDeclareOk:
|
||||
declareOk(frame);
|
||||
|
|
@ -51,7 +51,7 @@ bool QAmqpQueuePrivate::_q_method(const QAmqpMethodFrame &frame)
|
|||
return true;
|
||||
}
|
||||
|
||||
if (frame.methodClass() == QAmqpFrame::fcBasic) {
|
||||
if (frame.methodClass() == QAmqpFrame::Basic) {
|
||||
switch(frame.id()) {
|
||||
case bmConsumeOk:
|
||||
consumeOk(frame);
|
||||
|
|
@ -235,7 +235,7 @@ void QAmqpQueuePrivate::deliver(const QAmqpMethodFrame &frame)
|
|||
|
||||
void QAmqpQueuePrivate::declare()
|
||||
{
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miDeclare);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Queue, QAmqpQueuePrivate::miDeclare);
|
||||
frame.setChannel(channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -327,7 +327,7 @@ void QAmqpQueue::remove(int options)
|
|||
return;
|
||||
}
|
||||
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miDelete);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Queue, QAmqpQueuePrivate::miDelete);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -348,7 +348,7 @@ void QAmqpQueue::purge()
|
|||
if (!d->opened)
|
||||
return;
|
||||
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miPurge);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Queue, QAmqpQueuePrivate::miPurge);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -379,7 +379,7 @@ void QAmqpQueue::bind(const QString &exchangeName, const QString &key)
|
|||
return;
|
||||
}
|
||||
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miBind);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Queue, QAmqpQueuePrivate::miBind);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -415,7 +415,7 @@ void QAmqpQueue::unbind(const QString &exchangeName, const QString &key)
|
|||
return;
|
||||
}
|
||||
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miUnbind);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Queue, QAmqpQueuePrivate::miUnbind);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -443,7 +443,7 @@ bool QAmqpQueue::consume(int options)
|
|||
return false;
|
||||
}
|
||||
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpQueuePrivate::bmConsume);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Basic, QAmqpQueuePrivate::bmConsume);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -487,7 +487,7 @@ void QAmqpQueue::get(bool noAck)
|
|||
return;
|
||||
}
|
||||
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpQueuePrivate::bmGet);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Basic, QAmqpQueuePrivate::bmGet);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -509,7 +509,7 @@ void QAmqpQueue::ack(const QAmqpMessage &message)
|
|||
return;
|
||||
}
|
||||
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpQueuePrivate::bmAck);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Basic, QAmqpQueuePrivate::bmAck);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -535,7 +535,7 @@ bool QAmqpQueue::cancel(bool noWait)
|
|||
return false;
|
||||
}
|
||||
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpQueuePrivate::bmCancel);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::Basic, QAmqpQueuePrivate::bmCancel);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
|
|||
Loading…
Reference in New Issue