remove QAMQP namespace
This is a very small library, so there is no real pressing need for a library namespace. Further, the namespacing actually makes it rather difficult to work with in some cases. Opting for a more "Qt" style class naming scheme, using the QAmqp class prefix
This commit is contained in:
parent
9887fa2333
commit
10ab1423c2
|
|
@ -1,47 +1,46 @@
|
|||
#include "qamqptable.h"
|
||||
#include "qamqpframe_p.h"
|
||||
#include "qamqpauthenticator.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
AMQPlainAuthenticator::AMQPlainAuthenticator(const QString &l, const QString &p)
|
||||
QAmqpPlainAuthenticator::QAmqpPlainAuthenticator(const QString &l, const QString &p)
|
||||
: login_(l),
|
||||
password_(p)
|
||||
{
|
||||
}
|
||||
|
||||
AMQPlainAuthenticator::~AMQPlainAuthenticator()
|
||||
QAmqpPlainAuthenticator::~QAmqpPlainAuthenticator()
|
||||
{
|
||||
}
|
||||
|
||||
QString AMQPlainAuthenticator::login() const
|
||||
QString QAmqpPlainAuthenticator::login() const
|
||||
{
|
||||
return login_;
|
||||
}
|
||||
|
||||
QString AMQPlainAuthenticator::password() const
|
||||
QString QAmqpPlainAuthenticator::password() const
|
||||
{
|
||||
return password_;
|
||||
}
|
||||
|
||||
QString AMQPlainAuthenticator::type() const
|
||||
QString QAmqpPlainAuthenticator::type() const
|
||||
{
|
||||
return "AMQPLAIN";
|
||||
}
|
||||
|
||||
void AMQPlainAuthenticator::setLogin(const QString &l)
|
||||
void QAmqpPlainAuthenticator::setLogin(const QString &l)
|
||||
{
|
||||
login_ = l;
|
||||
}
|
||||
|
||||
void AMQPlainAuthenticator::setPassword(const QString &p)
|
||||
void QAmqpPlainAuthenticator::setPassword(const QString &p)
|
||||
{
|
||||
password_ = p;
|
||||
}
|
||||
|
||||
void AMQPlainAuthenticator::write(QDataStream &out)
|
||||
void QAmqpPlainAuthenticator::write(QDataStream &out)
|
||||
{
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, type());
|
||||
Table response;
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, type());
|
||||
QAmqpTable response;
|
||||
response["LOGIN"] = login_;
|
||||
response["PASSWORD"] = password_;
|
||||
out << response;
|
||||
|
|
|
|||
|
|
@ -6,22 +6,19 @@
|
|||
|
||||
#include "qamqpglobal.h"
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
class QAMQP_EXPORT Authenticator
|
||||
class QAMQP_EXPORT QAmqpAuthenticator
|
||||
{
|
||||
public:
|
||||
virtual ~Authenticator() {}
|
||||
virtual ~QAmqpAuthenticator() {}
|
||||
virtual QString type() const = 0;
|
||||
virtual void write(QDataStream &out) = 0;
|
||||
};
|
||||
|
||||
class QAMQP_EXPORT AMQPlainAuthenticator : public Authenticator
|
||||
class QAMQP_EXPORT QAmqpPlainAuthenticator : public QAmqpAuthenticator
|
||||
{
|
||||
public:
|
||||
AMQPlainAuthenticator(const QString &login = QString(), const QString &password = QString());
|
||||
virtual ~AMQPlainAuthenticator();
|
||||
QAmqpPlainAuthenticator(const QString &login = QString(), const QString &password = QString());
|
||||
virtual ~QAmqpPlainAuthenticator();
|
||||
|
||||
QString login() const;
|
||||
void setLogin(const QString &l);
|
||||
|
|
@ -38,6 +35,4 @@ private:
|
|||
|
||||
};
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
#endif // QAMQPAUTHENTICATOR_H
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
#include <QDataStream>
|
||||
#include <QDebug>
|
||||
|
||||
#include "qamqpchannel.h"
|
||||
#include "qamqpchannel_p.h"
|
||||
#include "qamqpclient.h"
|
||||
#include "qamqpclient_p.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDataStream>
|
||||
|
||||
using namespace QAMQP;
|
||||
|
||||
int ChannelPrivate::nextChannelNumber = 0;
|
||||
ChannelPrivate::ChannelPrivate(Channel *q)
|
||||
int QAmqpChannelPrivate::nextChannelNumber = 0;
|
||||
QAmqpChannelPrivate::QAmqpChannelPrivate(QAmqpChannel *q)
|
||||
: channelNumber(0),
|
||||
opened(false),
|
||||
needOpen(true),
|
||||
|
|
@ -22,11 +20,11 @@ ChannelPrivate::ChannelPrivate(Channel *q)
|
|||
{
|
||||
}
|
||||
|
||||
ChannelPrivate::~ChannelPrivate()
|
||||
QAmqpChannelPrivate::~QAmqpChannelPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void ChannelPrivate::init(int channel, Client *c)
|
||||
void QAmqpChannelPrivate::init(int channel, QAmqpClient *c)
|
||||
{
|
||||
client = c;
|
||||
needOpen = channel == -1 ? true : false;
|
||||
|
|
@ -34,13 +32,13 @@ void ChannelPrivate::init(int channel, Client *c)
|
|||
nextChannelNumber = qMax(channelNumber, (nextChannelNumber + 1));
|
||||
}
|
||||
|
||||
bool ChannelPrivate::_q_method(const Frame::Method &frame)
|
||||
bool QAmqpChannelPrivate::_q_method(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_ASSERT(frame.channel() == channelNumber);
|
||||
if (frame.channel() != channelNumber)
|
||||
return true;
|
||||
|
||||
if (frame.methodClass() == Frame::fcBasic) {
|
||||
if (frame.methodClass() == QAmqpFrame::fcBasic) {
|
||||
if (frame.id() == bmQosOk) {
|
||||
qosOk(frame);
|
||||
return true;
|
||||
|
|
@ -49,7 +47,7 @@ bool ChannelPrivate::_q_method(const Frame::Method &frame)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (frame.methodClass() != Frame::fcChannel)
|
||||
if (frame.methodClass() != QAmqpFrame::fcChannel)
|
||||
return false;
|
||||
|
||||
qAmqpDebug("Channel#%d:", channelNumber);
|
||||
|
|
@ -75,12 +73,12 @@ bool ChannelPrivate::_q_method(const Frame::Method &frame)
|
|||
return true;
|
||||
}
|
||||
|
||||
void ChannelPrivate::_q_open()
|
||||
void QAmqpChannelPrivate::_q_open()
|
||||
{
|
||||
open();
|
||||
}
|
||||
|
||||
void ChannelPrivate::sendFrame(const Frame::Base &frame)
|
||||
void QAmqpChannelPrivate::sendFrame(const QAmqpFrame &frame)
|
||||
{
|
||||
if (!client) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "invalid client";
|
||||
|
|
@ -90,7 +88,7 @@ void ChannelPrivate::sendFrame(const Frame::Base &frame)
|
|||
client->d_func()->sendFrame(frame);
|
||||
}
|
||||
|
||||
void ChannelPrivate::open()
|
||||
void QAmqpChannelPrivate::open()
|
||||
{
|
||||
if (!needOpen || opened)
|
||||
return;
|
||||
|
|
@ -99,7 +97,7 @@ void ChannelPrivate::open()
|
|||
return;
|
||||
|
||||
qAmqpDebug("Open channel #%d", channelNumber);
|
||||
Frame::Method frame(Frame::fcChannel, miOpen);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcChannel, miOpen);
|
||||
frame.setChannel(channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -110,13 +108,13 @@ void ChannelPrivate::open()
|
|||
sendFrame(frame);
|
||||
}
|
||||
|
||||
void ChannelPrivate::flow(bool active)
|
||||
void QAmqpChannelPrivate::flow(bool active)
|
||||
{
|
||||
QByteArray arguments;
|
||||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
Frame::writeAmqpField(stream, MetaType::ShortShortUint, (active ? 1 : 0));
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortShortUint, (active ? 1 : 0));
|
||||
|
||||
Frame::Method frame(Frame::fcChannel, miFlow);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcChannel, miFlow);
|
||||
frame.setChannel(channelNumber);
|
||||
frame.setArguments(arguments);
|
||||
sendFrame(frame);
|
||||
|
|
@ -125,65 +123,66 @@ void ChannelPrivate::flow(bool active)
|
|||
// NOTE: not implemented until I can figure out a good way to force the server
|
||||
// to pause the channel in a test. It seems like RabbitMQ just doesn't
|
||||
// care about flow control, preferring rather to use basic.qos
|
||||
void ChannelPrivate::flow(const Frame::Method &frame)
|
||||
void QAmqpChannelPrivate::flow(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_UNUSED(frame);
|
||||
qAmqpDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
void ChannelPrivate::flowOk()
|
||||
void QAmqpChannelPrivate::flowOk()
|
||||
{
|
||||
qAmqpDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
void ChannelPrivate::flowOk(const Frame::Method &frame)
|
||||
void QAmqpChannelPrivate::flowOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Channel);
|
||||
Q_Q(QAmqpChannel);
|
||||
QByteArray data = frame.arguments();
|
||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||
bool active = Frame::readAmqpField(stream, MetaType::Boolean).toBool();
|
||||
bool active = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::Boolean).toBool();
|
||||
if (active)
|
||||
Q_EMIT q->resumed();
|
||||
else
|
||||
Q_EMIT q->paused();
|
||||
}
|
||||
|
||||
void ChannelPrivate::close(int code, const QString &text, int classId, int methodId)
|
||||
void QAmqpChannelPrivate::close(int code, const QString &text, int classId, int methodId)
|
||||
{
|
||||
QByteArray arguments;
|
||||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
if (!code) code = 200;
|
||||
Frame::writeAmqpField(stream, MetaType::ShortUint, code);
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortUint, code);
|
||||
if (!text.isEmpty()) {
|
||||
Frame::writeAmqpField(stream, MetaType::ShortString, text);
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, text);
|
||||
} else {
|
||||
Frame::writeAmqpField(stream, MetaType::ShortString, QLatin1String("OK"));
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, QLatin1String("OK"));
|
||||
}
|
||||
|
||||
Frame::writeAmqpField(stream, MetaType::ShortUint, classId);
|
||||
Frame::writeAmqpField(stream, MetaType::ShortUint, methodId);
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortUint, classId);
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortUint, methodId);
|
||||
|
||||
Frame::Method frame(Frame::fcChannel, miClose);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcChannel, miClose);
|
||||
frame.setChannel(channelNumber);
|
||||
frame.setArguments(arguments);
|
||||
sendFrame(frame);
|
||||
}
|
||||
|
||||
void ChannelPrivate::close(const Frame::Method &frame)
|
||||
void QAmqpChannelPrivate::close(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Channel);
|
||||
Q_Q(QAmqpChannel);
|
||||
qAmqpDebug(">> CLOSE");
|
||||
QByteArray data = frame.arguments();
|
||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||
qint16 code = 0, classId, methodId;
|
||||
stream >> code;
|
||||
QString text = Frame::readAmqpField(stream, MetaType::ShortString).toString();
|
||||
QString text =
|
||||
QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString();
|
||||
|
||||
stream >> classId;
|
||||
stream >> methodId;
|
||||
|
||||
Error checkError = static_cast<Error>(code);
|
||||
QAMQP::Error checkError = static_cast<QAMQP::Error>(code);
|
||||
if (checkError != QAMQP::NoError) {
|
||||
error = checkError;
|
||||
errorString = qPrintable(text);
|
||||
|
|
@ -197,37 +196,37 @@ void ChannelPrivate::close(const Frame::Method &frame)
|
|||
Q_EMIT q->closed();
|
||||
|
||||
// complete handshake
|
||||
Frame::Method closeOkFrame(Frame::fcChannel, miCloseOk);
|
||||
QAmqpMethodFrame closeOkFrame(QAmqpFrame::fcChannel, miCloseOk);
|
||||
closeOkFrame.setChannel(channelNumber);
|
||||
sendFrame(closeOkFrame);
|
||||
}
|
||||
|
||||
void ChannelPrivate::closeOk(const Frame::Method &)
|
||||
void QAmqpChannelPrivate::closeOk(const QAmqpMethodFrame &)
|
||||
{
|
||||
Q_Q(Channel);
|
||||
Q_Q(QAmqpChannel);
|
||||
Q_EMIT q->closed();
|
||||
q->channelClosed();
|
||||
opened = false;
|
||||
}
|
||||
|
||||
void ChannelPrivate::openOk(const Frame::Method &)
|
||||
void QAmqpChannelPrivate::openOk(const QAmqpMethodFrame &)
|
||||
{
|
||||
Q_Q(Channel);
|
||||
Q_Q(QAmqpChannel);
|
||||
qAmqpDebug(">> OpenOK");
|
||||
opened = true;
|
||||
Q_EMIT q->opened();
|
||||
q->channelOpened();
|
||||
}
|
||||
|
||||
void ChannelPrivate::_q_disconnected()
|
||||
void QAmqpChannelPrivate::_q_disconnected()
|
||||
{
|
||||
nextChannelNumber = 0;
|
||||
opened = false;
|
||||
}
|
||||
|
||||
void ChannelPrivate::qosOk(const Frame::Method &frame)
|
||||
void QAmqpChannelPrivate::qosOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Channel);
|
||||
Q_Q(QAmqpChannel);
|
||||
Q_UNUSED(frame)
|
||||
|
||||
prefetchCount = requestedPrefetchCount;
|
||||
|
|
@ -237,60 +236,60 @@ void ChannelPrivate::qosOk(const Frame::Method &frame)
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Channel::Channel(ChannelPrivate *dd, Client *parent)
|
||||
QAmqpChannel::QAmqpChannel(QAmqpChannelPrivate *dd, QAmqpClient *parent)
|
||||
: QObject(parent),
|
||||
d_ptr(dd)
|
||||
{
|
||||
}
|
||||
|
||||
Channel::~Channel()
|
||||
QAmqpChannel::~QAmqpChannel()
|
||||
{
|
||||
}
|
||||
|
||||
void Channel::close()
|
||||
void QAmqpChannel::close()
|
||||
{
|
||||
Q_D(Channel);
|
||||
Q_D(QAmqpChannel);
|
||||
d->needOpen = true;
|
||||
if (d->opened)
|
||||
d->close(0, QString(), 0,0);
|
||||
}
|
||||
|
||||
void Channel::reopen()
|
||||
void QAmqpChannel::reopen()
|
||||
{
|
||||
Q_D(Channel);
|
||||
Q_D(QAmqpChannel);
|
||||
if (d->opened)
|
||||
close();
|
||||
d->open();
|
||||
}
|
||||
|
||||
QString Channel::name() const
|
||||
QString QAmqpChannel::name() const
|
||||
{
|
||||
Q_D(const Channel);
|
||||
Q_D(const QAmqpChannel);
|
||||
return d->name;
|
||||
}
|
||||
|
||||
int Channel::channelNumber() const
|
||||
int QAmqpChannel::channelNumber() const
|
||||
{
|
||||
Q_D(const Channel);
|
||||
Q_D(const QAmqpChannel);
|
||||
return d->channelNumber;
|
||||
}
|
||||
|
||||
void Channel::setName(const QString &name)
|
||||
void QAmqpChannel::setName(const QString &name)
|
||||
{
|
||||
Q_D(Channel);
|
||||
Q_D(QAmqpChannel);
|
||||
d->name = name;
|
||||
}
|
||||
|
||||
bool Channel::isOpened() const
|
||||
bool QAmqpChannel::isOpened() const
|
||||
{
|
||||
Q_D(const Channel);
|
||||
Q_D(const QAmqpChannel);
|
||||
return d->opened;
|
||||
}
|
||||
|
||||
void Channel::qos(qint16 prefetchCount, qint32 prefetchSize)
|
||||
void QAmqpChannel::qos(qint16 prefetchCount, qint32 prefetchSize)
|
||||
{
|
||||
Q_D(Channel);
|
||||
Frame::Method frame(Frame::fcBasic, ChannelPrivate::bmQos);
|
||||
Q_D(QAmqpChannel);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpChannelPrivate::bmQos);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -307,33 +306,33 @@ void Channel::qos(qint16 prefetchCount, qint32 prefetchSize)
|
|||
d->sendFrame(frame);
|
||||
}
|
||||
|
||||
qint32 Channel::prefetchSize() const
|
||||
qint32 QAmqpChannel::prefetchSize() const
|
||||
{
|
||||
Q_D(const Channel);
|
||||
Q_D(const QAmqpChannel);
|
||||
return d->prefetchSize;
|
||||
}
|
||||
|
||||
qint16 Channel::prefetchCount() const
|
||||
qint16 QAmqpChannel::prefetchCount() const
|
||||
{
|
||||
Q_D(const Channel);
|
||||
Q_D(const QAmqpChannel);
|
||||
return d->prefetchCount;
|
||||
}
|
||||
|
||||
Error Channel::error() const
|
||||
QAMQP::Error QAmqpChannel::error() const
|
||||
{
|
||||
Q_D(const Channel);
|
||||
Q_D(const QAmqpChannel);
|
||||
return d->error;
|
||||
}
|
||||
|
||||
QString Channel::errorString() const
|
||||
QString QAmqpChannel::errorString() const
|
||||
{
|
||||
Q_D(const Channel);
|
||||
Q_D(const QAmqpChannel);
|
||||
return d->errorString;
|
||||
}
|
||||
|
||||
void Channel::resume()
|
||||
void QAmqpChannel::resume()
|
||||
{
|
||||
Q_D(Channel);
|
||||
Q_D(QAmqpChannel);
|
||||
d->flow(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,19 +4,16 @@
|
|||
#include <QObject>
|
||||
#include "qamqpglobal.h"
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
class Client;
|
||||
class ChannelPrivate;
|
||||
class QAMQP_EXPORT Channel : public QObject
|
||||
class QAmqpClient;
|
||||
class QAmqpChannelPrivate;
|
||||
class QAMQP_EXPORT QAmqpChannel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int number READ channelNumber CONSTANT)
|
||||
Q_PROPERTY(bool opened READ isOpened CONSTANT)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
public:
|
||||
virtual ~Channel();
|
||||
virtual ~QAmqpChannel();
|
||||
|
||||
int channelNumber() const;
|
||||
bool isOpened() const;
|
||||
|
|
@ -24,7 +21,7 @@ public:
|
|||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
Error error() const;
|
||||
QAMQP::Error error() const;
|
||||
QString errorString() const;
|
||||
|
||||
qint32 prefetchSize() const;
|
||||
|
|
@ -51,18 +48,16 @@ protected:
|
|||
virtual void channelClosed() = 0;
|
||||
|
||||
protected:
|
||||
explicit Channel(ChannelPrivate *dd, Client *client);
|
||||
explicit QAmqpChannel(QAmqpChannelPrivate *dd, QAmqpClient *client);
|
||||
|
||||
Q_DISABLE_COPY(Channel)
|
||||
Q_DECLARE_PRIVATE(Channel)
|
||||
QScopedPointer<ChannelPrivate> d_ptr;
|
||||
Q_DISABLE_COPY(QAmqpChannel)
|
||||
Q_DECLARE_PRIVATE(QAmqpChannel)
|
||||
QScopedPointer<QAmqpChannelPrivate> d_ptr;
|
||||
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_open())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_disconnected())
|
||||
|
||||
friend class ClientPrivate;
|
||||
friend class QAmqpClientPrivate;
|
||||
};
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
#endif // QAMQPCHANNEL_H
|
||||
|
|
|
|||
|
|
@ -6,13 +6,9 @@
|
|||
|
||||
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
class Client;
|
||||
class Network;
|
||||
class ClientPrivate;
|
||||
class ChannelPrivate : public Frame::MethodHandler
|
||||
class QAmqpClient;
|
||||
class QAmqpClientPrivate;
|
||||
class QAmqpChannelPrivate : public QAmqpMethodFrameHandler
|
||||
{
|
||||
public:
|
||||
enum MethodId {
|
||||
|
|
@ -36,11 +32,11 @@ public:
|
|||
METHOD_ID_ENUM(bmRecover, 110)
|
||||
};
|
||||
|
||||
ChannelPrivate(Channel *q);
|
||||
virtual ~ChannelPrivate();
|
||||
QAmqpChannelPrivate(QAmqpChannel *q);
|
||||
virtual ~QAmqpChannelPrivate();
|
||||
|
||||
void init(int channel, Client *client);
|
||||
void sendFrame(const Frame::Base &frame);
|
||||
void init(int channel, QAmqpClient *client);
|
||||
void sendFrame(const QAmqpFrame &frame);
|
||||
|
||||
void open();
|
||||
void flow(bool active);
|
||||
|
|
@ -48,19 +44,19 @@ public:
|
|||
void close(int code, const QString &text, int classId, int methodId);
|
||||
|
||||
// reimp MethodHandler
|
||||
virtual bool _q_method(const Frame::Method &frame);
|
||||
void openOk(const Frame::Method &frame);
|
||||
void flow(const Frame::Method &frame);
|
||||
void flowOk(const Frame::Method &frame);
|
||||
void close(const Frame::Method &frame);
|
||||
void closeOk(const Frame::Method &frame);
|
||||
void qosOk(const Frame::Method &frame);
|
||||
virtual bool _q_method(const QAmqpMethodFrame &frame);
|
||||
void openOk(const QAmqpMethodFrame &frame);
|
||||
void flow(const QAmqpMethodFrame &frame);
|
||||
void flowOk(const QAmqpMethodFrame &frame);
|
||||
void close(const QAmqpMethodFrame &frame);
|
||||
void closeOk(const QAmqpMethodFrame &frame);
|
||||
void qosOk(const QAmqpMethodFrame &frame);
|
||||
|
||||
// private slots
|
||||
virtual void _q_disconnected();
|
||||
void _q_open();
|
||||
|
||||
QPointer<Client> client;
|
||||
QPointer<QAmqpClient> client;
|
||||
QString name;
|
||||
int channelNumber;
|
||||
static int nextChannelNumber;
|
||||
|
|
@ -72,13 +68,11 @@ public:
|
|||
qint16 prefetchCount;
|
||||
qint16 requestedPrefetchCount;
|
||||
|
||||
Error error;
|
||||
QAMQP::Error error;
|
||||
QString errorString;
|
||||
|
||||
Q_DECLARE_PUBLIC(Channel)
|
||||
Channel * const q_ptr;
|
||||
Q_DECLARE_PUBLIC(QAmqpChannel)
|
||||
QAmqpChannel * const q_ptr;
|
||||
};
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
#endif // QAMQPCHANNEL_P_H
|
||||
|
|
|
|||
|
|
@ -13,12 +13,11 @@
|
|||
#include "qamqptable.h"
|
||||
#include "qamqpclient_p.h"
|
||||
#include "qamqpclient.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
ClientPrivate::ClientPrivate(Client *q)
|
||||
QAmqpClientPrivate::QAmqpClientPrivate(QAmqpClient *q)
|
||||
: port(AMQP_PORT),
|
||||
host(QString::fromLatin1(AMQP_HOST)),
|
||||
virtualHost(QString::fromLatin1(AMQP_VHOST)),
|
||||
host(AMQP_HOST),
|
||||
virtualHost(AMQP_VHOST),
|
||||
autoReconnect(false),
|
||||
timeout(-1),
|
||||
connecting(false),
|
||||
|
|
@ -33,24 +32,24 @@ ClientPrivate::ClientPrivate(Client *q)
|
|||
{
|
||||
}
|
||||
|
||||
ClientPrivate::~ClientPrivate()
|
||||
QAmqpClientPrivate::~QAmqpClientPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void ClientPrivate::init()
|
||||
void QAmqpClientPrivate::init()
|
||||
{
|
||||
Q_Q(Client);
|
||||
Q_Q(QAmqpClient);
|
||||
initSocket();
|
||||
heartbeatTimer = new QTimer(q);
|
||||
QObject::connect(heartbeatTimer, SIGNAL(timeout()), q, SLOT(_q_heartbeat()));
|
||||
|
||||
authenticator = QSharedPointer<Authenticator>(
|
||||
new AMQPlainAuthenticator(QString::fromLatin1(AMQP_LOGIN), QString::fromLatin1(AMQP_PSWD)));
|
||||
authenticator = QSharedPointer<QAmqpAuthenticator>(
|
||||
new QAmqpPlainAuthenticator(QString::fromLatin1(AMQP_LOGIN), QString::fromLatin1(AMQP_PSWD)));
|
||||
}
|
||||
|
||||
void ClientPrivate::initSocket()
|
||||
void QAmqpClientPrivate::initSocket()
|
||||
{
|
||||
Q_Q(Client);
|
||||
Q_Q(QAmqpClient);
|
||||
socket = new QTcpSocket(q);
|
||||
QObject::connect(socket, SIGNAL(connected()), q, SLOT(_q_socketConnected()));
|
||||
QObject::connect(socket, SIGNAL(disconnected()), q, SLOT(_q_socketDisconnected()));
|
||||
|
|
@ -59,25 +58,25 @@ void ClientPrivate::initSocket()
|
|||
q, SLOT(_q_socketError(QAbstractSocket::SocketError)));
|
||||
}
|
||||
|
||||
void ClientPrivate::setUsername(const QString &username)
|
||||
void QAmqpClientPrivate::setUsername(const QString &username)
|
||||
{
|
||||
Authenticator *auth = authenticator.data();
|
||||
QAmqpAuthenticator *auth = authenticator.data();
|
||||
if (auth && auth->type() == QLatin1String("AMQPLAIN")) {
|
||||
AMQPlainAuthenticator *a = static_cast<AMQPlainAuthenticator*>(auth);
|
||||
QAmqpPlainAuthenticator *a = static_cast<QAmqpPlainAuthenticator*>(auth);
|
||||
a->setLogin(username);
|
||||
}
|
||||
}
|
||||
|
||||
void ClientPrivate::setPassword(const QString &password)
|
||||
void QAmqpClientPrivate::setPassword(const QString &password)
|
||||
{
|
||||
Authenticator *auth = authenticator.data();
|
||||
QAmqpAuthenticator *auth = authenticator.data();
|
||||
if (auth && auth->type() == QLatin1String("AMQPLAIN")) {
|
||||
AMQPlainAuthenticator *a = static_cast<AMQPlainAuthenticator*>(auth);
|
||||
QAmqpPlainAuthenticator *a = static_cast<QAmqpPlainAuthenticator*>(auth);
|
||||
a->setPassword(password);
|
||||
}
|
||||
}
|
||||
|
||||
void ClientPrivate::parseConnectionString(const QString &uri)
|
||||
void QAmqpClientPrivate::parseConnectionString(const QString &uri)
|
||||
{
|
||||
#if QT_VERSION > 0x040801
|
||||
QUrl connectionString = QUrl::fromUserInput(uri);
|
||||
|
|
@ -108,7 +107,7 @@ void ClientPrivate::parseConnectionString(const QString &uri)
|
|||
#endif
|
||||
}
|
||||
|
||||
void ClientPrivate::_q_connect()
|
||||
void QAmqpClientPrivate::_q_connect()
|
||||
{
|
||||
if (socket->state() != QAbstractSocket::UnconnectedState) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "socket already connected, disconnecting..";
|
||||
|
|
@ -118,7 +117,7 @@ void ClientPrivate::_q_connect()
|
|||
socket->connectToHost(host, port);
|
||||
}
|
||||
|
||||
void ClientPrivate::_q_disconnect()
|
||||
void QAmqpClientPrivate::_q_disconnect()
|
||||
{
|
||||
if (socket->state() == QAbstractSocket::UnconnectedState) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "already disconnected";
|
||||
|
|
@ -130,16 +129,16 @@ void ClientPrivate::_q_disconnect()
|
|||
}
|
||||
|
||||
// private slots
|
||||
void ClientPrivate::_q_socketConnected()
|
||||
void QAmqpClientPrivate::_q_socketConnected()
|
||||
{
|
||||
timeout = 0;
|
||||
char header[8] = {'A', 'M', 'Q', 'P', 0, 0, 9, 1};
|
||||
socket->write(header, 8);
|
||||
}
|
||||
|
||||
void ClientPrivate::_q_socketDisconnected()
|
||||
void QAmqpClientPrivate::_q_socketDisconnected()
|
||||
{
|
||||
Q_Q(Client);
|
||||
Q_Q(QAmqpClient);
|
||||
buffer.clear();
|
||||
if (connected) {
|
||||
connected = false;
|
||||
|
|
@ -147,15 +146,15 @@ void ClientPrivate::_q_socketDisconnected()
|
|||
}
|
||||
}
|
||||
|
||||
void ClientPrivate::_q_heartbeat()
|
||||
void QAmqpClientPrivate::_q_heartbeat()
|
||||
{
|
||||
Frame::Heartbeat frame;
|
||||
QAmqpHeartbeatFrame frame;
|
||||
sendFrame(frame);
|
||||
}
|
||||
|
||||
void ClientPrivate::_q_socketError(QAbstractSocket::SocketError error)
|
||||
void QAmqpClientPrivate::_q_socketError(QAbstractSocket::SocketError error)
|
||||
{
|
||||
Q_Q(Client);
|
||||
Q_Q(QAmqpClient);
|
||||
if (timeout == 0) {
|
||||
timeout = 1000;
|
||||
} else {
|
||||
|
|
@ -186,13 +185,13 @@ void ClientPrivate::_q_socketError(QAbstractSocket::SocketError error)
|
|||
}
|
||||
}
|
||||
|
||||
void ClientPrivate::_q_readyRead()
|
||||
void QAmqpClientPrivate::_q_readyRead()
|
||||
{
|
||||
while (socket->bytesAvailable() >= Frame::HEADER_SIZE) {
|
||||
unsigned char headerData[Frame::HEADER_SIZE];
|
||||
socket->peek((char*)headerData, Frame::HEADER_SIZE);
|
||||
while (socket->bytesAvailable() >= QAmqpFrame::HEADER_SIZE) {
|
||||
unsigned char headerData[QAmqpFrame::HEADER_SIZE];
|
||||
socket->peek((char*)headerData, QAmqpFrame::HEADER_SIZE);
|
||||
const quint32 payloadSize = qFromBigEndian<quint32>(headerData + 3);
|
||||
const qint64 readSize = Frame::HEADER_SIZE + payloadSize + Frame::FRAME_END_SIZE;
|
||||
const qint64 readSize = QAmqpFrame::HEADER_SIZE + payloadSize + QAmqpFrame::FRAME_END_SIZE;
|
||||
|
||||
if (socket->bytesAvailable() < readSize)
|
||||
return;
|
||||
|
|
@ -201,65 +200,65 @@ void ClientPrivate::_q_readyRead()
|
|||
socket->read(buffer.data(), readSize);
|
||||
const char *bufferData = buffer.constData();
|
||||
const quint8 type = *(quint8*)&bufferData[0];
|
||||
const quint8 magic = *(quint8*)&bufferData[Frame::HEADER_SIZE + payloadSize];
|
||||
if (magic != Frame::FRAME_END) {
|
||||
close(UnexpectedFrameError, "wrong end of frame");
|
||||
const quint8 magic = *(quint8*)&bufferData[QAmqpFrame::HEADER_SIZE + payloadSize];
|
||||
if (magic != QAmqpFrame::FRAME_END) {
|
||||
close(QAMQP::UnexpectedFrameError, "wrong end of frame");
|
||||
return;
|
||||
}
|
||||
|
||||
QDataStream streamB(&buffer, QIODevice::ReadOnly);
|
||||
switch(Frame::Type(type)) {
|
||||
case Frame::ftMethod:
|
||||
switch(QAmqpFrame::Type(type)) {
|
||||
case QAmqpFrame::ftMethod:
|
||||
{
|
||||
Frame::Method frame(streamB);
|
||||
QAmqpMethodFrame frame(streamB);
|
||||
if (frame.size() > frameMax) {
|
||||
close(FrameError, "frame size too large");
|
||||
close(QAMQP::FrameError, "frame size too large");
|
||||
return;
|
||||
}
|
||||
|
||||
if (frame.methodClass() == Frame::fcConnection) {
|
||||
if (frame.methodClass() == QAmqpFrame::fcConnection) {
|
||||
_q_method(frame);
|
||||
} else {
|
||||
foreach (Frame::MethodHandler *methodHandler, methodHandlersByChannel[frame.channel()])
|
||||
foreach (QAmqpMethodFrameHandler *methodHandler, methodHandlersByChannel[frame.channel()])
|
||||
methodHandler->_q_method(frame);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Frame::ftHeader:
|
||||
case QAmqpFrame::ftHeader:
|
||||
{
|
||||
Frame::Content frame(streamB);
|
||||
QAmqpContentFrame frame(streamB);
|
||||
if (frame.size() > frameMax) {
|
||||
close(FrameError, "frame size too large");
|
||||
close(QAMQP::FrameError, "frame size too large");
|
||||
return;
|
||||
} else if (frame.channel() <= 0) {
|
||||
close(ChannelError, "channel number must be greater than zero");
|
||||
close(QAMQP::ChannelError, "channel number must be greater than zero");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (Frame::ContentHandler *methodHandler, contentHandlerByChannel[frame.channel()])
|
||||
foreach (QAmqpContentFrameHandler *methodHandler, contentHandlerByChannel[frame.channel()])
|
||||
methodHandler->_q_content(frame);
|
||||
}
|
||||
break;
|
||||
case Frame::ftBody:
|
||||
case QAmqpFrame::ftBody:
|
||||
{
|
||||
Frame::ContentBody frame(streamB);
|
||||
QAmqpContentBodyFrame frame(streamB);
|
||||
if (frame.size() > frameMax) {
|
||||
close(FrameError, "frame size too large");
|
||||
close(QAMQP::FrameError, "frame size too large");
|
||||
return;
|
||||
} else if (frame.channel() <= 0) {
|
||||
close(ChannelError, "channel number must be greater than zero");
|
||||
close(QAMQP::ChannelError, "channel number must be greater than zero");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (Frame::ContentBodyHandler *methodHandler, bodyHandlersByChannel[frame.channel()])
|
||||
foreach (QAmqpContentBodyFrameHandler *methodHandler, bodyHandlersByChannel[frame.channel()])
|
||||
methodHandler->_q_body(frame);
|
||||
}
|
||||
break;
|
||||
case Frame::ftHeartbeat:
|
||||
case QAmqpFrame::ftHeartbeat:
|
||||
{
|
||||
Frame::Method frame(streamB);
|
||||
QAmqpMethodFrame frame(streamB);
|
||||
if (frame.channel() != 0) {
|
||||
close(FrameError, "heartbeat must have channel id zero");
|
||||
close(QAMQP::FrameError, "heartbeat must have channel id zero");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -268,13 +267,13 @@ void ClientPrivate::_q_readyRead()
|
|||
break;
|
||||
default:
|
||||
qAmqpDebug() << "AMQP: Unknown frame type: " << type;
|
||||
close(FrameError, "invalid frame type");
|
||||
close(QAMQP::FrameError, "invalid frame type");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClientPrivate::sendFrame(const Frame::Base &frame)
|
||||
void QAmqpClientPrivate::sendFrame(const QAmqpFrame &frame)
|
||||
{
|
||||
if (socket->state() != QAbstractSocket::ConnectedState) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "socket not connected: " << socket->state();
|
||||
|
|
@ -285,36 +284,36 @@ void ClientPrivate::sendFrame(const Frame::Base &frame)
|
|||
frame.toStream(stream);
|
||||
}
|
||||
|
||||
bool ClientPrivate::_q_method(const Frame::Method &frame)
|
||||
bool QAmqpClientPrivate::_q_method(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_ASSERT(frame.methodClass() == Frame::fcConnection);
|
||||
if (frame.methodClass() != Frame::fcConnection)
|
||||
Q_ASSERT(frame.methodClass() == QAmqpFrame::fcConnection);
|
||||
if (frame.methodClass() != QAmqpFrame::fcConnection)
|
||||
return false;
|
||||
|
||||
qAmqpDebug() << "Connection:";
|
||||
if (closed) {
|
||||
if (frame.id() == ClientPrivate::miCloseOk)
|
||||
if (frame.id() == QAmqpClientPrivate::miCloseOk)
|
||||
closeOk(frame);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (ClientPrivate::MethodId(frame.id())) {
|
||||
case ClientPrivate::miStart:
|
||||
switch (QAmqpClientPrivate::MethodId(frame.id())) {
|
||||
case QAmqpClientPrivate::miStart:
|
||||
start(frame);
|
||||
break;
|
||||
case ClientPrivate::miSecure:
|
||||
case QAmqpClientPrivate::miSecure:
|
||||
secure(frame);
|
||||
break;
|
||||
case ClientPrivate::miTune:
|
||||
case QAmqpClientPrivate::miTune:
|
||||
tune(frame);
|
||||
break;
|
||||
case ClientPrivate::miOpenOk:
|
||||
case QAmqpClientPrivate::miOpenOk:
|
||||
openOk(frame);
|
||||
break;
|
||||
case ClientPrivate::miClose:
|
||||
case QAmqpClientPrivate::miClose:
|
||||
close(frame);
|
||||
break;
|
||||
case ClientPrivate::miCloseOk:
|
||||
case QAmqpClientPrivate::miCloseOk:
|
||||
closeOk(frame);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -324,9 +323,9 @@ bool ClientPrivate::_q_method(const Frame::Method &frame)
|
|||
return true;
|
||||
}
|
||||
|
||||
void ClientPrivate::start(const Frame::Method &frame)
|
||||
void QAmqpClientPrivate::start(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Client);
|
||||
Q_Q(QAmqpClient);
|
||||
qAmqpDebug(">> Start");
|
||||
QByteArray data = frame.arguments();
|
||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||
|
|
@ -335,18 +334,18 @@ void ClientPrivate::start(const Frame::Method &frame)
|
|||
quint8 version_minor = 0;
|
||||
stream >> version_major >> version_minor;
|
||||
|
||||
Table table;
|
||||
QAmqpTable table;
|
||||
stream >> table;
|
||||
|
||||
QStringList mechanisms =
|
||||
Frame::readAmqpField(stream, MetaType::LongString).toString().split(' ');
|
||||
QString locales = Frame::readAmqpField(stream, MetaType::LongString).toString();
|
||||
QAmqpFrame::readAmqpField(stream, QAmqpMetaType::LongString).toString().split(' ');
|
||||
QString locales = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::LongString).toString();
|
||||
|
||||
qAmqpDebug(">> version_major: %d", version_major);
|
||||
qAmqpDebug(">> version_minor: %d", version_minor);
|
||||
|
||||
// NOTE: replace with qDebug overload
|
||||
// Frame::print(table);
|
||||
// QAmqpFrame::print(table);
|
||||
|
||||
qAmqpDebug() << ">> mechanisms: " << mechanisms;
|
||||
qAmqpDebug(">> locales: %s", qPrintable(locales));
|
||||
|
|
@ -360,13 +359,13 @@ void ClientPrivate::start(const Frame::Method &frame)
|
|||
startOk();
|
||||
}
|
||||
|
||||
void ClientPrivate::secure(const Frame::Method &frame)
|
||||
void QAmqpClientPrivate::secure(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_UNUSED(frame)
|
||||
qAmqpDebug() << Q_FUNC_INFO << "called!";
|
||||
}
|
||||
|
||||
void ClientPrivate::tune(const Frame::Method &frame)
|
||||
void QAmqpClientPrivate::tune(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
qAmqpDebug(">> Tune");
|
||||
QByteArray data = frame.arguments();
|
||||
|
|
@ -401,18 +400,18 @@ void ClientPrivate::tune(const Frame::Method &frame)
|
|||
open();
|
||||
}
|
||||
|
||||
void ClientPrivate::openOk(const Frame::Method &frame)
|
||||
void QAmqpClientPrivate::openOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Client);
|
||||
Q_Q(QAmqpClient);
|
||||
Q_UNUSED(frame)
|
||||
qAmqpDebug(">> OpenOK");
|
||||
connected = true;
|
||||
Q_EMIT q->connected();
|
||||
}
|
||||
|
||||
void ClientPrivate::closeOk(const Frame::Method &frame)
|
||||
void QAmqpClientPrivate::closeOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Client);
|
||||
Q_Q(QAmqpClient);
|
||||
Q_UNUSED(frame)
|
||||
qAmqpDebug() << Q_FUNC_INFO << "received";
|
||||
connected = false;
|
||||
|
|
@ -422,19 +421,19 @@ void ClientPrivate::closeOk(const Frame::Method &frame)
|
|||
Q_EMIT q->disconnected();
|
||||
}
|
||||
|
||||
void ClientPrivate::close(const Frame::Method &frame)
|
||||
void QAmqpClientPrivate::close(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Client);
|
||||
Q_Q(QAmqpClient);
|
||||
qAmqpDebug(">> CLOSE");
|
||||
QByteArray data = frame.arguments();
|
||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||
qint16 code = 0, classId, methodId;
|
||||
stream >> code;
|
||||
QString text = Frame::readAmqpField(stream, MetaType::ShortString).toString();
|
||||
QString text = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString();
|
||||
stream >> classId;
|
||||
stream >> methodId;
|
||||
|
||||
Error checkError = static_cast<Error>(code);
|
||||
QAMQP::Error checkError = static_cast<QAMQP::Error>(code);
|
||||
if (checkError != QAMQP::NoError) {
|
||||
error = checkError;
|
||||
errorString = qPrintable(text);
|
||||
|
|
@ -449,17 +448,17 @@ void ClientPrivate::close(const Frame::Method &frame)
|
|||
Q_EMIT q->disconnected();
|
||||
|
||||
// complete handshake
|
||||
Frame::Method closeOkFrame(Frame::fcConnection, ClientPrivate::miCloseOk);
|
||||
QAmqpMethodFrame closeOkFrame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miCloseOk);
|
||||
sendFrame(closeOkFrame);
|
||||
}
|
||||
|
||||
void ClientPrivate::startOk()
|
||||
void QAmqpClientPrivate::startOk()
|
||||
{
|
||||
Frame::Method frame(Frame::fcConnection, ClientPrivate::miStartOk);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miStartOk);
|
||||
QByteArray arguments;
|
||||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
Table clientProperties;
|
||||
QAmqpTable clientProperties;
|
||||
clientProperties["version"] = QString(QAMQP_VERSION);
|
||||
clientProperties["platform"] = QString("Qt %1").arg(qVersion());
|
||||
clientProperties["product"] = QString("QAMQP");
|
||||
|
|
@ -467,20 +466,20 @@ void ClientPrivate::startOk()
|
|||
stream << clientProperties;
|
||||
|
||||
authenticator->write(stream);
|
||||
Frame::writeAmqpField(stream, MetaType::ShortString, QLatin1String("en_US"));
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, QLatin1String("en_US"));
|
||||
|
||||
frame.setArguments(arguments);
|
||||
sendFrame(frame);
|
||||
}
|
||||
|
||||
void ClientPrivate::secureOk()
|
||||
void QAmqpClientPrivate::secureOk()
|
||||
{
|
||||
qAmqpDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
void ClientPrivate::tuneOk()
|
||||
void QAmqpClientPrivate::tuneOk()
|
||||
{
|
||||
Frame::Method frame(Frame::fcConnection, ClientPrivate::miTuneOk);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miTuneOk);
|
||||
QByteArray arguments;
|
||||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
|
|
@ -492,13 +491,13 @@ void ClientPrivate::tuneOk()
|
|||
sendFrame(frame);
|
||||
}
|
||||
|
||||
void ClientPrivate::open()
|
||||
void QAmqpClientPrivate::open()
|
||||
{
|
||||
Frame::Method frame(Frame::fcConnection, ClientPrivate::miOpen);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miOpen);
|
||||
QByteArray arguments;
|
||||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
Frame::writeAmqpField(stream, MetaType::ShortString, virtualHost);
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, virtualHost);
|
||||
|
||||
stream << qint8(0);
|
||||
stream << qint8(0);
|
||||
|
|
@ -507,130 +506,130 @@ void ClientPrivate::open()
|
|||
sendFrame(frame);
|
||||
}
|
||||
|
||||
void ClientPrivate::close(int code, const QString &text, int classId, int methodId)
|
||||
void QAmqpClientPrivate::close(int code, const QString &text, int classId, int methodId)
|
||||
{
|
||||
QByteArray arguments;
|
||||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
stream << qint16(code);
|
||||
Frame::writeAmqpField(stream, MetaType::ShortString, text);
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, text);
|
||||
stream << qint16(classId);
|
||||
stream << qint16(methodId);
|
||||
|
||||
Frame::Method frame(Frame::fcConnection, ClientPrivate::miClose);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miClose);
|
||||
frame.setArguments(arguments);
|
||||
sendFrame(frame);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Client::Client(QObject *parent)
|
||||
QAmqpClient::QAmqpClient(QObject *parent)
|
||||
: QObject(parent),
|
||||
d_ptr(new ClientPrivate(this))
|
||||
d_ptr(new QAmqpClientPrivate(this))
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
d->init();
|
||||
}
|
||||
|
||||
Client::Client(ClientPrivate *dd, QObject *parent)
|
||||
QAmqpClient::QAmqpClient(QAmqpClientPrivate *dd, QObject *parent)
|
||||
: QObject(parent),
|
||||
d_ptr(dd)
|
||||
{
|
||||
}
|
||||
|
||||
Client::~Client()
|
||||
QAmqpClient::~QAmqpClient()
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
if (d->connected)
|
||||
d->_q_disconnect();
|
||||
}
|
||||
|
||||
bool Client::isConnected() const
|
||||
bool QAmqpClient::isConnected() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
Q_D(const QAmqpClient);
|
||||
return d->connected;
|
||||
}
|
||||
|
||||
quint16 Client::port() const
|
||||
quint16 QAmqpClient::port() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
Q_D(const QAmqpClient);
|
||||
return d->port;
|
||||
}
|
||||
|
||||
void Client::setPort(quint16 port)
|
||||
void QAmqpClient::setPort(quint16 port)
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
d->port = port;
|
||||
}
|
||||
|
||||
QString Client::host() const
|
||||
QString QAmqpClient::host() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
Q_D(const QAmqpClient);
|
||||
return d->host;
|
||||
}
|
||||
|
||||
void Client::setHost(const QString &host)
|
||||
void QAmqpClient::setHost(const QString &host)
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
d->host = host;
|
||||
}
|
||||
|
||||
QString Client::virtualHost() const
|
||||
QString QAmqpClient::virtualHost() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
Q_D(const QAmqpClient);
|
||||
return d->virtualHost;
|
||||
}
|
||||
|
||||
void Client::setVirtualHost(const QString &virtualHost)
|
||||
void QAmqpClient::setVirtualHost(const QString &virtualHost)
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
d->virtualHost = virtualHost;
|
||||
}
|
||||
|
||||
QString Client::username() const
|
||||
QString QAmqpClient::username() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
const Authenticator *auth = d->authenticator.data();
|
||||
Q_D(const QAmqpClient);
|
||||
const QAmqpAuthenticator *auth = d->authenticator.data();
|
||||
if (auth && auth->type() == QLatin1String("AMQPLAIN")) {
|
||||
const AMQPlainAuthenticator *a = static_cast<const AMQPlainAuthenticator*>(auth);
|
||||
const QAmqpPlainAuthenticator *a = static_cast<const QAmqpPlainAuthenticator*>(auth);
|
||||
return a->login();
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
void Client::setUsername(const QString &username)
|
||||
void QAmqpClient::setUsername(const QString &username)
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
d->setUsername(username);
|
||||
}
|
||||
|
||||
QString Client::password() const
|
||||
QString QAmqpClient::password() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
const Authenticator *auth = d->authenticator.data();
|
||||
Q_D(const QAmqpClient);
|
||||
const QAmqpAuthenticator *auth = d->authenticator.data();
|
||||
if (auth && auth->type() == QLatin1String("AMQPLAIN")) {
|
||||
const AMQPlainAuthenticator *a = static_cast<const AMQPlainAuthenticator*>(auth);
|
||||
const QAmqpPlainAuthenticator *a = static_cast<const QAmqpPlainAuthenticator*>(auth);
|
||||
return a->password();
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
void Client::setPassword(const QString &password)
|
||||
void QAmqpClient::setPassword(const QString &password)
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
d->setPassword(password);
|
||||
}
|
||||
|
||||
Exchange *Client::createExchange(int channelNumber)
|
||||
QAmqpExchange *QAmqpClient::createExchange(int channelNumber)
|
||||
{
|
||||
return createExchange(QString(), channelNumber);
|
||||
}
|
||||
|
||||
Exchange *Client::createExchange(const QString &name, int channelNumber)
|
||||
QAmqpExchange *QAmqpClient::createExchange(const QString &name, int channelNumber)
|
||||
{
|
||||
Q_D(Client);
|
||||
Exchange *exchange = new Exchange(channelNumber, this);
|
||||
Q_D(QAmqpClient);
|
||||
QAmqpExchange *exchange = new QAmqpExchange(channelNumber, this);
|
||||
d->methodHandlersByChannel[exchange->channelNumber()].append(exchange->d_func());
|
||||
connect(this, SIGNAL(connected()), exchange, SLOT(_q_open()));
|
||||
connect(this, SIGNAL(disconnected()), exchange, SLOT(_q_disconnected()));
|
||||
|
|
@ -641,15 +640,15 @@ Exchange *Client::createExchange(const QString &name, int channelNumber)
|
|||
return exchange;
|
||||
}
|
||||
|
||||
Queue *Client::createQueue(int channelNumber)
|
||||
QAmqpQueue *QAmqpClient::createQueue(int channelNumber)
|
||||
{
|
||||
return createQueue(QString(), channelNumber);
|
||||
}
|
||||
|
||||
Queue *Client::createQueue(const QString &name, int channelNumber)
|
||||
QAmqpQueue *QAmqpClient::createQueue(const QString &name, int channelNumber)
|
||||
{
|
||||
Q_D(Client);
|
||||
Queue *queue = new Queue(channelNumber, this);
|
||||
Q_D(QAmqpClient);
|
||||
QAmqpQueue *queue = new QAmqpQueue(channelNumber, this);
|
||||
d->methodHandlersByChannel[queue->channelNumber()].append(queue->d_func());
|
||||
d->contentHandlerByChannel[queue->channelNumber()].append(queue->d_func());
|
||||
d->bodyHandlersByChannel[queue->channelNumber()].append(queue->d_func());
|
||||
|
|
@ -662,39 +661,39 @@ Queue *Client::createQueue(const QString &name, int channelNumber)
|
|||
return queue;
|
||||
}
|
||||
|
||||
void Client::setAuth(Authenticator *authenticator)
|
||||
void QAmqpClient::setAuth(QAmqpAuthenticator *authenticator)
|
||||
{
|
||||
Q_D(Client);
|
||||
d->authenticator = QSharedPointer<Authenticator>(authenticator);
|
||||
Q_D(QAmqpClient);
|
||||
d->authenticator = QSharedPointer<QAmqpAuthenticator>(authenticator);
|
||||
}
|
||||
|
||||
Authenticator *Client::auth() const
|
||||
QAmqpAuthenticator *QAmqpClient::auth() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
Q_D(const QAmqpClient);
|
||||
return d->authenticator.data();
|
||||
}
|
||||
|
||||
bool Client::autoReconnect() const
|
||||
bool QAmqpClient::autoReconnect() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
Q_D(const QAmqpClient);
|
||||
return d->autoReconnect;
|
||||
}
|
||||
|
||||
void Client::setAutoReconnect(bool value)
|
||||
void QAmqpClient::setAutoReconnect(bool value)
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
d->autoReconnect = value;
|
||||
}
|
||||
|
||||
qint16 Client::channelMax() const
|
||||
qint16 QAmqpClient::channelMax() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
Q_D(const QAmqpClient);
|
||||
return d->channelMax;
|
||||
}
|
||||
|
||||
void Client::setChannelMax(qint16 channelMax)
|
||||
void QAmqpClient::setChannelMax(qint16 channelMax)
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
if (d->connected) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "can't modify value while connected";
|
||||
return;
|
||||
|
|
@ -703,15 +702,15 @@ void Client::setChannelMax(qint16 channelMax)
|
|||
d->channelMax = channelMax;
|
||||
}
|
||||
|
||||
qint32 Client::frameMax() const
|
||||
qint32 QAmqpClient::frameMax() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
Q_D(const QAmqpClient);
|
||||
return d->frameMax;
|
||||
}
|
||||
|
||||
void Client::setFrameMax(qint32 frameMax)
|
||||
void QAmqpClient::setFrameMax(qint32 frameMax)
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
if (d->connected) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "can't modify value while connected";
|
||||
return;
|
||||
|
|
@ -720,15 +719,15 @@ void Client::setFrameMax(qint32 frameMax)
|
|||
d->frameMax = qMax(frameMax, AMQP_FRAME_MIN_SIZE);
|
||||
}
|
||||
|
||||
qint16 Client::heartbeatDelay() const
|
||||
qint16 QAmqpClient::heartbeatDelay() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
Q_D(const QAmqpClient);
|
||||
return d->heartbeatDelay;
|
||||
}
|
||||
|
||||
void Client::setHeartbeatDelay(qint16 delay)
|
||||
void QAmqpClient::setHeartbeatDelay(qint16 delay)
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
if (d->connected) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "can't modify value while connected";
|
||||
return;
|
||||
|
|
@ -737,33 +736,33 @@ void Client::setHeartbeatDelay(qint16 delay)
|
|||
d->heartbeatDelay = delay;
|
||||
}
|
||||
|
||||
void Client::addCustomProperty(const QString &name, const QString &value)
|
||||
void QAmqpClient::addCustomProperty(const QString &name, const QString &value)
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
d->customProperties.insert(name, value);
|
||||
}
|
||||
|
||||
QString Client::customProperty(const QString &name) const
|
||||
QString QAmqpClient::customProperty(const QString &name) const
|
||||
{
|
||||
Q_D(const Client);
|
||||
Q_D(const QAmqpClient);
|
||||
return d->customProperties.value(name).toString();
|
||||
}
|
||||
|
||||
Error Client::error() const
|
||||
QAMQP::Error QAmqpClient::error() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
Q_D(const QAmqpClient);
|
||||
return d->error;
|
||||
}
|
||||
|
||||
QString Client::errorString() const
|
||||
QString QAmqpClient::errorString() const
|
||||
{
|
||||
Q_D(const Client);
|
||||
Q_D(const QAmqpClient);
|
||||
return d->errorString;
|
||||
}
|
||||
|
||||
void Client::connectToHost(const QString &uri)
|
||||
void QAmqpClient::connectToHost(const QString &uri)
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
if (uri.isEmpty()) {
|
||||
d->_q_connect();
|
||||
return;
|
||||
|
|
@ -773,17 +772,17 @@ void Client::connectToHost(const QString &uri)
|
|||
d->_q_connect();
|
||||
}
|
||||
|
||||
void Client::connectToHost(const QHostAddress &address, quint16 port)
|
||||
void QAmqpClient::connectToHost(const QHostAddress &address, quint16 port)
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
d->host = address.toString();
|
||||
d->port = port;
|
||||
d->_q_connect();
|
||||
}
|
||||
|
||||
void Client::disconnectFromHost()
|
||||
void QAmqpClient::disconnectFromHost()
|
||||
{
|
||||
Q_D(Client);
|
||||
Q_D(QAmqpClient);
|
||||
d->_q_disconnect();
|
||||
}
|
||||
|
||||
|
|
@ -792,14 +791,14 @@ void Client::disconnectFromHost()
|
|||
#ifndef QT_NO_SSL
|
||||
#include <QSslSocket>
|
||||
|
||||
SslClientPrivate::SslClientPrivate(SslClient *q)
|
||||
: ClientPrivate(q)
|
||||
QAmqpSslClientPrivate::QAmqpSslClientPrivate(QAmqpSslClient *q)
|
||||
: QAmqpClientPrivate(q)
|
||||
{
|
||||
}
|
||||
|
||||
void SslClientPrivate::initSocket()
|
||||
void QAmqpSslClientPrivate::initSocket()
|
||||
{
|
||||
Q_Q(Client);
|
||||
Q_Q(QAmqpClient);
|
||||
QSslSocket *sslSocket = new QSslSocket(q);
|
||||
QObject::connect(sslSocket, SIGNAL(connected()), q, SLOT(_q_socketConnected()));
|
||||
QObject::connect(sslSocket, SIGNAL(disconnected()), q, SLOT(_q_socketDisconnected()));
|
||||
|
|
@ -811,7 +810,7 @@ void SslClientPrivate::initSocket()
|
|||
socket = sslSocket;
|
||||
}
|
||||
|
||||
void SslClientPrivate::_q_connect()
|
||||
void QAmqpSslClientPrivate::_q_connect()
|
||||
{
|
||||
if (socket->state() != QAbstractSocket::UnconnectedState) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "socket already connected, disconnecting..";
|
||||
|
|
@ -824,7 +823,7 @@ void SslClientPrivate::_q_connect()
|
|||
sslSocket->connectToHostEncrypted(host, port);
|
||||
}
|
||||
|
||||
void SslClientPrivate::_q_sslErrors(const QList<QSslError> &errors)
|
||||
void QAmqpSslClientPrivate::_q_sslErrors(const QList<QSslError> &errors)
|
||||
{
|
||||
// TODO: these need to be passed on to the user potentially, this is
|
||||
// very unsafe
|
||||
|
|
@ -832,12 +831,12 @@ void SslClientPrivate::_q_sslErrors(const QList<QSslError> &errors)
|
|||
sslSocket->ignoreSslErrors(errors);
|
||||
}
|
||||
|
||||
SslClient::SslClient(QObject *parent)
|
||||
: Client(new SslClientPrivate(this), parent)
|
||||
QAmqpSslClient::QAmqpSslClient(QObject *parent)
|
||||
: QAmqpClient(new QAmqpSslClientPrivate(this), parent)
|
||||
{
|
||||
}
|
||||
|
||||
SslClient::~SslClient()
|
||||
QAmqpSslClient::~QAmqpSslClient()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,14 +12,11 @@
|
|||
|
||||
#include "qamqpglobal.h"
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
class Exchange;
|
||||
class Queue;
|
||||
class Authenticator;
|
||||
class ClientPrivate;
|
||||
class QAMQP_EXPORT Client : public QObject
|
||||
class QAmqpExchange;
|
||||
class QAmqpQueue;
|
||||
class QAmqpAuthenticator;
|
||||
class QAmqpClientPrivate;
|
||||
class QAMQP_EXPORT QAmqpClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(quint32 port READ port WRITE setPort)
|
||||
|
|
@ -33,8 +30,8 @@ class QAMQP_EXPORT Client : public QObject
|
|||
Q_PROPERTY(qint16 heartbeatDelay READ heartbeatDelay() WRITE setHeartbeatDelay)
|
||||
|
||||
public:
|
||||
explicit Client(QObject *parent = 0);
|
||||
~Client();
|
||||
explicit QAmqpClient(QObject *parent = 0);
|
||||
~QAmqpClient();
|
||||
|
||||
// properties
|
||||
quint16 port() const;
|
||||
|
|
@ -52,8 +49,8 @@ public:
|
|||
QString password() const;
|
||||
void setPassword(const QString &password);
|
||||
|
||||
void setAuth(Authenticator *auth);
|
||||
Authenticator *auth() const;
|
||||
void setAuth(QAmqpAuthenticator *auth);
|
||||
QAmqpAuthenticator *auth() const;
|
||||
|
||||
bool autoReconnect() const;
|
||||
void setAutoReconnect(bool value);
|
||||
|
|
@ -72,15 +69,15 @@ public:
|
|||
void addCustomProperty(const QString &name, const QString &value);
|
||||
QString customProperty(const QString &name) const;
|
||||
|
||||
Error error() const;
|
||||
QAMQP::Error error() const;
|
||||
QString errorString() const;
|
||||
|
||||
// channels
|
||||
Exchange *createExchange(int channelNumber = -1);
|
||||
Exchange *createExchange(const QString &name, int channelNumber = -1);
|
||||
QAmqpExchange *createExchange(int channelNumber = -1);
|
||||
QAmqpExchange *createExchange(const QString &name, int channelNumber = -1);
|
||||
|
||||
Queue *createQueue(int channelNumber = -1);
|
||||
Queue *createQueue(const QString &name, int channelNumber = -1);
|
||||
QAmqpQueue *createQueue(int channelNumber = -1);
|
||||
QAmqpQueue *createQueue(const QString &name, int channelNumber = -1);
|
||||
|
||||
// methods
|
||||
void connectToHost(const QString &uri = QString());
|
||||
|
|
@ -93,11 +90,11 @@ Q_SIGNALS:
|
|||
void error(QAMQP::Error error);
|
||||
|
||||
protected:
|
||||
Client(ClientPrivate *dd, QObject *parent = 0);
|
||||
QAmqpClient(QAmqpClientPrivate *dd, QObject *parent = 0);
|
||||
|
||||
Q_DISABLE_COPY(Client)
|
||||
Q_DECLARE_PRIVATE(Client)
|
||||
QScopedPointer<ClientPrivate> d_ptr;
|
||||
Q_DISABLE_COPY(QAmqpClient)
|
||||
Q_DECLARE_PRIVATE(QAmqpClient)
|
||||
QScopedPointer<QAmqpClientPrivate> d_ptr;
|
||||
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_socketConnected())
|
||||
|
|
@ -108,32 +105,30 @@ private:
|
|||
Q_PRIVATE_SLOT(d_func(), void _q_connect())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_disconnect())
|
||||
|
||||
friend class ChannelPrivate;
|
||||
friend class QAmqpChannelPrivate;
|
||||
|
||||
};
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
class SslClientPrivate;
|
||||
class SslClient : public Client
|
||||
class QAmqpSslClientPrivate;
|
||||
class QAmqpSslClient : public QAmqpClient
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SslClient(QObject *parent = 0);
|
||||
SslClient(const QUrl &connectionString, QObject *parent = 0);
|
||||
~SslClient();
|
||||
QAmqpSslClient(QObject *parent = 0);
|
||||
QAmqpSslClient(const QUrl &connectionString, QObject *parent = 0);
|
||||
~QAmqpSslClient();
|
||||
|
||||
QSslConfiguration sslConfiguration() const;
|
||||
void setSslConfiguration(const QSslConfiguration &config);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(SslClient)
|
||||
Q_DECLARE_PRIVATE(SslClient)
|
||||
Q_DISABLE_COPY(QAmqpSslClient)
|
||||
Q_DECLARE_PRIVATE(QAmqpSslClient)
|
||||
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_sslErrors(const QList<QSslError> &errors))
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
#endif // QAMQPCLIENT_H
|
||||
|
|
|
|||
|
|
@ -20,16 +20,12 @@
|
|||
|
||||
class QTimer;
|
||||
class QTcpSocket;
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
class Client;
|
||||
class Queue;
|
||||
class Exchange;
|
||||
class Network;
|
||||
class Connection;
|
||||
class Authenticator;
|
||||
class QAMQP_EXPORT ClientPrivate : public Frame::MethodHandler
|
||||
class QAmqpClient;
|
||||
class QAmqpQueue;
|
||||
class QAmqpExchange;
|
||||
class QAmqpConnection;
|
||||
class QAmqpAuthenticator;
|
||||
class QAMQP_EXPORT QAmqpClientPrivate : public QAmqpMethodFrameHandler
|
||||
{
|
||||
public:
|
||||
enum MethodId {
|
||||
|
|
@ -40,15 +36,15 @@ public:
|
|||
METHOD_ID_ENUM(miClose, 50)
|
||||
};
|
||||
|
||||
ClientPrivate(Client *q);
|
||||
virtual ~ClientPrivate();
|
||||
QAmqpClientPrivate(QAmqpClient *q);
|
||||
virtual ~QAmqpClientPrivate();
|
||||
|
||||
virtual void init();
|
||||
virtual void initSocket();
|
||||
void setUsername(const QString &username);
|
||||
void setPassword(const QString &password);
|
||||
void parseConnectionString(const QString &uri);
|
||||
void sendFrame(const Frame::Base &frame);
|
||||
void sendFrame(const QAmqpFrame &frame);
|
||||
|
||||
// private slots
|
||||
void _q_socketConnected();
|
||||
|
|
@ -59,14 +55,14 @@ public:
|
|||
virtual void _q_connect();
|
||||
void _q_disconnect();
|
||||
|
||||
virtual bool _q_method(const Frame::Method &frame);
|
||||
virtual bool _q_method(const QAmqpMethodFrame &frame);
|
||||
|
||||
// method handlers, FROM server
|
||||
void start(const Frame::Method &frame);
|
||||
void secure(const Frame::Method &frame);
|
||||
void tune(const Frame::Method &frame);
|
||||
void openOk(const Frame::Method &frame);
|
||||
void closeOk(const Frame::Method &frame);
|
||||
void start(const QAmqpMethodFrame &frame);
|
||||
void secure(const QAmqpMethodFrame &frame);
|
||||
void tune(const QAmqpMethodFrame &frame);
|
||||
void openOk(const QAmqpMethodFrame &frame);
|
||||
void closeOk(const QAmqpMethodFrame &frame);
|
||||
|
||||
// method handlers, TO server
|
||||
void startOk();
|
||||
|
|
@ -76,13 +72,13 @@ public:
|
|||
|
||||
// method handlers, BOTH ways
|
||||
void close(int code, const QString &text, int classId = 0, int methodId = 0);
|
||||
void close(const Frame::Method &frame);
|
||||
void close(const QAmqpMethodFrame &frame);
|
||||
|
||||
quint16 port;
|
||||
QString host;
|
||||
QString virtualHost;
|
||||
|
||||
QSharedPointer<Authenticator> authenticator;
|
||||
QSharedPointer<QAmqpAuthenticator> authenticator;
|
||||
|
||||
// Network
|
||||
QByteArray buffer;
|
||||
|
|
@ -91,33 +87,33 @@ public:
|
|||
bool connecting;
|
||||
QTcpSocket *socket;
|
||||
|
||||
QHash<quint16, QList<Frame::MethodHandler*> > methodHandlersByChannel;
|
||||
QHash<quint16, QList<Frame::ContentHandler*> > contentHandlerByChannel;
|
||||
QHash<quint16, QList<Frame::ContentBodyHandler*> > bodyHandlersByChannel;
|
||||
QHash<quint16, QList<QAmqpMethodFrameHandler*> > methodHandlersByChannel;
|
||||
QHash<quint16, QList<QAmqpContentFrameHandler*> > contentHandlerByChannel;
|
||||
QHash<quint16, QList<QAmqpContentBodyFrameHandler*> > bodyHandlersByChannel;
|
||||
|
||||
// Connection
|
||||
bool closed;
|
||||
bool connected;
|
||||
QPointer<QTimer> heartbeatTimer;
|
||||
Table customProperties;
|
||||
QAmqpTable customProperties;
|
||||
qint16 channelMax;
|
||||
qint16 heartbeatDelay;
|
||||
qint32 frameMax;
|
||||
|
||||
Error error;
|
||||
QAMQP::Error error;
|
||||
QString errorString;
|
||||
|
||||
Client * const q_ptr;
|
||||
Q_DECLARE_PUBLIC(Client)
|
||||
QAmqpClient * const q_ptr;
|
||||
Q_DECLARE_PUBLIC(QAmqpClient)
|
||||
|
||||
};
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
class SslClient;
|
||||
class SslClientPrivate : public ClientPrivate
|
||||
class QAmqpSslClient;
|
||||
class QAmqpSslClientPrivate : public QAmqpClientPrivate
|
||||
{
|
||||
public:
|
||||
SslClientPrivate(SslClient *q);
|
||||
QAmqpSslClientPrivate(QAmqpSslClient *q);
|
||||
|
||||
virtual void initSocket();
|
||||
virtual void _q_connect();
|
||||
|
|
@ -130,6 +126,4 @@ public:
|
|||
};
|
||||
#endif
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
#endif // QAMQPCLIENT_P_H
|
||||
|
|
|
|||
|
|
@ -6,28 +6,27 @@
|
|||
#include "qamqpqueue.h"
|
||||
#include "qamqpglobal.h"
|
||||
#include "qamqpclient.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
QString ExchangePrivate::typeToString(Exchange::ExchangeType type)
|
||||
QString QAmqpExchangePrivate::typeToString(QAmqpExchange::ExchangeType type)
|
||||
{
|
||||
switch (type) {
|
||||
case Exchange::Direct: return QLatin1String("direct");
|
||||
case Exchange::FanOut: return QLatin1String("fanout");
|
||||
case Exchange::Topic: return QLatin1String("topic");
|
||||
case Exchange::Headers: return QLatin1String("headers");
|
||||
case QAmqpExchange::Direct: return QLatin1String("direct");
|
||||
case QAmqpExchange::FanOut: return QLatin1String("fanout");
|
||||
case QAmqpExchange::Topic: return QLatin1String("topic");
|
||||
case QAmqpExchange::Headers: return QLatin1String("headers");
|
||||
}
|
||||
|
||||
return QLatin1String("direct");
|
||||
}
|
||||
|
||||
ExchangePrivate::ExchangePrivate(Exchange *q)
|
||||
: ChannelPrivate(q),
|
||||
QAmqpExchangePrivate::QAmqpExchangePrivate(QAmqpExchange *q)
|
||||
: QAmqpChannelPrivate(q),
|
||||
delayedDeclare(false),
|
||||
declared(false)
|
||||
{
|
||||
}
|
||||
|
||||
void ExchangePrivate::declare()
|
||||
void QAmqpExchangePrivate::declare()
|
||||
{
|
||||
if (!opened) {
|
||||
delayedDeclare = true;
|
||||
|
|
@ -39,30 +38,30 @@ void ExchangePrivate::declare()
|
|||
return;
|
||||
}
|
||||
|
||||
Frame::Method frame(Frame::fcExchange, ExchangePrivate::miDeclare);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcExchange, QAmqpExchangePrivate::miDeclare);
|
||||
frame.setChannel(channelNumber);
|
||||
|
||||
QByteArray args;
|
||||
QDataStream stream(&args, QIODevice::WriteOnly);
|
||||
|
||||
stream << qint16(0); //reserved 1
|
||||
Frame::writeAmqpField(stream, MetaType::ShortString, name);
|
||||
Frame::writeAmqpField(stream, MetaType::ShortString, type);
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, name);
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, type);
|
||||
|
||||
stream << qint8(options);
|
||||
Frame::writeAmqpField(stream, MetaType::Hash, arguments);
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::Hash, arguments);
|
||||
|
||||
frame.setArguments(args);
|
||||
sendFrame(frame);
|
||||
delayedDeclare = false;
|
||||
}
|
||||
|
||||
bool ExchangePrivate::_q_method(const Frame::Method &frame)
|
||||
bool QAmqpExchangePrivate::_q_method(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
if (ChannelPrivate::_q_method(frame))
|
||||
if (QAmqpChannelPrivate::_q_method(frame))
|
||||
return true;
|
||||
|
||||
if (frame.methodClass() == Frame::fcExchange) {
|
||||
if (frame.methodClass() == QAmqpFrame::fcExchange) {
|
||||
switch (frame.id()) {
|
||||
case miDeclareOk:
|
||||
declareOk(frame);
|
||||
|
|
@ -77,7 +76,7 @@ bool ExchangePrivate::_q_method(const Frame::Method &frame)
|
|||
}
|
||||
|
||||
return true;
|
||||
} else if (frame.methodClass() == Frame::fcBasic) {
|
||||
} else if (frame.methodClass() == QAmqpFrame::fcBasic) {
|
||||
switch (frame.id()) {
|
||||
case bmReturn:
|
||||
basicReturn(frame);
|
||||
|
|
@ -93,47 +92,47 @@ bool ExchangePrivate::_q_method(const Frame::Method &frame)
|
|||
return false;
|
||||
}
|
||||
|
||||
void ExchangePrivate::declareOk(const Frame::Method &frame)
|
||||
void QAmqpExchangePrivate::declareOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_UNUSED(frame)
|
||||
|
||||
Q_Q(Exchange);
|
||||
Q_Q(QAmqpExchange);
|
||||
qAmqpDebug() << "declared exchange: " << name;
|
||||
declared = true;
|
||||
Q_EMIT q->declared();
|
||||
}
|
||||
|
||||
void ExchangePrivate::deleteOk(const Frame::Method &frame)
|
||||
void QAmqpExchangePrivate::deleteOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_UNUSED(frame)
|
||||
|
||||
Q_Q(Exchange);
|
||||
Q_Q(QAmqpExchange);
|
||||
qAmqpDebug() << "deleted exchange: " << name;
|
||||
declared = false;
|
||||
Q_EMIT q->removed();
|
||||
}
|
||||
|
||||
void ExchangePrivate::_q_disconnected()
|
||||
void QAmqpExchangePrivate::_q_disconnected()
|
||||
{
|
||||
ChannelPrivate::_q_disconnected();
|
||||
QAmqpChannelPrivate::_q_disconnected();
|
||||
qAmqpDebug() << "exchange " << name << " disconnected";
|
||||
delayedDeclare = false;
|
||||
declared = false;
|
||||
}
|
||||
|
||||
void ExchangePrivate::basicReturn(const Frame::Method &frame)
|
||||
void QAmqpExchangePrivate::basicReturn(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Exchange);
|
||||
Q_Q(QAmqpExchange);
|
||||
QByteArray data = frame.arguments();
|
||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||
|
||||
quint16 replyCode;
|
||||
stream >> replyCode;
|
||||
QString replyText = Frame::readAmqpField(stream, MetaType::ShortString).toString();
|
||||
QString exchangeName = Frame::readAmqpField(stream, MetaType::ShortString).toString();
|
||||
QString routingKey = Frame::readAmqpField(stream, MetaType::ShortString).toString();
|
||||
QString replyText = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString();
|
||||
QString exchangeName = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString();
|
||||
QString routingKey = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString();
|
||||
|
||||
Error checkError = static_cast<Error>(replyCode);
|
||||
QAMQP::Error checkError = static_cast<QAMQP::Error>(replyCode);
|
||||
if (checkError != QAMQP::NoError) {
|
||||
error = checkError;
|
||||
errorString = qPrintable(replyText);
|
||||
|
|
@ -148,113 +147,113 @@ void ExchangePrivate::basicReturn(const Frame::Method &frame)
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Exchange::Exchange(int channelNumber, Client *parent)
|
||||
: Channel(new ExchangePrivate(this), parent)
|
||||
QAmqpExchange::QAmqpExchange(int channelNumber, QAmqpClient *parent)
|
||||
: QAmqpChannel(new QAmqpExchangePrivate(this), parent)
|
||||
{
|
||||
Q_D(Exchange);
|
||||
Q_D(QAmqpExchange);
|
||||
d->init(channelNumber, parent);
|
||||
}
|
||||
|
||||
Exchange::~Exchange()
|
||||
QAmqpExchange::~QAmqpExchange()
|
||||
{
|
||||
}
|
||||
|
||||
void Exchange::channelOpened()
|
||||
void QAmqpExchange::channelOpened()
|
||||
{
|
||||
Q_D(Exchange);
|
||||
Q_D(QAmqpExchange);
|
||||
if (d->delayedDeclare)
|
||||
d->declare();
|
||||
}
|
||||
|
||||
void Exchange::channelClosed()
|
||||
void QAmqpExchange::channelClosed()
|
||||
{
|
||||
}
|
||||
|
||||
Exchange::ExchangeOptions Exchange::options() const
|
||||
QAmqpExchange::ExchangeOptions QAmqpExchange::options() const
|
||||
{
|
||||
Q_D(const Exchange);
|
||||
Q_D(const QAmqpExchange);
|
||||
return d->options;
|
||||
}
|
||||
|
||||
QString Exchange::type() const
|
||||
QString QAmqpExchange::type() const
|
||||
{
|
||||
Q_D(const Exchange);
|
||||
Q_D(const QAmqpExchange);
|
||||
return d->type;
|
||||
}
|
||||
|
||||
void Exchange::declare(ExchangeType type, ExchangeOptions options, const Table &args)
|
||||
void QAmqpExchange::declare(ExchangeType type, ExchangeOptions options, const QAmqpTable &args)
|
||||
{
|
||||
declare(ExchangePrivate::typeToString(type), options, args);
|
||||
declare(QAmqpExchangePrivate::typeToString(type), options, args);
|
||||
}
|
||||
|
||||
void Exchange::declare(const QString &type, ExchangeOptions options, const Table &args)
|
||||
void QAmqpExchange::declare(const QString &type, ExchangeOptions options, const QAmqpTable &args)
|
||||
{
|
||||
Q_D(Exchange);
|
||||
Q_D(QAmqpExchange);
|
||||
d->type = type;
|
||||
d->options = options;
|
||||
d->arguments = args;
|
||||
d->declare();
|
||||
}
|
||||
|
||||
void Exchange::remove(int options)
|
||||
void QAmqpExchange::remove(int options)
|
||||
{
|
||||
Q_D(Exchange);
|
||||
Frame::Method frame(Frame::fcExchange, ExchangePrivate::miDelete);
|
||||
Q_D(QAmqpExchange);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcExchange, QAmqpExchangePrivate::miDelete);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
stream << qint16(0); //reserved 1
|
||||
Frame::writeAmqpField(stream, MetaType::ShortString, d->name);
|
||||
QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, d->name);
|
||||
stream << qint8(options);
|
||||
|
||||
frame.setArguments(arguments);
|
||||
d->sendFrame(frame);
|
||||
}
|
||||
|
||||
void Exchange::publish(const QString &message, const QString &routingKey,
|
||||
const Message::PropertyHash &properties, int publishOptions)
|
||||
void QAmqpExchange::publish(const QString &message, const QString &routingKey,
|
||||
const QAmqpMessage::PropertyHash &properties, int publishOptions)
|
||||
{
|
||||
publish(message.toUtf8(), routingKey, QLatin1String("text.plain"),
|
||||
Table(), properties, publishOptions);
|
||||
QAmqpTable(), properties, publishOptions);
|
||||
}
|
||||
|
||||
void Exchange::publish(const QByteArray &message, const QString &routingKey,
|
||||
const QString &mimeType, const Message::PropertyHash &properties,
|
||||
int publishOptions)
|
||||
void QAmqpExchange::publish(const QByteArray &message, const QString &routingKey,
|
||||
const QString &mimeType, const QAmqpMessage::PropertyHash &properties,
|
||||
int publishOptions)
|
||||
{
|
||||
publish(message, routingKey, mimeType, Table(), properties, publishOptions);
|
||||
publish(message, routingKey, mimeType, QAmqpTable(), properties, publishOptions);
|
||||
}
|
||||
|
||||
void Exchange::publish(const QByteArray &message, const QString &routingKey,
|
||||
const QString &mimeType, const Table &headers,
|
||||
const Message::PropertyHash &properties, int publishOptions)
|
||||
void QAmqpExchange::publish(const QByteArray &message, const QString &routingKey,
|
||||
const QString &mimeType, const QAmqpTable &headers,
|
||||
const QAmqpMessage::PropertyHash &properties, int publishOptions)
|
||||
{
|
||||
Q_D(Exchange);
|
||||
Frame::Method frame(Frame::fcBasic, ExchangePrivate::bmPublish);
|
||||
Q_D(QAmqpExchange);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpExchangePrivate::bmPublish);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
QDataStream out(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
out << qint16(0); //reserved 1
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, d->name);
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, routingKey);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, routingKey);
|
||||
out << qint8(publishOptions);
|
||||
|
||||
frame.setArguments(arguments);
|
||||
d->sendFrame(frame);
|
||||
|
||||
Frame::Content content(Frame::fcBasic);
|
||||
QAmqpContentFrame content(QAmqpFrame::fcBasic);
|
||||
content.setChannel(d->channelNumber);
|
||||
content.setProperty(Message::ContentType, mimeType);
|
||||
content.setProperty(Message::ContentEncoding, "utf-8");
|
||||
content.setProperty(Message::Headers, headers);
|
||||
content.setProperty(Message::MessageId, "0");
|
||||
content.setProperty(QAmqpMessage::ContentType, mimeType);
|
||||
content.setProperty(QAmqpMessage::ContentEncoding, "utf-8");
|
||||
content.setProperty(QAmqpMessage::Headers, headers);
|
||||
content.setProperty(QAmqpMessage::MessageId, "0");
|
||||
|
||||
Message::PropertyHash::ConstIterator it;
|
||||
Message::PropertyHash::ConstIterator itEnd = properties.constEnd();
|
||||
QAmqpMessage::PropertyHash::ConstIterator it;
|
||||
QAmqpMessage::PropertyHash::ConstIterator itEnd = properties.constEnd();
|
||||
for (it = properties.constBegin(); it != itEnd; ++it)
|
||||
content.setProperty(it.key(), it.value());
|
||||
content.setBodySize(message.size());
|
||||
|
|
@ -262,7 +261,7 @@ void Exchange::publish(const QByteArray &message, const QString &routingKey,
|
|||
|
||||
int fullSize = message.size();
|
||||
for (int sent = 0; sent < fullSize; sent += (d->client->frameMax() - 7)) {
|
||||
Frame::ContentBody body;
|
||||
QAmqpContentBodyFrame body;
|
||||
QByteArray partition = message.mid(sent, (d->client->frameMax() - 7));
|
||||
body.setChannel(d->channelNumber);
|
||||
body.setBody(partition);
|
||||
|
|
|
|||
|
|
@ -5,14 +5,11 @@
|
|||
#include "qamqpchannel.h"
|
||||
#include "qamqpmessage.h"
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
class Client;
|
||||
class Queue;
|
||||
class ClientPrivate;
|
||||
class ExchangePrivate;
|
||||
class QAMQP_EXPORT Exchange : public Channel
|
||||
class QAmqpClient;
|
||||
class QAmqpQueue;
|
||||
class QAmqpClientPrivate;
|
||||
class QAmqpExchangePrivate;
|
||||
class QAMQP_EXPORT QAmqpExchange : public QAmqpChannel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString type READ type CONSTANT)
|
||||
|
|
@ -53,27 +50,27 @@ public:
|
|||
Q_DECLARE_FLAGS(ExchangeOptions, ExchangeOption)
|
||||
ExchangeOptions options() const;
|
||||
|
||||
virtual ~Exchange();
|
||||
virtual ~QAmqpExchange();
|
||||
|
||||
// AMQP Exchange
|
||||
void declare(ExchangeType type = Direct,
|
||||
ExchangeOptions options = NoOptions,
|
||||
const Table &args = Table());
|
||||
const QAmqpTable &args = QAmqpTable());
|
||||
void declare(const QString &type = QLatin1String("direct"),
|
||||
ExchangeOptions options = NoOptions,
|
||||
const Table &args = Table());
|
||||
const QAmqpTable &args = QAmqpTable());
|
||||
void remove(int options = roIfUnused|roNoWait);
|
||||
|
||||
// AMQP Basic
|
||||
void publish(const QString &message, const QString &routingKey,
|
||||
const Message::PropertyHash &properties = Message::PropertyHash(),
|
||||
const QAmqpMessage::PropertyHash &properties = QAmqpMessage::PropertyHash(),
|
||||
int publishOptions = poNoOptions);
|
||||
void publish(const QByteArray &message, const QString &routingKey, const QString &mimeType,
|
||||
const Message::PropertyHash &properties = Message::PropertyHash(),
|
||||
const QAmqpMessage::PropertyHash &properties = QAmqpMessage::PropertyHash(),
|
||||
int publishOptions = poNoOptions);
|
||||
void publish(const QByteArray &message, const QString &routingKey,
|
||||
const QString &mimeType, const Table &headers,
|
||||
const Message::PropertyHash &properties = Message::PropertyHash(),
|
||||
const QString &mimeType, const QAmqpTable &headers,
|
||||
const QAmqpMessage::PropertyHash &properties = QAmqpMessage::PropertyHash(),
|
||||
int publishOptions = poNoOptions);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
@ -85,18 +82,16 @@ protected:
|
|||
virtual void channelClosed();
|
||||
|
||||
private:
|
||||
explicit Exchange(int channelNumber = -1, Client *parent = 0);
|
||||
explicit QAmqpExchange(int channelNumber = -1, QAmqpClient *parent = 0);
|
||||
|
||||
Q_DISABLE_COPY(Exchange)
|
||||
Q_DECLARE_PRIVATE(Exchange)
|
||||
Q_DISABLE_COPY(QAmqpExchange)
|
||||
Q_DECLARE_PRIVATE(QAmqpExchange)
|
||||
|
||||
friend class Client;
|
||||
friend class QAmqpClient;
|
||||
|
||||
};
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QAMQP::Exchange::ExchangeOptions)
|
||||
Q_DECLARE_METATYPE(QAMQP::Exchange::ExchangeType)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QAmqpExchange::ExchangeOptions)
|
||||
Q_DECLARE_METATYPE(QAmqpExchange::ExchangeType)
|
||||
|
||||
#endif // QAMQPEXCHANGE_H
|
||||
|
|
|
|||
|
|
@ -5,10 +5,7 @@
|
|||
#include "qamqpexchange.h"
|
||||
#include "qamqpchannel_p.h"
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
class ExchangePrivate: public ChannelPrivate
|
||||
class QAmqpExchangePrivate: public QAmqpChannelPrivate
|
||||
{
|
||||
public:
|
||||
enum MethodId {
|
||||
|
|
@ -16,27 +13,25 @@ public:
|
|||
METHOD_ID_ENUM(miDelete, 20)
|
||||
};
|
||||
|
||||
ExchangePrivate(Exchange *q);
|
||||
static QString typeToString(Exchange::ExchangeType type);
|
||||
QAmqpExchangePrivate(QAmqpExchange *q);
|
||||
static QString typeToString(QAmqpExchange::ExchangeType type);
|
||||
|
||||
void declare();
|
||||
|
||||
// method handler related
|
||||
virtual void _q_disconnected();
|
||||
virtual bool _q_method(const Frame::Method &frame);
|
||||
void declareOk(const Frame::Method &frame);
|
||||
void deleteOk(const Frame::Method &frame);
|
||||
void basicReturn(const Frame::Method &frame);
|
||||
virtual bool _q_method(const QAmqpMethodFrame &frame);
|
||||
void declareOk(const QAmqpMethodFrame &frame);
|
||||
void deleteOk(const QAmqpMethodFrame &frame);
|
||||
void basicReturn(const QAmqpMethodFrame &frame);
|
||||
|
||||
QString type;
|
||||
Exchange::ExchangeOptions options;
|
||||
Table arguments;
|
||||
QAmqpExchange::ExchangeOptions options;
|
||||
QAmqpTable arguments;
|
||||
bool delayedDeclare;
|
||||
bool declared;
|
||||
|
||||
Q_DECLARE_PUBLIC(Exchange)
|
||||
Q_DECLARE_PUBLIC(QAmqpExchange)
|
||||
};
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
#endif // QAMQPEXCHANGE_P_H
|
||||
|
|
|
|||
|
|
@ -6,59 +6,56 @@
|
|||
#include "qamqpglobal.h"
|
||||
#include "qamqpframe_p.h"
|
||||
|
||||
using namespace QAMQP;
|
||||
using namespace QAMQP::Frame;
|
||||
|
||||
Base::Base(Type type)
|
||||
QAmqpFrame::QAmqpFrame(Type type)
|
||||
: size_(0),
|
||||
type_(type),
|
||||
channel_(0)
|
||||
{
|
||||
}
|
||||
|
||||
Base::Base(QDataStream &raw)
|
||||
QAmqpFrame::QAmqpFrame(QDataStream &raw)
|
||||
{
|
||||
readHeader(raw);
|
||||
}
|
||||
|
||||
Type Base::type() const
|
||||
QAmqpFrame::Type QAmqpFrame::type() const
|
||||
{
|
||||
return Type(type_);
|
||||
}
|
||||
|
||||
Base::~Base()
|
||||
QAmqpFrame::~QAmqpFrame()
|
||||
{
|
||||
}
|
||||
|
||||
void Base::setChannel(qint16 channel)
|
||||
void QAmqpFrame::setChannel(qint16 channel)
|
||||
{
|
||||
channel_ = channel;
|
||||
}
|
||||
|
||||
qint16 Base::channel() const
|
||||
qint16 QAmqpFrame::channel() const
|
||||
{
|
||||
return channel_;
|
||||
}
|
||||
|
||||
qint32 Base::size() const
|
||||
qint32 QAmqpFrame::size() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Base::writeHeader(QDataStream &stream) const
|
||||
void QAmqpFrame::writeHeader(QDataStream &stream) const
|
||||
{
|
||||
stream << type_;
|
||||
stream << channel_;
|
||||
stream << qint32(size());
|
||||
}
|
||||
|
||||
void Base::writeEnd(QDataStream &stream) const
|
||||
void QAmqpFrame::writeEnd(QDataStream &stream) const
|
||||
{
|
||||
stream << qint8(FRAME_END);
|
||||
stream.device()->waitForBytesWritten(1000);
|
||||
}
|
||||
|
||||
void Base::readHeader(QDataStream &stream)
|
||||
void QAmqpFrame::readHeader(QDataStream &stream)
|
||||
{
|
||||
stream >> type_;
|
||||
stream >> channel_;
|
||||
|
|
@ -66,7 +63,7 @@ void Base::readHeader(QDataStream &stream)
|
|||
}
|
||||
|
||||
/*
|
||||
void Base::readEnd(QDataStream &stream)
|
||||
void QAmqpFrame::readEnd(QDataStream &stream)
|
||||
{
|
||||
unsigned char end_ = 0;
|
||||
stream.readRawData(reinterpret_cast<char*>(&end_), sizeof(end_));
|
||||
|
|
@ -74,7 +71,8 @@ void Base::readEnd(QDataStream &stream)
|
|||
qAmqpDebug("Wrong end of frame");
|
||||
}
|
||||
*/
|
||||
void Base::toStream(QDataStream &stream) const
|
||||
|
||||
void QAmqpFrame::toStream(QDataStream &stream) const
|
||||
{
|
||||
writeHeader(stream);
|
||||
writePayload(stream);
|
||||
|
|
@ -83,45 +81,45 @@ void Base::toStream(QDataStream &stream) const
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Method::Method(MethodClass methodClass, qint16 id)
|
||||
: Base(ftMethod),
|
||||
QAmqpMethodFrame::QAmqpMethodFrame(MethodClass methodClass, qint16 id)
|
||||
: QAmqpFrame(QAmqpFrame::ftMethod),
|
||||
methodClass_(methodClass),
|
||||
id_(id)
|
||||
{
|
||||
}
|
||||
|
||||
Method::Method(QDataStream &raw)
|
||||
: Base(raw)
|
||||
QAmqpMethodFrame::QAmqpMethodFrame(QDataStream &raw)
|
||||
: QAmqpFrame(raw)
|
||||
{
|
||||
readPayload(raw);
|
||||
}
|
||||
|
||||
MethodClass Method::methodClass() const
|
||||
QAmqpFrame::MethodClass QAmqpMethodFrame::methodClass() const
|
||||
{
|
||||
return MethodClass(methodClass_);
|
||||
}
|
||||
|
||||
qint16 Method::id() const
|
||||
qint16 QAmqpMethodFrame::id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
qint32 Method::size() const
|
||||
qint32 QAmqpMethodFrame::size() const
|
||||
{
|
||||
return sizeof(id_) + sizeof(methodClass_) + arguments_.size();
|
||||
}
|
||||
|
||||
void Method::setArguments(const QByteArray &data)
|
||||
void QAmqpMethodFrame::setArguments(const QByteArray &data)
|
||||
{
|
||||
arguments_ = data;
|
||||
}
|
||||
|
||||
QByteArray Method::arguments() const
|
||||
QByteArray QAmqpMethodFrame::arguments() const
|
||||
{
|
||||
return arguments_;
|
||||
}
|
||||
|
||||
void Method::readPayload(QDataStream &stream)
|
||||
void QAmqpMethodFrame::readPayload(QDataStream &stream)
|
||||
{
|
||||
stream >> methodClass_;
|
||||
stream >> id_;
|
||||
|
|
@ -130,7 +128,7 @@ void Method::readPayload(QDataStream &stream)
|
|||
stream.readRawData(arguments_.data(), arguments_.size());
|
||||
}
|
||||
|
||||
void Method::writePayload(QDataStream &stream) const
|
||||
void QAmqpMethodFrame::writePayload(QDataStream &stream) const
|
||||
{
|
||||
stream << quint16(methodClass_);
|
||||
stream << quint16(id_);
|
||||
|
|
@ -139,40 +137,40 @@ void Method::writePayload(QDataStream &stream) const
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
QVariant Frame::readAmqpField(QDataStream &s, MetaType::ValueType type)
|
||||
QVariant QAmqpFrame::readAmqpField(QDataStream &s, QAmqpMetaType::ValueType type)
|
||||
{
|
||||
switch (type) {
|
||||
case MetaType::Boolean:
|
||||
case QAmqpMetaType::Boolean:
|
||||
{
|
||||
quint8 octet = 0;
|
||||
s >> octet;
|
||||
return QVariant::fromValue<bool>(octet > 0);
|
||||
}
|
||||
case MetaType::ShortShortUint:
|
||||
case QAmqpMetaType::ShortShortUint:
|
||||
{
|
||||
quint8 octet = 0;
|
||||
s >> octet;
|
||||
return QVariant::fromValue<int>(octet);
|
||||
}
|
||||
case MetaType::ShortUint:
|
||||
case QAmqpMetaType::ShortUint:
|
||||
{
|
||||
quint16 tmp_value = 0;
|
||||
s >> tmp_value;
|
||||
return QVariant::fromValue<uint>(tmp_value);
|
||||
}
|
||||
case MetaType::LongUint:
|
||||
case QAmqpMetaType::LongUint:
|
||||
{
|
||||
quint32 tmp_value = 0;
|
||||
s >> tmp_value;
|
||||
return QVariant::fromValue<uint>(tmp_value);
|
||||
}
|
||||
case MetaType::LongLongUint:
|
||||
case QAmqpMetaType::LongLongUint:
|
||||
{
|
||||
qulonglong v = 0 ;
|
||||
s >> v;
|
||||
return v;
|
||||
}
|
||||
case MetaType::ShortString:
|
||||
case QAmqpMetaType::ShortString:
|
||||
{
|
||||
qint8 size = 0;
|
||||
QByteArray buffer;
|
||||
|
|
@ -182,7 +180,7 @@ QVariant Frame::readAmqpField(QDataStream &s, MetaType::ValueType type)
|
|||
s.readRawData(buffer.data(), buffer.size());
|
||||
return QString::fromLatin1(buffer.data(), size);
|
||||
}
|
||||
case MetaType::LongString:
|
||||
case QAmqpMetaType::LongString:
|
||||
{
|
||||
quint32 size = 0;
|
||||
QByteArray buffer;
|
||||
|
|
@ -192,19 +190,19 @@ QVariant Frame::readAmqpField(QDataStream &s, MetaType::ValueType type)
|
|||
s.readRawData(buffer.data(), buffer.size());
|
||||
return QString::fromUtf8(buffer.data(), buffer.size());
|
||||
}
|
||||
case MetaType::Timestamp:
|
||||
case QAmqpMetaType::Timestamp:
|
||||
{
|
||||
qulonglong tmp_value;
|
||||
s >> tmp_value;
|
||||
return QDateTime::fromMSecsSinceEpoch(tmp_value);
|
||||
}
|
||||
case MetaType::Hash:
|
||||
case QAmqpMetaType::Hash:
|
||||
{
|
||||
Table table;
|
||||
QAmqpTable table;
|
||||
s >> table;
|
||||
return table;
|
||||
}
|
||||
case MetaType::Void:
|
||||
case QAmqpMetaType::Void:
|
||||
return QVariant();
|
||||
default:
|
||||
qAmqpDebug() << Q_FUNC_INFO << "unsupported value type: " << type;
|
||||
|
|
@ -213,25 +211,25 @@ QVariant Frame::readAmqpField(QDataStream &s, MetaType::ValueType type)
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
void Frame::writeAmqpField(QDataStream &s, MetaType::ValueType type, const QVariant &value)
|
||||
void QAmqpFrame::writeAmqpField(QDataStream &s, QAmqpMetaType::ValueType type, const QVariant &value)
|
||||
{
|
||||
switch (type) {
|
||||
case MetaType::Boolean:
|
||||
case QAmqpMetaType::Boolean:
|
||||
s << (value.toBool() ? qint8(1) : qint8(0));
|
||||
break;
|
||||
case MetaType::ShortShortUint:
|
||||
case QAmqpMetaType::ShortShortUint:
|
||||
s << qint8(value.toUInt());
|
||||
break;
|
||||
case MetaType::ShortUint:
|
||||
case QAmqpMetaType::ShortUint:
|
||||
s << quint16(value.toUInt());
|
||||
break;
|
||||
case MetaType::LongUint:
|
||||
case QAmqpMetaType::LongUint:
|
||||
s << quint32(value.toUInt());
|
||||
break;
|
||||
case MetaType::LongLongUint:
|
||||
case QAmqpMetaType::LongLongUint:
|
||||
s << qulonglong(value.toULongLong());
|
||||
break;
|
||||
case MetaType::ShortString:
|
||||
case QAmqpMetaType::ShortString:
|
||||
{
|
||||
QString str = value.toString();
|
||||
if (str.length() >= 256) {
|
||||
|
|
@ -242,19 +240,19 @@ void Frame::writeAmqpField(QDataStream &s, MetaType::ValueType type, const QVari
|
|||
s.writeRawData(str.toUtf8().data(), str.length());
|
||||
}
|
||||
break;
|
||||
case MetaType::LongString:
|
||||
case QAmqpMetaType::LongString:
|
||||
{
|
||||
QString str = value.toString();
|
||||
s << quint32(str.length());
|
||||
s.writeRawData(str.toLatin1().data(), str.length());
|
||||
}
|
||||
break;
|
||||
case MetaType::Timestamp:
|
||||
case QAmqpMetaType::Timestamp:
|
||||
s << qulonglong(value.toDateTime().toMSecsSinceEpoch());
|
||||
break;
|
||||
case MetaType::Hash:
|
||||
case QAmqpMetaType::Hash:
|
||||
{
|
||||
Table table(value.toHash());
|
||||
QAmqpTable table(value.toHash());
|
||||
s << table;
|
||||
}
|
||||
break;
|
||||
|
|
@ -265,29 +263,29 @@ void Frame::writeAmqpField(QDataStream &s, MetaType::ValueType type, const QVari
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Content::Content()
|
||||
: Base(ftHeader)
|
||||
QAmqpContentFrame::QAmqpContentFrame()
|
||||
: QAmqpFrame(QAmqpFrame::ftHeader)
|
||||
{
|
||||
}
|
||||
|
||||
Content::Content(MethodClass methodClass)
|
||||
: Base(ftHeader)
|
||||
QAmqpContentFrame::QAmqpContentFrame(QAmqpFrame::MethodClass methodClass)
|
||||
: QAmqpFrame(QAmqpFrame::ftHeader)
|
||||
{
|
||||
methodClass_ = methodClass;
|
||||
}
|
||||
|
||||
Content::Content(QDataStream &raw)
|
||||
: Base(raw)
|
||||
QAmqpContentFrame::QAmqpContentFrame(QDataStream &raw)
|
||||
: QAmqpFrame(raw)
|
||||
{
|
||||
readPayload(raw);
|
||||
}
|
||||
|
||||
MethodClass Content::methodClass() const
|
||||
QAmqpFrame::MethodClass QAmqpContentFrame::methodClass() const
|
||||
{
|
||||
return MethodClass(methodClass_);
|
||||
}
|
||||
|
||||
qint32 Content::size() const
|
||||
qint32 QAmqpContentFrame::size() const
|
||||
{
|
||||
QDataStream out(&buffer_, QIODevice::WriteOnly);
|
||||
buffer_.clear();
|
||||
|
|
@ -300,178 +298,178 @@ qint32 Content::size() const
|
|||
prop_ |= p;
|
||||
out << prop_;
|
||||
|
||||
if (prop_ & Message::ContentType)
|
||||
writeAmqpField(out, MetaType::ShortString, properties_[Message::ContentType]);
|
||||
if (prop_ & QAmqpMessage::ContentType)
|
||||
writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::ContentType]);
|
||||
|
||||
if (prop_ & Message::ContentEncoding)
|
||||
writeAmqpField(out, MetaType::ShortString, properties_[Message::ContentEncoding]);
|
||||
if (prop_ & QAmqpMessage::ContentEncoding)
|
||||
writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::ContentEncoding]);
|
||||
|
||||
if (prop_ & Message::Headers)
|
||||
writeAmqpField(out, MetaType::Hash, properties_[Message::Headers]);
|
||||
if (prop_ & QAmqpMessage::Headers)
|
||||
writeAmqpField(out, QAmqpMetaType::Hash, properties_[QAmqpMessage::Headers]);
|
||||
|
||||
if (prop_ & Message::DeliveryMode)
|
||||
writeAmqpField(out, MetaType::ShortShortUint, properties_[Message::DeliveryMode]);
|
||||
if (prop_ & QAmqpMessage::DeliveryMode)
|
||||
writeAmqpField(out, QAmqpMetaType::ShortShortUint, properties_[QAmqpMessage::DeliveryMode]);
|
||||
|
||||
if (prop_ & Message::Priority)
|
||||
writeAmqpField(out, MetaType::ShortShortUint, properties_[Message::Priority]);
|
||||
if (prop_ & QAmqpMessage::Priority)
|
||||
writeAmqpField(out, QAmqpMetaType::ShortShortUint, properties_[QAmqpMessage::Priority]);
|
||||
|
||||
if (prop_ & Message::CorrelationId)
|
||||
writeAmqpField(out, MetaType::ShortString, properties_[Message::CorrelationId]);
|
||||
if (prop_ & QAmqpMessage::CorrelationId)
|
||||
writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::CorrelationId]);
|
||||
|
||||
if (prop_ & Message::ReplyTo)
|
||||
writeAmqpField(out, MetaType::ShortString, properties_[Message::ReplyTo]);
|
||||
if (prop_ & QAmqpMessage::ReplyTo)
|
||||
writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::ReplyTo]);
|
||||
|
||||
if (prop_ & Message::Expiration)
|
||||
writeAmqpField(out, MetaType::ShortString, properties_[Message::Expiration]);
|
||||
if (prop_ & QAmqpMessage::Expiration)
|
||||
writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::Expiration]);
|
||||
|
||||
if (prop_ & Message::MessageId)
|
||||
writeAmqpField(out, MetaType::ShortString, properties_[Message::MessageId]);
|
||||
if (prop_ & QAmqpMessage::MessageId)
|
||||
writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::MessageId]);
|
||||
|
||||
if (prop_ & Message::Timestamp)
|
||||
writeAmqpField(out, MetaType::Timestamp, properties_[Message::Timestamp]);
|
||||
if (prop_ & QAmqpMessage::Timestamp)
|
||||
writeAmqpField(out, QAmqpMetaType::Timestamp, properties_[QAmqpMessage::Timestamp]);
|
||||
|
||||
if (prop_ & Message::Type)
|
||||
writeAmqpField(out, MetaType::ShortString, properties_[Message::Type]);
|
||||
if (prop_ & QAmqpMessage::Type)
|
||||
writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::Type]);
|
||||
|
||||
if (prop_ & Message::UserId)
|
||||
writeAmqpField(out, MetaType::ShortString, properties_[Message::UserId]);
|
||||
if (prop_ & QAmqpMessage::UserId)
|
||||
writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::UserId]);
|
||||
|
||||
if (prop_ & Message::AppId)
|
||||
writeAmqpField(out, MetaType::ShortString, properties_[Message::AppId]);
|
||||
if (prop_ & QAmqpMessage::AppId)
|
||||
writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::AppId]);
|
||||
|
||||
if (prop_ & Message::ClusterID)
|
||||
writeAmqpField(out, MetaType::ShortString, properties_[Message::ClusterID]);
|
||||
if (prop_ & QAmqpMessage::ClusterID)
|
||||
writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::ClusterID]);
|
||||
|
||||
return buffer_.size();
|
||||
}
|
||||
|
||||
qlonglong Content::bodySize() const
|
||||
qlonglong QAmqpContentFrame::bodySize() const
|
||||
{
|
||||
return bodySize_;
|
||||
}
|
||||
|
||||
void Content::setBodySize(qlonglong size)
|
||||
void QAmqpContentFrame::setBodySize(qlonglong size)
|
||||
{
|
||||
bodySize_ = size;
|
||||
}
|
||||
|
||||
void Content::setProperty(Message::Property prop, const QVariant &value)
|
||||
void QAmqpContentFrame::setProperty(QAmqpMessage::Property prop, const QVariant &value)
|
||||
{
|
||||
properties_[prop] = value;
|
||||
}
|
||||
|
||||
QVariant Content::property(Message::Property prop) const
|
||||
QVariant QAmqpContentFrame::property(QAmqpMessage::Property prop) const
|
||||
{
|
||||
return properties_.value(prop);
|
||||
}
|
||||
|
||||
void Content::writePayload(QDataStream &out) const
|
||||
void QAmqpContentFrame::writePayload(QDataStream &out) const
|
||||
{
|
||||
out.writeRawData(buffer_.data(), buffer_.size());
|
||||
}
|
||||
|
||||
void Content::readPayload(QDataStream &in)
|
||||
void QAmqpContentFrame::readPayload(QDataStream &in)
|
||||
{
|
||||
in >> methodClass_;
|
||||
in.skipRawData(2); //weight
|
||||
in >> bodySize_;
|
||||
qint16 flags_ = 0;
|
||||
in >> flags_;
|
||||
if (flags_ & Message::ContentType)
|
||||
properties_[Message::ContentType] = readAmqpField(in, MetaType::ShortString);
|
||||
if (flags_ & QAmqpMessage::ContentType)
|
||||
properties_[QAmqpMessage::ContentType] = readAmqpField(in, QAmqpMetaType::ShortString);
|
||||
|
||||
if (flags_ & Message::ContentEncoding)
|
||||
properties_[Message::ContentEncoding] = readAmqpField(in, MetaType::ShortString);
|
||||
if (flags_ & QAmqpMessage::ContentEncoding)
|
||||
properties_[QAmqpMessage::ContentEncoding] = readAmqpField(in, QAmqpMetaType::ShortString);
|
||||
|
||||
if (flags_ & Message::Headers)
|
||||
properties_[Message::Headers] = readAmqpField(in, MetaType::Hash);
|
||||
if (flags_ & QAmqpMessage::Headers)
|
||||
properties_[QAmqpMessage::Headers] = readAmqpField(in, QAmqpMetaType::Hash);
|
||||
|
||||
if (flags_ & Message::DeliveryMode)
|
||||
properties_[Message::DeliveryMode] = readAmqpField(in, MetaType::ShortShortUint);
|
||||
if (flags_ & QAmqpMessage::DeliveryMode)
|
||||
properties_[QAmqpMessage::DeliveryMode] = readAmqpField(in, QAmqpMetaType::ShortShortUint);
|
||||
|
||||
if (flags_ & Message::Priority)
|
||||
properties_[Message::Priority] = readAmqpField(in, MetaType::ShortShortUint);
|
||||
if (flags_ & QAmqpMessage::Priority)
|
||||
properties_[QAmqpMessage::Priority] = readAmqpField(in, QAmqpMetaType::ShortShortUint);
|
||||
|
||||
if (flags_ & Message::CorrelationId)
|
||||
properties_[Message::CorrelationId] = readAmqpField(in, MetaType::ShortString);
|
||||
if (flags_ & QAmqpMessage::CorrelationId)
|
||||
properties_[QAmqpMessage::CorrelationId] = readAmqpField(in, QAmqpMetaType::ShortString);
|
||||
|
||||
if (flags_ & Message::ReplyTo)
|
||||
properties_[Message::ReplyTo] = readAmqpField(in, MetaType::ShortString);
|
||||
if (flags_ & QAmqpMessage::ReplyTo)
|
||||
properties_[QAmqpMessage::ReplyTo] = readAmqpField(in, QAmqpMetaType::ShortString);
|
||||
|
||||
if (flags_ & Message::Expiration)
|
||||
properties_[Message::Expiration] = readAmqpField(in, MetaType::ShortString);
|
||||
if (flags_ & QAmqpMessage::Expiration)
|
||||
properties_[QAmqpMessage::Expiration] = readAmqpField(in, QAmqpMetaType::ShortString);
|
||||
|
||||
if (flags_ & Message::MessageId)
|
||||
properties_[Message::MessageId] = readAmqpField(in, MetaType::ShortString);
|
||||
if (flags_ & QAmqpMessage::MessageId)
|
||||
properties_[QAmqpMessage::MessageId] = readAmqpField(in, QAmqpMetaType::ShortString);
|
||||
|
||||
if (flags_ & Message::Timestamp)
|
||||
properties_[Message::Timestamp] = readAmqpField(in, MetaType::Timestamp);
|
||||
if (flags_ & QAmqpMessage::Timestamp)
|
||||
properties_[QAmqpMessage::Timestamp] = readAmqpField(in, QAmqpMetaType::Timestamp);
|
||||
|
||||
if (flags_ & Message::Type)
|
||||
properties_[Message::Type] = readAmqpField(in, MetaType::ShortString);
|
||||
if (flags_ & QAmqpMessage::Type)
|
||||
properties_[QAmqpMessage::Type] = readAmqpField(in, QAmqpMetaType::ShortString);
|
||||
|
||||
if (flags_ & Message::UserId)
|
||||
properties_[Message::UserId] = readAmqpField(in, MetaType::ShortString);
|
||||
if (flags_ & QAmqpMessage::UserId)
|
||||
properties_[QAmqpMessage::UserId] = readAmqpField(in, QAmqpMetaType::ShortString);
|
||||
|
||||
if (flags_ & Message::AppId)
|
||||
properties_[Message::AppId] = readAmqpField(in, MetaType::ShortString);
|
||||
if (flags_ & QAmqpMessage::AppId)
|
||||
properties_[QAmqpMessage::AppId] = readAmqpField(in, QAmqpMetaType::ShortString);
|
||||
|
||||
if (flags_ & Message::ClusterID)
|
||||
properties_[Message::ClusterID] = readAmqpField(in, MetaType::ShortString);
|
||||
if (flags_ & QAmqpMessage::ClusterID)
|
||||
properties_[QAmqpMessage::ClusterID] = readAmqpField(in, QAmqpMetaType::ShortString);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ContentBody::ContentBody()
|
||||
: Base(ftBody)
|
||||
QAmqpContentBodyFrame::QAmqpContentBodyFrame()
|
||||
: QAmqpFrame(QAmqpFrame::ftBody)
|
||||
{
|
||||
}
|
||||
|
||||
ContentBody::ContentBody(QDataStream &raw)
|
||||
: Base(raw)
|
||||
QAmqpContentBodyFrame::QAmqpContentBodyFrame(QDataStream &raw)
|
||||
: QAmqpFrame(raw)
|
||||
{
|
||||
readPayload(raw);
|
||||
}
|
||||
|
||||
void ContentBody::setBody(const QByteArray &data)
|
||||
void QAmqpContentBodyFrame::setBody(const QByteArray &data)
|
||||
{
|
||||
body_ = data;
|
||||
}
|
||||
|
||||
QByteArray ContentBody::body() const
|
||||
QByteArray QAmqpContentBodyFrame::body() const
|
||||
{
|
||||
return body_;
|
||||
}
|
||||
|
||||
void ContentBody::writePayload(QDataStream &out) const
|
||||
void QAmqpContentBodyFrame::writePayload(QDataStream &out) const
|
||||
{
|
||||
out.writeRawData(body_.data(), body_.size());
|
||||
}
|
||||
|
||||
void ContentBody::readPayload(QDataStream &in)
|
||||
void QAmqpContentBodyFrame::readPayload(QDataStream &in)
|
||||
{
|
||||
body_.resize(size_);
|
||||
in.readRawData(body_.data(), body_.size());
|
||||
}
|
||||
|
||||
qint32 ContentBody::size() const
|
||||
qint32 QAmqpContentBodyFrame::size() const
|
||||
{
|
||||
return body_.size();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Heartbeat::Heartbeat()
|
||||
: Base(ftHeartbeat)
|
||||
QAmqpHeartbeatFrame::QAmqpHeartbeatFrame()
|
||||
: QAmqpFrame(QAmqpFrame::ftHeartbeat)
|
||||
{
|
||||
}
|
||||
|
||||
void Heartbeat::readPayload(QDataStream &stream)
|
||||
void QAmqpHeartbeatFrame::readPayload(QDataStream &stream)
|
||||
{
|
||||
Q_UNUSED(stream)
|
||||
}
|
||||
|
||||
void Heartbeat::writePayload(QDataStream &stream) const
|
||||
void QAmqpHeartbeatFrame::writePayload(QDataStream &stream) const
|
||||
{
|
||||
Q_UNUSED(stream)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,18 +8,16 @@
|
|||
#include "qamqpglobal.h"
|
||||
#include "qamqpmessage.h"
|
||||
|
||||
class QAmqpQueuePrivate;
|
||||
|
||||
/**
|
||||
* Library namespace
|
||||
* @namespace QAMQP
|
||||
*/
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
class QueuePrivate;
|
||||
namespace Frame
|
||||
class QAmqpFrame
|
||||
{
|
||||
typedef quint16 channel_t;
|
||||
|
||||
public:
|
||||
/*
|
||||
* @brief Header size in bytes
|
||||
*/
|
||||
|
|
@ -60,8 +58,8 @@ namespace Frame
|
|||
fcTx = 90,
|
||||
};
|
||||
|
||||
QVariant readAmqpField(QDataStream &s, MetaType::ValueType type);
|
||||
void writeAmqpField(QDataStream &s, MetaType::ValueType type, const QVariant &value);
|
||||
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.
|
||||
|
|
@ -76,286 +74,279 @@ namespace Frame
|
|||
* @endcode
|
||||
* octet short long 'size' octets octet
|
||||
*/
|
||||
class QAMQP_EXPORT Base
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Base class constructor.
|
||||
* @detailed Construct frame class for sending.
|
||||
* @param type Define type of constructed frame.
|
||||
*/
|
||||
Base(Type type);
|
||||
|
||||
/*
|
||||
* Base class constructor.
|
||||
* @detailed Construct frame class from received raw data.
|
||||
* @param raw Data stream for reading source data.
|
||||
*/
|
||||
Base(QDataStream &raw);
|
||||
|
||||
/*
|
||||
* Base class virtual destructor
|
||||
*/
|
||||
virtual ~Base();
|
||||
|
||||
/*
|
||||
* 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;
|
||||
virtual void writePayload(QDataStream &stream) const = 0;
|
||||
void writeEnd(QDataStream &stream) const;
|
||||
|
||||
void readHeader(QDataStream &stream);
|
||||
virtual void readPayload(QDataStream &stream) = 0;
|
||||
// void readEnd(QDataStream &stream);
|
||||
|
||||
qint32 size_;
|
||||
|
||||
private:
|
||||
qint8 type_;
|
||||
qint16 channel_;
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* @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
|
||||
* Base class constructor.
|
||||
* @detailed Construct frame class for sending.
|
||||
* @param type Define type of constructed frame.
|
||||
*/
|
||||
class QAMQP_EXPORT Method : public Base
|
||||
{
|
||||
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 Method(MethodClass methodClass, qint16 id);
|
||||
|
||||
/*
|
||||
* Method class constructor.
|
||||
* @detailed Construct frame class from received raw data.
|
||||
* @param raw Data stream for reading source data.
|
||||
*/
|
||||
explicit Method(QDataStream &raw);
|
||||
|
||||
/*
|
||||
* Method class type.
|
||||
*/
|
||||
MethodClass methodClass() const;
|
||||
|
||||
/*
|
||||
* Method id.
|
||||
*/
|
||||
qint16 id() const;
|
||||
qint32 size() const;
|
||||
|
||||
/*
|
||||
* Set arguments for method.
|
||||
* @param data Serialized method arguments.
|
||||
* @sa arguments
|
||||
*/
|
||||
void setArguments(const QByteArray &data);
|
||||
|
||||
/*
|
||||
* Return arguments for method.
|
||||
* @sa setArguments
|
||||
*/
|
||||
QByteArray arguments() const;
|
||||
|
||||
protected:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
short methodClass_;
|
||||
qint16 id_;
|
||||
QByteArray arguments_;
|
||||
|
||||
};
|
||||
QAmqpFrame(Type type);
|
||||
|
||||
/*
|
||||
* @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
|
||||
* Base class constructor.
|
||||
* @detailed Construct frame class from received raw data.
|
||||
* @param raw Data stream for reading source data.
|
||||
*/
|
||||
class QAMQP_EXPORT Content : public Base
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Content class constructor.
|
||||
* @detailed Construct frame content header class for sending.
|
||||
*/
|
||||
Content();
|
||||
|
||||
/*
|
||||
* Content class constructor.
|
||||
* @detailed Construct frame content header class for sending.
|
||||
* @param methodClass Define method class id of constructed frame.
|
||||
*/
|
||||
Content(MethodClass methodClass);
|
||||
|
||||
/*
|
||||
* Content class constructor.
|
||||
* @detailed Construct frame content header class for sending.
|
||||
* @param raw Data stream for reading source data.
|
||||
*/
|
||||
Content(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(Message::Property prop, const QVariant &value);
|
||||
|
||||
/*
|
||||
* Return associated with property value
|
||||
* @param prop Any default content header property
|
||||
*/
|
||||
QVariant property(Message::Property prop) const;
|
||||
|
||||
qlonglong bodySize() const;
|
||||
void setBodySize(qlonglong size);
|
||||
|
||||
protected:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
short methodClass_;
|
||||
qint16 id_;
|
||||
mutable QByteArray buffer_;
|
||||
Message::PropertyHash properties_;
|
||||
qlonglong bodySize_;
|
||||
|
||||
private:
|
||||
friend class QAMQP::QueuePrivate;
|
||||
|
||||
};
|
||||
|
||||
class QAMQP_EXPORT ContentBody : public Base
|
||||
{
|
||||
public:
|
||||
ContentBody();
|
||||
ContentBody(QDataStream &raw);
|
||||
|
||||
void setBody(const QByteArray &data);
|
||||
QByteArray body() const;
|
||||
|
||||
qint32 size() const;
|
||||
protected:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
|
||||
private:
|
||||
QByteArray body_;
|
||||
};
|
||||
QAmqpFrame(QDataStream &raw);
|
||||
|
||||
/*
|
||||
* @brief Class for working with heartbeat frames.
|
||||
* @detailed Implement frame for heartbeat send.
|
||||
* Base class virtual destructor
|
||||
*/
|
||||
class QAMQP_EXPORT Heartbeat : public Base
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Heartbeat class constructor.
|
||||
* @detailed Construct frame class for sending.
|
||||
*/
|
||||
Heartbeat();
|
||||
virtual ~QAmqpFrame();
|
||||
|
||||
protected:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
};
|
||||
/*
|
||||
* Frame type
|
||||
* @detailed Return type of current frame.
|
||||
*/
|
||||
Type type() const;
|
||||
|
||||
class QAMQP_EXPORT MethodHandler
|
||||
{
|
||||
public:
|
||||
virtual bool _q_method(const Frame::Method &frame) = 0;
|
||||
};
|
||||
/*
|
||||
* Set number of associated channel.
|
||||
* @param channel Number of channel.
|
||||
* @sa channel()
|
||||
*/
|
||||
void setChannel(qint16 channel);
|
||||
|
||||
class QAMQP_EXPORT ContentHandler
|
||||
{
|
||||
public:
|
||||
virtual void _q_content(const Frame::Content &frame) = 0;
|
||||
};
|
||||
/*
|
||||
* Return number of associated channel.
|
||||
* @sa setChannel()
|
||||
*/
|
||||
qint16 channel() const;
|
||||
|
||||
class QAMQP_EXPORT ContentBodyHandler
|
||||
{
|
||||
public:
|
||||
virtual void _q_body(const Frame::ContentBody &frame) = 0;
|
||||
};
|
||||
/*
|
||||
* Return size of frame.
|
||||
*/
|
||||
virtual qint32 size() const;
|
||||
|
||||
} // namespace Frame
|
||||
/*
|
||||
* Output frame to stream.
|
||||
* @param stream Stream for serilize frame.
|
||||
*/
|
||||
void toStream(QDataStream &stream) const;
|
||||
|
||||
} // namespace QAMQP
|
||||
protected:
|
||||
void writeHeader(QDataStream &stream) const;
|
||||
virtual void writePayload(QDataStream &stream) const = 0;
|
||||
void writeEnd(QDataStream &stream) const;
|
||||
|
||||
void readHeader(QDataStream &stream);
|
||||
virtual void readPayload(QDataStream &stream) = 0;
|
||||
|
||||
qint32 size_;
|
||||
|
||||
private:
|
||||
qint8 type_;
|
||||
qint16 channel_;
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* @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
|
||||
*/
|
||||
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);
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
MethodClass methodClass() const;
|
||||
|
||||
/*
|
||||
* Method id.
|
||||
*/
|
||||
qint16 id() const;
|
||||
qint32 size() const;
|
||||
|
||||
/*
|
||||
* Set arguments for method.
|
||||
* @param data Serialized method arguments.
|
||||
* @sa arguments
|
||||
*/
|
||||
void setArguments(const QByteArray &data);
|
||||
|
||||
/*
|
||||
* Return arguments for method.
|
||||
* @sa setArguments
|
||||
*/
|
||||
QByteArray arguments() const;
|
||||
|
||||
protected:
|
||||
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
|
||||
{
|
||||
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);
|
||||
|
||||
/*
|
||||
* Return associated with property value
|
||||
* @param prop Any default content header property
|
||||
*/
|
||||
QVariant property(QAmqpMessage::Property prop) const;
|
||||
|
||||
qlonglong bodySize() const;
|
||||
void setBodySize(qlonglong size);
|
||||
|
||||
protected:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
short methodClass_;
|
||||
qint16 id_;
|
||||
mutable QByteArray buffer_;
|
||||
QAmqpMessage::PropertyHash properties_;
|
||||
qlonglong bodySize_;
|
||||
|
||||
private:
|
||||
friend class QAmqpQueuePrivate;
|
||||
|
||||
};
|
||||
|
||||
class QAMQP_EXPORT QAmqpContentBodyFrame : public QAmqpFrame
|
||||
{
|
||||
public:
|
||||
QAmqpContentBodyFrame();
|
||||
QAmqpContentBodyFrame(QDataStream &raw);
|
||||
|
||||
void setBody(const QByteArray &data);
|
||||
QByteArray body() const;
|
||||
|
||||
qint32 size() const;
|
||||
protected:
|
||||
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
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Heartbeat class constructor.
|
||||
* @detailed Construct frame class for sending.
|
||||
*/
|
||||
QAmqpHeartbeatFrame();
|
||||
|
||||
protected:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
};
|
||||
|
||||
class QAMQP_EXPORT QAmqpMethodFrameHandler
|
||||
{
|
||||
public:
|
||||
virtual bool _q_method(const QAmqpMethodFrame &frame) = 0;
|
||||
};
|
||||
|
||||
class QAMQP_EXPORT QAmqpContentFrameHandler
|
||||
{
|
||||
public:
|
||||
virtual void _q_content(const QAmqpContentFrame &frame) = 0;
|
||||
};
|
||||
|
||||
class QAMQP_EXPORT QAmqpContentBodyFrameHandler
|
||||
{
|
||||
public:
|
||||
virtual void _q_body(const QAmqpContentBodyFrame &frame) = 0;
|
||||
};
|
||||
|
||||
#endif // QAMQPFRAME_P_H
|
||||
|
|
|
|||
|
|
@ -45,9 +45,7 @@
|
|||
|
||||
#define qAmqpDebug if (qgetenv("QAMQP_DEBUG").isEmpty()); else qDebug
|
||||
|
||||
namespace QAMQP {
|
||||
|
||||
namespace MetaType {
|
||||
namespace QAmqpMetaType {
|
||||
|
||||
enum ValueType
|
||||
{
|
||||
|
|
@ -77,7 +75,9 @@ enum ValueType
|
|||
Void
|
||||
};
|
||||
|
||||
} // namespace MetaType
|
||||
} // namespace QAmqpMetaType
|
||||
|
||||
namespace QAMQP {
|
||||
|
||||
enum Error
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
#include "qamqpmessage.h"
|
||||
#include "qamqpmessage_p.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
MessagePrivate::MessagePrivate()
|
||||
QAmqpMessagePrivate::QAmqpMessagePrivate()
|
||||
: deliveryTag(0),
|
||||
leftSize(0)
|
||||
{
|
||||
|
|
@ -12,27 +11,27 @@ MessagePrivate::MessagePrivate()
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Message::Message()
|
||||
: d(new MessagePrivate)
|
||||
QAmqpMessage::QAmqpMessage()
|
||||
: d(new QAmqpMessagePrivate)
|
||||
{
|
||||
}
|
||||
|
||||
Message::Message(const Message &other)
|
||||
QAmqpMessage::QAmqpMessage(const QAmqpMessage &other)
|
||||
: d(other.d)
|
||||
{
|
||||
}
|
||||
|
||||
Message::~Message()
|
||||
QAmqpMessage::~QAmqpMessage()
|
||||
{
|
||||
}
|
||||
|
||||
Message &Message::operator=(const Message &other)
|
||||
QAmqpMessage &QAmqpMessage::operator=(const QAmqpMessage &other)
|
||||
{
|
||||
d = other.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Message::operator==(const Message &message) const
|
||||
bool QAmqpMessage::operator==(const QAmqpMessage &message) const
|
||||
{
|
||||
if (message.d == d)
|
||||
return true;
|
||||
|
|
@ -47,76 +46,76 @@ bool Message::operator==(const Message &message) const
|
|||
message.d->leftSize == d->leftSize);
|
||||
}
|
||||
|
||||
bool Message::isValid() const
|
||||
bool QAmqpMessage::isValid() const
|
||||
{
|
||||
return d->deliveryTag != 0 &&
|
||||
!d->exchangeName.isNull() &&
|
||||
!d->routingKey.isNull();
|
||||
}
|
||||
|
||||
qlonglong Message::deliveryTag() const
|
||||
qlonglong QAmqpMessage::deliveryTag() const
|
||||
{
|
||||
return d->deliveryTag;
|
||||
}
|
||||
|
||||
bool Message::isRedelivered() const
|
||||
bool QAmqpMessage::isRedelivered() const
|
||||
{
|
||||
return d->redelivered;
|
||||
}
|
||||
|
||||
QString Message::exchangeName() const
|
||||
QString QAmqpMessage::exchangeName() const
|
||||
{
|
||||
return d->exchangeName;
|
||||
}
|
||||
|
||||
QString Message::routingKey() const
|
||||
QString QAmqpMessage::routingKey() const
|
||||
{
|
||||
return d->routingKey;
|
||||
}
|
||||
|
||||
QByteArray Message::payload() const
|
||||
QByteArray QAmqpMessage::payload() const
|
||||
{
|
||||
return d->payload;
|
||||
}
|
||||
|
||||
bool Message::hasProperty(Property property) const
|
||||
bool QAmqpMessage::hasProperty(Property property) const
|
||||
{
|
||||
return d->properties.contains(property);
|
||||
}
|
||||
|
||||
void Message::setProperty(Property property, const QVariant &value)
|
||||
void QAmqpMessage::setProperty(Property property, const QVariant &value)
|
||||
{
|
||||
d->properties.insert(property, value);
|
||||
}
|
||||
|
||||
QVariant Message::property(Property property, const QVariant &defaultValue) const
|
||||
QVariant QAmqpMessage::property(Property property, const QVariant &defaultValue) const
|
||||
{
|
||||
return d->properties.value(property, defaultValue);
|
||||
}
|
||||
|
||||
bool Message::hasHeader(const QString &header) const
|
||||
bool QAmqpMessage::hasHeader(const QString &header) const
|
||||
{
|
||||
return d->headers.contains(header);
|
||||
}
|
||||
|
||||
void Message::setHeader(const QString &header, const QVariant &value)
|
||||
void QAmqpMessage::setHeader(const QString &header, const QVariant &value)
|
||||
{
|
||||
d->headers.insert(header, value);
|
||||
}
|
||||
|
||||
QVariant Message::header(const QString &header, const QVariant &defaultValue) const
|
||||
QVariant QAmqpMessage::header(const QString &header, const QVariant &defaultValue) const
|
||||
{
|
||||
return d->headers.value(header, defaultValue);
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
bool Message::isDetached() const
|
||||
bool QAmqpMessage::isDetached() const
|
||||
{
|
||||
return d && d->ref == 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint qHash(const QAMQP::Message &message, uint seed)
|
||||
uint qHash(const QAmqpMessage &message, uint seed)
|
||||
{
|
||||
Q_UNUSED(seed);
|
||||
return qHash(message.deliveryTag()) ^
|
||||
|
|
|
|||
|
|
@ -8,24 +8,21 @@
|
|||
|
||||
#include "qamqpglobal.h"
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
class MessagePrivate;
|
||||
class QAMQP_EXPORT Message
|
||||
class QAmqpMessagePrivate;
|
||||
class QAMQP_EXPORT QAmqpMessage
|
||||
{
|
||||
public:
|
||||
Message();
|
||||
Message(const Message &other);
|
||||
Message &operator=(const Message &other);
|
||||
~Message();
|
||||
QAmqpMessage();
|
||||
QAmqpMessage(const QAmqpMessage &other);
|
||||
QAmqpMessage &operator=(const QAmqpMessage &other);
|
||||
~QAmqpMessage();
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
inline void swap(Message &other) { qSwap(d, other.d); }
|
||||
inline void swap(QAmqpMessage &other) { qSwap(d, other.d); }
|
||||
#endif
|
||||
|
||||
bool operator==(const Message &message) const;
|
||||
inline bool operator!=(const Message &message) const { return !(operator==(message)); }
|
||||
bool operator==(const QAmqpMessage &message) const;
|
||||
inline bool operator!=(const QAmqpMessage &message) const { return !(operator==(message)); }
|
||||
|
||||
enum Property {
|
||||
ContentType = AMQP_BASIC_CONTENT_TYPE_FLAG,
|
||||
|
|
@ -62,13 +59,13 @@ public:
|
|||
QByteArray payload() const;
|
||||
|
||||
private:
|
||||
QSharedDataPointer<MessagePrivate> d;
|
||||
friend class QueuePrivate;
|
||||
friend class Queue;
|
||||
QSharedDataPointer<QAmqpMessagePrivate> d;
|
||||
friend class QAmqpQueuePrivate;
|
||||
friend class QAmqpQueue;
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
public:
|
||||
typedef QSharedDataPointer<MessagePrivate> DataPtr;
|
||||
typedef QSharedDataPointer<QAmqpMessagePrivate> DataPtr;
|
||||
inline DataPtr &data_ptr() { return d; }
|
||||
|
||||
// internal
|
||||
|
|
@ -76,16 +73,14 @@ public:
|
|||
#endif
|
||||
};
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
Q_DECLARE_METATYPE(QAMQP::Message::PropertyHash)
|
||||
Q_DECLARE_METATYPE(QAmqpMessage::PropertyHash)
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
Q_DECLARE_TYPEINFO(QAMQP::Message, Q_MOVABLE_TYPE);
|
||||
Q_DECLARE_TYPEINFO(QAmqpMessage, Q_MOVABLE_TYPE);
|
||||
#endif
|
||||
Q_DECLARE_SHARED(QAMQP::Message)
|
||||
Q_DECLARE_SHARED(QAmqpMessage)
|
||||
|
||||
// NOTE: needed only for MSVC support, don't depend on this hash
|
||||
QAMQP_EXPORT uint qHash(const QAMQP::Message &key, uint seed = 0);
|
||||
QAMQP_EXPORT uint qHash(const QAmqpMessage &key, uint seed = 0);
|
||||
|
||||
#endif // QAMQPMESSAGE_H
|
||||
|
|
|
|||
|
|
@ -7,24 +7,20 @@
|
|||
#include "qamqpframe_p.h"
|
||||
#include "qamqpmessage.h"
|
||||
|
||||
namespace QAMQP {
|
||||
|
||||
class MessagePrivate : public QSharedData
|
||||
class QAmqpMessagePrivate : public QSharedData
|
||||
{
|
||||
public:
|
||||
MessagePrivate();
|
||||
QAmqpMessagePrivate();
|
||||
|
||||
qlonglong deliveryTag;
|
||||
bool redelivered;
|
||||
QString exchangeName;
|
||||
QString routingKey;
|
||||
QByteArray payload;
|
||||
QHash<Message::Property, QVariant> properties;
|
||||
QHash<QAmqpMessage::Property, QVariant> properties;
|
||||
QHash<QString, QVariant> headers;
|
||||
int leftSize;
|
||||
|
||||
};
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
#endif // QAMQPMESSAGE_P_H
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
#include "qamqptable.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
QueuePrivate::QueuePrivate(Queue *q)
|
||||
: ChannelPrivate(q),
|
||||
QAmqpQueuePrivate::QAmqpQueuePrivate(QAmqpQueue *q)
|
||||
: QAmqpChannelPrivate(q),
|
||||
delayedDeclare(false),
|
||||
declared(false),
|
||||
recievingMessage(false),
|
||||
|
|
@ -19,17 +19,17 @@ QueuePrivate::QueuePrivate(Queue *q)
|
|||
{
|
||||
}
|
||||
|
||||
QueuePrivate::~QueuePrivate()
|
||||
QAmqpQueuePrivate::~QAmqpQueuePrivate()
|
||||
{
|
||||
}
|
||||
|
||||
bool QueuePrivate::_q_method(const Frame::Method &frame)
|
||||
bool QAmqpQueuePrivate::_q_method(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Queue);
|
||||
if (ChannelPrivate::_q_method(frame))
|
||||
Q_Q(QAmqpQueue);
|
||||
if (QAmqpChannelPrivate::_q_method(frame))
|
||||
return true;
|
||||
|
||||
if (frame.methodClass() == Frame::fcQueue) {
|
||||
if (frame.methodClass() == QAmqpFrame::fcQueue) {
|
||||
switch (frame.id()) {
|
||||
case miDeclareOk:
|
||||
declareOk(frame);
|
||||
|
|
@ -51,7 +51,7 @@ bool QueuePrivate::_q_method(const Frame::Method &frame)
|
|||
return true;
|
||||
}
|
||||
|
||||
if (frame.methodClass() == Frame::fcBasic) {
|
||||
if (frame.methodClass() == QAmqpFrame::fcBasic) {
|
||||
switch(frame.id()) {
|
||||
case bmConsumeOk:
|
||||
consumeOk(frame);
|
||||
|
|
@ -76,9 +76,9 @@ bool QueuePrivate::_q_method(const Frame::Method &frame)
|
|||
return false;
|
||||
}
|
||||
|
||||
void QueuePrivate::_q_content(const Frame::Content &frame)
|
||||
void QAmqpQueuePrivate::_q_content(const QAmqpContentFrame &frame)
|
||||
{
|
||||
Q_Q(Queue);
|
||||
Q_Q(QAmqpQueue);
|
||||
Q_ASSERT(frame.channel() == channelNumber);
|
||||
if (frame.channel() != channelNumber)
|
||||
return;
|
||||
|
|
@ -89,11 +89,11 @@ void QueuePrivate::_q_content(const Frame::Content &frame)
|
|||
}
|
||||
|
||||
currentMessage.d->leftSize = frame.bodySize();
|
||||
Message::PropertyHash::ConstIterator it;
|
||||
Message::PropertyHash::ConstIterator itEnd = frame.properties_.constEnd();
|
||||
QAmqpMessage::PropertyHash::ConstIterator it;
|
||||
QAmqpMessage::PropertyHash::ConstIterator itEnd = frame.properties_.constEnd();
|
||||
for (it = frame.properties_.constBegin(); it != itEnd; ++it) {
|
||||
Message::Property property = (it.key());
|
||||
if (property == Message::Headers)
|
||||
QAmqpMessage::Property property = (it.key());
|
||||
if (property == QAmqpMessage::Headers)
|
||||
currentMessage.d->headers = (it.value()).toHash();
|
||||
currentMessage.d->properties[property] = it.value();
|
||||
}
|
||||
|
|
@ -105,9 +105,9 @@ void QueuePrivate::_q_content(const Frame::Content &frame)
|
|||
}
|
||||
}
|
||||
|
||||
void QueuePrivate::_q_body(const Frame::ContentBody &frame)
|
||||
void QAmqpQueuePrivate::_q_body(const QAmqpContentBodyFrame &frame)
|
||||
{
|
||||
Q_Q(Queue);
|
||||
Q_Q(QAmqpQueue);
|
||||
Q_ASSERT(frame.channel() == channelNumber);
|
||||
if (frame.channel() != channelNumber)
|
||||
return;
|
||||
|
|
@ -125,16 +125,16 @@ void QueuePrivate::_q_body(const Frame::ContentBody &frame)
|
|||
}
|
||||
}
|
||||
|
||||
void QueuePrivate::declareOk(const Frame::Method &frame)
|
||||
void QAmqpQueuePrivate::declareOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Queue);
|
||||
Q_Q(QAmqpQueue);
|
||||
qAmqpDebug() << "declared queue: " << name;
|
||||
declared = true;
|
||||
|
||||
QByteArray data = frame.arguments();
|
||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||
|
||||
name = Frame::readAmqpField(stream, MetaType::ShortString).toString();
|
||||
name = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString();
|
||||
qint32 messageCount = 0, consumerCount = 0;
|
||||
stream >> messageCount >> consumerCount;
|
||||
qAmqpDebug("message count %d\nConsumer count: %d", messageCount, consumerCount);
|
||||
|
|
@ -142,9 +142,9 @@ void QueuePrivate::declareOk(const Frame::Method &frame)
|
|||
Q_EMIT q->declared();
|
||||
}
|
||||
|
||||
void QueuePrivate::purgeOk(const Frame::Method &frame)
|
||||
void QAmqpQueuePrivate::purgeOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Queue);
|
||||
Q_Q(QAmqpQueue);
|
||||
qAmqpDebug() << "purged queue: " << name;
|
||||
|
||||
QByteArray data = frame.arguments();
|
||||
|
|
@ -156,9 +156,9 @@ void QueuePrivate::purgeOk(const Frame::Method &frame)
|
|||
Q_EMIT q->purged(messageCount);
|
||||
}
|
||||
|
||||
void QueuePrivate::deleteOk(const Frame::Method &frame)
|
||||
void QAmqpQueuePrivate::deleteOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Queue);
|
||||
Q_Q(QAmqpQueue);
|
||||
qAmqpDebug() << "deleted queue: " << name;
|
||||
declared = false;
|
||||
|
||||
|
|
@ -171,80 +171,80 @@ void QueuePrivate::deleteOk(const Frame::Method &frame)
|
|||
Q_EMIT q->removed();
|
||||
}
|
||||
|
||||
void QueuePrivate::bindOk(const Frame::Method &frame)
|
||||
void QAmqpQueuePrivate::bindOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_UNUSED(frame)
|
||||
|
||||
Q_Q(Queue);
|
||||
Q_Q(QAmqpQueue);
|
||||
qAmqpDebug() << Q_FUNC_INFO << "bound to exchange";
|
||||
Q_EMIT q->bound();
|
||||
}
|
||||
|
||||
void QueuePrivate::unbindOk(const Frame::Method &frame)
|
||||
void QAmqpQueuePrivate::unbindOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_UNUSED(frame)
|
||||
|
||||
Q_Q(Queue);
|
||||
Q_Q(QAmqpQueue);
|
||||
qAmqpDebug() << Q_FUNC_INFO << "unbound from exchange";
|
||||
Q_EMIT q->unbound();
|
||||
}
|
||||
|
||||
void QueuePrivate::getOk(const Frame::Method &frame)
|
||||
void QAmqpQueuePrivate::getOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
QByteArray data = frame.arguments();
|
||||
QDataStream in(&data, QIODevice::ReadOnly);
|
||||
|
||||
Message message;
|
||||
message.d->deliveryTag = Frame::readAmqpField(in, MetaType::LongLongUint).toLongLong();
|
||||
message.d->redelivered = Frame::readAmqpField(in, MetaType::Boolean).toBool();
|
||||
message.d->exchangeName = Frame::readAmqpField(in, MetaType::ShortString).toString();
|
||||
message.d->routingKey = Frame::readAmqpField(in, MetaType::ShortString).toString();
|
||||
QAmqpMessage message;
|
||||
message.d->deliveryTag = QAmqpFrame::readAmqpField(in, QAmqpMetaType::LongLongUint).toLongLong();
|
||||
message.d->redelivered = QAmqpFrame::readAmqpField(in, QAmqpMetaType::Boolean).toBool();
|
||||
message.d->exchangeName = QAmqpFrame::readAmqpField(in, QAmqpMetaType::ShortString).toString();
|
||||
message.d->routingKey = QAmqpFrame::readAmqpField(in, QAmqpMetaType::ShortString).toString();
|
||||
currentMessage = message;
|
||||
}
|
||||
|
||||
void QueuePrivate::consumeOk(const Frame::Method &frame)
|
||||
void QAmqpQueuePrivate::consumeOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Queue);
|
||||
Q_Q(QAmqpQueue);
|
||||
qAmqpDebug() << "consume ok: " << name;
|
||||
QByteArray data = frame.arguments();
|
||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||
consumerTag = Frame::readAmqpField(stream, MetaType::ShortString).toString();
|
||||
consumerTag = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString();
|
||||
qAmqpDebug("consumer tag = %s", qPrintable(consumerTag));
|
||||
consuming = true;
|
||||
Q_EMIT q->consuming(consumerTag);
|
||||
}
|
||||
|
||||
void QueuePrivate::deliver(const Frame::Method &frame)
|
||||
void QAmqpQueuePrivate::deliver(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
qAmqpDebug() << Q_FUNC_INFO;
|
||||
QByteArray data = frame.arguments();
|
||||
QDataStream in(&data, QIODevice::ReadOnly);
|
||||
QString consumer = Frame::readAmqpField(in, MetaType::ShortString).toString();
|
||||
QString consumer = QAmqpFrame::readAmqpField(in, QAmqpMetaType::ShortString).toString();
|
||||
if (consumerTag != consumer) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "invalid consumer tag: " << consumer;
|
||||
return;
|
||||
}
|
||||
|
||||
Message message;
|
||||
message.d->deliveryTag = Frame::readAmqpField(in, MetaType::LongLongUint).toLongLong();
|
||||
message.d->redelivered = Frame::readAmqpField(in, MetaType::Boolean).toBool();
|
||||
message.d->exchangeName = Frame::readAmqpField(in, MetaType::ShortString).toString();
|
||||
message.d->routingKey = Frame::readAmqpField(in, MetaType::ShortString).toString();
|
||||
QAmqpMessage message;
|
||||
message.d->deliveryTag = QAmqpFrame::readAmqpField(in, QAmqpMetaType::LongLongUint).toLongLong();
|
||||
message.d->redelivered = QAmqpFrame::readAmqpField(in, QAmqpMetaType::Boolean).toBool();
|
||||
message.d->exchangeName = QAmqpFrame::readAmqpField(in, QAmqpMetaType::ShortString).toString();
|
||||
message.d->routingKey = QAmqpFrame::readAmqpField(in, QAmqpMetaType::ShortString).toString();
|
||||
currentMessage = message;
|
||||
}
|
||||
|
||||
void QueuePrivate::declare()
|
||||
void QAmqpQueuePrivate::declare()
|
||||
{
|
||||
Frame::Method frame(Frame::fcQueue, QueuePrivate::miDeclare);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miDeclare);
|
||||
frame.setChannel(channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
QDataStream out(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
out << qint16(0); //reserved 1
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, name);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, name);
|
||||
out << qint8(options);
|
||||
Frame::writeAmqpField(out, MetaType::Hash, Table());
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::Hash, QAmqpTable());
|
||||
|
||||
frame.setArguments(arguments);
|
||||
sendFrame(frame);
|
||||
|
|
@ -253,13 +253,13 @@ void QueuePrivate::declare()
|
|||
delayedDeclare = false;
|
||||
}
|
||||
|
||||
void QueuePrivate::cancelOk(const Frame::Method &frame)
|
||||
void QAmqpQueuePrivate::cancelOk(const QAmqpMethodFrame &frame)
|
||||
{
|
||||
Q_Q(Queue);
|
||||
Q_Q(QAmqpQueue);
|
||||
qAmqpDebug() << Q_FUNC_INFO;
|
||||
QByteArray data = frame.arguments();
|
||||
QDataStream in(&data, QIODevice::ReadOnly);
|
||||
QString consumer = Frame::readAmqpField(in, MetaType::ShortString).toString();
|
||||
QString consumer = QAmqpFrame::readAmqpField(in, QAmqpMetaType::ShortString).toString();
|
||||
if (consumerTag != consumer) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "invalid consumer tag: " << consumer;
|
||||
return;
|
||||
|
|
@ -271,20 +271,20 @@ void QueuePrivate::cancelOk(const Frame::Method &frame)
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Queue::Queue(int channelNumber, Client *parent)
|
||||
: Channel(new QueuePrivate(this), parent)
|
||||
QAmqpQueue::QAmqpQueue(int channelNumber, QAmqpClient *parent)
|
||||
: QAmqpChannel(new QAmqpQueuePrivate(this), parent)
|
||||
{
|
||||
Q_D(Queue);
|
||||
Q_D(QAmqpQueue);
|
||||
d->init(channelNumber, parent);
|
||||
}
|
||||
|
||||
Queue::~Queue()
|
||||
QAmqpQueue::~QAmqpQueue()
|
||||
{
|
||||
}
|
||||
|
||||
void Queue::channelOpened()
|
||||
void QAmqpQueue::channelOpened()
|
||||
{
|
||||
Q_D(Queue);
|
||||
Q_D(QAmqpQueue);
|
||||
if (d->delayedDeclare)
|
||||
d->declare();
|
||||
|
||||
|
|
@ -296,19 +296,19 @@ void Queue::channelOpened()
|
|||
}
|
||||
}
|
||||
|
||||
void Queue::channelClosed()
|
||||
void QAmqpQueue::channelClosed()
|
||||
{
|
||||
}
|
||||
|
||||
int Queue::options() const
|
||||
int QAmqpQueue::options() const
|
||||
{
|
||||
Q_D(const Queue);
|
||||
Q_D(const QAmqpQueue);
|
||||
return d->options;
|
||||
}
|
||||
|
||||
void Queue::declare(int options)
|
||||
void QAmqpQueue::declare(int options)
|
||||
{
|
||||
Q_D(Queue);
|
||||
Q_D(QAmqpQueue);
|
||||
d->options = options;
|
||||
|
||||
if (!d->opened) {
|
||||
|
|
@ -319,49 +319,49 @@ void Queue::declare(int options)
|
|||
d->declare();
|
||||
}
|
||||
|
||||
void Queue::remove(int options)
|
||||
void QAmqpQueue::remove(int options)
|
||||
{
|
||||
Q_D(Queue);
|
||||
Q_D(QAmqpQueue);
|
||||
if (!d->declared) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "trying to remove undeclared queue, aborting...";
|
||||
return;
|
||||
}
|
||||
|
||||
Frame::Method frame(Frame::fcQueue, QueuePrivate::miDelete);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miDelete);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
QDataStream out(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
out << qint16(0); //reserved 1
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, d->name);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
|
||||
out << qint8(options);
|
||||
|
||||
frame.setArguments(arguments);
|
||||
d->sendFrame(frame);
|
||||
}
|
||||
|
||||
void Queue::purge()
|
||||
void QAmqpQueue::purge()
|
||||
{
|
||||
Q_D(Queue);
|
||||
Q_D(QAmqpQueue);
|
||||
|
||||
if (!d->opened)
|
||||
return;
|
||||
|
||||
Frame::Method frame(Frame::fcQueue, QueuePrivate::miPurge);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miPurge);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
QDataStream out(&arguments, QIODevice::WriteOnly);
|
||||
out << qint16(0); //reserved 1
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, d->name);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
|
||||
out << qint8(0); // no-wait
|
||||
|
||||
frame.setArguments(arguments);
|
||||
d->sendFrame(frame);
|
||||
}
|
||||
|
||||
void Queue::bind(Exchange *exchange, const QString &key)
|
||||
void QAmqpQueue::bind(QAmqpExchange *exchange, const QString &key)
|
||||
{
|
||||
if (!exchange) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "invalid exchange provided";
|
||||
|
|
@ -371,33 +371,33 @@ void Queue::bind(Exchange *exchange, const QString &key)
|
|||
bind(exchange->name(), key);
|
||||
}
|
||||
|
||||
void Queue::bind(const QString &exchangeName, const QString &key)
|
||||
void QAmqpQueue::bind(const QString &exchangeName, const QString &key)
|
||||
{
|
||||
Q_D(Queue);
|
||||
Q_D(QAmqpQueue);
|
||||
if (!d->opened) {
|
||||
d->delayedBindings.append(QPair<QString,QString>(exchangeName, key));
|
||||
return;
|
||||
}
|
||||
|
||||
Frame::Method frame(Frame::fcQueue, QueuePrivate::miBind);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miBind);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
QDataStream out(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
out << qint16(0); // reserved 1
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, d->name);
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, exchangeName);
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, key);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, exchangeName);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, key);
|
||||
|
||||
out << qint8(0); // no-wait
|
||||
Frame::writeAmqpField(out, MetaType::Hash, Table());
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::Hash, QAmqpTable());
|
||||
|
||||
frame.setArguments(arguments);
|
||||
d->sendFrame(frame);
|
||||
}
|
||||
|
||||
void Queue::unbind(Exchange *exchange, const QString &key)
|
||||
void QAmqpQueue::unbind(QAmqpExchange *exchange, const QString &key)
|
||||
{
|
||||
if (!exchange) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "invalid exchange provided";
|
||||
|
|
@ -407,32 +407,32 @@ void Queue::unbind(Exchange *exchange, const QString &key)
|
|||
unbind(exchange->name(), key);
|
||||
}
|
||||
|
||||
void Queue::unbind(const QString &exchangeName, const QString &key)
|
||||
void QAmqpQueue::unbind(const QString &exchangeName, const QString &key)
|
||||
{
|
||||
Q_D(Queue);
|
||||
Q_D(QAmqpQueue);
|
||||
if (!d->opened) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "queue is not open";
|
||||
return;
|
||||
}
|
||||
|
||||
Frame::Method frame(Frame::fcQueue, QueuePrivate::miUnbind);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miUnbind);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
QDataStream out(&arguments, QIODevice::WriteOnly);
|
||||
out << qint16(0); //reserved 1
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, d->name);
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, exchangeName);
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, key);
|
||||
Frame::writeAmqpField(out, MetaType::Hash, Table());
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, exchangeName);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, key);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::Hash, QAmqpTable());
|
||||
|
||||
frame.setArguments(arguments);
|
||||
d->sendFrame(frame);
|
||||
}
|
||||
|
||||
bool Queue::consume(int options)
|
||||
bool QAmqpQueue::consume(int options)
|
||||
{
|
||||
Q_D(Queue);
|
||||
Q_D(QAmqpQueue);
|
||||
if (!d->opened) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "queue is not open";
|
||||
return false;
|
||||
|
|
@ -443,73 +443,73 @@ bool Queue::consume(int options)
|
|||
return false;
|
||||
}
|
||||
|
||||
Frame::Method frame(Frame::fcBasic, QueuePrivate::bmConsume);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpQueuePrivate::bmConsume);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
QDataStream out(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
out << qint16(0); //reserved 1
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, d->name);
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, d->consumerTag);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->consumerTag);
|
||||
|
||||
out << qint8(options);
|
||||
Frame::writeAmqpField(out, MetaType::Hash, Table());
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::Hash, QAmqpTable());
|
||||
|
||||
frame.setArguments(arguments);
|
||||
d->sendFrame(frame);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Queue::setConsumerTag(const QString &consumerTag)
|
||||
void QAmqpQueue::setConsumerTag(const QString &consumerTag)
|
||||
{
|
||||
Q_D(Queue);
|
||||
Q_D(QAmqpQueue);
|
||||
d->consumerTag = consumerTag;
|
||||
}
|
||||
|
||||
QString Queue::consumerTag() const
|
||||
QString QAmqpQueue::consumerTag() const
|
||||
{
|
||||
Q_D(const Queue);
|
||||
Q_D(const QAmqpQueue);
|
||||
return d->consumerTag;
|
||||
}
|
||||
|
||||
bool Queue::isConsuming() const
|
||||
bool QAmqpQueue::isConsuming() const
|
||||
{
|
||||
Q_D(const Queue);
|
||||
Q_D(const QAmqpQueue);
|
||||
return d->consuming;
|
||||
}
|
||||
|
||||
void Queue::get(bool noAck)
|
||||
void QAmqpQueue::get(bool noAck)
|
||||
{
|
||||
Q_D(Queue);
|
||||
Q_D(QAmqpQueue);
|
||||
if (!d->opened) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "channel is not open";
|
||||
return;
|
||||
}
|
||||
|
||||
Frame::Method frame(Frame::fcBasic, QueuePrivate::bmGet);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpQueuePrivate::bmGet);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
QDataStream out(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
out << qint16(0); //reserved 1
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, d->name);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
|
||||
out << qint8(noAck ? 1 : 0); // no-ack
|
||||
|
||||
frame.setArguments(arguments);
|
||||
d->sendFrame(frame);
|
||||
}
|
||||
|
||||
void Queue::ack(const Message &message)
|
||||
void QAmqpQueue::ack(const QAmqpMessage &message)
|
||||
{
|
||||
Q_D(Queue);
|
||||
Q_D(QAmqpQueue);
|
||||
if (!d->opened) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "channel is not open";
|
||||
return;
|
||||
}
|
||||
|
||||
Frame::Method frame(Frame::fcBasic, QueuePrivate::bmAck);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpQueuePrivate::bmAck);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
|
|
@ -522,9 +522,9 @@ void Queue::ack(const Message &message)
|
|||
d->sendFrame(frame);
|
||||
}
|
||||
|
||||
bool Queue::cancel(bool noWait)
|
||||
bool QAmqpQueue::cancel(bool noWait)
|
||||
{
|
||||
Q_D(Queue);
|
||||
Q_D(QAmqpQueue);
|
||||
if (!d->consuming) {
|
||||
qAmqpDebug() << Q_FUNC_INFO << "not consuming!";
|
||||
return false;
|
||||
|
|
@ -535,13 +535,13 @@ bool Queue::cancel(bool noWait)
|
|||
return false;
|
||||
}
|
||||
|
||||
Frame::Method frame(Frame::fcBasic, QueuePrivate::bmCancel);
|
||||
QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpQueuePrivate::bmCancel);
|
||||
frame.setChannel(d->channelNumber);
|
||||
|
||||
QByteArray arguments;
|
||||
QDataStream out(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
Frame::writeAmqpField(out, MetaType::ShortString, d->consumerTag);
|
||||
QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->consumerTag);
|
||||
out << (noWait ? qint8(0x01) : qint8(0x0));
|
||||
|
||||
frame.setArguments(arguments);
|
||||
|
|
|
|||
|
|
@ -7,14 +7,11 @@
|
|||
#include "qamqpmessage.h"
|
||||
#include "qamqpglobal.h"
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
class Client;
|
||||
class ClientPrivate;
|
||||
class Exchange;
|
||||
class QueuePrivate;
|
||||
class QAMQP_EXPORT Queue : public Channel, public QQueue<Message>
|
||||
class QAmqpClient;
|
||||
class QAmqpClientPrivate;
|
||||
class QAmqpExchange;
|
||||
class QAmqpQueuePrivate;
|
||||
class QAMQP_EXPORT QAmqpQueue : public QAmqpChannel, public QQueue<QAmqpMessage>
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(QueueOptions)
|
||||
|
|
@ -52,7 +49,7 @@ public:
|
|||
};
|
||||
Q_DECLARE_FLAGS(RemoveOptions, RemoveOption)
|
||||
|
||||
~Queue();
|
||||
~QAmqpQueue();
|
||||
|
||||
bool isConsuming() const;
|
||||
void setConsumerTag(const QString &consumerTag);
|
||||
|
|
@ -61,16 +58,16 @@ public:
|
|||
// AMQP Queue
|
||||
void declare(int options = Durable|AutoDelete);
|
||||
void bind(const QString &exchangeName, const QString &key);
|
||||
void bind(Exchange *exchange, const QString &key);
|
||||
void bind(QAmqpExchange *exchange, const QString &key);
|
||||
void unbind(const QString &exchangeName, const QString &key);
|
||||
void unbind(Exchange *exchange, const QString &key);
|
||||
void unbind(QAmqpExchange *exchange, const QString &key);
|
||||
void purge();
|
||||
void remove(int options = roIfUnused|roIfEmpty|roNoWait);
|
||||
|
||||
// AMQP Basic
|
||||
bool consume(int options = NoOptions);
|
||||
void get(bool noAck = true);
|
||||
void ack(const Message &message);
|
||||
void ack(const QAmqpMessage &message);
|
||||
bool cancel(bool noWait = false);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
@ -91,14 +88,12 @@ protected:
|
|||
virtual void channelClosed();
|
||||
|
||||
private:
|
||||
explicit Queue(int channelNumber = -1, Client *parent = 0);
|
||||
explicit QAmqpQueue(int channelNumber = -1, QAmqpClient *parent = 0);
|
||||
|
||||
Q_DISABLE_COPY(Queue)
|
||||
Q_DECLARE_PRIVATE(Queue)
|
||||
Q_DISABLE_COPY(QAmqpQueue)
|
||||
Q_DECLARE_PRIVATE(QAmqpQueue)
|
||||
|
||||
friend class Client;
|
||||
friend class QAmqpClient;
|
||||
};
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
#endif // QAMQPQUEUE_H
|
||||
|
|
|
|||
|
|
@ -6,12 +6,9 @@
|
|||
|
||||
#include "qamqpchannel_p.h"
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
class QueuePrivate: public ChannelPrivate,
|
||||
public Frame::ContentHandler,
|
||||
public Frame::ContentBodyHandler
|
||||
class QAmqpQueuePrivate: public QAmqpChannelPrivate,
|
||||
public QAmqpContentFrameHandler,
|
||||
public QAmqpContentBodyFrameHandler
|
||||
{
|
||||
public:
|
||||
enum MethodId {
|
||||
|
|
@ -22,26 +19,26 @@ public:
|
|||
METHOD_ID_ENUM(miDelete, 40)
|
||||
};
|
||||
|
||||
QueuePrivate(Queue *q);
|
||||
~QueuePrivate();
|
||||
QAmqpQueuePrivate(QAmqpQueue *q);
|
||||
~QAmqpQueuePrivate();
|
||||
|
||||
void declare();
|
||||
virtual bool _q_method(const Frame::Method &frame);
|
||||
virtual bool _q_method(const QAmqpMethodFrame &frame);
|
||||
|
||||
// AMQP Queue method handlers
|
||||
void declareOk(const Frame::Method &frame);
|
||||
void deleteOk(const Frame::Method &frame);
|
||||
void purgeOk(const Frame::Method &frame);
|
||||
void bindOk(const Frame::Method &frame);
|
||||
void unbindOk(const Frame::Method &frame);
|
||||
void consumeOk(const Frame::Method &frame);
|
||||
void declareOk(const QAmqpMethodFrame &frame);
|
||||
void deleteOk(const QAmqpMethodFrame &frame);
|
||||
void purgeOk(const QAmqpMethodFrame &frame);
|
||||
void bindOk(const QAmqpMethodFrame &frame);
|
||||
void unbindOk(const QAmqpMethodFrame &frame);
|
||||
void consumeOk(const QAmqpMethodFrame &frame);
|
||||
|
||||
// AMQP Basic method handlers
|
||||
virtual void _q_content(const Frame::Content &frame);
|
||||
virtual void _q_body(const Frame::ContentBody &frame);
|
||||
void deliver(const Frame::Method &frame);
|
||||
void getOk(const Frame::Method &frame);
|
||||
void cancelOk(const Frame::Method &frame);
|
||||
virtual void _q_content(const QAmqpContentFrame &frame);
|
||||
virtual void _q_body(const QAmqpContentBodyFrame &frame);
|
||||
void deliver(const QAmqpMethodFrame &frame);
|
||||
void getOk(const QAmqpMethodFrame &frame);
|
||||
void cancelOk(const QAmqpMethodFrame &frame);
|
||||
|
||||
QString type;
|
||||
int options;
|
||||
|
|
@ -51,13 +48,11 @@ public:
|
|||
|
||||
QString consumerTag;
|
||||
bool recievingMessage;
|
||||
Message currentMessage;
|
||||
QAmqpMessage currentMessage;
|
||||
bool consuming;
|
||||
|
||||
Q_DECLARE_PUBLIC(Queue)
|
||||
Q_DECLARE_PUBLIC(QAmqpQueue)
|
||||
|
||||
};
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
#endif // QAMQPQUEUE_P_H
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include "qamqpframe_p.h"
|
||||
#include "qamqptable.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
/*
|
||||
* field value types according to: https://www.rabbitmq.com/amqp-0-9-1-errata.html
|
||||
|
|
@ -29,47 +28,47 @@ V - Void
|
|||
x - Byte array
|
||||
*/
|
||||
|
||||
MetaType::ValueType valueTypeForOctet(qint8 octet)
|
||||
QAmqpMetaType::ValueType valueTypeForOctet(qint8 octet)
|
||||
{
|
||||
switch (octet) {
|
||||
case 't': return MetaType::Boolean;
|
||||
case 'b': return MetaType::ShortShortInt;
|
||||
case 's': return MetaType::ShortInt;
|
||||
case 'I': return MetaType::LongInt;
|
||||
case 'l': return MetaType::LongLongInt;
|
||||
case 'f': return MetaType::Float;
|
||||
case 'd': return MetaType::Double;
|
||||
case 'D': return MetaType::Decimal;
|
||||
case 'S': return MetaType::LongString;
|
||||
case 'A': return MetaType::Array;
|
||||
case 'T': return MetaType::Timestamp;
|
||||
case 'F': return MetaType::Hash;
|
||||
case 'V': return MetaType::Void;
|
||||
case 'x': return MetaType::Bytes;
|
||||
case 't': return QAmqpMetaType::Boolean;
|
||||
case 'b': return QAmqpMetaType::ShortShortInt;
|
||||
case 's': return QAmqpMetaType::ShortInt;
|
||||
case 'I': return QAmqpMetaType::LongInt;
|
||||
case 'l': return QAmqpMetaType::LongLongInt;
|
||||
case 'f': return QAmqpMetaType::Float;
|
||||
case 'd': return QAmqpMetaType::Double;
|
||||
case 'D': return QAmqpMetaType::Decimal;
|
||||
case 'S': return QAmqpMetaType::LongString;
|
||||
case 'A': return QAmqpMetaType::Array;
|
||||
case 'T': return QAmqpMetaType::Timestamp;
|
||||
case 'F': return QAmqpMetaType::Hash;
|
||||
case 'V': return QAmqpMetaType::Void;
|
||||
case 'x': return QAmqpMetaType::Bytes;
|
||||
default:
|
||||
qAmqpDebug() << Q_FUNC_INFO << "invalid octet received: " << char(octet);
|
||||
}
|
||||
|
||||
return MetaType::Invalid;
|
||||
return QAmqpMetaType::Invalid;
|
||||
}
|
||||
|
||||
qint8 valueTypeToOctet(MetaType::ValueType type)
|
||||
qint8 valueTypeToOctet(QAmqpMetaType::ValueType type)
|
||||
{
|
||||
switch (type) {
|
||||
case MetaType::Boolean: return 't';
|
||||
case MetaType::ShortShortInt: return 'b';
|
||||
case MetaType::ShortInt: return 's';
|
||||
case MetaType::LongInt: return 'I';
|
||||
case MetaType::LongLongInt: return 'l';
|
||||
case MetaType::Float: return 'f';
|
||||
case MetaType::Double: return 'd';
|
||||
case MetaType::Decimal: return 'D';
|
||||
case MetaType::LongString: return 'S';
|
||||
case MetaType::Array: return 'A';
|
||||
case MetaType::Timestamp: return 'T';
|
||||
case MetaType::Hash: return 'F';
|
||||
case MetaType::Void: return 'V';
|
||||
case MetaType::Bytes: return 'x';
|
||||
case QAmqpMetaType::Boolean: return 't';
|
||||
case QAmqpMetaType::ShortShortInt: return 'b';
|
||||
case QAmqpMetaType::ShortInt: return 's';
|
||||
case QAmqpMetaType::LongInt: return 'I';
|
||||
case QAmqpMetaType::LongLongInt: return 'l';
|
||||
case QAmqpMetaType::Float: return 'f';
|
||||
case QAmqpMetaType::Double: return 'd';
|
||||
case QAmqpMetaType::Decimal: return 'D';
|
||||
case QAmqpMetaType::LongString: return 'S';
|
||||
case QAmqpMetaType::Array: return 'A';
|
||||
case QAmqpMetaType::Timestamp: return 'T';
|
||||
case QAmqpMetaType::Hash: return 'F';
|
||||
case QAmqpMetaType::Void: return 'V';
|
||||
case QAmqpMetaType::Bytes: return 'x';
|
||||
default:
|
||||
qAmqpDebug() << Q_FUNC_INFO << "invalid type received: " << char(type);
|
||||
}
|
||||
|
|
@ -77,71 +76,71 @@ qint8 valueTypeToOctet(MetaType::ValueType type)
|
|||
return 'V';
|
||||
}
|
||||
|
||||
void Table::writeFieldValue(QDataStream &stream, const QVariant &value)
|
||||
void QAmqpTable::writeFieldValue(QDataStream &stream, const QVariant &value)
|
||||
{
|
||||
MetaType::ValueType type;
|
||||
QAmqpMetaType::ValueType type;
|
||||
switch (value.userType()) {
|
||||
case QMetaType::Bool:
|
||||
type = MetaType::Boolean;
|
||||
type = QAmqpMetaType::Boolean;
|
||||
break;
|
||||
case QMetaType::QByteArray:
|
||||
type = MetaType::Bytes;
|
||||
type = QAmqpMetaType::Bytes;
|
||||
break;
|
||||
case QMetaType::Int:
|
||||
{
|
||||
int i = qAbs(value.toInt());
|
||||
if (i <= qint8(SCHAR_MAX)) {
|
||||
type = MetaType::ShortShortInt;
|
||||
type = QAmqpMetaType::ShortShortInt;
|
||||
} else if (i <= qint16(SHRT_MAX)) {
|
||||
type = MetaType::ShortInt;
|
||||
type = QAmqpMetaType::ShortInt;
|
||||
} else {
|
||||
type = MetaType::LongInt;
|
||||
type = QAmqpMetaType::LongInt;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QMetaType::UShort:
|
||||
type = MetaType::ShortInt;
|
||||
type = QAmqpMetaType::ShortInt;
|
||||
break;
|
||||
case QMetaType::UInt:
|
||||
{
|
||||
int i = value.toInt();
|
||||
if (i <= qint8(SCHAR_MAX)) {
|
||||
type = MetaType::ShortShortInt;
|
||||
type = QAmqpMetaType::ShortShortInt;
|
||||
} else if (i <= qint16(SHRT_MAX)) {
|
||||
type = MetaType::ShortInt;
|
||||
type = QAmqpMetaType::ShortInt;
|
||||
} else {
|
||||
type = MetaType::LongInt;
|
||||
type = QAmqpMetaType::LongInt;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QMetaType::LongLong:
|
||||
case QMetaType::ULongLong:
|
||||
type = MetaType::LongLongInt;
|
||||
type = QAmqpMetaType::LongLongInt;
|
||||
break;
|
||||
case QMetaType::QString:
|
||||
type = MetaType::LongString;
|
||||
type = QAmqpMetaType::LongString;
|
||||
break;
|
||||
case QMetaType::QDateTime:
|
||||
type = MetaType::Timestamp;
|
||||
type = QAmqpMetaType::Timestamp;
|
||||
break;
|
||||
case QMetaType::Double:
|
||||
type = value.toDouble() > FLT_MAX ? MetaType::Double : MetaType::Float;
|
||||
type = value.toDouble() > FLT_MAX ? QAmqpMetaType::Double : QAmqpMetaType::Float;
|
||||
break;
|
||||
case QMetaType::QVariantHash:
|
||||
type = MetaType::Hash;
|
||||
type = QAmqpMetaType::Hash;
|
||||
break;
|
||||
case QMetaType::QVariantList:
|
||||
type = MetaType::Array;
|
||||
type = QAmqpMetaType::Array;
|
||||
break;
|
||||
case QMetaType::Void:
|
||||
type = MetaType::Void;
|
||||
type = QAmqpMetaType::Void;
|
||||
break;
|
||||
default:
|
||||
if (value.userType() == qMetaTypeId<QAMQP::Decimal>()) {
|
||||
type = MetaType::Decimal;
|
||||
type = QAmqpMetaType::Decimal;
|
||||
break;
|
||||
} else if (!value.isValid()) {
|
||||
type = MetaType::Void;
|
||||
type = QAmqpMetaType::Void;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -154,33 +153,33 @@ void Table::writeFieldValue(QDataStream &stream, const QVariant &value)
|
|||
writeFieldValue(stream, type, value);
|
||||
}
|
||||
|
||||
void Table::writeFieldValue(QDataStream &stream, MetaType::ValueType type, const QVariant &value)
|
||||
void QAmqpTable::writeFieldValue(QDataStream &stream, QAmqpMetaType::ValueType type, const QVariant &value)
|
||||
{
|
||||
switch (type) {
|
||||
case MetaType::Boolean:
|
||||
case MetaType::ShortShortUint:
|
||||
case MetaType::ShortUint:
|
||||
case MetaType::LongUint:
|
||||
case MetaType::LongLongUint:
|
||||
case MetaType::ShortString:
|
||||
case MetaType::LongString:
|
||||
case MetaType::Timestamp:
|
||||
case MetaType::Hash:
|
||||
return Frame::writeAmqpField(stream, type, value);
|
||||
case QAmqpMetaType::Boolean:
|
||||
case QAmqpMetaType::ShortShortUint:
|
||||
case QAmqpMetaType::ShortUint:
|
||||
case QAmqpMetaType::LongUint:
|
||||
case QAmqpMetaType::LongLongUint:
|
||||
case QAmqpMetaType::ShortString:
|
||||
case QAmqpMetaType::LongString:
|
||||
case QAmqpMetaType::Timestamp:
|
||||
case QAmqpMetaType::Hash:
|
||||
return QAmqpFrame::writeAmqpField(stream, type, value);
|
||||
|
||||
case MetaType::ShortShortInt:
|
||||
case QAmqpMetaType::ShortShortInt:
|
||||
stream << qint8(value.toInt());
|
||||
break;
|
||||
case MetaType::ShortInt:
|
||||
case QAmqpMetaType::ShortInt:
|
||||
stream << qint16(value.toInt());
|
||||
break;
|
||||
case MetaType::LongInt:
|
||||
case QAmqpMetaType::LongInt:
|
||||
stream << qint32(value.toInt());
|
||||
break;
|
||||
case MetaType::LongLongInt:
|
||||
case QAmqpMetaType::LongLongInt:
|
||||
stream << qlonglong(value.toLongLong());
|
||||
break;
|
||||
case MetaType::Float:
|
||||
case QAmqpMetaType::Float:
|
||||
{
|
||||
float g = value.toFloat();
|
||||
QDataStream::FloatingPointPrecision oldPrecision = stream.floatingPointPrecision();
|
||||
|
|
@ -189,7 +188,7 @@ void Table::writeFieldValue(QDataStream &stream, MetaType::ValueType type, const
|
|||
stream.setFloatingPointPrecision(oldPrecision);
|
||||
}
|
||||
break;
|
||||
case MetaType::Double:
|
||||
case QAmqpMetaType::Double:
|
||||
{
|
||||
double g = value.toDouble();
|
||||
QDataStream::FloatingPointPrecision oldPrecision = stream.floatingPointPrecision();
|
||||
|
|
@ -198,14 +197,14 @@ void Table::writeFieldValue(QDataStream &stream, MetaType::ValueType type, const
|
|||
stream.setFloatingPointPrecision(oldPrecision);
|
||||
}
|
||||
break;
|
||||
case MetaType::Decimal:
|
||||
case QAmqpMetaType::Decimal:
|
||||
{
|
||||
QAMQP::Decimal v(value.value<QAMQP::Decimal>());
|
||||
stream << v.scale;
|
||||
stream << v.value;
|
||||
}
|
||||
break;
|
||||
case MetaType::Array:
|
||||
case QAmqpMetaType::Array:
|
||||
{
|
||||
QByteArray buffer;
|
||||
QDataStream arrayStream(&buffer, QIODevice::WriteOnly);
|
||||
|
|
@ -220,14 +219,14 @@ void Table::writeFieldValue(QDataStream &stream, MetaType::ValueType type, const
|
|||
}
|
||||
}
|
||||
break;
|
||||
case MetaType::Bytes:
|
||||
case QAmqpMetaType::Bytes:
|
||||
{
|
||||
QByteArray ba = value.toByteArray();
|
||||
stream << quint32(ba.length());
|
||||
stream.writeRawData(ba.data(), ba.length());
|
||||
}
|
||||
break;
|
||||
case MetaType::Void:
|
||||
case QAmqpMetaType::Void:
|
||||
stream << qint32(0);
|
||||
break;
|
||||
|
||||
|
|
@ -236,45 +235,45 @@ void Table::writeFieldValue(QDataStream &stream, MetaType::ValueType type, const
|
|||
}
|
||||
}
|
||||
|
||||
QVariant Table::readFieldValue(QDataStream &stream, MetaType::ValueType type)
|
||||
QVariant QAmqpTable::readFieldValue(QDataStream &stream, QAmqpMetaType::ValueType type)
|
||||
{
|
||||
switch (type) {
|
||||
case MetaType::Boolean:
|
||||
case MetaType::ShortShortUint:
|
||||
case MetaType::ShortUint:
|
||||
case MetaType::LongUint:
|
||||
case MetaType::LongLongUint:
|
||||
case MetaType::ShortString:
|
||||
case MetaType::LongString:
|
||||
case MetaType::Timestamp:
|
||||
case MetaType::Hash:
|
||||
return Frame::readAmqpField(stream, type);
|
||||
case QAmqpMetaType::Boolean:
|
||||
case QAmqpMetaType::ShortShortUint:
|
||||
case QAmqpMetaType::ShortUint:
|
||||
case QAmqpMetaType::LongUint:
|
||||
case QAmqpMetaType::LongLongUint:
|
||||
case QAmqpMetaType::ShortString:
|
||||
case QAmqpMetaType::LongString:
|
||||
case QAmqpMetaType::Timestamp:
|
||||
case QAmqpMetaType::Hash:
|
||||
return QAmqpFrame::readAmqpField(stream, type);
|
||||
|
||||
case MetaType::ShortShortInt:
|
||||
case QAmqpMetaType::ShortShortInt:
|
||||
{
|
||||
char octet;
|
||||
stream.readRawData(&octet, sizeof(octet));
|
||||
return QVariant::fromValue<int>(octet);
|
||||
}
|
||||
case MetaType::ShortInt:
|
||||
case QAmqpMetaType::ShortInt:
|
||||
{
|
||||
qint16 tmp_value = 0;
|
||||
stream >> tmp_value;
|
||||
return QVariant::fromValue<int>(tmp_value);
|
||||
}
|
||||
case MetaType::LongInt:
|
||||
case QAmqpMetaType::LongInt:
|
||||
{
|
||||
qint32 tmp_value = 0;
|
||||
stream >> tmp_value;
|
||||
return QVariant::fromValue<int>(tmp_value);
|
||||
}
|
||||
case MetaType::LongLongInt:
|
||||
case QAmqpMetaType::LongLongInt:
|
||||
{
|
||||
qlonglong v = 0 ;
|
||||
stream >> v;
|
||||
return v;
|
||||
}
|
||||
case MetaType::Float:
|
||||
case QAmqpMetaType::Float:
|
||||
{
|
||||
float tmp_value;
|
||||
QDataStream::FloatingPointPrecision precision = stream.floatingPointPrecision();
|
||||
|
|
@ -283,7 +282,7 @@ QVariant Table::readFieldValue(QDataStream &stream, MetaType::ValueType type)
|
|||
stream.setFloatingPointPrecision(precision);
|
||||
return QVariant::fromValue<float>(tmp_value);
|
||||
}
|
||||
case MetaType::Double:
|
||||
case QAmqpMetaType::Double:
|
||||
{
|
||||
double tmp_value;
|
||||
QDataStream::FloatingPointPrecision precision = stream.floatingPointPrecision();
|
||||
|
|
@ -292,14 +291,14 @@ QVariant Table::readFieldValue(QDataStream &stream, MetaType::ValueType type)
|
|||
stream.setFloatingPointPrecision(precision);
|
||||
return QVariant::fromValue<double>(tmp_value);
|
||||
}
|
||||
case MetaType::Decimal:
|
||||
case QAmqpMetaType::Decimal:
|
||||
{
|
||||
QAMQP::Decimal v;
|
||||
stream >> v.scale;
|
||||
stream >> v.value;
|
||||
return QVariant::fromValue<QAMQP::Decimal>(v);
|
||||
}
|
||||
case MetaType::Array:
|
||||
case QAmqpMetaType::Array:
|
||||
{
|
||||
QByteArray data;
|
||||
quint32 size = 0;
|
||||
|
|
@ -317,7 +316,7 @@ QVariant Table::readFieldValue(QDataStream &stream, MetaType::ValueType type)
|
|||
|
||||
return result;
|
||||
}
|
||||
case MetaType::Bytes:
|
||||
case QAmqpMetaType::Bytes:
|
||||
{
|
||||
QByteArray bytes;
|
||||
quint32 length = 0;
|
||||
|
|
@ -326,7 +325,7 @@ QVariant Table::readFieldValue(QDataStream &stream, MetaType::ValueType type)
|
|||
stream.readRawData(bytes.data(), bytes.size());
|
||||
return bytes;
|
||||
}
|
||||
case MetaType::Void:
|
||||
case QAmqpMetaType::Void:
|
||||
break;
|
||||
default:
|
||||
qAmqpDebug() << Q_FUNC_INFO << "unhandled type: " << type;
|
||||
|
|
@ -335,15 +334,15 @@ QVariant Table::readFieldValue(QDataStream &stream, MetaType::ValueType type)
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &stream, const Table &table)
|
||||
QDataStream &operator<<(QDataStream &stream, const QAmqpTable &table)
|
||||
{
|
||||
QByteArray data;
|
||||
QDataStream s(&data, QIODevice::WriteOnly);
|
||||
Table::ConstIterator it;
|
||||
Table::ConstIterator itEnd = table.constEnd();
|
||||
QAmqpTable::ConstIterator it;
|
||||
QAmqpTable::ConstIterator itEnd = table.constEnd();
|
||||
for (it = table.constBegin(); it != itEnd; ++it) {
|
||||
Table::writeFieldValue(s, MetaType::ShortString, it.key());
|
||||
Table::writeFieldValue(s, it.value());
|
||||
QAmqpTable::writeFieldValue(s, QAmqpMetaType::ShortString, it.key());
|
||||
QAmqpTable::writeFieldValue(s, it.value());
|
||||
}
|
||||
|
||||
if (data.isEmpty()) {
|
||||
|
|
@ -355,16 +354,16 @@ QDataStream &operator<<(QDataStream &stream, const Table &table)
|
|||
return stream;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &stream, Table &table)
|
||||
QDataStream &operator>>(QDataStream &stream, QAmqpTable &table)
|
||||
{
|
||||
QByteArray data;
|
||||
stream >> data;
|
||||
QDataStream tableStream(&data, QIODevice::ReadOnly);
|
||||
while (!tableStream.atEnd()) {
|
||||
qint8 octet = 0;
|
||||
QString field = Frame::readAmqpField(tableStream, MetaType::ShortString).toString();
|
||||
QString field = QAmqpFrame::readAmqpField(tableStream, QAmqpMetaType::ShortString).toString();
|
||||
tableStream >> octet;
|
||||
table[field] = Table::readFieldValue(tableStream, valueTypeForOctet(octet));
|
||||
table[field] = QAmqpTable::readFieldValue(tableStream, valueTypeForOctet(octet));
|
||||
}
|
||||
|
||||
return stream;
|
||||
|
|
|
|||
|
|
@ -5,26 +5,22 @@
|
|||
|
||||
#include "qamqpglobal.h"
|
||||
|
||||
namespace QAMQP {
|
||||
|
||||
class QAMQP_EXPORT Table : public QVariantHash
|
||||
class QAMQP_EXPORT QAmqpTable : public QVariantHash
|
||||
{
|
||||
public:
|
||||
Table() {}
|
||||
inline Table(const QVariantHash &variantHash)
|
||||
QAmqpTable() {}
|
||||
inline QAmqpTable(const QVariantHash &variantHash)
|
||||
: QVariantHash(variantHash)
|
||||
{
|
||||
}
|
||||
|
||||
static void writeFieldValue(QDataStream &stream, const QVariant &value);
|
||||
static void writeFieldValue(QDataStream &stream, MetaType::ValueType type, const QVariant &value);
|
||||
static QVariant readFieldValue(QDataStream &stream, MetaType::ValueType type);
|
||||
static void writeFieldValue(QDataStream &stream, QAmqpMetaType::ValueType type, const QVariant &value);
|
||||
static QVariant readFieldValue(QDataStream &stream, QAmqpMetaType::ValueType type);
|
||||
};
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
QAMQP_EXPORT QDataStream &operator<<(QDataStream &, const QAMQP::Table &table);
|
||||
QAMQP_EXPORT QDataStream &operator>>(QDataStream &, QAMQP::Table &table);
|
||||
Q_DECLARE_METATYPE(QAMQP::Table)
|
||||
QAMQP_EXPORT QDataStream &operator<<(QDataStream &, const QAmqpTable &table);
|
||||
QAMQP_EXPORT QDataStream &operator>>(QDataStream &, QAmqpTable &table);
|
||||
Q_DECLARE_METATYPE(QAmqpTable)
|
||||
|
||||
#endif // QAMQPTABLE_H
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include "qamqpclient.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
class tst_QAMQPChannel : public TestCase
|
||||
{
|
||||
|
|
@ -20,13 +19,13 @@ private Q_SLOTS:
|
|||
void sharedChannel();
|
||||
|
||||
private:
|
||||
QScopedPointer<Client> client;
|
||||
QScopedPointer<QAmqpClient> client;
|
||||
|
||||
};
|
||||
|
||||
void tst_QAMQPChannel::init()
|
||||
{
|
||||
client.reset(new Client);
|
||||
client.reset(new QAmqpClient);
|
||||
client->connectToHost();
|
||||
QVERIFY(waitForSignal(client.data(), SIGNAL(connected())));
|
||||
}
|
||||
|
|
@ -42,19 +41,19 @@ void tst_QAMQPChannel::cleanup()
|
|||
void tst_QAMQPChannel::close()
|
||||
{
|
||||
// exchange
|
||||
Exchange *exchange = client->createExchange("test-close-channel");
|
||||
QAmqpExchange *exchange = client->createExchange("test-close-channel");
|
||||
QVERIFY(waitForSignal(exchange, SIGNAL(opened())));
|
||||
exchange->declare(Exchange::Direct);
|
||||
exchange->declare(QAmqpExchange::Direct);
|
||||
QVERIFY(waitForSignal(exchange, SIGNAL(declared())));
|
||||
exchange->close();
|
||||
QVERIFY(waitForSignal(exchange, SIGNAL(closed())));
|
||||
exchange->reopen();
|
||||
QVERIFY(waitForSignal(exchange, SIGNAL(opened())));
|
||||
exchange->remove(Exchange::roForce);
|
||||
exchange->remove(QAmqpExchange::roForce);
|
||||
QVERIFY(waitForSignal(exchange, SIGNAL(removed())));
|
||||
|
||||
// queue
|
||||
Queue *queue = client->createQueue("test-close-channel");
|
||||
QAmqpQueue *queue = client->createQueue("test-close-channel");
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(opened())));
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
queue->close();
|
||||
|
|
@ -63,7 +62,7 @@ void tst_QAMQPChannel::close()
|
|||
|
||||
void tst_QAMQPChannel::resume()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-resume");
|
||||
QAmqpQueue *queue = client->createQueue("test-resume");
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(opened())));
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
|
|
@ -74,13 +73,13 @@ void tst_QAMQPChannel::resume()
|
|||
void tst_QAMQPChannel::sharedChannel()
|
||||
{
|
||||
QString routingKey = "test-shared-channel";
|
||||
Queue *queue = client->createQueue(routingKey);
|
||||
QAmqpQueue *queue = client->createQueue(routingKey);
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
Exchange *defaultExchange = client->createExchange("", queue->channelNumber());
|
||||
QAmqpExchange *defaultExchange = client->createExchange("", queue->channelNumber());
|
||||
defaultExchange->publish("first message", routingKey);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
|
||||
Message message = queue->dequeue();
|
||||
QAmqpMessage message = queue->dequeue();
|
||||
verifyStandardMessageHeaders(message, routingKey);
|
||||
QCOMPARE(message.payload(), QByteArray("first message"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include "qamqpclient_p.h"
|
||||
#include "qamqpauthenticator.h"
|
||||
|
||||
using namespace QAMQP;
|
||||
class tst_QAMQPClient : public TestCase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -28,7 +27,7 @@ private:
|
|||
|
||||
void tst_QAMQPClient::connect()
|
||||
{
|
||||
Client client;
|
||||
QAmqpClient client;
|
||||
client.connectToHost();
|
||||
QVERIFY(waitForSignal(&client, SIGNAL(connected())));
|
||||
|
||||
|
|
@ -45,7 +44,7 @@ void tst_QAMQPClient::connect()
|
|||
|
||||
void tst_QAMQPClient::connectProperties()
|
||||
{
|
||||
Client client;
|
||||
QAmqpClient client;
|
||||
client.setHost("localhost");
|
||||
client.setPort(5672);
|
||||
client.setVirtualHost("/");
|
||||
|
|
@ -60,7 +59,7 @@ void tst_QAMQPClient::connectProperties()
|
|||
|
||||
void tst_QAMQPClient::connectHostAddress()
|
||||
{
|
||||
Client client;
|
||||
QAmqpClient client;
|
||||
client.connectToHost(QHostAddress::LocalHost, 5672);
|
||||
QVERIFY(waitForSignal(&client, SIGNAL(connected())));
|
||||
client.disconnectFromHost();
|
||||
|
|
@ -69,14 +68,14 @@ void tst_QAMQPClient::connectHostAddress()
|
|||
|
||||
void tst_QAMQPClient::connectDisconnect()
|
||||
{
|
||||
Client client;
|
||||
QAmqpClient client;
|
||||
client.connectToHost();
|
||||
QVERIFY(waitForSignal(&client, SIGNAL(connected())));
|
||||
client.disconnectFromHost();
|
||||
QVERIFY(waitForSignal(&client, SIGNAL(disconnected())));
|
||||
}
|
||||
|
||||
class InvalidAuthenticator : public Authenticator
|
||||
class InvalidAuthenticator : public QAmqpAuthenticator
|
||||
{
|
||||
public:
|
||||
virtual QString type() const { return "CRAZYAUTH"; }
|
||||
|
|
@ -87,7 +86,7 @@ public:
|
|||
|
||||
void tst_QAMQPClient::invalidAuthenticationMechanism()
|
||||
{
|
||||
Client client;
|
||||
QAmqpClient client;
|
||||
client.setAuth(new InvalidAuthenticator);
|
||||
client.connectToHost();
|
||||
QVERIFY(waitForSignal(&client, SIGNAL(disconnected())));
|
||||
|
|
@ -98,7 +97,7 @@ void tst_QAMQPClient::autoReconnect()
|
|||
// TODO: this is a fairly crude way of testing this, research
|
||||
// better alternatives
|
||||
|
||||
Client client;
|
||||
QAmqpClient client;
|
||||
client.setAutoReconnect(true);
|
||||
client.connectToHost();
|
||||
QVERIFY(waitForSignal(&client, SIGNAL(connected())));
|
||||
|
|
@ -110,7 +109,7 @@ void tst_QAMQPClient::autoReconnect()
|
|||
|
||||
void tst_QAMQPClient::tune()
|
||||
{
|
||||
Client client;
|
||||
QAmqpClient client;
|
||||
client.setChannelMax(15);
|
||||
client.setFrameMax(5000);
|
||||
client.setHeartbeatDelay(600);
|
||||
|
|
@ -163,15 +162,15 @@ void tst_QAMQPClient::validateUri()
|
|||
QFETCH(quint16, expectedPort);
|
||||
QFETCH(QString, expectedVirtualHost);
|
||||
|
||||
ClientPrivate clientPrivate(0);
|
||||
QAmqpClientPrivate clientPrivate(0);
|
||||
// fake init
|
||||
clientPrivate.authenticator = QSharedPointer<Authenticator>(
|
||||
new AMQPlainAuthenticator(QString::fromLatin1(AMQP_LOGIN), QString::fromLatin1(AMQP_PSWD)));
|
||||
clientPrivate.authenticator = QSharedPointer<QAmqpAuthenticator>(
|
||||
new QAmqpPlainAuthenticator(QString::fromLatin1(AMQP_LOGIN), QString::fromLatin1(AMQP_PSWD)));
|
||||
|
||||
// test parsing
|
||||
clientPrivate.parseConnectionString(uri);
|
||||
AMQPlainAuthenticator *auth =
|
||||
static_cast<AMQPlainAuthenticator*>(clientPrivate.authenticator.data());
|
||||
QAmqpPlainAuthenticator *auth =
|
||||
static_cast<QAmqpPlainAuthenticator*>(clientPrivate.authenticator.data());
|
||||
|
||||
QCOMPARE(auth->login(), expectedUsername);
|
||||
QCOMPARE(auth->password(), expectedPassword);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
|
||||
using namespace QAMQP;
|
||||
class tst_QAMQPExchange : public TestCase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -26,13 +25,13 @@ private Q_SLOTS:
|
|||
void invalidImmediateRouting();
|
||||
|
||||
private:
|
||||
QScopedPointer<Client> client;
|
||||
QScopedPointer<QAmqpClient> client;
|
||||
|
||||
};
|
||||
|
||||
void tst_QAMQPExchange::init()
|
||||
{
|
||||
client.reset(new Client);
|
||||
client.reset(new QAmqpClient);
|
||||
client->connectToHost();
|
||||
QVERIFY(waitForSignal(client.data(), SIGNAL(connected())));
|
||||
}
|
||||
|
|
@ -47,55 +46,55 @@ void tst_QAMQPExchange::cleanup()
|
|||
|
||||
void tst_QAMQPExchange::standardTypes_data()
|
||||
{
|
||||
QTest::addColumn<Exchange::ExchangeType>("type");
|
||||
QTest::addColumn<QAmqpExchange::ExchangeType>("type");
|
||||
QTest::addColumn<bool>("delayedDeclaration");
|
||||
|
||||
QTest::newRow("direct") << Exchange::Direct << false;
|
||||
QTest::newRow("direct-delayed") << Exchange::Direct << true;
|
||||
QTest::newRow("fanout") << Exchange::FanOut << false;
|
||||
QTest::newRow("fanout-delayed") << Exchange::FanOut << true;
|
||||
QTest::newRow("topic") << Exchange::Topic << false;
|
||||
QTest::newRow("topic-delayed") << Exchange::Topic << true;
|
||||
QTest::newRow("headers") << Exchange::Headers << false;
|
||||
QTest::newRow("headers-delayed") << Exchange::Headers << true;
|
||||
QTest::newRow("direct") << QAmqpExchange::Direct << false;
|
||||
QTest::newRow("direct-delayed") << QAmqpExchange::Direct << true;
|
||||
QTest::newRow("fanout") << QAmqpExchange::FanOut << false;
|
||||
QTest::newRow("fanout-delayed") << QAmqpExchange::FanOut << true;
|
||||
QTest::newRow("topic") << QAmqpExchange::Topic << false;
|
||||
QTest::newRow("topic-delayed") << QAmqpExchange::Topic << true;
|
||||
QTest::newRow("headers") << QAmqpExchange::Headers << false;
|
||||
QTest::newRow("headers-delayed") << QAmqpExchange::Headers << true;
|
||||
}
|
||||
|
||||
void tst_QAMQPExchange::standardTypes()
|
||||
{
|
||||
QFETCH(Exchange::ExchangeType, type);
|
||||
QFETCH(QAmqpExchange::ExchangeType, type);
|
||||
QFETCH(bool, delayedDeclaration);
|
||||
|
||||
Exchange *exchange = client->createExchange("test");
|
||||
QAmqpExchange *exchange = client->createExchange("test");
|
||||
if (!delayedDeclaration)
|
||||
QVERIFY(waitForSignal(exchange, SIGNAL(opened())));
|
||||
|
||||
exchange->declare(type);
|
||||
QVERIFY(waitForSignal(exchange, SIGNAL(declared())));
|
||||
exchange->remove(Exchange::roForce);
|
||||
exchange->remove(QAmqpExchange::roForce);
|
||||
QVERIFY(waitForSignal(exchange, SIGNAL(removed())));
|
||||
}
|
||||
|
||||
void tst_QAMQPExchange::invalidStandardDeclaration_data()
|
||||
{
|
||||
QTest::addColumn<QString>("exchangeName");
|
||||
QTest::addColumn<Exchange::ExchangeType>("type");
|
||||
QTest::addColumn<QAmqpExchange::ExchangeType>("type");
|
||||
QTest::addColumn<QAMQP::Error>("error");
|
||||
|
||||
QTest::newRow("amq.direct") << "amq.direct" << Exchange::Direct << QAMQP::PreconditionFailedError;
|
||||
QTest::newRow("amq.fanout") << "amq.fanout" << Exchange::FanOut << QAMQP::PreconditionFailedError;
|
||||
QTest::newRow("amq.headers") << "amq.headers" << Exchange::Headers << QAMQP::PreconditionFailedError;
|
||||
QTest::newRow("amq.match") << "amq.match" << Exchange::Headers << QAMQP::PreconditionFailedError;
|
||||
QTest::newRow("amq.topic") << "amq.topic" << Exchange::Topic << QAMQP::PreconditionFailedError;
|
||||
QTest::newRow("amq.reserved") << "amq.reserved" << Exchange::Direct << QAMQP::AccessRefusedError;
|
||||
QTest::newRow("amq.direct") << "amq.direct" << QAmqpExchange::Direct << QAMQP::PreconditionFailedError;
|
||||
QTest::newRow("amq.fanout") << "amq.fanout" << QAmqpExchange::FanOut << QAMQP::PreconditionFailedError;
|
||||
QTest::newRow("amq.headers") << "amq.headers" << QAmqpExchange::Headers << QAMQP::PreconditionFailedError;
|
||||
QTest::newRow("amq.match") << "amq.match" << QAmqpExchange::Headers << QAMQP::PreconditionFailedError;
|
||||
QTest::newRow("amq.topic") << "amq.topic" << QAmqpExchange::Topic << QAMQP::PreconditionFailedError;
|
||||
QTest::newRow("amq.reserved") << "amq.reserved" << QAmqpExchange::Direct << QAMQP::AccessRefusedError;
|
||||
}
|
||||
|
||||
void tst_QAMQPExchange::invalidStandardDeclaration()
|
||||
{
|
||||
QFETCH(QString, exchangeName);
|
||||
QFETCH(Exchange::ExchangeType, type);
|
||||
QFETCH(QAmqpExchange::ExchangeType, type);
|
||||
QFETCH(QAMQP::Error, error);
|
||||
|
||||
Exchange *exchange = client->createExchange(exchangeName);
|
||||
QAmqpExchange *exchange = client->createExchange(exchangeName);
|
||||
exchange->declare(type);
|
||||
QVERIFY(waitForSignal(exchange, SIGNAL(error(QAMQP::Error))));
|
||||
QCOMPARE(exchange->error(), error);
|
||||
|
|
@ -103,7 +102,7 @@ void tst_QAMQPExchange::invalidStandardDeclaration()
|
|||
|
||||
void tst_QAMQPExchange::invalidDeclaration()
|
||||
{
|
||||
Exchange *exchange = client->createExchange("test-invalid-declaration");
|
||||
QAmqpExchange *exchange = client->createExchange("test-invalid-declaration");
|
||||
exchange->declare("invalidExchangeType");
|
||||
QVERIFY(waitForSignal(client.data(), SIGNAL(error(QAMQP::Error))));
|
||||
QCOMPARE(client->error(), QAMQP::CommandInvalidError);
|
||||
|
|
@ -111,12 +110,12 @@ void tst_QAMQPExchange::invalidDeclaration()
|
|||
|
||||
void tst_QAMQPExchange::invalidRedeclaration()
|
||||
{
|
||||
Exchange *exchange = client->createExchange("test-invalid-redeclaration");
|
||||
exchange->declare(Exchange::Direct);
|
||||
QAmqpExchange *exchange = client->createExchange("test-invalid-redeclaration");
|
||||
exchange->declare(QAmqpExchange::Direct);
|
||||
QVERIFY(waitForSignal(exchange, SIGNAL(declared())));
|
||||
|
||||
Exchange *redeclared = client->createExchange("test-invalid-redeclaration");
|
||||
redeclared->declare(Exchange::FanOut);
|
||||
QAmqpExchange *redeclared = client->createExchange("test-invalid-redeclaration");
|
||||
redeclared->declare(QAmqpExchange::FanOut);
|
||||
QVERIFY(waitForSignal(redeclared, SIGNAL(error(QAMQP::Error))));
|
||||
|
||||
// this is per spec:
|
||||
|
|
@ -132,38 +131,38 @@ void tst_QAMQPExchange::invalidRedeclaration()
|
|||
|
||||
void tst_QAMQPExchange::removeIfUnused()
|
||||
{
|
||||
Exchange *exchange = client->createExchange("test-if-unused-exchange");
|
||||
exchange->declare(Exchange::Direct, Exchange::AutoDelete);
|
||||
QAmqpExchange *exchange = client->createExchange("test-if-unused-exchange");
|
||||
exchange->declare(QAmqpExchange::Direct, QAmqpExchange::AutoDelete);
|
||||
QVERIFY(waitForSignal(exchange, SIGNAL(declared())));
|
||||
|
||||
Queue *queue = client->createQueue("test-if-unused-queue");
|
||||
QAmqpQueue *queue = client->createQueue("test-if-unused-queue");
|
||||
queue->declare();
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(declared())));
|
||||
queue->bind("test-if-unused-exchange", "testRoutingKey");
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(bound())));
|
||||
|
||||
exchange->remove(Exchange::roIfUnused);
|
||||
exchange->remove(QAmqpExchange::roIfUnused);
|
||||
QVERIFY(waitForSignal(exchange, SIGNAL(error(QAMQP::Error))));
|
||||
QCOMPARE(exchange->error(), QAMQP::PreconditionFailedError);
|
||||
QVERIFY(!exchange->errorString().isEmpty());
|
||||
|
||||
// cleanup
|
||||
queue->remove(Queue::roForce);
|
||||
queue->remove(QAmqpQueue::roForce);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(removed())));
|
||||
}
|
||||
|
||||
void tst_QAMQPExchange::invalidMandatoryRouting()
|
||||
{
|
||||
Exchange *defaultExchange = client->createExchange();
|
||||
defaultExchange->publish("some message", "unroutable-key", Message::PropertyHash(), Exchange::poMandatory);
|
||||
QAmqpExchange *defaultExchange = client->createExchange();
|
||||
defaultExchange->publish("some message", "unroutable-key", QAmqpMessage::PropertyHash(), QAmqpExchange::poMandatory);
|
||||
QVERIFY(waitForSignal(defaultExchange, SIGNAL(error(QAMQP::Error))));
|
||||
QCOMPARE(defaultExchange->error(), QAMQP::UnroutableKey);
|
||||
}
|
||||
|
||||
void tst_QAMQPExchange::invalidImmediateRouting()
|
||||
{
|
||||
Exchange *defaultExchange = client->createExchange();
|
||||
defaultExchange->publish("some message", "unroutable-key", Message::PropertyHash(), Exchange::poImmediate);
|
||||
QAmqpExchange *defaultExchange = client->createExchange();
|
||||
defaultExchange->publish("some message", "unroutable-key", QAmqpMessage::PropertyHash(), QAmqpExchange::poImmediate);
|
||||
QVERIFY(waitForSignal(client.data(), SIGNAL(error(QAMQP::Error))));
|
||||
QCOMPARE(client->error(), QAMQP::NotImplementedError);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
#include "qamqpqueue.h"
|
||||
#include "qamqpexchange.h"
|
||||
|
||||
using namespace QAMQP;
|
||||
class tst_QAMQPQueue : public TestCase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -49,13 +48,13 @@ private Q_SLOTS:
|
|||
void emptyMessage();
|
||||
|
||||
private:
|
||||
QScopedPointer<Client> client;
|
||||
QScopedPointer<QAmqpClient> client;
|
||||
|
||||
};
|
||||
|
||||
void tst_QAMQPQueue::init()
|
||||
{
|
||||
client.reset(new Client);
|
||||
client.reset(new QAmqpClient);
|
||||
client->connectToHost();
|
||||
QVERIFY(waitForSignal(client.data(), SIGNAL(connected())));
|
||||
}
|
||||
|
|
@ -70,13 +69,13 @@ void tst_QAMQPQueue::cleanup()
|
|||
|
||||
void tst_QAMQPQueue::defaultExchange()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-default-exchange");
|
||||
QAmqpQueue *queue = client->createQueue("test-default-exchange");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
Exchange *defaultExchange = client->createExchange();
|
||||
QAmqpExchange *defaultExchange = client->createExchange();
|
||||
defaultExchange->publish("first message", "test-default-exchange");
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
|
||||
Message message = queue->dequeue();
|
||||
QAmqpMessage message = queue->dequeue();
|
||||
verifyStandardMessageHeaders(message, "test-default-exchange");
|
||||
QCOMPARE(message.payload(), QByteArray("first message"));
|
||||
}
|
||||
|
|
@ -106,7 +105,7 @@ void tst_QAMQPQueue::standardExchanges()
|
|||
QString queueName = QString("test-%1").arg(exchange);
|
||||
QString routingKey = QString("testRoutingKey-%1").arg(exchange);
|
||||
|
||||
Queue *queue = client->createQueue(queueName);
|
||||
QAmqpQueue *queue = client->createQueue(queueName);
|
||||
if (!delayedDeclaration)
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(opened())));
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
|
@ -114,10 +113,10 @@ void tst_QAMQPQueue::standardExchanges()
|
|||
queue->bind(exchange, routingKey);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(bound())));
|
||||
|
||||
Exchange *defaultExchange = client->createExchange(exchange);
|
||||
QAmqpExchange *defaultExchange = client->createExchange(exchange);
|
||||
defaultExchange->publish("test message", routingKey);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
|
||||
Message message = queue->dequeue();
|
||||
QAmqpMessage message = queue->dequeue();
|
||||
verifyStandardMessageHeaders(message, routingKey, exchange);
|
||||
QCOMPARE(message.payload(), QByteArray("test message"));
|
||||
}
|
||||
|
|
@ -140,7 +139,7 @@ void tst_QAMQPQueue::invalidDeclaration()
|
|||
QFETCH(QString, queueName);
|
||||
QFETCH(QAMQP::Error, error);
|
||||
|
||||
Queue *queue = client->createQueue(queueName);
|
||||
QAmqpQueue *queue = client->createQueue(queueName);
|
||||
queue->declare();
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(error(QAMQP::Error))));
|
||||
QCOMPARE(queue->error(), error);
|
||||
|
|
@ -148,7 +147,7 @@ void tst_QAMQPQueue::invalidDeclaration()
|
|||
|
||||
void tst_QAMQPQueue::invalidBind()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-invalid-bind");
|
||||
QAmqpQueue *queue = client->createQueue("test-invalid-bind");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
queue->bind("non-existant-exchange", "routingKey");
|
||||
|
|
@ -158,23 +157,23 @@ void tst_QAMQPQueue::invalidBind()
|
|||
|
||||
void tst_QAMQPQueue::unnamed()
|
||||
{
|
||||
Queue *queue = client->createQueue();
|
||||
QAmqpQueue *queue = client->createQueue();
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
QVERIFY(!queue->name().isEmpty());
|
||||
}
|
||||
|
||||
void tst_QAMQPQueue::exclusiveAccess()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-exclusive-queue");
|
||||
queue->declare(Queue::Exclusive);
|
||||
QAmqpQueue *queue = client->createQueue("test-exclusive-queue");
|
||||
queue->declare(QAmqpQueue::Exclusive);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(declared())));
|
||||
QVERIFY(queue->options() & Queue::Exclusive);
|
||||
QVERIFY(queue->options() & QAmqpQueue::Exclusive);
|
||||
|
||||
Client secondClient;
|
||||
QAmqpClient secondClient;
|
||||
secondClient.connectToHost();
|
||||
QVERIFY(waitForSignal(&secondClient, SIGNAL(connected())));
|
||||
Queue *passiveQueue = secondClient.createQueue("test-exclusive-queue");
|
||||
passiveQueue->declare(Queue::Passive);
|
||||
QAmqpQueue *passiveQueue = secondClient.createQueue("test-exclusive-queue");
|
||||
passiveQueue->declare(QAmqpQueue::Passive);
|
||||
QVERIFY(waitForSignal(passiveQueue, SIGNAL(error(QAMQP::Error))));
|
||||
QCOMPARE(passiveQueue->error(), QAMQP::ResourceLockedError);
|
||||
|
||||
|
|
@ -184,20 +183,20 @@ void tst_QAMQPQueue::exclusiveAccess()
|
|||
|
||||
void tst_QAMQPQueue::exclusiveRemoval()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-exclusive-queue");
|
||||
queue->declare(Queue::Exclusive);
|
||||
QAmqpQueue *queue = client->createQueue("test-exclusive-queue");
|
||||
queue->declare(QAmqpQueue::Exclusive);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(declared())));
|
||||
QVERIFY(queue->options() & Queue::Exclusive);
|
||||
QVERIFY(queue->options() & QAmqpQueue::Exclusive);
|
||||
client.data()->disconnectFromHost();
|
||||
QVERIFY(waitForSignal(client.data(), SIGNAL(disconnected())));
|
||||
|
||||
// create a new client and try to access the queue that should
|
||||
// no longer exist
|
||||
Client secondClient;
|
||||
QAmqpClient secondClient;
|
||||
secondClient.connectToHost();
|
||||
QVERIFY(waitForSignal(&secondClient, SIGNAL(connected())));
|
||||
Queue *passiveQueue = secondClient.createQueue("test-exclusive-queue");
|
||||
passiveQueue->declare(Queue::Passive);
|
||||
QAmqpQueue *passiveQueue = secondClient.createQueue("test-exclusive-queue");
|
||||
passiveQueue->declare(QAmqpQueue::Passive);
|
||||
QVERIFY(waitForSignal(passiveQueue, SIGNAL(error(QAMQP::Error))));
|
||||
QCOMPARE(passiveQueue->error(), QAMQP::NotFoundError);
|
||||
secondClient.disconnectFromHost();
|
||||
|
|
@ -206,27 +205,27 @@ void tst_QAMQPQueue::exclusiveRemoval()
|
|||
|
||||
void tst_QAMQPQueue::notFound()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-not-found");
|
||||
queue->declare(Queue::Passive);
|
||||
QAmqpQueue *queue = client->createQueue("test-not-found");
|
||||
queue->declare(QAmqpQueue::Passive);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(error(QAMQP::Error))));
|
||||
QCOMPARE(queue->error(), QAMQP::NotFoundError);
|
||||
}
|
||||
|
||||
void tst_QAMQPQueue::remove()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-remove");
|
||||
QAmqpQueue *queue = client->createQueue("test-remove");
|
||||
queue->declare();
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(declared())));
|
||||
queue->remove(Queue::roIfEmpty|Queue::roIfUnused);
|
||||
queue->remove(QAmqpQueue::roIfEmpty|QAmqpQueue::roIfUnused);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(removed())));
|
||||
}
|
||||
|
||||
void tst_QAMQPQueue::removeIfUnused()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-remove-if-unused");
|
||||
QAmqpQueue *queue = client->createQueue("test-remove-if-unused");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
queue->remove(Queue::roIfUnused);
|
||||
queue->remove(QAmqpQueue::roIfUnused);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(error(QAMQP::Error))));
|
||||
QCOMPARE(queue->error(), QAMQP::PreconditionFailedError);
|
||||
QVERIFY(!queue->errorString().isEmpty());
|
||||
|
|
@ -235,25 +234,25 @@ void tst_QAMQPQueue::removeIfUnused()
|
|||
void tst_QAMQPQueue::removeIfEmpty()
|
||||
{
|
||||
// declare the queue and send messages to it
|
||||
Queue *queue = client->createQueue("test-remove-if-empty");
|
||||
queue->declare(Queue::Durable);
|
||||
QAmqpQueue *queue = client->createQueue("test-remove-if-empty");
|
||||
queue->declare(QAmqpQueue::Durable);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(declared())));
|
||||
QVERIFY(queue->options() & Queue::Durable);
|
||||
QVERIFY(queue->options() & QAmqpQueue::Durable);
|
||||
|
||||
Exchange *defaultExchange = client->createExchange();
|
||||
QAmqpExchange *defaultExchange = client->createExchange();
|
||||
defaultExchange->publish("first message", "test-remove-if-empty");
|
||||
|
||||
// create a second client and try to delete the queue
|
||||
{
|
||||
Client secondClient;
|
||||
QAmqpClient secondClient;
|
||||
secondClient.connectToHost();
|
||||
QVERIFY(waitForSignal(&secondClient, SIGNAL(connected())));
|
||||
Queue *testDeleteQueue = secondClient.createQueue("test-remove-if-empty");
|
||||
testDeleteQueue->declare(Queue::Passive);
|
||||
QAmqpQueue *testDeleteQueue = secondClient.createQueue("test-remove-if-empty");
|
||||
testDeleteQueue->declare(QAmqpQueue::Passive);
|
||||
QVERIFY(waitForSignal(testDeleteQueue, SIGNAL(declared())));
|
||||
QVERIFY(testDeleteQueue->options() & Queue::Passive);
|
||||
QVERIFY(testDeleteQueue->options() & QAmqpQueue::Passive);
|
||||
|
||||
testDeleteQueue->remove(Queue::roIfEmpty);
|
||||
testDeleteQueue->remove(QAmqpQueue::roIfEmpty);
|
||||
QVERIFY(waitForSignal(testDeleteQueue, SIGNAL(error(QAMQP::Error))));
|
||||
QCOMPARE(testDeleteQueue->error(), QAMQP::PreconditionFailedError);
|
||||
QVERIFY(!testDeleteQueue->errorString().isEmpty());
|
||||
|
|
@ -263,13 +262,13 @@ void tst_QAMQPQueue::removeIfEmpty()
|
|||
}
|
||||
|
||||
// clean up queue
|
||||
queue->remove(Queue::roForce);
|
||||
queue->remove(QAmqpQueue::roForce);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(removed())));
|
||||
}
|
||||
|
||||
void tst_QAMQPQueue::bindUnbind()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-bind-unbind");
|
||||
QAmqpQueue *queue = client->createQueue("test-bind-unbind");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
queue->bind("amq.topic", "routingKey");
|
||||
|
|
@ -277,8 +276,8 @@ void tst_QAMQPQueue::bindUnbind()
|
|||
queue->unbind("amq.topic", "routingKey");
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(unbound())));
|
||||
|
||||
Exchange *amqTopic = client->createExchange("amq.topic");
|
||||
amqTopic->declare(Exchange::Direct, Exchange::Passive);
|
||||
QAmqpExchange *amqTopic = client->createExchange("amq.topic");
|
||||
amqTopic->declare(QAmqpExchange::Direct, QAmqpExchange::Passive);
|
||||
QVERIFY(waitForSignal(amqTopic, SIGNAL(declared())));
|
||||
queue->bind(amqTopic, "routingKey");
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(bound())));
|
||||
|
|
@ -290,7 +289,7 @@ void tst_QAMQPQueue::delayedBind()
|
|||
{
|
||||
client->disconnectFromHost();
|
||||
QVERIFY(waitForSignal(client.data(), SIGNAL(disconnected())));
|
||||
Queue *queue = client->createQueue("test-delayed-bind");
|
||||
QAmqpQueue *queue = client->createQueue("test-delayed-bind");
|
||||
queue->declare();
|
||||
queue->bind("amq.topic", "routingKey");
|
||||
|
||||
|
|
@ -300,31 +299,31 @@ void tst_QAMQPQueue::delayedBind()
|
|||
QVERIFY(waitForSignal(queue, SIGNAL(bound())));
|
||||
|
||||
// clean up queue
|
||||
queue->remove(Queue::roForce);
|
||||
queue->remove(QAmqpQueue::roForce);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(removed())));
|
||||
}
|
||||
|
||||
void tst_QAMQPQueue::purge()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-purge");
|
||||
queue->declare(Queue::Durable);
|
||||
QAmqpQueue *queue = client->createQueue("test-purge");
|
||||
queue->declare(QAmqpQueue::Durable);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(declared())));
|
||||
QVERIFY(queue->options() & Queue::Durable);
|
||||
QVERIFY(queue->options() & QAmqpQueue::Durable);
|
||||
|
||||
Exchange *defaultExchange = client->createExchange();
|
||||
QAmqpExchange *defaultExchange = client->createExchange();
|
||||
defaultExchange->publish("first message", "test-purge");
|
||||
defaultExchange->publish("second message", "test-purge");
|
||||
defaultExchange->publish("third message", "test-purge");
|
||||
|
||||
// create second client to listen to messages and attempt purge
|
||||
{
|
||||
Client secondClient;
|
||||
QAmqpClient secondClient;
|
||||
secondClient.connectToHost();
|
||||
QVERIFY(waitForSignal(&secondClient, SIGNAL(connected())));
|
||||
Queue *testPurgeQueue = secondClient.createQueue("test-purge");
|
||||
testPurgeQueue->declare(Queue::Passive);
|
||||
QAmqpQueue *testPurgeQueue = secondClient.createQueue("test-purge");
|
||||
testPurgeQueue->declare(QAmqpQueue::Passive);
|
||||
QVERIFY(waitForSignal(testPurgeQueue, SIGNAL(declared())));
|
||||
QVERIFY(testPurgeQueue->options() & Queue::Passive);
|
||||
QVERIFY(testPurgeQueue->options() & QAmqpQueue::Passive);
|
||||
|
||||
QSignalSpy spy(testPurgeQueue, SIGNAL(purged(int)));
|
||||
testPurgeQueue->purge();
|
||||
|
|
@ -339,20 +338,20 @@ void tst_QAMQPQueue::purge()
|
|||
}
|
||||
|
||||
// clean up queue
|
||||
queue->remove(Queue::roForce);
|
||||
queue->remove(QAmqpQueue::roForce);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(removed())));
|
||||
}
|
||||
|
||||
void tst_QAMQPQueue::canOnlyStartConsumingOnce()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-single-consumer");
|
||||
QAmqpQueue *queue = client->createQueue("test-single-consumer");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
QCOMPARE(queue->consume(), false);
|
||||
}
|
||||
|
||||
void tst_QAMQPQueue::cancel()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-cancel");
|
||||
QAmqpQueue *queue = client->createQueue("test-cancel");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
QString consumerTag = queue->consumerTag();
|
||||
|
|
@ -366,19 +365,19 @@ void tst_QAMQPQueue::cancel()
|
|||
|
||||
void tst_QAMQPQueue::invalidCancelBecauseNotConsuming()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-invalid-cancel-because-not-consuming");
|
||||
QAmqpQueue *queue = client->createQueue("test-invalid-cancel-because-not-consuming");
|
||||
queue->declare();
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(declared())));
|
||||
QCOMPARE(queue->cancel(), false);
|
||||
|
||||
// clean up queue
|
||||
queue->remove(Queue::roForce);
|
||||
queue->remove(QAmqpQueue::roForce);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(removed())));
|
||||
}
|
||||
|
||||
void tst_QAMQPQueue::invalidCancelBecauseInvalidConsumerTag()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-invalid-cancel-because-invalid-consumer-tag");
|
||||
QAmqpQueue *queue = client->createQueue("test-invalid-cancel-because-invalid-consumer-tag");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
queue->setConsumerTag(QString());
|
||||
QCOMPARE(queue->cancel(), false);
|
||||
|
|
@ -386,7 +385,7 @@ void tst_QAMQPQueue::invalidCancelBecauseInvalidConsumerTag()
|
|||
|
||||
void tst_QAMQPQueue::getEmpty()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-get-empty");
|
||||
QAmqpQueue *queue = client->createQueue("test-get-empty");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
queue->get();
|
||||
|
|
@ -395,12 +394,12 @@ void tst_QAMQPQueue::getEmpty()
|
|||
|
||||
void tst_QAMQPQueue::get()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-get");
|
||||
QAmqpQueue *queue = client->createQueue("test-get");
|
||||
queue->declare();
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(declared())));
|
||||
|
||||
const int messageCount = 200;
|
||||
Exchange *defaultExchange = client->createExchange();
|
||||
QAmqpExchange *defaultExchange = client->createExchange();
|
||||
for (int i = 0; i < messageCount; ++i) {
|
||||
QString expected = QString("message %1").arg(i);
|
||||
defaultExchange->publish(expected, "test-get");
|
||||
|
|
@ -417,7 +416,7 @@ void tst_QAMQPQueue::get()
|
|||
continue;
|
||||
}
|
||||
|
||||
Message message = queue->dequeue();
|
||||
QAmqpMessage message = queue->dequeue();
|
||||
verifyStandardMessageHeaders(message, "test-get");
|
||||
QCOMPARE(message.payload(), expected.toUtf8());
|
||||
queue->ack(message);
|
||||
|
|
@ -427,31 +426,31 @@ void tst_QAMQPQueue::get()
|
|||
QVERIFY(waitForSignal(queue, SIGNAL(empty())));
|
||||
|
||||
// clean up queue
|
||||
queue->remove(Queue::roForce);
|
||||
queue->remove(QAmqpQueue::roForce);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(removed())));
|
||||
}
|
||||
|
||||
void tst_QAMQPQueue::verifyContentEncodingIssue33()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-issue-33");
|
||||
QAmqpQueue *queue = client->createQueue("test-issue-33");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
Exchange *defaultExchange = client->createExchange();
|
||||
Message::PropertyHash properties;
|
||||
properties.insert(Message::ContentEncoding, "fakeContentEncoding");
|
||||
QAmqpExchange *defaultExchange = client->createExchange();
|
||||
QAmqpMessage::PropertyHash properties;
|
||||
properties.insert(QAmqpMessage::ContentEncoding, "fakeContentEncoding");
|
||||
defaultExchange->publish("some data", "test-issue-33", properties);
|
||||
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
|
||||
Message message = queue->dequeue();
|
||||
QAmqpMessage message = queue->dequeue();
|
||||
verifyStandardMessageHeaders(message, "test-issue-33");
|
||||
QVERIFY(message.hasProperty(Message::ContentEncoding));
|
||||
QString contentType = message.property(Message::ContentEncoding).toString();
|
||||
QVERIFY(message.hasProperty(QAmqpMessage::ContentEncoding));
|
||||
QString contentType = message.property(QAmqpMessage::ContentEncoding).toString();
|
||||
QCOMPARE(contentType, QLatin1String("fakeContentEncoding"));
|
||||
}
|
||||
|
||||
void tst_QAMQPQueue::defineQos()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-define-qos");
|
||||
QAmqpQueue *queue = client->createQueue("test-define-qos");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
queue->qos(10);
|
||||
|
|
@ -460,13 +459,13 @@ void tst_QAMQPQueue::defineQos()
|
|||
QCOMPARE(queue->prefetchSize(), 0);
|
||||
|
||||
// clean up queue
|
||||
queue->remove(Queue::roForce);
|
||||
queue->remove(QAmqpQueue::roForce);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(removed())));
|
||||
}
|
||||
|
||||
void tst_QAMQPQueue::invalidQos()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-invalid-define-qos");
|
||||
QAmqpQueue *queue = client->createQueue("test-invalid-define-qos");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
queue->qos(10, 10);
|
||||
|
|
@ -476,7 +475,7 @@ void tst_QAMQPQueue::invalidQos()
|
|||
|
||||
void tst_QAMQPQueue::qos()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-qos");
|
||||
QAmqpQueue *queue = client->createQueue("test-qos");
|
||||
queue->declare();
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(declared())));
|
||||
|
||||
|
|
@ -489,7 +488,7 @@ void tst_QAMQPQueue::qos()
|
|||
|
||||
// load up the queue
|
||||
const int messageCount = 10;
|
||||
Exchange *defaultExchange = client->createExchange();
|
||||
QAmqpExchange *defaultExchange = client->createExchange();
|
||||
for (int i = 0; i < messageCount; ++i) {
|
||||
QString message = QString("message %1").arg(i);
|
||||
defaultExchange->publish(message, "test-qos");
|
||||
|
|
@ -499,7 +498,7 @@ void tst_QAMQPQueue::qos()
|
|||
int messageReceivedCount = 0;
|
||||
while (!queue->isEmpty()) {
|
||||
QString expected = QString("message %1").arg(messageReceivedCount);
|
||||
Message message = queue->dequeue();
|
||||
QAmqpMessage message = queue->dequeue();
|
||||
verifyStandardMessageHeaders(message, "test-qos");
|
||||
QCOMPARE(message.payload(), expected.toUtf8());
|
||||
queue->ack(message);
|
||||
|
|
@ -515,7 +514,7 @@ void tst_QAMQPQueue::qos()
|
|||
void tst_QAMQPQueue::invalidRoutingKey()
|
||||
{
|
||||
QString routingKey = QString("%1").arg('1', 256, QLatin1Char('0'));
|
||||
Queue *queue = client->createQueue(routingKey);
|
||||
QAmqpQueue *queue = client->createQueue(routingKey);
|
||||
queue->declare();
|
||||
QVERIFY(waitForSignal(client.data(), SIGNAL(error(QAMQP::Error))));
|
||||
QCOMPARE(client->error(), QAMQP::FrameError);
|
||||
|
|
@ -523,7 +522,7 @@ void tst_QAMQPQueue::invalidRoutingKey()
|
|||
|
||||
void tst_QAMQPQueue::tableFieldDataTypes()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-table-field-data-types");
|
||||
QAmqpQueue *queue = client->createQueue("test-table-field-data-types");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
QAMQP::Decimal decimal;
|
||||
|
|
@ -531,7 +530,7 @@ void tst_QAMQPQueue::tableFieldDataTypes()
|
|||
decimal.value = 12345;
|
||||
QVariant decimalVariant = QVariant::fromValue<QAMQP::Decimal>(decimal);
|
||||
|
||||
Table nestedTable;
|
||||
QAmqpTable nestedTable;
|
||||
nestedTable.insert("boolean", true);
|
||||
nestedTable.insert("long-int", qint32(-65536));
|
||||
|
||||
|
|
@ -541,7 +540,7 @@ void tst_QAMQPQueue::tableFieldDataTypes()
|
|||
|
||||
QDateTime timestamp = QDateTime::currentDateTime();
|
||||
|
||||
Table headers;
|
||||
QAmqpTable headers;
|
||||
headers.insert("boolean", true);
|
||||
headers.insert("short-short-int", qint8(-15));
|
||||
headers.insert("short-short-uint", quint8(15));
|
||||
|
|
@ -561,11 +560,11 @@ void tst_QAMQPQueue::tableFieldDataTypes()
|
|||
headers.insert("array", array);
|
||||
headers.insert("bytes", QByteArray("abcdefg1234567"));
|
||||
|
||||
Exchange *defaultExchange = client->createExchange();
|
||||
QAmqpExchange *defaultExchange = client->createExchange();
|
||||
defaultExchange->publish("dummy", "test-table-field-data-types", "text.plain", headers);
|
||||
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
|
||||
Message message = queue->dequeue();
|
||||
QAmqpMessage message = queue->dequeue();
|
||||
|
||||
QCOMPARE(message.header("boolean").toBool(), true);
|
||||
QCOMPARE(qint8(message.header("short-short-int").toInt()), qint8(-15));
|
||||
|
|
@ -584,7 +583,7 @@ void tst_QAMQPQueue::tableFieldDataTypes()
|
|||
QCOMPARE(message.header("bytes").toByteArray(), QByteArray("abcdefg1234567"));
|
||||
|
||||
QVERIFY(message.hasHeader("nested-table"));
|
||||
Table compareTable(message.header("nested-table").toHash());
|
||||
QAmqpTable compareTable(message.header("nested-table").toHash());
|
||||
foreach (QString key, nestedTable.keys()) {
|
||||
QVERIFY(compareTable.contains(key));
|
||||
QCOMPARE(nestedTable.value(key), compareTable.value(key));
|
||||
|
|
@ -601,55 +600,55 @@ void tst_QAMQPQueue::tableFieldDataTypes()
|
|||
|
||||
void tst_QAMQPQueue::messageProperties()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-message-properties");
|
||||
QAmqpQueue *queue = client->createQueue("test-message-properties");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
QDateTime timestamp = QDateTime::currentDateTime();
|
||||
Message::PropertyHash properties;
|
||||
properties.insert(Message::ContentType, "some-content-type");
|
||||
properties.insert(Message::ContentEncoding, "some-content-encoding");
|
||||
properties.insert(Message::DeliveryMode, 2);
|
||||
properties.insert(Message::Priority, 5);
|
||||
properties.insert(Message::CorrelationId, 42);
|
||||
properties.insert(Message::ReplyTo, "another-queue");
|
||||
properties.insert(Message::MessageId, "some-message-id");
|
||||
properties.insert(Message::Expiration, "60000");
|
||||
properties.insert(Message::Timestamp, timestamp);
|
||||
properties.insert(Message::Type, "some-message-type");
|
||||
properties.insert(Message::UserId, "guest");
|
||||
properties.insert(Message::AppId, "some-app-id");
|
||||
properties.insert(Message::ClusterID, "some-cluster-id");
|
||||
QAmqpMessage::PropertyHash properties;
|
||||
properties.insert(QAmqpMessage::ContentType, "some-content-type");
|
||||
properties.insert(QAmqpMessage::ContentEncoding, "some-content-encoding");
|
||||
properties.insert(QAmqpMessage::DeliveryMode, 2);
|
||||
properties.insert(QAmqpMessage::Priority, 5);
|
||||
properties.insert(QAmqpMessage::CorrelationId, 42);
|
||||
properties.insert(QAmqpMessage::ReplyTo, "another-queue");
|
||||
properties.insert(QAmqpMessage::MessageId, "some-message-id");
|
||||
properties.insert(QAmqpMessage::Expiration, "60000");
|
||||
properties.insert(QAmqpMessage::Timestamp, timestamp);
|
||||
properties.insert(QAmqpMessage::Type, "some-message-type");
|
||||
properties.insert(QAmqpMessage::UserId, "guest");
|
||||
properties.insert(QAmqpMessage::AppId, "some-app-id");
|
||||
properties.insert(QAmqpMessage::ClusterID, "some-cluster-id");
|
||||
|
||||
Exchange *defaultExchange = client->createExchange();
|
||||
QAmqpExchange *defaultExchange = client->createExchange();
|
||||
defaultExchange->publish("dummy", "test-message-properties", properties);
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
|
||||
Message message = queue->dequeue();
|
||||
QAmqpMessage message = queue->dequeue();
|
||||
|
||||
QCOMPARE(message.property(Message::ContentType).toString(), QLatin1String("some-content-type"));
|
||||
QCOMPARE(message.property(Message::ContentEncoding).toString(), QLatin1String("some-content-encoding"));
|
||||
QCOMPARE(message.property(Message::DeliveryMode).toInt(), 2);
|
||||
QCOMPARE(message.property(Message::Priority).toInt(), 5);
|
||||
QCOMPARE(message.property(Message::CorrelationId).toInt(), 42);
|
||||
QCOMPARE(message.property(Message::ReplyTo).toString(), QLatin1String("another-queue"));
|
||||
QCOMPARE(message.property(Message::MessageId).toString(), QLatin1String("some-message-id"));
|
||||
QCOMPARE(message.property(Message::Expiration).toString(), QLatin1String("60000"));
|
||||
QCOMPARE(message.property(Message::Timestamp).toDateTime(), timestamp);
|
||||
QCOMPARE(message.property(Message::Type).toString(), QLatin1String("some-message-type"));
|
||||
QCOMPARE(message.property(Message::UserId).toString(), QLatin1String("guest"));
|
||||
QCOMPARE(message.property(Message::AppId).toString(), QLatin1String("some-app-id"));
|
||||
QCOMPARE(message.property(Message::ClusterID).toString(), QLatin1String("some-cluster-id"));
|
||||
QCOMPARE(message.property(QAmqpMessage::ContentType).toString(), QLatin1String("some-content-type"));
|
||||
QCOMPARE(message.property(QAmqpMessage::ContentEncoding).toString(), QLatin1String("some-content-encoding"));
|
||||
QCOMPARE(message.property(QAmqpMessage::DeliveryMode).toInt(), 2);
|
||||
QCOMPARE(message.property(QAmqpMessage::Priority).toInt(), 5);
|
||||
QCOMPARE(message.property(QAmqpMessage::CorrelationId).toInt(), 42);
|
||||
QCOMPARE(message.property(QAmqpMessage::ReplyTo).toString(), QLatin1String("another-queue"));
|
||||
QCOMPARE(message.property(QAmqpMessage::MessageId).toString(), QLatin1String("some-message-id"));
|
||||
QCOMPARE(message.property(QAmqpMessage::Expiration).toString(), QLatin1String("60000"));
|
||||
QCOMPARE(message.property(QAmqpMessage::Timestamp).toDateTime(), timestamp);
|
||||
QCOMPARE(message.property(QAmqpMessage::Type).toString(), QLatin1String("some-message-type"));
|
||||
QCOMPARE(message.property(QAmqpMessage::UserId).toString(), QLatin1String("guest"));
|
||||
QCOMPARE(message.property(QAmqpMessage::AppId).toString(), QLatin1String("some-app-id"));
|
||||
QCOMPARE(message.property(QAmqpMessage::ClusterID).toString(), QLatin1String("some-cluster-id"));
|
||||
}
|
||||
|
||||
void tst_QAMQPQueue::emptyMessage()
|
||||
{
|
||||
Queue *queue = client->createQueue("test-issue-43");
|
||||
QAmqpQueue *queue = client->createQueue("test-issue-43");
|
||||
declareQueueAndVerifyConsuming(queue);
|
||||
|
||||
Exchange *defaultExchange = client->createExchange();
|
||||
QAmqpExchange *defaultExchange = client->createExchange();
|
||||
defaultExchange->publish("", "test-issue-43");
|
||||
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
|
||||
Message message = queue->dequeue();
|
||||
QAmqpMessage message = queue->dequeue();
|
||||
verifyStandardMessageHeaders(message, "test-issue-43");
|
||||
QVERIFY(message.payload().isEmpty());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
#include "qamqpqueue.h"
|
||||
|
||||
namespace QAMQP {
|
||||
|
||||
class TestCase : public QObject
|
||||
{
|
||||
public:
|
||||
|
|
@ -26,7 +24,7 @@ protected:
|
|||
return !QTestEventLoop::instance().timeout();
|
||||
}
|
||||
|
||||
void declareQueueAndVerifyConsuming(Queue *queue)
|
||||
void declareQueueAndVerifyConsuming(QAmqpQueue *queue)
|
||||
{
|
||||
queue->declare();
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(declared())));
|
||||
|
|
@ -39,7 +37,7 @@ protected:
|
|||
QCOMPARE(arguments.at(0).toString(), queue->consumerTag());
|
||||
}
|
||||
|
||||
void verifyStandardMessageHeaders(const Message &message, const QString &routingKey,
|
||||
void verifyStandardMessageHeaders(const QAmqpMessage &message, const QString &routingKey,
|
||||
const QString &exchangeName = QLatin1String(""),
|
||||
bool redelivered = false)
|
||||
{
|
||||
|
|
@ -47,9 +45,6 @@ protected:
|
|||
QCOMPARE(message.exchangeName(), exchangeName);
|
||||
QCOMPARE(message.isRedelivered(), redelivered);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
#endif // QAMQPTESTCASE_H
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include "qamqpclient.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
class Receiver : public QObject
|
||||
{
|
||||
|
|
@ -20,32 +19,32 @@ public Q_SLOTS:
|
|||
|
||||
private Q_SLOTS:
|
||||
void clientConnected() {
|
||||
Queue *queue = m_client.createQueue("hello");
|
||||
QAmqpQueue *queue = m_client.createQueue("hello");
|
||||
connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared()));
|
||||
queue->declare();
|
||||
}
|
||||
|
||||
void queueDeclared() {
|
||||
Queue *queue = qobject_cast<Queue*>(sender());
|
||||
QAmqpQueue *queue = qobject_cast<QAmqpQueue*>(sender());
|
||||
if (!queue)
|
||||
return;
|
||||
|
||||
connect(queue, SIGNAL(messageReceived()), this, SLOT(messageReceived()));
|
||||
queue->consume(Queue::coNoAck);
|
||||
queue->consume(QAmqpQueue::coNoAck);
|
||||
qDebug() << " [*] Waiting for messages. To exit press CTRL+C";
|
||||
}
|
||||
|
||||
void messageReceived() {
|
||||
Queue *queue = qobject_cast<Queue*>(sender());
|
||||
QAmqpQueue *queue = qobject_cast<QAmqpQueue*>(sender());
|
||||
if (!queue)
|
||||
return;
|
||||
|
||||
Message message = queue->dequeue();
|
||||
QAmqpMessage message = queue->dequeue();
|
||||
qDebug() << " [x] Received " << message.payload();
|
||||
}
|
||||
|
||||
private:
|
||||
Client m_client;
|
||||
QAmqpClient m_client;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include "qamqpclient.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
class Sender : public QObject
|
||||
{
|
||||
|
|
@ -22,23 +21,23 @@ public Q_SLOTS:
|
|||
|
||||
private Q_SLOTS:
|
||||
void clientConnected() {
|
||||
Queue *queue = m_client.createQueue("hello");
|
||||
QAmqpQueue *queue = m_client.createQueue("hello");
|
||||
connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared()));
|
||||
queue->declare();
|
||||
}
|
||||
|
||||
void queueDeclared() {
|
||||
Queue *queue = qobject_cast<Queue*>(sender());
|
||||
QAmqpQueue *queue = qobject_cast<QAmqpQueue*>(sender());
|
||||
if (!queue)
|
||||
return;
|
||||
Exchange *defaultExchange = m_client.createExchange();
|
||||
QAmqpExchange *defaultExchange = m_client.createExchange();
|
||||
defaultExchange->publish("Hello World!", "hello");
|
||||
qDebug() << " [x] Sent 'Hello World!'";
|
||||
m_client.disconnectFromHost();
|
||||
}
|
||||
|
||||
private:
|
||||
Client m_client;
|
||||
QAmqpClient m_client;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include "qamqpclient.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
class LogEmitter : public QObject
|
||||
{
|
||||
|
|
@ -22,13 +21,13 @@ public Q_SLOTS:
|
|||
|
||||
private Q_SLOTS:
|
||||
void clientConnected() {
|
||||
Exchange *exchange = m_client.createExchange("logs");
|
||||
QAmqpExchange *exchange = m_client.createExchange("logs");
|
||||
connect(exchange, SIGNAL(declared()), this, SLOT(exchangeDeclared()));
|
||||
exchange->declare(Exchange::FanOut);
|
||||
exchange->declare(QAmqpExchange::FanOut);
|
||||
}
|
||||
|
||||
void exchangeDeclared() {
|
||||
Exchange *exchange = qobject_cast<Exchange*>(sender());
|
||||
QAmqpExchange *exchange = qobject_cast<QAmqpExchange*>(sender());
|
||||
if (!exchange)
|
||||
return;
|
||||
|
||||
|
|
@ -43,7 +42,7 @@ private Q_SLOTS:
|
|||
}
|
||||
|
||||
private:
|
||||
Client m_client;
|
||||
QAmqpClient m_client;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include "qamqpclient.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
class LogReceiver : public QObject
|
||||
{
|
||||
|
|
@ -21,21 +20,21 @@ public Q_SLOTS:
|
|||
|
||||
private Q_SLOTS:
|
||||
void clientConnected() {
|
||||
Exchange *exchange = m_client.createExchange("logs");
|
||||
QAmqpExchange *exchange = m_client.createExchange("logs");
|
||||
connect(exchange, SIGNAL(declared()), this, SLOT(exchangeDeclared()));
|
||||
exchange->declare(Exchange::FanOut);
|
||||
exchange->declare(QAmqpExchange::FanOut);
|
||||
}
|
||||
|
||||
void exchangeDeclared() {
|
||||
Queue *temporaryQueue = m_client.createQueue();
|
||||
QAmqpQueue *temporaryQueue = m_client.createQueue();
|
||||
connect(temporaryQueue, SIGNAL(declared()), this, SLOT(queueDeclared()));
|
||||
connect(temporaryQueue, SIGNAL(bound()), this, SLOT(queueBound()));
|
||||
connect(temporaryQueue, SIGNAL(messageReceived()), this, SLOT(messageReceived()));
|
||||
temporaryQueue->declare(Queue::Exclusive);
|
||||
temporaryQueue->declare(QAmqpQueue::Exclusive);
|
||||
}
|
||||
|
||||
void queueDeclared() {
|
||||
Queue *temporaryQueue = qobject_cast<Queue*>(sender());
|
||||
QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
|
||||
if (!temporaryQueue)
|
||||
return;
|
||||
|
||||
|
|
@ -43,25 +42,25 @@ private Q_SLOTS:
|
|||
}
|
||||
|
||||
void queueBound() {
|
||||
Queue *temporaryQueue = qobject_cast<Queue*>(sender());
|
||||
QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
|
||||
if (!temporaryQueue)
|
||||
return;
|
||||
|
||||
qDebug() << " [*] Waiting for logs. To exit press CTRL+C";
|
||||
temporaryQueue->consume(Queue::coNoAck);
|
||||
temporaryQueue->consume(QAmqpQueue::coNoAck);
|
||||
}
|
||||
|
||||
void messageReceived() {
|
||||
Queue *temporaryQueue = qobject_cast<Queue*>(sender());
|
||||
QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
|
||||
if (!temporaryQueue)
|
||||
return;
|
||||
|
||||
Message message = temporaryQueue->dequeue();
|
||||
QAmqpMessage message = temporaryQueue->dequeue();
|
||||
qDebug() << " [x] " << message.payload();
|
||||
}
|
||||
|
||||
private:
|
||||
Client m_client;
|
||||
QAmqpClient m_client;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include "qamqpclient.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
class DirectLogEmitter : public QObject
|
||||
{
|
||||
|
|
@ -22,13 +21,13 @@ public Q_SLOTS:
|
|||
|
||||
private Q_SLOTS:
|
||||
void clientConnected() {
|
||||
Exchange *direct_logs = m_client.createExchange("direct_logs");
|
||||
QAmqpExchange *direct_logs = m_client.createExchange("direct_logs");
|
||||
connect(direct_logs, SIGNAL(declared()), this, SLOT(exchangeDeclared()));
|
||||
direct_logs->declare(Exchange::Direct);
|
||||
direct_logs->declare(QAmqpExchange::Direct);
|
||||
}
|
||||
|
||||
void exchangeDeclared() {
|
||||
Exchange *direct_logs = qobject_cast<Exchange*>(sender());
|
||||
QAmqpExchange *direct_logs = qobject_cast<QAmqpExchange*>(sender());
|
||||
if (!direct_logs)
|
||||
return;
|
||||
|
||||
|
|
@ -50,7 +49,7 @@ private Q_SLOTS:
|
|||
}
|
||||
|
||||
private:
|
||||
Client m_client;
|
||||
QAmqpClient m_client;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include "qamqpclient.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
class DirectLogReceiver : public QObject
|
||||
{
|
||||
|
|
@ -22,25 +21,25 @@ public Q_SLOTS:
|
|||
|
||||
private Q_SLOTS:
|
||||
void clientConnected() {
|
||||
Exchange *exchange = m_client.createExchange("direct_logs");
|
||||
QAmqpExchange *exchange = m_client.createExchange("direct_logs");
|
||||
connect(exchange, SIGNAL(declared()), this, SLOT(exchangeDeclared()));
|
||||
exchange->declare(Exchange::Direct);
|
||||
exchange->declare(QAmqpExchange::Direct);
|
||||
}
|
||||
|
||||
void exchangeDeclared() {
|
||||
Queue *temporaryQueue = m_client.createQueue();
|
||||
QAmqpQueue *temporaryQueue = m_client.createQueue();
|
||||
connect(temporaryQueue, SIGNAL(declared()), this, SLOT(queueDeclared()));
|
||||
connect(temporaryQueue, SIGNAL(messageReceived()), this, SLOT(messageReceived()));
|
||||
temporaryQueue->declare(Queue::Exclusive);
|
||||
temporaryQueue->declare(QAmqpQueue::Exclusive);
|
||||
}
|
||||
|
||||
void queueDeclared() {
|
||||
Queue *temporaryQueue = qobject_cast<Queue*>(sender());
|
||||
QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
|
||||
if (!temporaryQueue)
|
||||
return;
|
||||
|
||||
// start consuming
|
||||
temporaryQueue->consume(Queue::coNoAck);
|
||||
temporaryQueue->consume(QAmqpQueue::coNoAck);
|
||||
|
||||
foreach (QString severity, m_severities)
|
||||
temporaryQueue->bind("direct_logs", severity);
|
||||
|
|
@ -48,16 +47,16 @@ private Q_SLOTS:
|
|||
}
|
||||
|
||||
void messageReceived() {
|
||||
Queue *temporaryQueue = qobject_cast<Queue*>(sender());
|
||||
QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
|
||||
if (!temporaryQueue)
|
||||
return;
|
||||
|
||||
Message message = temporaryQueue->dequeue();
|
||||
QAmqpMessage message = temporaryQueue->dequeue();
|
||||
qDebug() << " [x] " << message.routingKey() << ":" << message.payload();
|
||||
}
|
||||
|
||||
private:
|
||||
Client m_client;
|
||||
QAmqpClient m_client;
|
||||
QStringList m_severities;
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include "qamqpclient.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
class TopicLogEmitter : public QObject
|
||||
{
|
||||
|
|
@ -22,13 +21,13 @@ public Q_SLOTS:
|
|||
|
||||
private Q_SLOTS:
|
||||
void clientConnected() {
|
||||
Exchange *topic_logs = m_client.createExchange("topic_logs");
|
||||
QAmqpExchange *topic_logs = m_client.createExchange("topic_logs");
|
||||
connect(topic_logs, SIGNAL(declared()), this, SLOT(exchangeDeclared()));
|
||||
topic_logs->declare(Exchange::Topic);
|
||||
topic_logs->declare(QAmqpExchange::Topic);
|
||||
}
|
||||
|
||||
void exchangeDeclared() {
|
||||
Exchange *topic_logs = qobject_cast<Exchange*>(sender());
|
||||
QAmqpExchange *topic_logs = qobject_cast<QAmqpExchange*>(sender());
|
||||
if (!topic_logs)
|
||||
return;
|
||||
|
||||
|
|
@ -50,7 +49,7 @@ private Q_SLOTS:
|
|||
}
|
||||
|
||||
private:
|
||||
Client m_client;
|
||||
QAmqpClient m_client;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include "qamqpclient.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
class TopicLogReceiver : public QObject
|
||||
{
|
||||
|
|
@ -22,21 +21,21 @@ public Q_SLOTS:
|
|||
|
||||
private Q_SLOTS:
|
||||
void clientConnected() {
|
||||
Exchange *topic_logs = m_client.createExchange("topic_logs");
|
||||
QAmqpExchange *topic_logs = m_client.createExchange("topic_logs");
|
||||
connect(topic_logs, SIGNAL(declared()), this, SLOT(exchangeDeclared()));
|
||||
topic_logs->declare(Exchange::Topic);
|
||||
topic_logs->declare(QAmqpExchange::Topic);
|
||||
}
|
||||
|
||||
void exchangeDeclared() {
|
||||
Queue *temporaryQueue = m_client.createQueue();
|
||||
QAmqpQueue *temporaryQueue = m_client.createQueue();
|
||||
connect(temporaryQueue, SIGNAL(declared()), this, SLOT(queueDeclared()));
|
||||
connect(temporaryQueue, SIGNAL(bound()), this, SLOT(queueBound()));
|
||||
connect(temporaryQueue, SIGNAL(messageReceived()), this, SLOT(messageReceived()));
|
||||
temporaryQueue->declare(Queue::Exclusive);
|
||||
temporaryQueue->declare(QAmqpQueue::Exclusive);
|
||||
}
|
||||
|
||||
void queueDeclared() {
|
||||
Queue *temporaryQueue = qobject_cast<Queue*>(sender());
|
||||
QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
|
||||
if (!temporaryQueue)
|
||||
return;
|
||||
|
||||
|
|
@ -46,23 +45,23 @@ private Q_SLOTS:
|
|||
}
|
||||
|
||||
void queueBound() {
|
||||
Queue *temporaryQueue = qobject_cast<Queue*>(sender());
|
||||
QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
|
||||
if (!temporaryQueue)
|
||||
return;
|
||||
temporaryQueue->consume(Queue::coNoAck);
|
||||
temporaryQueue->consume(QAmqpQueue::coNoAck);
|
||||
}
|
||||
|
||||
void messageReceived() {
|
||||
Queue *temporaryQueue = qobject_cast<Queue*>(sender());
|
||||
QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
|
||||
if (!temporaryQueue)
|
||||
return;
|
||||
|
||||
Message message = temporaryQueue->dequeue();
|
||||
QAmqpMessage message = temporaryQueue->dequeue();
|
||||
qDebug() << " [x] " << message.routingKey() << ":" << message.payload();
|
||||
}
|
||||
|
||||
private:
|
||||
Client m_client;
|
||||
QAmqpClient m_client;
|
||||
QStringList m_bindingKeys;
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include "qamqpclient.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
class TaskCreator : public QObject
|
||||
{
|
||||
|
|
@ -22,19 +21,19 @@ public Q_SLOTS:
|
|||
|
||||
private Q_SLOTS:
|
||||
void clientConnected() {
|
||||
Queue *queue = m_client.createQueue("task_queue");
|
||||
QAmqpQueue *queue = m_client.createQueue("task_queue");
|
||||
connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared()));
|
||||
queue->declare();
|
||||
}
|
||||
|
||||
void queueDeclared() {
|
||||
Queue *queue = qobject_cast<Queue*>(sender());
|
||||
QAmqpQueue *queue = qobject_cast<QAmqpQueue*>(sender());
|
||||
if (!queue)
|
||||
return;
|
||||
|
||||
Exchange *defaultExchange = m_client.createExchange();
|
||||
Message::PropertyHash properties;
|
||||
properties[Message::DeliveryMode] = "2"; // make message persistent
|
||||
QAmqpExchange *defaultExchange = m_client.createExchange();
|
||||
QAmqpMessage::PropertyHash properties;
|
||||
properties[QAmqpMessage::DeliveryMode] = "2"; // make message persistent
|
||||
|
||||
QString message;
|
||||
if (qApp->arguments().size() < 2)
|
||||
|
|
@ -48,7 +47,7 @@ private Q_SLOTS:
|
|||
}
|
||||
|
||||
private:
|
||||
Client m_client;
|
||||
QAmqpClient m_client;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "qamqpclient.h"
|
||||
#include "qamqpqueue.h"
|
||||
using namespace QAMQP;
|
||||
|
||||
class Worker : public QObject
|
||||
{
|
||||
|
|
@ -46,9 +45,9 @@ private Q_SLOTS:
|
|||
}
|
||||
|
||||
private:
|
||||
Client m_client;
|
||||
Queue *m_queue;
|
||||
Message m_currentMessage;
|
||||
QAmqpClient m_client;
|
||||
QAmqpQueue *m_queue;
|
||||
QAmqpMessage m_currentMessage;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue