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:
Matt Broadstone 2014-09-15 11:51:48 -04:00
parent 9887fa2333
commit 10ab1423c2
37 changed files with 1369 additions and 1465 deletions

View File

@ -1,47 +1,46 @@
#include "qamqptable.h" #include "qamqptable.h"
#include "qamqpframe_p.h" #include "qamqpframe_p.h"
#include "qamqpauthenticator.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), : login_(l),
password_(p) password_(p)
{ {
} }
AMQPlainAuthenticator::~AMQPlainAuthenticator() QAmqpPlainAuthenticator::~QAmqpPlainAuthenticator()
{ {
} }
QString AMQPlainAuthenticator::login() const QString QAmqpPlainAuthenticator::login() const
{ {
return login_; return login_;
} }
QString AMQPlainAuthenticator::password() const QString QAmqpPlainAuthenticator::password() const
{ {
return password_; return password_;
} }
QString AMQPlainAuthenticator::type() const QString QAmqpPlainAuthenticator::type() const
{ {
return "AMQPLAIN"; return "AMQPLAIN";
} }
void AMQPlainAuthenticator::setLogin(const QString &l) void QAmqpPlainAuthenticator::setLogin(const QString &l)
{ {
login_ = l; login_ = l;
} }
void AMQPlainAuthenticator::setPassword(const QString &p) void QAmqpPlainAuthenticator::setPassword(const QString &p)
{ {
password_ = p; password_ = p;
} }
void AMQPlainAuthenticator::write(QDataStream &out) void QAmqpPlainAuthenticator::write(QDataStream &out)
{ {
Frame::writeAmqpField(out, MetaType::ShortString, type()); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, type());
Table response; QAmqpTable response;
response["LOGIN"] = login_; response["LOGIN"] = login_;
response["PASSWORD"] = password_; response["PASSWORD"] = password_;
out << response; out << response;

View File

@ -6,22 +6,19 @@
#include "qamqpglobal.h" #include "qamqpglobal.h"
namespace QAMQP class QAMQP_EXPORT QAmqpAuthenticator
{
class QAMQP_EXPORT Authenticator
{ {
public: public:
virtual ~Authenticator() {} virtual ~QAmqpAuthenticator() {}
virtual QString type() const = 0; virtual QString type() const = 0;
virtual void write(QDataStream &out) = 0; virtual void write(QDataStream &out) = 0;
}; };
class QAMQP_EXPORT AMQPlainAuthenticator : public Authenticator class QAMQP_EXPORT QAmqpPlainAuthenticator : public QAmqpAuthenticator
{ {
public: public:
AMQPlainAuthenticator(const QString &login = QString(), const QString &password = QString()); QAmqpPlainAuthenticator(const QString &login = QString(), const QString &password = QString());
virtual ~AMQPlainAuthenticator(); virtual ~QAmqpPlainAuthenticator();
QString login() const; QString login() const;
void setLogin(const QString &l); void setLogin(const QString &l);
@ -38,6 +35,4 @@ private:
}; };
} // namespace QAMQP
#endif // QAMQPAUTHENTICATOR_H #endif // QAMQPAUTHENTICATOR_H

View File

@ -1,15 +1,13 @@
#include <QDataStream>
#include <QDebug>
#include "qamqpchannel.h" #include "qamqpchannel.h"
#include "qamqpchannel_p.h" #include "qamqpchannel_p.h"
#include "qamqpclient.h" #include "qamqpclient.h"
#include "qamqpclient_p.h" #include "qamqpclient_p.h"
#include <QDebug> int QAmqpChannelPrivate::nextChannelNumber = 0;
#include <QDataStream> QAmqpChannelPrivate::QAmqpChannelPrivate(QAmqpChannel *q)
using namespace QAMQP;
int ChannelPrivate::nextChannelNumber = 0;
ChannelPrivate::ChannelPrivate(Channel *q)
: channelNumber(0), : channelNumber(0),
opened(false), opened(false),
needOpen(true), 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; client = c;
needOpen = channel == -1 ? true : false; needOpen = channel == -1 ? true : false;
@ -34,13 +32,13 @@ void ChannelPrivate::init(int channel, Client *c)
nextChannelNumber = qMax(channelNumber, (nextChannelNumber + 1)); 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); Q_ASSERT(frame.channel() == channelNumber);
if (frame.channel() != channelNumber) if (frame.channel() != channelNumber)
return true; return true;
if (frame.methodClass() == Frame::fcBasic) { if (frame.methodClass() == QAmqpFrame::fcBasic) {
if (frame.id() == bmQosOk) { if (frame.id() == bmQosOk) {
qosOk(frame); qosOk(frame);
return true; return true;
@ -49,7 +47,7 @@ bool ChannelPrivate::_q_method(const Frame::Method &frame)
return false; return false;
} }
if (frame.methodClass() != Frame::fcChannel) if (frame.methodClass() != QAmqpFrame::fcChannel)
return false; return false;
qAmqpDebug("Channel#%d:", channelNumber); qAmqpDebug("Channel#%d:", channelNumber);
@ -75,12 +73,12 @@ bool ChannelPrivate::_q_method(const Frame::Method &frame)
return true; return true;
} }
void ChannelPrivate::_q_open() void QAmqpChannelPrivate::_q_open()
{ {
open(); open();
} }
void ChannelPrivate::sendFrame(const Frame::Base &frame) void QAmqpChannelPrivate::sendFrame(const QAmqpFrame &frame)
{ {
if (!client) { if (!client) {
qAmqpDebug() << Q_FUNC_INFO << "invalid client"; qAmqpDebug() << Q_FUNC_INFO << "invalid client";
@ -90,7 +88,7 @@ void ChannelPrivate::sendFrame(const Frame::Base &frame)
client->d_func()->sendFrame(frame); client->d_func()->sendFrame(frame);
} }
void ChannelPrivate::open() void QAmqpChannelPrivate::open()
{ {
if (!needOpen || opened) if (!needOpen || opened)
return; return;
@ -99,7 +97,7 @@ void ChannelPrivate::open()
return; return;
qAmqpDebug("Open channel #%d", channelNumber); qAmqpDebug("Open channel #%d", channelNumber);
Frame::Method frame(Frame::fcChannel, miOpen); QAmqpMethodFrame frame(QAmqpFrame::fcChannel, miOpen);
frame.setChannel(channelNumber); frame.setChannel(channelNumber);
QByteArray arguments; QByteArray arguments;
@ -110,13 +108,13 @@ void ChannelPrivate::open()
sendFrame(frame); sendFrame(frame);
} }
void ChannelPrivate::flow(bool active) void QAmqpChannelPrivate::flow(bool active)
{ {
QByteArray arguments; QByteArray arguments;
QDataStream stream(&arguments, QIODevice::WriteOnly); 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.setChannel(channelNumber);
frame.setArguments(arguments); frame.setArguments(arguments);
sendFrame(frame); 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 // 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 // to pause the channel in a test. It seems like RabbitMQ just doesn't
// care about flow control, preferring rather to use basic.qos // 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); Q_UNUSED(frame);
qAmqpDebug() << Q_FUNC_INFO; qAmqpDebug() << Q_FUNC_INFO;
} }
void ChannelPrivate::flowOk() void QAmqpChannelPrivate::flowOk()
{ {
qAmqpDebug() << Q_FUNC_INFO; 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(); QByteArray data = frame.arguments();
QDataStream stream(&data, QIODevice::ReadOnly); QDataStream stream(&data, QIODevice::ReadOnly);
bool active = Frame::readAmqpField(stream, MetaType::Boolean).toBool(); bool active = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::Boolean).toBool();
if (active) if (active)
Q_EMIT q->resumed(); Q_EMIT q->resumed();
else else
Q_EMIT q->paused(); 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; QByteArray arguments;
QDataStream stream(&arguments, QIODevice::WriteOnly); QDataStream stream(&arguments, QIODevice::WriteOnly);
if (!code) code = 200; if (!code) code = 200;
Frame::writeAmqpField(stream, MetaType::ShortUint, code); QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortUint, code);
if (!text.isEmpty()) { if (!text.isEmpty()) {
Frame::writeAmqpField(stream, MetaType::ShortString, text); QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, text);
} else { } else {
Frame::writeAmqpField(stream, MetaType::ShortString, QLatin1String("OK")); QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, QLatin1String("OK"));
} }
Frame::writeAmqpField(stream, MetaType::ShortUint, classId); QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortUint, classId);
Frame::writeAmqpField(stream, MetaType::ShortUint, methodId); QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortUint, methodId);
Frame::Method frame(Frame::fcChannel, miClose); QAmqpMethodFrame frame(QAmqpFrame::fcChannel, miClose);
frame.setChannel(channelNumber); frame.setChannel(channelNumber);
frame.setArguments(arguments); frame.setArguments(arguments);
sendFrame(frame); sendFrame(frame);
} }
void ChannelPrivate::close(const Frame::Method &frame) void QAmqpChannelPrivate::close(const QAmqpMethodFrame &frame)
{ {
Q_Q(Channel); Q_Q(QAmqpChannel);
qAmqpDebug(">> CLOSE"); qAmqpDebug(">> CLOSE");
QByteArray data = frame.arguments(); QByteArray data = frame.arguments();
QDataStream stream(&data, QIODevice::ReadOnly); QDataStream stream(&data, QIODevice::ReadOnly);
qint16 code = 0, classId, methodId; qint16 code = 0, classId, methodId;
stream >> code; stream >> code;
QString text = Frame::readAmqpField(stream, MetaType::ShortString).toString(); QString text =
QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString();
stream >> classId; stream >> classId;
stream >> methodId; stream >> methodId;
Error checkError = static_cast<Error>(code); QAMQP::Error checkError = static_cast<QAMQP::Error>(code);
if (checkError != QAMQP::NoError) { if (checkError != QAMQP::NoError) {
error = checkError; error = checkError;
errorString = qPrintable(text); errorString = qPrintable(text);
@ -197,37 +196,37 @@ void ChannelPrivate::close(const Frame::Method &frame)
Q_EMIT q->closed(); Q_EMIT q->closed();
// complete handshake // complete handshake
Frame::Method closeOkFrame(Frame::fcChannel, miCloseOk); QAmqpMethodFrame closeOkFrame(QAmqpFrame::fcChannel, miCloseOk);
closeOkFrame.setChannel(channelNumber); closeOkFrame.setChannel(channelNumber);
sendFrame(closeOkFrame); sendFrame(closeOkFrame);
} }
void ChannelPrivate::closeOk(const Frame::Method &) void QAmqpChannelPrivate::closeOk(const QAmqpMethodFrame &)
{ {
Q_Q(Channel); Q_Q(QAmqpChannel);
Q_EMIT q->closed(); Q_EMIT q->closed();
q->channelClosed(); q->channelClosed();
opened = false; opened = false;
} }
void ChannelPrivate::openOk(const Frame::Method &) void QAmqpChannelPrivate::openOk(const QAmqpMethodFrame &)
{ {
Q_Q(Channel); Q_Q(QAmqpChannel);
qAmqpDebug(">> OpenOK"); qAmqpDebug(">> OpenOK");
opened = true; opened = true;
Q_EMIT q->opened(); Q_EMIT q->opened();
q->channelOpened(); q->channelOpened();
} }
void ChannelPrivate::_q_disconnected() void QAmqpChannelPrivate::_q_disconnected()
{ {
nextChannelNumber = 0; nextChannelNumber = 0;
opened = false; opened = false;
} }
void ChannelPrivate::qosOk(const Frame::Method &frame) void QAmqpChannelPrivate::qosOk(const QAmqpMethodFrame &frame)
{ {
Q_Q(Channel); Q_Q(QAmqpChannel);
Q_UNUSED(frame) Q_UNUSED(frame)
prefetchCount = requestedPrefetchCount; 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), : QObject(parent),
d_ptr(dd) d_ptr(dd)
{ {
} }
Channel::~Channel() QAmqpChannel::~QAmqpChannel()
{ {
} }
void Channel::close() void QAmqpChannel::close()
{ {
Q_D(Channel); Q_D(QAmqpChannel);
d->needOpen = true; d->needOpen = true;
if (d->opened) if (d->opened)
d->close(0, QString(), 0,0); d->close(0, QString(), 0,0);
} }
void Channel::reopen() void QAmqpChannel::reopen()
{ {
Q_D(Channel); Q_D(QAmqpChannel);
if (d->opened) if (d->opened)
close(); close();
d->open(); d->open();
} }
QString Channel::name() const QString QAmqpChannel::name() const
{ {
Q_D(const Channel); Q_D(const QAmqpChannel);
return d->name; return d->name;
} }
int Channel::channelNumber() const int QAmqpChannel::channelNumber() const
{ {
Q_D(const Channel); Q_D(const QAmqpChannel);
return d->channelNumber; return d->channelNumber;
} }
void Channel::setName(const QString &name) void QAmqpChannel::setName(const QString &name)
{ {
Q_D(Channel); Q_D(QAmqpChannel);
d->name = name; d->name = name;
} }
bool Channel::isOpened() const bool QAmqpChannel::isOpened() const
{ {
Q_D(const Channel); Q_D(const QAmqpChannel);
return d->opened; return d->opened;
} }
void Channel::qos(qint16 prefetchCount, qint32 prefetchSize) void QAmqpChannel::qos(qint16 prefetchCount, qint32 prefetchSize)
{ {
Q_D(Channel); Q_D(QAmqpChannel);
Frame::Method frame(Frame::fcBasic, ChannelPrivate::bmQos); QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpChannelPrivate::bmQos);
frame.setChannel(d->channelNumber); frame.setChannel(d->channelNumber);
QByteArray arguments; QByteArray arguments;
@ -307,33 +306,33 @@ void Channel::qos(qint16 prefetchCount, qint32 prefetchSize)
d->sendFrame(frame); d->sendFrame(frame);
} }
qint32 Channel::prefetchSize() const qint32 QAmqpChannel::prefetchSize() const
{ {
Q_D(const Channel); Q_D(const QAmqpChannel);
return d->prefetchSize; return d->prefetchSize;
} }
qint16 Channel::prefetchCount() const qint16 QAmqpChannel::prefetchCount() const
{ {
Q_D(const Channel); Q_D(const QAmqpChannel);
return d->prefetchCount; return d->prefetchCount;
} }
Error Channel::error() const QAMQP::Error QAmqpChannel::error() const
{ {
Q_D(const Channel); Q_D(const QAmqpChannel);
return d->error; return d->error;
} }
QString Channel::errorString() const QString QAmqpChannel::errorString() const
{ {
Q_D(const Channel); Q_D(const QAmqpChannel);
return d->errorString; return d->errorString;
} }
void Channel::resume() void QAmqpChannel::resume()
{ {
Q_D(Channel); Q_D(QAmqpChannel);
d->flow(true); d->flow(true);
} }

View File

@ -4,19 +4,16 @@
#include <QObject> #include <QObject>
#include "qamqpglobal.h" #include "qamqpglobal.h"
namespace QAMQP class QAmqpClient;
{ class QAmqpChannelPrivate;
class QAMQP_EXPORT QAmqpChannel : public QObject
class Client;
class ChannelPrivate;
class QAMQP_EXPORT Channel : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int number READ channelNumber CONSTANT) Q_PROPERTY(int number READ channelNumber CONSTANT)
Q_PROPERTY(bool opened READ isOpened CONSTANT) Q_PROPERTY(bool opened READ isOpened CONSTANT)
Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QString name READ name WRITE setName)
public: public:
virtual ~Channel(); virtual ~QAmqpChannel();
int channelNumber() const; int channelNumber() const;
bool isOpened() const; bool isOpened() const;
@ -24,7 +21,7 @@ public:
QString name() const; QString name() const;
void setName(const QString &name); void setName(const QString &name);
Error error() const; QAMQP::Error error() const;
QString errorString() const; QString errorString() const;
qint32 prefetchSize() const; qint32 prefetchSize() const;
@ -51,18 +48,16 @@ protected:
virtual void channelClosed() = 0; virtual void channelClosed() = 0;
protected: protected:
explicit Channel(ChannelPrivate *dd, Client *client); explicit QAmqpChannel(QAmqpChannelPrivate *dd, QAmqpClient *client);
Q_DISABLE_COPY(Channel) Q_DISABLE_COPY(QAmqpChannel)
Q_DECLARE_PRIVATE(Channel) Q_DECLARE_PRIVATE(QAmqpChannel)
QScopedPointer<ChannelPrivate> d_ptr; QScopedPointer<QAmqpChannelPrivate> d_ptr;
Q_PRIVATE_SLOT(d_func(), void _q_open()) Q_PRIVATE_SLOT(d_func(), void _q_open())
Q_PRIVATE_SLOT(d_func(), void _q_disconnected()) Q_PRIVATE_SLOT(d_func(), void _q_disconnected())
friend class ClientPrivate; friend class QAmqpClientPrivate;
}; };
} // namespace QAMQP
#endif // QAMQPCHANNEL_H #endif // QAMQPCHANNEL_H

View File

@ -6,13 +6,9 @@
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok #define METHOD_ID_ENUM(name, id) name = id, name ## Ok
namespace QAMQP class QAmqpClient;
{ class QAmqpClientPrivate;
class QAmqpChannelPrivate : public QAmqpMethodFrameHandler
class Client;
class Network;
class ClientPrivate;
class ChannelPrivate : public Frame::MethodHandler
{ {
public: public:
enum MethodId { enum MethodId {
@ -36,11 +32,11 @@ public:
METHOD_ID_ENUM(bmRecover, 110) METHOD_ID_ENUM(bmRecover, 110)
}; };
ChannelPrivate(Channel *q); QAmqpChannelPrivate(QAmqpChannel *q);
virtual ~ChannelPrivate(); virtual ~QAmqpChannelPrivate();
void init(int channel, Client *client); void init(int channel, QAmqpClient *client);
void sendFrame(const Frame::Base &frame); void sendFrame(const QAmqpFrame &frame);
void open(); void open();
void flow(bool active); void flow(bool active);
@ -48,19 +44,19 @@ public:
void close(int code, const QString &text, int classId, int methodId); void close(int code, const QString &text, int classId, int methodId);
// reimp MethodHandler // reimp MethodHandler
virtual bool _q_method(const Frame::Method &frame); virtual bool _q_method(const QAmqpMethodFrame &frame);
void openOk(const Frame::Method &frame); void openOk(const QAmqpMethodFrame &frame);
void flow(const Frame::Method &frame); void flow(const QAmqpMethodFrame &frame);
void flowOk(const Frame::Method &frame); void flowOk(const QAmqpMethodFrame &frame);
void close(const Frame::Method &frame); void close(const QAmqpMethodFrame &frame);
void closeOk(const Frame::Method &frame); void closeOk(const QAmqpMethodFrame &frame);
void qosOk(const Frame::Method &frame); void qosOk(const QAmqpMethodFrame &frame);
// private slots // private slots
virtual void _q_disconnected(); virtual void _q_disconnected();
void _q_open(); void _q_open();
QPointer<Client> client; QPointer<QAmqpClient> client;
QString name; QString name;
int channelNumber; int channelNumber;
static int nextChannelNumber; static int nextChannelNumber;
@ -72,13 +68,11 @@ public:
qint16 prefetchCount; qint16 prefetchCount;
qint16 requestedPrefetchCount; qint16 requestedPrefetchCount;
Error error; QAMQP::Error error;
QString errorString; QString errorString;
Q_DECLARE_PUBLIC(Channel) Q_DECLARE_PUBLIC(QAmqpChannel)
Channel * const q_ptr; QAmqpChannel * const q_ptr;
}; };
} // namespace QAMQP
#endif // QAMQPCHANNEL_P_H #endif // QAMQPCHANNEL_P_H

View File

@ -13,12 +13,11 @@
#include "qamqptable.h" #include "qamqptable.h"
#include "qamqpclient_p.h" #include "qamqpclient_p.h"
#include "qamqpclient.h" #include "qamqpclient.h"
using namespace QAMQP;
ClientPrivate::ClientPrivate(Client *q) QAmqpClientPrivate::QAmqpClientPrivate(QAmqpClient *q)
: port(AMQP_PORT), : port(AMQP_PORT),
host(QString::fromLatin1(AMQP_HOST)), host(AMQP_HOST),
virtualHost(QString::fromLatin1(AMQP_VHOST)), virtualHost(AMQP_VHOST),
autoReconnect(false), autoReconnect(false),
timeout(-1), timeout(-1),
connecting(false), 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(); initSocket();
heartbeatTimer = new QTimer(q); heartbeatTimer = new QTimer(q);
QObject::connect(heartbeatTimer, SIGNAL(timeout()), q, SLOT(_q_heartbeat())); QObject::connect(heartbeatTimer, SIGNAL(timeout()), q, SLOT(_q_heartbeat()));
authenticator = QSharedPointer<Authenticator>( authenticator = QSharedPointer<QAmqpAuthenticator>(
new AMQPlainAuthenticator(QString::fromLatin1(AMQP_LOGIN), QString::fromLatin1(AMQP_PSWD))); 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); socket = new QTcpSocket(q);
QObject::connect(socket, SIGNAL(connected()), q, SLOT(_q_socketConnected())); QObject::connect(socket, SIGNAL(connected()), q, SLOT(_q_socketConnected()));
QObject::connect(socket, SIGNAL(disconnected()), q, SLOT(_q_socketDisconnected())); QObject::connect(socket, SIGNAL(disconnected()), q, SLOT(_q_socketDisconnected()));
@ -59,25 +58,25 @@ void ClientPrivate::initSocket()
q, SLOT(_q_socketError(QAbstractSocket::SocketError))); 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")) { if (auth && auth->type() == QLatin1String("AMQPLAIN")) {
AMQPlainAuthenticator *a = static_cast<AMQPlainAuthenticator*>(auth); QAmqpPlainAuthenticator *a = static_cast<QAmqpPlainAuthenticator*>(auth);
a->setLogin(username); 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")) { if (auth && auth->type() == QLatin1String("AMQPLAIN")) {
AMQPlainAuthenticator *a = static_cast<AMQPlainAuthenticator*>(auth); QAmqpPlainAuthenticator *a = static_cast<QAmqpPlainAuthenticator*>(auth);
a->setPassword(password); a->setPassword(password);
} }
} }
void ClientPrivate::parseConnectionString(const QString &uri) void QAmqpClientPrivate::parseConnectionString(const QString &uri)
{ {
#if QT_VERSION > 0x040801 #if QT_VERSION > 0x040801
QUrl connectionString = QUrl::fromUserInput(uri); QUrl connectionString = QUrl::fromUserInput(uri);
@ -108,7 +107,7 @@ void ClientPrivate::parseConnectionString(const QString &uri)
#endif #endif
} }
void ClientPrivate::_q_connect() void QAmqpClientPrivate::_q_connect()
{ {
if (socket->state() != QAbstractSocket::UnconnectedState) { if (socket->state() != QAbstractSocket::UnconnectedState) {
qAmqpDebug() << Q_FUNC_INFO << "socket already connected, disconnecting.."; qAmqpDebug() << Q_FUNC_INFO << "socket already connected, disconnecting..";
@ -118,7 +117,7 @@ void ClientPrivate::_q_connect()
socket->connectToHost(host, port); socket->connectToHost(host, port);
} }
void ClientPrivate::_q_disconnect() void QAmqpClientPrivate::_q_disconnect()
{ {
if (socket->state() == QAbstractSocket::UnconnectedState) { if (socket->state() == QAbstractSocket::UnconnectedState) {
qAmqpDebug() << Q_FUNC_INFO << "already disconnected"; qAmqpDebug() << Q_FUNC_INFO << "already disconnected";
@ -130,16 +129,16 @@ void ClientPrivate::_q_disconnect()
} }
// private slots // private slots
void ClientPrivate::_q_socketConnected() void QAmqpClientPrivate::_q_socketConnected()
{ {
timeout = 0; timeout = 0;
char header[8] = {'A', 'M', 'Q', 'P', 0, 0, 9, 1}; char header[8] = {'A', 'M', 'Q', 'P', 0, 0, 9, 1};
socket->write(header, 8); socket->write(header, 8);
} }
void ClientPrivate::_q_socketDisconnected() void QAmqpClientPrivate::_q_socketDisconnected()
{ {
Q_Q(Client); Q_Q(QAmqpClient);
buffer.clear(); buffer.clear();
if (connected) { if (connected) {
connected = false; 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); 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) { if (timeout == 0) {
timeout = 1000; timeout = 1000;
} else { } 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) { while (socket->bytesAvailable() >= QAmqpFrame::HEADER_SIZE) {
unsigned char headerData[Frame::HEADER_SIZE]; unsigned char headerData[QAmqpFrame::HEADER_SIZE];
socket->peek((char*)headerData, Frame::HEADER_SIZE); socket->peek((char*)headerData, QAmqpFrame::HEADER_SIZE);
const quint32 payloadSize = qFromBigEndian<quint32>(headerData + 3); 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) if (socket->bytesAvailable() < readSize)
return; return;
@ -201,65 +200,65 @@ void ClientPrivate::_q_readyRead()
socket->read(buffer.data(), readSize); socket->read(buffer.data(), readSize);
const char *bufferData = buffer.constData(); const char *bufferData = buffer.constData();
const quint8 type = *(quint8*)&bufferData[0]; const quint8 type = *(quint8*)&bufferData[0];
const quint8 magic = *(quint8*)&bufferData[Frame::HEADER_SIZE + payloadSize]; const quint8 magic = *(quint8*)&bufferData[QAmqpFrame::HEADER_SIZE + payloadSize];
if (magic != Frame::FRAME_END) { if (magic != QAmqpFrame::FRAME_END) {
close(UnexpectedFrameError, "wrong end of frame"); close(QAMQP::UnexpectedFrameError, "wrong end of frame");
return; return;
} }
QDataStream streamB(&buffer, QIODevice::ReadOnly); QDataStream streamB(&buffer, QIODevice::ReadOnly);
switch(Frame::Type(type)) { switch(QAmqpFrame::Type(type)) {
case Frame::ftMethod: case QAmqpFrame::ftMethod:
{ {
Frame::Method frame(streamB); QAmqpMethodFrame frame(streamB);
if (frame.size() > frameMax) { if (frame.size() > frameMax) {
close(FrameError, "frame size too large"); close(QAMQP::FrameError, "frame size too large");
return; return;
} }
if (frame.methodClass() == Frame::fcConnection) { if (frame.methodClass() == QAmqpFrame::fcConnection) {
_q_method(frame); _q_method(frame);
} else { } else {
foreach (Frame::MethodHandler *methodHandler, methodHandlersByChannel[frame.channel()]) foreach (QAmqpMethodFrameHandler *methodHandler, methodHandlersByChannel[frame.channel()])
methodHandler->_q_method(frame); methodHandler->_q_method(frame);
} }
} }
break; break;
case Frame::ftHeader: case QAmqpFrame::ftHeader:
{ {
Frame::Content frame(streamB); QAmqpContentFrame frame(streamB);
if (frame.size() > frameMax) { if (frame.size() > frameMax) {
close(FrameError, "frame size too large"); close(QAMQP::FrameError, "frame size too large");
return; return;
} else if (frame.channel() <= 0) { } 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; return;
} }
foreach (Frame::ContentHandler *methodHandler, contentHandlerByChannel[frame.channel()]) foreach (QAmqpContentFrameHandler *methodHandler, contentHandlerByChannel[frame.channel()])
methodHandler->_q_content(frame); methodHandler->_q_content(frame);
} }
break; break;
case Frame::ftBody: case QAmqpFrame::ftBody:
{ {
Frame::ContentBody frame(streamB); QAmqpContentBodyFrame frame(streamB);
if (frame.size() > frameMax) { if (frame.size() > frameMax) {
close(FrameError, "frame size too large"); close(QAMQP::FrameError, "frame size too large");
return; return;
} else if (frame.channel() <= 0) { } 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; return;
} }
foreach (Frame::ContentBodyHandler *methodHandler, bodyHandlersByChannel[frame.channel()]) foreach (QAmqpContentBodyFrameHandler *methodHandler, bodyHandlersByChannel[frame.channel()])
methodHandler->_q_body(frame); methodHandler->_q_body(frame);
} }
break; break;
case Frame::ftHeartbeat: case QAmqpFrame::ftHeartbeat:
{ {
Frame::Method frame(streamB); QAmqpMethodFrame frame(streamB);
if (frame.channel() != 0) { if (frame.channel() != 0) {
close(FrameError, "heartbeat must have channel id zero"); close(QAMQP::FrameError, "heartbeat must have channel id zero");
return; return;
} }
@ -268,13 +267,13 @@ void ClientPrivate::_q_readyRead()
break; break;
default: default:
qAmqpDebug() << "AMQP: Unknown frame type: " << type; qAmqpDebug() << "AMQP: Unknown frame type: " << type;
close(FrameError, "invalid frame type"); close(QAMQP::FrameError, "invalid frame type");
return; return;
} }
} }
} }
void ClientPrivate::sendFrame(const Frame::Base &frame) void QAmqpClientPrivate::sendFrame(const QAmqpFrame &frame)
{ {
if (socket->state() != QAbstractSocket::ConnectedState) { if (socket->state() != QAbstractSocket::ConnectedState) {
qAmqpDebug() << Q_FUNC_INFO << "socket not connected: " << socket->state(); qAmqpDebug() << Q_FUNC_INFO << "socket not connected: " << socket->state();
@ -285,36 +284,36 @@ void ClientPrivate::sendFrame(const Frame::Base &frame)
frame.toStream(stream); frame.toStream(stream);
} }
bool ClientPrivate::_q_method(const Frame::Method &frame) bool QAmqpClientPrivate::_q_method(const QAmqpMethodFrame &frame)
{ {
Q_ASSERT(frame.methodClass() == Frame::fcConnection); Q_ASSERT(frame.methodClass() == QAmqpFrame::fcConnection);
if (frame.methodClass() != Frame::fcConnection) if (frame.methodClass() != QAmqpFrame::fcConnection)
return false; return false;
qAmqpDebug() << "Connection:"; qAmqpDebug() << "Connection:";
if (closed) { if (closed) {
if (frame.id() == ClientPrivate::miCloseOk) if (frame.id() == QAmqpClientPrivate::miCloseOk)
closeOk(frame); closeOk(frame);
return false; return false;
} }
switch (ClientPrivate::MethodId(frame.id())) { switch (QAmqpClientPrivate::MethodId(frame.id())) {
case ClientPrivate::miStart: case QAmqpClientPrivate::miStart:
start(frame); start(frame);
break; break;
case ClientPrivate::miSecure: case QAmqpClientPrivate::miSecure:
secure(frame); secure(frame);
break; break;
case ClientPrivate::miTune: case QAmqpClientPrivate::miTune:
tune(frame); tune(frame);
break; break;
case ClientPrivate::miOpenOk: case QAmqpClientPrivate::miOpenOk:
openOk(frame); openOk(frame);
break; break;
case ClientPrivate::miClose: case QAmqpClientPrivate::miClose:
close(frame); close(frame);
break; break;
case ClientPrivate::miCloseOk: case QAmqpClientPrivate::miCloseOk:
closeOk(frame); closeOk(frame);
break; break;
default: default:
@ -324,9 +323,9 @@ bool ClientPrivate::_q_method(const Frame::Method &frame)
return true; return true;
} }
void ClientPrivate::start(const Frame::Method &frame) void QAmqpClientPrivate::start(const QAmqpMethodFrame &frame)
{ {
Q_Q(Client); Q_Q(QAmqpClient);
qAmqpDebug(">> Start"); qAmqpDebug(">> Start");
QByteArray data = frame.arguments(); QByteArray data = frame.arguments();
QDataStream stream(&data, QIODevice::ReadOnly); QDataStream stream(&data, QIODevice::ReadOnly);
@ -335,18 +334,18 @@ void ClientPrivate::start(const Frame::Method &frame)
quint8 version_minor = 0; quint8 version_minor = 0;
stream >> version_major >> version_minor; stream >> version_major >> version_minor;
Table table; QAmqpTable table;
stream >> table; stream >> table;
QStringList mechanisms = QStringList mechanisms =
Frame::readAmqpField(stream, MetaType::LongString).toString().split(' '); QAmqpFrame::readAmqpField(stream, QAmqpMetaType::LongString).toString().split(' ');
QString locales = Frame::readAmqpField(stream, MetaType::LongString).toString(); QString locales = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::LongString).toString();
qAmqpDebug(">> version_major: %d", version_major); qAmqpDebug(">> version_major: %d", version_major);
qAmqpDebug(">> version_minor: %d", version_minor); qAmqpDebug(">> version_minor: %d", version_minor);
// NOTE: replace with qDebug overload // NOTE: replace with qDebug overload
// Frame::print(table); // QAmqpFrame::print(table);
qAmqpDebug() << ">> mechanisms: " << mechanisms; qAmqpDebug() << ">> mechanisms: " << mechanisms;
qAmqpDebug(">> locales: %s", qPrintable(locales)); qAmqpDebug(">> locales: %s", qPrintable(locales));
@ -360,13 +359,13 @@ void ClientPrivate::start(const Frame::Method &frame)
startOk(); startOk();
} }
void ClientPrivate::secure(const Frame::Method &frame) void QAmqpClientPrivate::secure(const QAmqpMethodFrame &frame)
{ {
Q_UNUSED(frame) Q_UNUSED(frame)
qAmqpDebug() << Q_FUNC_INFO << "called!"; qAmqpDebug() << Q_FUNC_INFO << "called!";
} }
void ClientPrivate::tune(const Frame::Method &frame) void QAmqpClientPrivate::tune(const QAmqpMethodFrame &frame)
{ {
qAmqpDebug(">> Tune"); qAmqpDebug(">> Tune");
QByteArray data = frame.arguments(); QByteArray data = frame.arguments();
@ -401,18 +400,18 @@ void ClientPrivate::tune(const Frame::Method &frame)
open(); open();
} }
void ClientPrivate::openOk(const Frame::Method &frame) void QAmqpClientPrivate::openOk(const QAmqpMethodFrame &frame)
{ {
Q_Q(Client); Q_Q(QAmqpClient);
Q_UNUSED(frame) Q_UNUSED(frame)
qAmqpDebug(">> OpenOK"); qAmqpDebug(">> OpenOK");
connected = true; connected = true;
Q_EMIT q->connected(); 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) Q_UNUSED(frame)
qAmqpDebug() << Q_FUNC_INFO << "received"; qAmqpDebug() << Q_FUNC_INFO << "received";
connected = false; connected = false;
@ -422,19 +421,19 @@ void ClientPrivate::closeOk(const Frame::Method &frame)
Q_EMIT q->disconnected(); 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"); qAmqpDebug(">> CLOSE");
QByteArray data = frame.arguments(); QByteArray data = frame.arguments();
QDataStream stream(&data, QIODevice::ReadOnly); QDataStream stream(&data, QIODevice::ReadOnly);
qint16 code = 0, classId, methodId; qint16 code = 0, classId, methodId;
stream >> code; stream >> code;
QString text = Frame::readAmqpField(stream, MetaType::ShortString).toString(); QString text = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString();
stream >> classId; stream >> classId;
stream >> methodId; stream >> methodId;
Error checkError = static_cast<Error>(code); QAMQP::Error checkError = static_cast<QAMQP::Error>(code);
if (checkError != QAMQP::NoError) { if (checkError != QAMQP::NoError) {
error = checkError; error = checkError;
errorString = qPrintable(text); errorString = qPrintable(text);
@ -449,17 +448,17 @@ void ClientPrivate::close(const Frame::Method &frame)
Q_EMIT q->disconnected(); Q_EMIT q->disconnected();
// complete handshake // complete handshake
Frame::Method closeOkFrame(Frame::fcConnection, ClientPrivate::miCloseOk); QAmqpMethodFrame closeOkFrame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miCloseOk);
sendFrame(closeOkFrame); sendFrame(closeOkFrame);
} }
void ClientPrivate::startOk() void QAmqpClientPrivate::startOk()
{ {
Frame::Method frame(Frame::fcConnection, ClientPrivate::miStartOk); QAmqpMethodFrame frame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miStartOk);
QByteArray arguments; QByteArray arguments;
QDataStream stream(&arguments, QIODevice::WriteOnly); QDataStream stream(&arguments, QIODevice::WriteOnly);
Table clientProperties; QAmqpTable clientProperties;
clientProperties["version"] = QString(QAMQP_VERSION); clientProperties["version"] = QString(QAMQP_VERSION);
clientProperties["platform"] = QString("Qt %1").arg(qVersion()); clientProperties["platform"] = QString("Qt %1").arg(qVersion());
clientProperties["product"] = QString("QAMQP"); clientProperties["product"] = QString("QAMQP");
@ -467,20 +466,20 @@ void ClientPrivate::startOk()
stream << clientProperties; stream << clientProperties;
authenticator->write(stream); authenticator->write(stream);
Frame::writeAmqpField(stream, MetaType::ShortString, QLatin1String("en_US")); QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, QLatin1String("en_US"));
frame.setArguments(arguments); frame.setArguments(arguments);
sendFrame(frame); sendFrame(frame);
} }
void ClientPrivate::secureOk() void QAmqpClientPrivate::secureOk()
{ {
qAmqpDebug() << Q_FUNC_INFO; 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; QByteArray arguments;
QDataStream stream(&arguments, QIODevice::WriteOnly); QDataStream stream(&arguments, QIODevice::WriteOnly);
@ -492,13 +491,13 @@ void ClientPrivate::tuneOk()
sendFrame(frame); sendFrame(frame);
} }
void ClientPrivate::open() void QAmqpClientPrivate::open()
{ {
Frame::Method frame(Frame::fcConnection, ClientPrivate::miOpen); QAmqpMethodFrame frame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miOpen);
QByteArray arguments; QByteArray arguments;
QDataStream stream(&arguments, QIODevice::WriteOnly); QDataStream stream(&arguments, QIODevice::WriteOnly);
Frame::writeAmqpField(stream, MetaType::ShortString, virtualHost); QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, virtualHost);
stream << qint8(0); stream << qint8(0);
stream << qint8(0); stream << qint8(0);
@ -507,130 +506,130 @@ void ClientPrivate::open()
sendFrame(frame); 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; QByteArray arguments;
QDataStream stream(&arguments, QIODevice::WriteOnly); QDataStream stream(&arguments, QIODevice::WriteOnly);
stream << qint16(code); stream << qint16(code);
Frame::writeAmqpField(stream, MetaType::ShortString, text); QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, text);
stream << qint16(classId); stream << qint16(classId);
stream << qint16(methodId); stream << qint16(methodId);
Frame::Method frame(Frame::fcConnection, ClientPrivate::miClose); QAmqpMethodFrame frame(QAmqpFrame::fcConnection, QAmqpClientPrivate::miClose);
frame.setArguments(arguments); frame.setArguments(arguments);
sendFrame(frame); sendFrame(frame);
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
Client::Client(QObject *parent) QAmqpClient::QAmqpClient(QObject *parent)
: QObject(parent), : QObject(parent),
d_ptr(new ClientPrivate(this)) d_ptr(new QAmqpClientPrivate(this))
{ {
Q_D(Client); Q_D(QAmqpClient);
d->init(); d->init();
} }
Client::Client(ClientPrivate *dd, QObject *parent) QAmqpClient::QAmqpClient(QAmqpClientPrivate *dd, QObject *parent)
: QObject(parent), : QObject(parent),
d_ptr(dd) d_ptr(dd)
{ {
} }
Client::~Client() QAmqpClient::~QAmqpClient()
{ {
Q_D(Client); Q_D(QAmqpClient);
if (d->connected) if (d->connected)
d->_q_disconnect(); d->_q_disconnect();
} }
bool Client::isConnected() const bool QAmqpClient::isConnected() const
{ {
Q_D(const Client); Q_D(const QAmqpClient);
return d->connected; return d->connected;
} }
quint16 Client::port() const quint16 QAmqpClient::port() const
{ {
Q_D(const Client); Q_D(const QAmqpClient);
return d->port; return d->port;
} }
void Client::setPort(quint16 port) void QAmqpClient::setPort(quint16 port)
{ {
Q_D(Client); Q_D(QAmqpClient);
d->port = port; d->port = port;
} }
QString Client::host() const QString QAmqpClient::host() const
{ {
Q_D(const Client); Q_D(const QAmqpClient);
return d->host; return d->host;
} }
void Client::setHost(const QString &host) void QAmqpClient::setHost(const QString &host)
{ {
Q_D(Client); Q_D(QAmqpClient);
d->host = host; d->host = host;
} }
QString Client::virtualHost() const QString QAmqpClient::virtualHost() const
{ {
Q_D(const Client); Q_D(const QAmqpClient);
return d->virtualHost; return d->virtualHost;
} }
void Client::setVirtualHost(const QString &virtualHost) void QAmqpClient::setVirtualHost(const QString &virtualHost)
{ {
Q_D(Client); Q_D(QAmqpClient);
d->virtualHost = virtualHost; d->virtualHost = virtualHost;
} }
QString Client::username() const QString QAmqpClient::username() const
{ {
Q_D(const Client); Q_D(const QAmqpClient);
const Authenticator *auth = d->authenticator.data(); const QAmqpAuthenticator *auth = d->authenticator.data();
if (auth && auth->type() == QLatin1String("AMQPLAIN")) { 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 a->login();
} }
return QString(); return QString();
} }
void Client::setUsername(const QString &username) void QAmqpClient::setUsername(const QString &username)
{ {
Q_D(Client); Q_D(QAmqpClient);
d->setUsername(username); d->setUsername(username);
} }
QString Client::password() const QString QAmqpClient::password() const
{ {
Q_D(const Client); Q_D(const QAmqpClient);
const Authenticator *auth = d->authenticator.data(); const QAmqpAuthenticator *auth = d->authenticator.data();
if (auth && auth->type() == QLatin1String("AMQPLAIN")) { 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 a->password();
} }
return QString(); return QString();
} }
void Client::setPassword(const QString &password) void QAmqpClient::setPassword(const QString &password)
{ {
Q_D(Client); Q_D(QAmqpClient);
d->setPassword(password); d->setPassword(password);
} }
Exchange *Client::createExchange(int channelNumber) QAmqpExchange *QAmqpClient::createExchange(int channelNumber)
{ {
return createExchange(QString(), channelNumber); return createExchange(QString(), channelNumber);
} }
Exchange *Client::createExchange(const QString &name, int channelNumber) QAmqpExchange *QAmqpClient::createExchange(const QString &name, int channelNumber)
{ {
Q_D(Client); Q_D(QAmqpClient);
Exchange *exchange = new Exchange(channelNumber, this); QAmqpExchange *exchange = new QAmqpExchange(channelNumber, this);
d->methodHandlersByChannel[exchange->channelNumber()].append(exchange->d_func()); d->methodHandlersByChannel[exchange->channelNumber()].append(exchange->d_func());
connect(this, SIGNAL(connected()), exchange, SLOT(_q_open())); connect(this, SIGNAL(connected()), exchange, SLOT(_q_open()));
connect(this, SIGNAL(disconnected()), exchange, SLOT(_q_disconnected())); connect(this, SIGNAL(disconnected()), exchange, SLOT(_q_disconnected()));
@ -641,15 +640,15 @@ Exchange *Client::createExchange(const QString &name, int channelNumber)
return exchange; return exchange;
} }
Queue *Client::createQueue(int channelNumber) QAmqpQueue *QAmqpClient::createQueue(int channelNumber)
{ {
return createQueue(QString(), channelNumber); return createQueue(QString(), channelNumber);
} }
Queue *Client::createQueue(const QString &name, int channelNumber) QAmqpQueue *QAmqpClient::createQueue(const QString &name, int channelNumber)
{ {
Q_D(Client); Q_D(QAmqpClient);
Queue *queue = new Queue(channelNumber, this); QAmqpQueue *queue = new QAmqpQueue(channelNumber, this);
d->methodHandlersByChannel[queue->channelNumber()].append(queue->d_func()); d->methodHandlersByChannel[queue->channelNumber()].append(queue->d_func());
d->contentHandlerByChannel[queue->channelNumber()].append(queue->d_func()); d->contentHandlerByChannel[queue->channelNumber()].append(queue->d_func());
d->bodyHandlersByChannel[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; return queue;
} }
void Client::setAuth(Authenticator *authenticator) void QAmqpClient::setAuth(QAmqpAuthenticator *authenticator)
{ {
Q_D(Client); Q_D(QAmqpClient);
d->authenticator = QSharedPointer<Authenticator>(authenticator); 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(); return d->authenticator.data();
} }
bool Client::autoReconnect() const bool QAmqpClient::autoReconnect() const
{ {
Q_D(const Client); Q_D(const QAmqpClient);
return d->autoReconnect; return d->autoReconnect;
} }
void Client::setAutoReconnect(bool value) void QAmqpClient::setAutoReconnect(bool value)
{ {
Q_D(Client); Q_D(QAmqpClient);
d->autoReconnect = value; d->autoReconnect = value;
} }
qint16 Client::channelMax() const qint16 QAmqpClient::channelMax() const
{ {
Q_D(const Client); Q_D(const QAmqpClient);
return d->channelMax; return d->channelMax;
} }
void Client::setChannelMax(qint16 channelMax) void QAmqpClient::setChannelMax(qint16 channelMax)
{ {
Q_D(Client); Q_D(QAmqpClient);
if (d->connected) { if (d->connected) {
qAmqpDebug() << Q_FUNC_INFO << "can't modify value while connected"; qAmqpDebug() << Q_FUNC_INFO << "can't modify value while connected";
return; return;
@ -703,15 +702,15 @@ void Client::setChannelMax(qint16 channelMax)
d->channelMax = channelMax; d->channelMax = channelMax;
} }
qint32 Client::frameMax() const qint32 QAmqpClient::frameMax() const
{ {
Q_D(const Client); Q_D(const QAmqpClient);
return d->frameMax; return d->frameMax;
} }
void Client::setFrameMax(qint32 frameMax) void QAmqpClient::setFrameMax(qint32 frameMax)
{ {
Q_D(Client); Q_D(QAmqpClient);
if (d->connected) { if (d->connected) {
qAmqpDebug() << Q_FUNC_INFO << "can't modify value while connected"; qAmqpDebug() << Q_FUNC_INFO << "can't modify value while connected";
return; return;
@ -720,15 +719,15 @@ void Client::setFrameMax(qint32 frameMax)
d->frameMax = qMax(frameMax, AMQP_FRAME_MIN_SIZE); 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; return d->heartbeatDelay;
} }
void Client::setHeartbeatDelay(qint16 delay) void QAmqpClient::setHeartbeatDelay(qint16 delay)
{ {
Q_D(Client); Q_D(QAmqpClient);
if (d->connected) { if (d->connected) {
qAmqpDebug() << Q_FUNC_INFO << "can't modify value while connected"; qAmqpDebug() << Q_FUNC_INFO << "can't modify value while connected";
return; return;
@ -737,33 +736,33 @@ void Client::setHeartbeatDelay(qint16 delay)
d->heartbeatDelay = 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); 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(); 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; return d->error;
} }
QString Client::errorString() const QString QAmqpClient::errorString() const
{ {
Q_D(const Client); Q_D(const QAmqpClient);
return d->errorString; return d->errorString;
} }
void Client::connectToHost(const QString &uri) void QAmqpClient::connectToHost(const QString &uri)
{ {
Q_D(Client); Q_D(QAmqpClient);
if (uri.isEmpty()) { if (uri.isEmpty()) {
d->_q_connect(); d->_q_connect();
return; return;
@ -773,17 +772,17 @@ void Client::connectToHost(const QString &uri)
d->_q_connect(); 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->host = address.toString();
d->port = port; d->port = port;
d->_q_connect(); d->_q_connect();
} }
void Client::disconnectFromHost() void QAmqpClient::disconnectFromHost()
{ {
Q_D(Client); Q_D(QAmqpClient);
d->_q_disconnect(); d->_q_disconnect();
} }
@ -792,14 +791,14 @@ void Client::disconnectFromHost()
#ifndef QT_NO_SSL #ifndef QT_NO_SSL
#include <QSslSocket> #include <QSslSocket>
SslClientPrivate::SslClientPrivate(SslClient *q) QAmqpSslClientPrivate::QAmqpSslClientPrivate(QAmqpSslClient *q)
: ClientPrivate(q) : QAmqpClientPrivate(q)
{ {
} }
void SslClientPrivate::initSocket() void QAmqpSslClientPrivate::initSocket()
{ {
Q_Q(Client); Q_Q(QAmqpClient);
QSslSocket *sslSocket = new QSslSocket(q); QSslSocket *sslSocket = new QSslSocket(q);
QObject::connect(sslSocket, SIGNAL(connected()), q, SLOT(_q_socketConnected())); QObject::connect(sslSocket, SIGNAL(connected()), q, SLOT(_q_socketConnected()));
QObject::connect(sslSocket, SIGNAL(disconnected()), q, SLOT(_q_socketDisconnected())); QObject::connect(sslSocket, SIGNAL(disconnected()), q, SLOT(_q_socketDisconnected()));
@ -811,7 +810,7 @@ void SslClientPrivate::initSocket()
socket = sslSocket; socket = sslSocket;
} }
void SslClientPrivate::_q_connect() void QAmqpSslClientPrivate::_q_connect()
{ {
if (socket->state() != QAbstractSocket::UnconnectedState) { if (socket->state() != QAbstractSocket::UnconnectedState) {
qAmqpDebug() << Q_FUNC_INFO << "socket already connected, disconnecting.."; qAmqpDebug() << Q_FUNC_INFO << "socket already connected, disconnecting..";
@ -824,7 +823,7 @@ void SslClientPrivate::_q_connect()
sslSocket->connectToHostEncrypted(host, port); 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 // TODO: these need to be passed on to the user potentially, this is
// very unsafe // very unsafe
@ -832,12 +831,12 @@ void SslClientPrivate::_q_sslErrors(const QList<QSslError> &errors)
sslSocket->ignoreSslErrors(errors); sslSocket->ignoreSslErrors(errors);
} }
SslClient::SslClient(QObject *parent) QAmqpSslClient::QAmqpSslClient(QObject *parent)
: Client(new SslClientPrivate(this), parent) : QAmqpClient(new QAmqpSslClientPrivate(this), parent)
{ {
} }
SslClient::~SslClient() QAmqpSslClient::~QAmqpSslClient()
{ {
} }

View File

@ -12,14 +12,11 @@
#include "qamqpglobal.h" #include "qamqpglobal.h"
namespace QAMQP class QAmqpExchange;
{ class QAmqpQueue;
class QAmqpAuthenticator;
class Exchange; class QAmqpClientPrivate;
class Queue; class QAMQP_EXPORT QAmqpClient : public QObject
class Authenticator;
class ClientPrivate;
class QAMQP_EXPORT Client : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(quint32 port READ port WRITE setPort) 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) Q_PROPERTY(qint16 heartbeatDelay READ heartbeatDelay() WRITE setHeartbeatDelay)
public: public:
explicit Client(QObject *parent = 0); explicit QAmqpClient(QObject *parent = 0);
~Client(); ~QAmqpClient();
// properties // properties
quint16 port() const; quint16 port() const;
@ -52,8 +49,8 @@ public:
QString password() const; QString password() const;
void setPassword(const QString &password); void setPassword(const QString &password);
void setAuth(Authenticator *auth); void setAuth(QAmqpAuthenticator *auth);
Authenticator *auth() const; QAmqpAuthenticator *auth() const;
bool autoReconnect() const; bool autoReconnect() const;
void setAutoReconnect(bool value); void setAutoReconnect(bool value);
@ -72,15 +69,15 @@ public:
void addCustomProperty(const QString &name, const QString &value); void addCustomProperty(const QString &name, const QString &value);
QString customProperty(const QString &name) const; QString customProperty(const QString &name) const;
Error error() const; QAMQP::Error error() const;
QString errorString() const; QString errorString() const;
// channels // channels
Exchange *createExchange(int channelNumber = -1); QAmqpExchange *createExchange(int channelNumber = -1);
Exchange *createExchange(const QString &name, int channelNumber = -1); QAmqpExchange *createExchange(const QString &name, int channelNumber = -1);
Queue *createQueue(int channelNumber = -1); QAmqpQueue *createQueue(int channelNumber = -1);
Queue *createQueue(const QString &name, int channelNumber = -1); QAmqpQueue *createQueue(const QString &name, int channelNumber = -1);
// methods // methods
void connectToHost(const QString &uri = QString()); void connectToHost(const QString &uri = QString());
@ -93,11 +90,11 @@ Q_SIGNALS:
void error(QAMQP::Error error); void error(QAMQP::Error error);
protected: protected:
Client(ClientPrivate *dd, QObject *parent = 0); QAmqpClient(QAmqpClientPrivate *dd, QObject *parent = 0);
Q_DISABLE_COPY(Client) Q_DISABLE_COPY(QAmqpClient)
Q_DECLARE_PRIVATE(Client) Q_DECLARE_PRIVATE(QAmqpClient)
QScopedPointer<ClientPrivate> d_ptr; QScopedPointer<QAmqpClientPrivate> d_ptr;
private: private:
Q_PRIVATE_SLOT(d_func(), void _q_socketConnected()) 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_connect())
Q_PRIVATE_SLOT(d_func(), void _q_disconnect()) Q_PRIVATE_SLOT(d_func(), void _q_disconnect())
friend class ChannelPrivate; friend class QAmqpChannelPrivate;
}; };
#ifndef QT_NO_SSL #ifndef QT_NO_SSL
class SslClientPrivate; class QAmqpSslClientPrivate;
class SslClient : public Client class QAmqpSslClient : public QAmqpClient
{ {
Q_OBJECT Q_OBJECT
public: public:
SslClient(QObject *parent = 0); QAmqpSslClient(QObject *parent = 0);
SslClient(const QUrl &connectionString, QObject *parent = 0); QAmqpSslClient(const QUrl &connectionString, QObject *parent = 0);
~SslClient(); ~QAmqpSslClient();
QSslConfiguration sslConfiguration() const; QSslConfiguration sslConfiguration() const;
void setSslConfiguration(const QSslConfiguration &config); void setSslConfiguration(const QSslConfiguration &config);
private: private:
Q_DISABLE_COPY(SslClient) Q_DISABLE_COPY(QAmqpSslClient)
Q_DECLARE_PRIVATE(SslClient) Q_DECLARE_PRIVATE(QAmqpSslClient)
Q_PRIVATE_SLOT(d_func(), void _q_sslErrors(const QList<QSslError> &errors)) Q_PRIVATE_SLOT(d_func(), void _q_sslErrors(const QList<QSslError> &errors))
}; };
#endif #endif
} // namespace QAMQP
#endif // QAMQPCLIENT_H #endif // QAMQPCLIENT_H

View File

@ -20,16 +20,12 @@
class QTimer; class QTimer;
class QTcpSocket; class QTcpSocket;
namespace QAMQP class QAmqpClient;
{ class QAmqpQueue;
class QAmqpExchange;
class Client; class QAmqpConnection;
class Queue; class QAmqpAuthenticator;
class Exchange; class QAMQP_EXPORT QAmqpClientPrivate : public QAmqpMethodFrameHandler
class Network;
class Connection;
class Authenticator;
class QAMQP_EXPORT ClientPrivate : public Frame::MethodHandler
{ {
public: public:
enum MethodId { enum MethodId {
@ -40,15 +36,15 @@ public:
METHOD_ID_ENUM(miClose, 50) METHOD_ID_ENUM(miClose, 50)
}; };
ClientPrivate(Client *q); QAmqpClientPrivate(QAmqpClient *q);
virtual ~ClientPrivate(); virtual ~QAmqpClientPrivate();
virtual void init(); virtual void init();
virtual void initSocket(); virtual void initSocket();
void setUsername(const QString &username); void setUsername(const QString &username);
void setPassword(const QString &password); void setPassword(const QString &password);
void parseConnectionString(const QString &uri); void parseConnectionString(const QString &uri);
void sendFrame(const Frame::Base &frame); void sendFrame(const QAmqpFrame &frame);
// private slots // private slots
void _q_socketConnected(); void _q_socketConnected();
@ -59,14 +55,14 @@ public:
virtual void _q_connect(); virtual void _q_connect();
void _q_disconnect(); void _q_disconnect();
virtual bool _q_method(const Frame::Method &frame); virtual bool _q_method(const QAmqpMethodFrame &frame);
// method handlers, FROM server // method handlers, FROM server
void start(const Frame::Method &frame); void start(const QAmqpMethodFrame &frame);
void secure(const Frame::Method &frame); void secure(const QAmqpMethodFrame &frame);
void tune(const Frame::Method &frame); void tune(const QAmqpMethodFrame &frame);
void openOk(const Frame::Method &frame); void openOk(const QAmqpMethodFrame &frame);
void closeOk(const Frame::Method &frame); void closeOk(const QAmqpMethodFrame &frame);
// method handlers, TO server // method handlers, TO server
void startOk(); void startOk();
@ -76,13 +72,13 @@ public:
// method handlers, BOTH ways // method handlers, BOTH ways
void close(int code, const QString &text, int classId = 0, int methodId = 0); 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; quint16 port;
QString host; QString host;
QString virtualHost; QString virtualHost;
QSharedPointer<Authenticator> authenticator; QSharedPointer<QAmqpAuthenticator> authenticator;
// Network // Network
QByteArray buffer; QByteArray buffer;
@ -91,33 +87,33 @@ public:
bool connecting; bool connecting;
QTcpSocket *socket; QTcpSocket *socket;
QHash<quint16, QList<Frame::MethodHandler*> > methodHandlersByChannel; QHash<quint16, QList<QAmqpMethodFrameHandler*> > methodHandlersByChannel;
QHash<quint16, QList<Frame::ContentHandler*> > contentHandlerByChannel; QHash<quint16, QList<QAmqpContentFrameHandler*> > contentHandlerByChannel;
QHash<quint16, QList<Frame::ContentBodyHandler*> > bodyHandlersByChannel; QHash<quint16, QList<QAmqpContentBodyFrameHandler*> > bodyHandlersByChannel;
// Connection // Connection
bool closed; bool closed;
bool connected; bool connected;
QPointer<QTimer> heartbeatTimer; QPointer<QTimer> heartbeatTimer;
Table customProperties; QAmqpTable customProperties;
qint16 channelMax; qint16 channelMax;
qint16 heartbeatDelay; qint16 heartbeatDelay;
qint32 frameMax; qint32 frameMax;
Error error; QAMQP::Error error;
QString errorString; QString errorString;
Client * const q_ptr; QAmqpClient * const q_ptr;
Q_DECLARE_PUBLIC(Client) Q_DECLARE_PUBLIC(QAmqpClient)
}; };
#ifndef QT_NO_SSL #ifndef QT_NO_SSL
class SslClient; class QAmqpSslClient;
class SslClientPrivate : public ClientPrivate class QAmqpSslClientPrivate : public QAmqpClientPrivate
{ {
public: public:
SslClientPrivate(SslClient *q); QAmqpSslClientPrivate(QAmqpSslClient *q);
virtual void initSocket(); virtual void initSocket();
virtual void _q_connect(); virtual void _q_connect();
@ -130,6 +126,4 @@ public:
}; };
#endif #endif
} // namespace QAMQP
#endif // QAMQPCLIENT_P_H #endif // QAMQPCLIENT_P_H

View File

@ -6,28 +6,27 @@
#include "qamqpqueue.h" #include "qamqpqueue.h"
#include "qamqpglobal.h" #include "qamqpglobal.h"
#include "qamqpclient.h" #include "qamqpclient.h"
using namespace QAMQP;
QString ExchangePrivate::typeToString(Exchange::ExchangeType type) QString QAmqpExchangePrivate::typeToString(QAmqpExchange::ExchangeType type)
{ {
switch (type) { switch (type) {
case Exchange::Direct: return QLatin1String("direct"); case QAmqpExchange::Direct: return QLatin1String("direct");
case Exchange::FanOut: return QLatin1String("fanout"); case QAmqpExchange::FanOut: return QLatin1String("fanout");
case Exchange::Topic: return QLatin1String("topic"); case QAmqpExchange::Topic: return QLatin1String("topic");
case Exchange::Headers: return QLatin1String("headers"); case QAmqpExchange::Headers: return QLatin1String("headers");
} }
return QLatin1String("direct"); return QLatin1String("direct");
} }
ExchangePrivate::ExchangePrivate(Exchange *q) QAmqpExchangePrivate::QAmqpExchangePrivate(QAmqpExchange *q)
: ChannelPrivate(q), : QAmqpChannelPrivate(q),
delayedDeclare(false), delayedDeclare(false),
declared(false) declared(false)
{ {
} }
void ExchangePrivate::declare() void QAmqpExchangePrivate::declare()
{ {
if (!opened) { if (!opened) {
delayedDeclare = true; delayedDeclare = true;
@ -39,30 +38,30 @@ void ExchangePrivate::declare()
return; return;
} }
Frame::Method frame(Frame::fcExchange, ExchangePrivate::miDeclare); QAmqpMethodFrame frame(QAmqpFrame::fcExchange, QAmqpExchangePrivate::miDeclare);
frame.setChannel(channelNumber); frame.setChannel(channelNumber);
QByteArray args; QByteArray args;
QDataStream stream(&args, QIODevice::WriteOnly); QDataStream stream(&args, QIODevice::WriteOnly);
stream << qint16(0); //reserved 1 stream << qint16(0); //reserved 1
Frame::writeAmqpField(stream, MetaType::ShortString, name); QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, name);
Frame::writeAmqpField(stream, MetaType::ShortString, type); QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, type);
stream << qint8(options); stream << qint8(options);
Frame::writeAmqpField(stream, MetaType::Hash, arguments); QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::Hash, arguments);
frame.setArguments(args); frame.setArguments(args);
sendFrame(frame); sendFrame(frame);
delayedDeclare = false; 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; return true;
if (frame.methodClass() == Frame::fcExchange) { if (frame.methodClass() == QAmqpFrame::fcExchange) {
switch (frame.id()) { switch (frame.id()) {
case miDeclareOk: case miDeclareOk:
declareOk(frame); declareOk(frame);
@ -77,7 +76,7 @@ bool ExchangePrivate::_q_method(const Frame::Method &frame)
} }
return true; return true;
} else if (frame.methodClass() == Frame::fcBasic) { } else if (frame.methodClass() == QAmqpFrame::fcBasic) {
switch (frame.id()) { switch (frame.id()) {
case bmReturn: case bmReturn:
basicReturn(frame); basicReturn(frame);
@ -93,47 +92,47 @@ bool ExchangePrivate::_q_method(const Frame::Method &frame)
return false; return false;
} }
void ExchangePrivate::declareOk(const Frame::Method &frame) void QAmqpExchangePrivate::declareOk(const QAmqpMethodFrame &frame)
{ {
Q_UNUSED(frame) Q_UNUSED(frame)
Q_Q(Exchange); Q_Q(QAmqpExchange);
qAmqpDebug() << "declared exchange: " << name; qAmqpDebug() << "declared exchange: " << name;
declared = true; declared = true;
Q_EMIT q->declared(); Q_EMIT q->declared();
} }
void ExchangePrivate::deleteOk(const Frame::Method &frame) void QAmqpExchangePrivate::deleteOk(const QAmqpMethodFrame &frame)
{ {
Q_UNUSED(frame) Q_UNUSED(frame)
Q_Q(Exchange); Q_Q(QAmqpExchange);
qAmqpDebug() << "deleted exchange: " << name; qAmqpDebug() << "deleted exchange: " << name;
declared = false; declared = false;
Q_EMIT q->removed(); Q_EMIT q->removed();
} }
void ExchangePrivate::_q_disconnected() void QAmqpExchangePrivate::_q_disconnected()
{ {
ChannelPrivate::_q_disconnected(); QAmqpChannelPrivate::_q_disconnected();
qAmqpDebug() << "exchange " << name << " disconnected"; qAmqpDebug() << "exchange " << name << " disconnected";
delayedDeclare = false; delayedDeclare = false;
declared = 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(); QByteArray data = frame.arguments();
QDataStream stream(&data, QIODevice::ReadOnly); QDataStream stream(&data, QIODevice::ReadOnly);
quint16 replyCode; quint16 replyCode;
stream >> replyCode; stream >> replyCode;
QString replyText = Frame::readAmqpField(stream, MetaType::ShortString).toString(); QString replyText = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString();
QString exchangeName = Frame::readAmqpField(stream, MetaType::ShortString).toString(); QString exchangeName = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString();
QString routingKey = Frame::readAmqpField(stream, MetaType::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) { if (checkError != QAMQP::NoError) {
error = checkError; error = checkError;
errorString = qPrintable(replyText); errorString = qPrintable(replyText);
@ -148,113 +147,113 @@ void ExchangePrivate::basicReturn(const Frame::Method &frame)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
Exchange::Exchange(int channelNumber, Client *parent) QAmqpExchange::QAmqpExchange(int channelNumber, QAmqpClient *parent)
: Channel(new ExchangePrivate(this), parent) : QAmqpChannel(new QAmqpExchangePrivate(this), parent)
{ {
Q_D(Exchange); Q_D(QAmqpExchange);
d->init(channelNumber, parent); d->init(channelNumber, parent);
} }
Exchange::~Exchange() QAmqpExchange::~QAmqpExchange()
{ {
} }
void Exchange::channelOpened() void QAmqpExchange::channelOpened()
{ {
Q_D(Exchange); Q_D(QAmqpExchange);
if (d->delayedDeclare) if (d->delayedDeclare)
d->declare(); 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; return d->options;
} }
QString Exchange::type() const QString QAmqpExchange::type() const
{ {
Q_D(const Exchange); Q_D(const QAmqpExchange);
return d->type; 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->type = type;
d->options = options; d->options = options;
d->arguments = args; d->arguments = args;
d->declare(); d->declare();
} }
void Exchange::remove(int options) void QAmqpExchange::remove(int options)
{ {
Q_D(Exchange); Q_D(QAmqpExchange);
Frame::Method frame(Frame::fcExchange, ExchangePrivate::miDelete); QAmqpMethodFrame frame(QAmqpFrame::fcExchange, QAmqpExchangePrivate::miDelete);
frame.setChannel(d->channelNumber); frame.setChannel(d->channelNumber);
QByteArray arguments; QByteArray arguments;
QDataStream stream(&arguments, QIODevice::WriteOnly); QDataStream stream(&arguments, QIODevice::WriteOnly);
stream << qint16(0); //reserved 1 stream << qint16(0); //reserved 1
Frame::writeAmqpField(stream, MetaType::ShortString, d->name); QAmqpFrame::writeAmqpField(stream, QAmqpMetaType::ShortString, d->name);
stream << qint8(options); stream << qint8(options);
frame.setArguments(arguments); frame.setArguments(arguments);
d->sendFrame(frame); d->sendFrame(frame);
} }
void Exchange::publish(const QString &message, const QString &routingKey, void QAmqpExchange::publish(const QString &message, const QString &routingKey,
const Message::PropertyHash &properties, int publishOptions) const QAmqpMessage::PropertyHash &properties, int publishOptions)
{ {
publish(message.toUtf8(), routingKey, QLatin1String("text.plain"), publish(message.toUtf8(), routingKey, QLatin1String("text.plain"),
Table(), properties, publishOptions); QAmqpTable(), properties, publishOptions);
} }
void Exchange::publish(const QByteArray &message, const QString &routingKey, void QAmqpExchange::publish(const QByteArray &message, const QString &routingKey,
const QString &mimeType, const Message::PropertyHash &properties, const QString &mimeType, const QAmqpMessage::PropertyHash &properties,
int publishOptions) 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, void QAmqpExchange::publish(const QByteArray &message, const QString &routingKey,
const QString &mimeType, const Table &headers, const QString &mimeType, const QAmqpTable &headers,
const Message::PropertyHash &properties, int publishOptions) const QAmqpMessage::PropertyHash &properties, int publishOptions)
{ {
Q_D(Exchange); Q_D(QAmqpExchange);
Frame::Method frame(Frame::fcBasic, ExchangePrivate::bmPublish); QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpExchangePrivate::bmPublish);
frame.setChannel(d->channelNumber); frame.setChannel(d->channelNumber);
QByteArray arguments; QByteArray arguments;
QDataStream out(&arguments, QIODevice::WriteOnly); QDataStream out(&arguments, QIODevice::WriteOnly);
out << qint16(0); //reserved 1 out << qint16(0); //reserved 1
Frame::writeAmqpField(out, MetaType::ShortString, d->name); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
Frame::writeAmqpField(out, MetaType::ShortString, routingKey); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, routingKey);
out << qint8(publishOptions); out << qint8(publishOptions);
frame.setArguments(arguments); frame.setArguments(arguments);
d->sendFrame(frame); d->sendFrame(frame);
Frame::Content content(Frame::fcBasic); QAmqpContentFrame content(QAmqpFrame::fcBasic);
content.setChannel(d->channelNumber); content.setChannel(d->channelNumber);
content.setProperty(Message::ContentType, mimeType); content.setProperty(QAmqpMessage::ContentType, mimeType);
content.setProperty(Message::ContentEncoding, "utf-8"); content.setProperty(QAmqpMessage::ContentEncoding, "utf-8");
content.setProperty(Message::Headers, headers); content.setProperty(QAmqpMessage::Headers, headers);
content.setProperty(Message::MessageId, "0"); content.setProperty(QAmqpMessage::MessageId, "0");
Message::PropertyHash::ConstIterator it; QAmqpMessage::PropertyHash::ConstIterator it;
Message::PropertyHash::ConstIterator itEnd = properties.constEnd(); QAmqpMessage::PropertyHash::ConstIterator itEnd = properties.constEnd();
for (it = properties.constBegin(); it != itEnd; ++it) for (it = properties.constBegin(); it != itEnd; ++it)
content.setProperty(it.key(), it.value()); content.setProperty(it.key(), it.value());
content.setBodySize(message.size()); content.setBodySize(message.size());
@ -262,7 +261,7 @@ void Exchange::publish(const QByteArray &message, const QString &routingKey,
int fullSize = message.size(); int fullSize = message.size();
for (int sent = 0; sent < fullSize; sent += (d->client->frameMax() - 7)) { 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)); QByteArray partition = message.mid(sent, (d->client->frameMax() - 7));
body.setChannel(d->channelNumber); body.setChannel(d->channelNumber);
body.setBody(partition); body.setBody(partition);

View File

@ -5,14 +5,11 @@
#include "qamqpchannel.h" #include "qamqpchannel.h"
#include "qamqpmessage.h" #include "qamqpmessage.h"
namespace QAMQP class QAmqpClient;
{ class QAmqpQueue;
class QAmqpClientPrivate;
class Client; class QAmqpExchangePrivate;
class Queue; class QAMQP_EXPORT QAmqpExchange : public QAmqpChannel
class ClientPrivate;
class ExchangePrivate;
class QAMQP_EXPORT Exchange : public Channel
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString type READ type CONSTANT) Q_PROPERTY(QString type READ type CONSTANT)
@ -53,27 +50,27 @@ public:
Q_DECLARE_FLAGS(ExchangeOptions, ExchangeOption) Q_DECLARE_FLAGS(ExchangeOptions, ExchangeOption)
ExchangeOptions options() const; ExchangeOptions options() const;
virtual ~Exchange(); virtual ~QAmqpExchange();
// AMQP Exchange // AMQP Exchange
void declare(ExchangeType type = Direct, void declare(ExchangeType type = Direct,
ExchangeOptions options = NoOptions, ExchangeOptions options = NoOptions,
const Table &args = Table()); const QAmqpTable &args = QAmqpTable());
void declare(const QString &type = QLatin1String("direct"), void declare(const QString &type = QLatin1String("direct"),
ExchangeOptions options = NoOptions, ExchangeOptions options = NoOptions,
const Table &args = Table()); const QAmqpTable &args = QAmqpTable());
void remove(int options = roIfUnused|roNoWait); void remove(int options = roIfUnused|roNoWait);
// AMQP Basic // AMQP Basic
void publish(const QString &message, const QString &routingKey, void publish(const QString &message, const QString &routingKey,
const Message::PropertyHash &properties = Message::PropertyHash(), const QAmqpMessage::PropertyHash &properties = QAmqpMessage::PropertyHash(),
int publishOptions = poNoOptions); int publishOptions = poNoOptions);
void publish(const QByteArray &message, const QString &routingKey, const QString &mimeType, 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); int publishOptions = poNoOptions);
void publish(const QByteArray &message, const QString &routingKey, void publish(const QByteArray &message, const QString &routingKey,
const QString &mimeType, const Table &headers, const QString &mimeType, const QAmqpTable &headers,
const Message::PropertyHash &properties = Message::PropertyHash(), const QAmqpMessage::PropertyHash &properties = QAmqpMessage::PropertyHash(),
int publishOptions = poNoOptions); int publishOptions = poNoOptions);
Q_SIGNALS: Q_SIGNALS:
@ -85,18 +82,16 @@ protected:
virtual void channelClosed(); virtual void channelClosed();
private: private:
explicit Exchange(int channelNumber = -1, Client *parent = 0); explicit QAmqpExchange(int channelNumber = -1, QAmqpClient *parent = 0);
Q_DISABLE_COPY(Exchange) Q_DISABLE_COPY(QAmqpExchange)
Q_DECLARE_PRIVATE(Exchange) Q_DECLARE_PRIVATE(QAmqpExchange)
friend class Client; friend class QAmqpClient;
}; };
} // namespace QAMQP Q_DECLARE_OPERATORS_FOR_FLAGS(QAmqpExchange::ExchangeOptions)
Q_DECLARE_METATYPE(QAmqpExchange::ExchangeType)
Q_DECLARE_OPERATORS_FOR_FLAGS(QAMQP::Exchange::ExchangeOptions)
Q_DECLARE_METATYPE(QAMQP::Exchange::ExchangeType)
#endif // QAMQPEXCHANGE_H #endif // QAMQPEXCHANGE_H

View File

@ -5,10 +5,7 @@
#include "qamqpexchange.h" #include "qamqpexchange.h"
#include "qamqpchannel_p.h" #include "qamqpchannel_p.h"
namespace QAMQP class QAmqpExchangePrivate: public QAmqpChannelPrivate
{
class ExchangePrivate: public ChannelPrivate
{ {
public: public:
enum MethodId { enum MethodId {
@ -16,27 +13,25 @@ public:
METHOD_ID_ENUM(miDelete, 20) METHOD_ID_ENUM(miDelete, 20)
}; };
ExchangePrivate(Exchange *q); QAmqpExchangePrivate(QAmqpExchange *q);
static QString typeToString(Exchange::ExchangeType type); static QString typeToString(QAmqpExchange::ExchangeType type);
void declare(); void declare();
// method handler related // method handler related
virtual void _q_disconnected(); virtual void _q_disconnected();
virtual bool _q_method(const Frame::Method &frame); virtual bool _q_method(const QAmqpMethodFrame &frame);
void declareOk(const Frame::Method &frame); void declareOk(const QAmqpMethodFrame &frame);
void deleteOk(const Frame::Method &frame); void deleteOk(const QAmqpMethodFrame &frame);
void basicReturn(const Frame::Method &frame); void basicReturn(const QAmqpMethodFrame &frame);
QString type; QString type;
Exchange::ExchangeOptions options; QAmqpExchange::ExchangeOptions options;
Table arguments; QAmqpTable arguments;
bool delayedDeclare; bool delayedDeclare;
bool declared; bool declared;
Q_DECLARE_PUBLIC(Exchange) Q_DECLARE_PUBLIC(QAmqpExchange)
}; };
} // namespace QAMQP
#endif // QAMQPEXCHANGE_P_H #endif // QAMQPEXCHANGE_P_H

View File

@ -6,59 +6,56 @@
#include "qamqpglobal.h" #include "qamqpglobal.h"
#include "qamqpframe_p.h" #include "qamqpframe_p.h"
using namespace QAMQP; QAmqpFrame::QAmqpFrame(Type type)
using namespace QAMQP::Frame;
Base::Base(Type type)
: size_(0), : size_(0),
type_(type), type_(type),
channel_(0) channel_(0)
{ {
} }
Base::Base(QDataStream &raw) QAmqpFrame::QAmqpFrame(QDataStream &raw)
{ {
readHeader(raw); readHeader(raw);
} }
Type Base::type() const QAmqpFrame::Type QAmqpFrame::type() const
{ {
return Type(type_); return Type(type_);
} }
Base::~Base() QAmqpFrame::~QAmqpFrame()
{ {
} }
void Base::setChannel(qint16 channel) void QAmqpFrame::setChannel(qint16 channel)
{ {
channel_ = channel; channel_ = channel;
} }
qint16 Base::channel() const qint16 QAmqpFrame::channel() const
{ {
return channel_; return channel_;
} }
qint32 Base::size() const qint32 QAmqpFrame::size() const
{ {
return 0; return 0;
} }
void Base::writeHeader(QDataStream &stream) const void QAmqpFrame::writeHeader(QDataStream &stream) const
{ {
stream << type_; stream << type_;
stream << channel_; stream << channel_;
stream << qint32(size()); stream << qint32(size());
} }
void Base::writeEnd(QDataStream &stream) const void QAmqpFrame::writeEnd(QDataStream &stream) const
{ {
stream << qint8(FRAME_END); stream << qint8(FRAME_END);
stream.device()->waitForBytesWritten(1000); stream.device()->waitForBytesWritten(1000);
} }
void Base::readHeader(QDataStream &stream) void QAmqpFrame::readHeader(QDataStream &stream)
{ {
stream >> type_; stream >> type_;
stream >> channel_; 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; unsigned char end_ = 0;
stream.readRawData(reinterpret_cast<char*>(&end_), sizeof(end_)); stream.readRawData(reinterpret_cast<char*>(&end_), sizeof(end_));
@ -74,7 +71,8 @@ void Base::readEnd(QDataStream &stream)
qAmqpDebug("Wrong end of frame"); qAmqpDebug("Wrong end of frame");
} }
*/ */
void Base::toStream(QDataStream &stream) const
void QAmqpFrame::toStream(QDataStream &stream) const
{ {
writeHeader(stream); writeHeader(stream);
writePayload(stream); writePayload(stream);
@ -83,45 +81,45 @@ void Base::toStream(QDataStream &stream) const
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
Method::Method(MethodClass methodClass, qint16 id) QAmqpMethodFrame::QAmqpMethodFrame(MethodClass methodClass, qint16 id)
: Base(ftMethod), : QAmqpFrame(QAmqpFrame::ftMethod),
methodClass_(methodClass), methodClass_(methodClass),
id_(id) id_(id)
{ {
} }
Method::Method(QDataStream &raw) QAmqpMethodFrame::QAmqpMethodFrame(QDataStream &raw)
: Base(raw) : QAmqpFrame(raw)
{ {
readPayload(raw); readPayload(raw);
} }
MethodClass Method::methodClass() const QAmqpFrame::MethodClass QAmqpMethodFrame::methodClass() const
{ {
return MethodClass(methodClass_); return MethodClass(methodClass_);
} }
qint16 Method::id() const qint16 QAmqpMethodFrame::id() const
{ {
return id_; return id_;
} }
qint32 Method::size() const qint32 QAmqpMethodFrame::size() const
{ {
return sizeof(id_) + sizeof(methodClass_) + arguments_.size(); return sizeof(id_) + sizeof(methodClass_) + arguments_.size();
} }
void Method::setArguments(const QByteArray &data) void QAmqpMethodFrame::setArguments(const QByteArray &data)
{ {
arguments_ = data; arguments_ = data;
} }
QByteArray Method::arguments() const QByteArray QAmqpMethodFrame::arguments() const
{ {
return arguments_; return arguments_;
} }
void Method::readPayload(QDataStream &stream) void QAmqpMethodFrame::readPayload(QDataStream &stream)
{ {
stream >> methodClass_; stream >> methodClass_;
stream >> id_; stream >> id_;
@ -130,7 +128,7 @@ void Method::readPayload(QDataStream &stream)
stream.readRawData(arguments_.data(), arguments_.size()); stream.readRawData(arguments_.data(), arguments_.size());
} }
void Method::writePayload(QDataStream &stream) const void QAmqpMethodFrame::writePayload(QDataStream &stream) const
{ {
stream << quint16(methodClass_); stream << quint16(methodClass_);
stream << quint16(id_); 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) { switch (type) {
case MetaType::Boolean: case QAmqpMetaType::Boolean:
{ {
quint8 octet = 0; quint8 octet = 0;
s >> octet; s >> octet;
return QVariant::fromValue<bool>(octet > 0); return QVariant::fromValue<bool>(octet > 0);
} }
case MetaType::ShortShortUint: case QAmqpMetaType::ShortShortUint:
{ {
quint8 octet = 0; quint8 octet = 0;
s >> octet; s >> octet;
return QVariant::fromValue<int>(octet); return QVariant::fromValue<int>(octet);
} }
case MetaType::ShortUint: case QAmqpMetaType::ShortUint:
{ {
quint16 tmp_value = 0; quint16 tmp_value = 0;
s >> tmp_value; s >> tmp_value;
return QVariant::fromValue<uint>(tmp_value); return QVariant::fromValue<uint>(tmp_value);
} }
case MetaType::LongUint: case QAmqpMetaType::LongUint:
{ {
quint32 tmp_value = 0; quint32 tmp_value = 0;
s >> tmp_value; s >> tmp_value;
return QVariant::fromValue<uint>(tmp_value); return QVariant::fromValue<uint>(tmp_value);
} }
case MetaType::LongLongUint: case QAmqpMetaType::LongLongUint:
{ {
qulonglong v = 0 ; qulonglong v = 0 ;
s >> v; s >> v;
return v; return v;
} }
case MetaType::ShortString: case QAmqpMetaType::ShortString:
{ {
qint8 size = 0; qint8 size = 0;
QByteArray buffer; QByteArray buffer;
@ -182,7 +180,7 @@ QVariant Frame::readAmqpField(QDataStream &s, MetaType::ValueType type)
s.readRawData(buffer.data(), buffer.size()); s.readRawData(buffer.data(), buffer.size());
return QString::fromLatin1(buffer.data(), size); return QString::fromLatin1(buffer.data(), size);
} }
case MetaType::LongString: case QAmqpMetaType::LongString:
{ {
quint32 size = 0; quint32 size = 0;
QByteArray buffer; QByteArray buffer;
@ -192,19 +190,19 @@ QVariant Frame::readAmqpField(QDataStream &s, MetaType::ValueType type)
s.readRawData(buffer.data(), buffer.size()); s.readRawData(buffer.data(), buffer.size());
return QString::fromUtf8(buffer.data(), buffer.size()); return QString::fromUtf8(buffer.data(), buffer.size());
} }
case MetaType::Timestamp: case QAmqpMetaType::Timestamp:
{ {
qulonglong tmp_value; qulonglong tmp_value;
s >> tmp_value; s >> tmp_value;
return QDateTime::fromMSecsSinceEpoch(tmp_value); return QDateTime::fromMSecsSinceEpoch(tmp_value);
} }
case MetaType::Hash: case QAmqpMetaType::Hash:
{ {
Table table; QAmqpTable table;
s >> table; s >> table;
return table; return table;
} }
case MetaType::Void: case QAmqpMetaType::Void:
return QVariant(); return QVariant();
default: default:
qAmqpDebug() << Q_FUNC_INFO << "unsupported value type: " << type; qAmqpDebug() << Q_FUNC_INFO << "unsupported value type: " << type;
@ -213,25 +211,25 @@ QVariant Frame::readAmqpField(QDataStream &s, MetaType::ValueType type)
return QVariant(); 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) { switch (type) {
case MetaType::Boolean: case QAmqpMetaType::Boolean:
s << (value.toBool() ? qint8(1) : qint8(0)); s << (value.toBool() ? qint8(1) : qint8(0));
break; break;
case MetaType::ShortShortUint: case QAmqpMetaType::ShortShortUint:
s << qint8(value.toUInt()); s << qint8(value.toUInt());
break; break;
case MetaType::ShortUint: case QAmqpMetaType::ShortUint:
s << quint16(value.toUInt()); s << quint16(value.toUInt());
break; break;
case MetaType::LongUint: case QAmqpMetaType::LongUint:
s << quint32(value.toUInt()); s << quint32(value.toUInt());
break; break;
case MetaType::LongLongUint: case QAmqpMetaType::LongLongUint:
s << qulonglong(value.toULongLong()); s << qulonglong(value.toULongLong());
break; break;
case MetaType::ShortString: case QAmqpMetaType::ShortString:
{ {
QString str = value.toString(); QString str = value.toString();
if (str.length() >= 256) { 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()); s.writeRawData(str.toUtf8().data(), str.length());
} }
break; break;
case MetaType::LongString: case QAmqpMetaType::LongString:
{ {
QString str = value.toString(); QString str = value.toString();
s << quint32(str.length()); s << quint32(str.length());
s.writeRawData(str.toLatin1().data(), str.length()); s.writeRawData(str.toLatin1().data(), str.length());
} }
break; break;
case MetaType::Timestamp: case QAmqpMetaType::Timestamp:
s << qulonglong(value.toDateTime().toMSecsSinceEpoch()); s << qulonglong(value.toDateTime().toMSecsSinceEpoch());
break; break;
case MetaType::Hash: case QAmqpMetaType::Hash:
{ {
Table table(value.toHash()); QAmqpTable table(value.toHash());
s << table; s << table;
} }
break; break;
@ -265,29 +263,29 @@ void Frame::writeAmqpField(QDataStream &s, MetaType::ValueType type, const QVari
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
Content::Content() QAmqpContentFrame::QAmqpContentFrame()
: Base(ftHeader) : QAmqpFrame(QAmqpFrame::ftHeader)
{ {
} }
Content::Content(MethodClass methodClass) QAmqpContentFrame::QAmqpContentFrame(QAmqpFrame::MethodClass methodClass)
: Base(ftHeader) : QAmqpFrame(QAmqpFrame::ftHeader)
{ {
methodClass_ = methodClass; methodClass_ = methodClass;
} }
Content::Content(QDataStream &raw) QAmqpContentFrame::QAmqpContentFrame(QDataStream &raw)
: Base(raw) : QAmqpFrame(raw)
{ {
readPayload(raw); readPayload(raw);
} }
MethodClass Content::methodClass() const QAmqpFrame::MethodClass QAmqpContentFrame::methodClass() const
{ {
return MethodClass(methodClass_); return MethodClass(methodClass_);
} }
qint32 Content::size() const qint32 QAmqpContentFrame::size() const
{ {
QDataStream out(&buffer_, QIODevice::WriteOnly); QDataStream out(&buffer_, QIODevice::WriteOnly);
buffer_.clear(); buffer_.clear();
@ -300,178 +298,178 @@ qint32 Content::size() const
prop_ |= p; prop_ |= p;
out << prop_; out << prop_;
if (prop_ & Message::ContentType) if (prop_ & QAmqpMessage::ContentType)
writeAmqpField(out, MetaType::ShortString, properties_[Message::ContentType]); writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::ContentType]);
if (prop_ & Message::ContentEncoding) if (prop_ & QAmqpMessage::ContentEncoding)
writeAmqpField(out, MetaType::ShortString, properties_[Message::ContentEncoding]); writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::ContentEncoding]);
if (prop_ & Message::Headers) if (prop_ & QAmqpMessage::Headers)
writeAmqpField(out, MetaType::Hash, properties_[Message::Headers]); writeAmqpField(out, QAmqpMetaType::Hash, properties_[QAmqpMessage::Headers]);
if (prop_ & Message::DeliveryMode) if (prop_ & QAmqpMessage::DeliveryMode)
writeAmqpField(out, MetaType::ShortShortUint, properties_[Message::DeliveryMode]); writeAmqpField(out, QAmqpMetaType::ShortShortUint, properties_[QAmqpMessage::DeliveryMode]);
if (prop_ & Message::Priority) if (prop_ & QAmqpMessage::Priority)
writeAmqpField(out, MetaType::ShortShortUint, properties_[Message::Priority]); writeAmqpField(out, QAmqpMetaType::ShortShortUint, properties_[QAmqpMessage::Priority]);
if (prop_ & Message::CorrelationId) if (prop_ & QAmqpMessage::CorrelationId)
writeAmqpField(out, MetaType::ShortString, properties_[Message::CorrelationId]); writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::CorrelationId]);
if (prop_ & Message::ReplyTo) if (prop_ & QAmqpMessage::ReplyTo)
writeAmqpField(out, MetaType::ShortString, properties_[Message::ReplyTo]); writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::ReplyTo]);
if (prop_ & Message::Expiration) if (prop_ & QAmqpMessage::Expiration)
writeAmqpField(out, MetaType::ShortString, properties_[Message::Expiration]); writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::Expiration]);
if (prop_ & Message::MessageId) if (prop_ & QAmqpMessage::MessageId)
writeAmqpField(out, MetaType::ShortString, properties_[Message::MessageId]); writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::MessageId]);
if (prop_ & Message::Timestamp) if (prop_ & QAmqpMessage::Timestamp)
writeAmqpField(out, MetaType::Timestamp, properties_[Message::Timestamp]); writeAmqpField(out, QAmqpMetaType::Timestamp, properties_[QAmqpMessage::Timestamp]);
if (prop_ & Message::Type) if (prop_ & QAmqpMessage::Type)
writeAmqpField(out, MetaType::ShortString, properties_[Message::Type]); writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::Type]);
if (prop_ & Message::UserId) if (prop_ & QAmqpMessage::UserId)
writeAmqpField(out, MetaType::ShortString, properties_[Message::UserId]); writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::UserId]);
if (prop_ & Message::AppId) if (prop_ & QAmqpMessage::AppId)
writeAmqpField(out, MetaType::ShortString, properties_[Message::AppId]); writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::AppId]);
if (prop_ & Message::ClusterID) if (prop_ & QAmqpMessage::ClusterID)
writeAmqpField(out, MetaType::ShortString, properties_[Message::ClusterID]); writeAmqpField(out, QAmqpMetaType::ShortString, properties_[QAmqpMessage::ClusterID]);
return buffer_.size(); return buffer_.size();
} }
qlonglong Content::bodySize() const qlonglong QAmqpContentFrame::bodySize() const
{ {
return bodySize_; return bodySize_;
} }
void Content::setBodySize(qlonglong size) void QAmqpContentFrame::setBodySize(qlonglong size)
{ {
bodySize_ = size; bodySize_ = size;
} }
void Content::setProperty(Message::Property prop, const QVariant &value) void QAmqpContentFrame::setProperty(QAmqpMessage::Property prop, const QVariant &value)
{ {
properties_[prop] = value; properties_[prop] = value;
} }
QVariant Content::property(Message::Property prop) const QVariant QAmqpContentFrame::property(QAmqpMessage::Property prop) const
{ {
return properties_.value(prop); return properties_.value(prop);
} }
void Content::writePayload(QDataStream &out) const void QAmqpContentFrame::writePayload(QDataStream &out) const
{ {
out.writeRawData(buffer_.data(), buffer_.size()); out.writeRawData(buffer_.data(), buffer_.size());
} }
void Content::readPayload(QDataStream &in) void QAmqpContentFrame::readPayload(QDataStream &in)
{ {
in >> methodClass_; in >> methodClass_;
in.skipRawData(2); //weight in.skipRawData(2); //weight
in >> bodySize_; in >> bodySize_;
qint16 flags_ = 0; qint16 flags_ = 0;
in >> flags_; in >> flags_;
if (flags_ & Message::ContentType) if (flags_ & QAmqpMessage::ContentType)
properties_[Message::ContentType] = readAmqpField(in, MetaType::ShortString); properties_[QAmqpMessage::ContentType] = readAmqpField(in, QAmqpMetaType::ShortString);
if (flags_ & Message::ContentEncoding) if (flags_ & QAmqpMessage::ContentEncoding)
properties_[Message::ContentEncoding] = readAmqpField(in, MetaType::ShortString); properties_[QAmqpMessage::ContentEncoding] = readAmqpField(in, QAmqpMetaType::ShortString);
if (flags_ & Message::Headers) if (flags_ & QAmqpMessage::Headers)
properties_[Message::Headers] = readAmqpField(in, MetaType::Hash); properties_[QAmqpMessage::Headers] = readAmqpField(in, QAmqpMetaType::Hash);
if (flags_ & Message::DeliveryMode) if (flags_ & QAmqpMessage::DeliveryMode)
properties_[Message::DeliveryMode] = readAmqpField(in, MetaType::ShortShortUint); properties_[QAmqpMessage::DeliveryMode] = readAmqpField(in, QAmqpMetaType::ShortShortUint);
if (flags_ & Message::Priority) if (flags_ & QAmqpMessage::Priority)
properties_[Message::Priority] = readAmqpField(in, MetaType::ShortShortUint); properties_[QAmqpMessage::Priority] = readAmqpField(in, QAmqpMetaType::ShortShortUint);
if (flags_ & Message::CorrelationId) if (flags_ & QAmqpMessage::CorrelationId)
properties_[Message::CorrelationId] = readAmqpField(in, MetaType::ShortString); properties_[QAmqpMessage::CorrelationId] = readAmqpField(in, QAmqpMetaType::ShortString);
if (flags_ & Message::ReplyTo) if (flags_ & QAmqpMessage::ReplyTo)
properties_[Message::ReplyTo] = readAmqpField(in, MetaType::ShortString); properties_[QAmqpMessage::ReplyTo] = readAmqpField(in, QAmqpMetaType::ShortString);
if (flags_ & Message::Expiration) if (flags_ & QAmqpMessage::Expiration)
properties_[Message::Expiration] = readAmqpField(in, MetaType::ShortString); properties_[QAmqpMessage::Expiration] = readAmqpField(in, QAmqpMetaType::ShortString);
if (flags_ & Message::MessageId) if (flags_ & QAmqpMessage::MessageId)
properties_[Message::MessageId] = readAmqpField(in, MetaType::ShortString); properties_[QAmqpMessage::MessageId] = readAmqpField(in, QAmqpMetaType::ShortString);
if (flags_ & Message::Timestamp) if (flags_ & QAmqpMessage::Timestamp)
properties_[Message::Timestamp] = readAmqpField(in, MetaType::Timestamp); properties_[QAmqpMessage::Timestamp] = readAmqpField(in, QAmqpMetaType::Timestamp);
if (flags_ & Message::Type) if (flags_ & QAmqpMessage::Type)
properties_[Message::Type] = readAmqpField(in, MetaType::ShortString); properties_[QAmqpMessage::Type] = readAmqpField(in, QAmqpMetaType::ShortString);
if (flags_ & Message::UserId) if (flags_ & QAmqpMessage::UserId)
properties_[Message::UserId] = readAmqpField(in, MetaType::ShortString); properties_[QAmqpMessage::UserId] = readAmqpField(in, QAmqpMetaType::ShortString);
if (flags_ & Message::AppId) if (flags_ & QAmqpMessage::AppId)
properties_[Message::AppId] = readAmqpField(in, MetaType::ShortString); properties_[QAmqpMessage::AppId] = readAmqpField(in, QAmqpMetaType::ShortString);
if (flags_ & Message::ClusterID) if (flags_ & QAmqpMessage::ClusterID)
properties_[Message::ClusterID] = readAmqpField(in, MetaType::ShortString); properties_[QAmqpMessage::ClusterID] = readAmqpField(in, QAmqpMetaType::ShortString);
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
ContentBody::ContentBody() QAmqpContentBodyFrame::QAmqpContentBodyFrame()
: Base(ftBody) : QAmqpFrame(QAmqpFrame::ftBody)
{ {
} }
ContentBody::ContentBody(QDataStream &raw) QAmqpContentBodyFrame::QAmqpContentBodyFrame(QDataStream &raw)
: Base(raw) : QAmqpFrame(raw)
{ {
readPayload(raw); readPayload(raw);
} }
void ContentBody::setBody(const QByteArray &data) void QAmqpContentBodyFrame::setBody(const QByteArray &data)
{ {
body_ = data; body_ = data;
} }
QByteArray ContentBody::body() const QByteArray QAmqpContentBodyFrame::body() const
{ {
return body_; return body_;
} }
void ContentBody::writePayload(QDataStream &out) const void QAmqpContentBodyFrame::writePayload(QDataStream &out) const
{ {
out.writeRawData(body_.data(), body_.size()); out.writeRawData(body_.data(), body_.size());
} }
void ContentBody::readPayload(QDataStream &in) void QAmqpContentBodyFrame::readPayload(QDataStream &in)
{ {
body_.resize(size_); body_.resize(size_);
in.readRawData(body_.data(), body_.size()); in.readRawData(body_.data(), body_.size());
} }
qint32 ContentBody::size() const qint32 QAmqpContentBodyFrame::size() const
{ {
return body_.size(); return body_.size();
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
Heartbeat::Heartbeat() QAmqpHeartbeatFrame::QAmqpHeartbeatFrame()
: Base(ftHeartbeat) : QAmqpFrame(QAmqpFrame::ftHeartbeat)
{ {
} }
void Heartbeat::readPayload(QDataStream &stream) void QAmqpHeartbeatFrame::readPayload(QDataStream &stream)
{ {
Q_UNUSED(stream) Q_UNUSED(stream)
} }
void Heartbeat::writePayload(QDataStream &stream) const void QAmqpHeartbeatFrame::writePayload(QDataStream &stream) const
{ {
Q_UNUSED(stream) Q_UNUSED(stream)
} }

View File

@ -8,18 +8,16 @@
#include "qamqpglobal.h" #include "qamqpglobal.h"
#include "qamqpmessage.h" #include "qamqpmessage.h"
class QAmqpQueuePrivate;
/** /**
* Library namespace * Library namespace
* @namespace QAMQP * @namespace QAMQP
*/ */
namespace QAMQP
{
class QueuePrivate; class QAmqpFrame
namespace Frame
{ {
typedef quint16 channel_t; public:
/* /*
* @brief Header size in bytes * @brief Header size in bytes
*/ */
@ -60,8 +58,8 @@ namespace Frame
fcTx = 90, fcTx = 90,
}; };
QVariant readAmqpField(QDataStream &s, MetaType::ValueType type); static QVariant readAmqpField(QDataStream &s, QAmqpMetaType::ValueType type);
void writeAmqpField(QDataStream &s, MetaType::ValueType type, const QVariant &value); static void writeAmqpField(QDataStream &s, QAmqpMetaType::ValueType type, const QVariant &value);
/* /*
* @brief Base class for any frames. * @brief Base class for any frames.
@ -76,286 +74,279 @@ namespace Frame
* @endcode * @endcode
* octet short long 'size' octets octet * 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. * Base class constructor.
* @detailed Implement main methods for serialize and deserialize raw method frame data. * @detailed Construct frame class for sending.
* Method frame bodies consist of an invariant list of data fields, called "arguments". All method bodies start * @param type Define type of constructed frame.
* 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 Method : public Base QAmqpFrame(Type type);
{
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_;
};
/* /*
* @brief Class for working with content frames. * Base class constructor.
* @detailed Implement main methods for serialize and deserialize raw content frame data. * @detailed Construct frame class from received raw data.
* A content header payload has this format: * @param raw Data stream for reading source data.
* @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 Content : public Base QAmqpFrame(QDataStream &raw);
{
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_;
};
/* /*
* @brief Class for working with heartbeat frames. * Base class virtual destructor
* @detailed Implement frame for heartbeat send.
*/ */
class QAMQP_EXPORT Heartbeat : public Base virtual ~QAmqpFrame();
{
public:
/*
* Heartbeat class constructor.
* @detailed Construct frame class for sending.
*/
Heartbeat();
protected: /*
void writePayload(QDataStream &stream) const; * Frame type
void readPayload(QDataStream &stream); * @detailed Return type of current frame.
}; */
Type type() const;
class QAMQP_EXPORT MethodHandler /*
{ * Set number of associated channel.
public: * @param channel Number of channel.
virtual bool _q_method(const Frame::Method &frame) = 0; * @sa channel()
}; */
void setChannel(qint16 channel);
class QAMQP_EXPORT ContentHandler /*
{ * Return number of associated channel.
public: * @sa setChannel()
virtual void _q_content(const Frame::Content &frame) = 0; */
}; qint16 channel() const;
class QAMQP_EXPORT ContentBodyHandler /*
{ * Return size of frame.
public: */
virtual void _q_body(const Frame::ContentBody &frame) = 0; 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 #endif // QAMQPFRAME_P_H

View File

@ -45,9 +45,7 @@
#define qAmqpDebug if (qgetenv("QAMQP_DEBUG").isEmpty()); else qDebug #define qAmqpDebug if (qgetenv("QAMQP_DEBUG").isEmpty()); else qDebug
namespace QAMQP { namespace QAmqpMetaType {
namespace MetaType {
enum ValueType enum ValueType
{ {
@ -77,7 +75,9 @@ enum ValueType
Void Void
}; };
} // namespace MetaType } // namespace QAmqpMetaType
namespace QAMQP {
enum Error enum Error
{ {

View File

@ -2,9 +2,8 @@
#include "qamqpmessage.h" #include "qamqpmessage.h"
#include "qamqpmessage_p.h" #include "qamqpmessage_p.h"
using namespace QAMQP;
MessagePrivate::MessagePrivate() QAmqpMessagePrivate::QAmqpMessagePrivate()
: deliveryTag(0), : deliveryTag(0),
leftSize(0) leftSize(0)
{ {
@ -12,27 +11,27 @@ MessagePrivate::MessagePrivate()
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
Message::Message() QAmqpMessage::QAmqpMessage()
: d(new MessagePrivate) : d(new QAmqpMessagePrivate)
{ {
} }
Message::Message(const Message &other) QAmqpMessage::QAmqpMessage(const QAmqpMessage &other)
: d(other.d) : d(other.d)
{ {
} }
Message::~Message() QAmqpMessage::~QAmqpMessage()
{ {
} }
Message &Message::operator=(const Message &other) QAmqpMessage &QAmqpMessage::operator=(const QAmqpMessage &other)
{ {
d = other.d; d = other.d;
return *this; return *this;
} }
bool Message::operator==(const Message &message) const bool QAmqpMessage::operator==(const QAmqpMessage &message) const
{ {
if (message.d == d) if (message.d == d)
return true; return true;
@ -47,76 +46,76 @@ bool Message::operator==(const Message &message) const
message.d->leftSize == d->leftSize); message.d->leftSize == d->leftSize);
} }
bool Message::isValid() const bool QAmqpMessage::isValid() const
{ {
return d->deliveryTag != 0 && return d->deliveryTag != 0 &&
!d->exchangeName.isNull() && !d->exchangeName.isNull() &&
!d->routingKey.isNull(); !d->routingKey.isNull();
} }
qlonglong Message::deliveryTag() const qlonglong QAmqpMessage::deliveryTag() const
{ {
return d->deliveryTag; return d->deliveryTag;
} }
bool Message::isRedelivered() const bool QAmqpMessage::isRedelivered() const
{ {
return d->redelivered; return d->redelivered;
} }
QString Message::exchangeName() const QString QAmqpMessage::exchangeName() const
{ {
return d->exchangeName; return d->exchangeName;
} }
QString Message::routingKey() const QString QAmqpMessage::routingKey() const
{ {
return d->routingKey; return d->routingKey;
} }
QByteArray Message::payload() const QByteArray QAmqpMessage::payload() const
{ {
return d->payload; return d->payload;
} }
bool Message::hasProperty(Property property) const bool QAmqpMessage::hasProperty(Property property) const
{ {
return d->properties.contains(property); 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); 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); 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); 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); 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); return d->headers.value(header, defaultValue);
} }
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
bool Message::isDetached() const bool QAmqpMessage::isDetached() const
{ {
return d && d->ref == 1; return d && d->ref == 1;
} }
#endif #endif
uint qHash(const QAMQP::Message &message, uint seed) uint qHash(const QAmqpMessage &message, uint seed)
{ {
Q_UNUSED(seed); Q_UNUSED(seed);
return qHash(message.deliveryTag()) ^ return qHash(message.deliveryTag()) ^

View File

@ -8,24 +8,21 @@
#include "qamqpglobal.h" #include "qamqpglobal.h"
namespace QAMQP class QAmqpMessagePrivate;
{ class QAMQP_EXPORT QAmqpMessage
class MessagePrivate;
class QAMQP_EXPORT Message
{ {
public: public:
Message(); QAmqpMessage();
Message(const Message &other); QAmqpMessage(const QAmqpMessage &other);
Message &operator=(const Message &other); QAmqpMessage &operator=(const QAmqpMessage &other);
~Message(); ~QAmqpMessage();
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
inline void swap(Message &other) { qSwap(d, other.d); } inline void swap(QAmqpMessage &other) { qSwap(d, other.d); }
#endif #endif
bool operator==(const Message &message) const; bool operator==(const QAmqpMessage &message) const;
inline bool operator!=(const Message &message) const { return !(operator==(message)); } inline bool operator!=(const QAmqpMessage &message) const { return !(operator==(message)); }
enum Property { enum Property {
ContentType = AMQP_BASIC_CONTENT_TYPE_FLAG, ContentType = AMQP_BASIC_CONTENT_TYPE_FLAG,
@ -62,13 +59,13 @@ public:
QByteArray payload() const; QByteArray payload() const;
private: private:
QSharedDataPointer<MessagePrivate> d; QSharedDataPointer<QAmqpMessagePrivate> d;
friend class QueuePrivate; friend class QAmqpQueuePrivate;
friend class Queue; friend class QAmqpQueue;
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
public: public:
typedef QSharedDataPointer<MessagePrivate> DataPtr; typedef QSharedDataPointer<QAmqpMessagePrivate> DataPtr;
inline DataPtr &data_ptr() { return d; } inline DataPtr &data_ptr() { return d; }
// internal // internal
@ -76,16 +73,14 @@ public:
#endif #endif
}; };
} // namespace QAMQP Q_DECLARE_METATYPE(QAmqpMessage::PropertyHash)
Q_DECLARE_METATYPE(QAMQP::Message::PropertyHash)
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
Q_DECLARE_TYPEINFO(QAMQP::Message, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(QAmqpMessage, Q_MOVABLE_TYPE);
#endif #endif
Q_DECLARE_SHARED(QAMQP::Message) Q_DECLARE_SHARED(QAmqpMessage)
// NOTE: needed only for MSVC support, don't depend on this hash // 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 #endif // QAMQPMESSAGE_H

View File

@ -7,24 +7,20 @@
#include "qamqpframe_p.h" #include "qamqpframe_p.h"
#include "qamqpmessage.h" #include "qamqpmessage.h"
namespace QAMQP { class QAmqpMessagePrivate : public QSharedData
class MessagePrivate : public QSharedData
{ {
public: public:
MessagePrivate(); QAmqpMessagePrivate();
qlonglong deliveryTag; qlonglong deliveryTag;
bool redelivered; bool redelivered;
QString exchangeName; QString exchangeName;
QString routingKey; QString routingKey;
QByteArray payload; QByteArray payload;
QHash<Message::Property, QVariant> properties; QHash<QAmqpMessage::Property, QVariant> properties;
QHash<QString, QVariant> headers; QHash<QString, QVariant> headers;
int leftSize; int leftSize;
}; };
} // namespace QAMQP
#endif // QAMQPMESSAGE_P_H #endif // QAMQPMESSAGE_P_H

View File

@ -10,8 +10,8 @@
#include "qamqptable.h" #include "qamqptable.h"
using namespace QAMQP; using namespace QAMQP;
QueuePrivate::QueuePrivate(Queue *q) QAmqpQueuePrivate::QAmqpQueuePrivate(QAmqpQueue *q)
: ChannelPrivate(q), : QAmqpChannelPrivate(q),
delayedDeclare(false), delayedDeclare(false),
declared(false), declared(false),
recievingMessage(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); Q_Q(QAmqpQueue);
if (ChannelPrivate::_q_method(frame)) if (QAmqpChannelPrivate::_q_method(frame))
return true; return true;
if (frame.methodClass() == Frame::fcQueue) { if (frame.methodClass() == QAmqpFrame::fcQueue) {
switch (frame.id()) { switch (frame.id()) {
case miDeclareOk: case miDeclareOk:
declareOk(frame); declareOk(frame);
@ -51,7 +51,7 @@ bool QueuePrivate::_q_method(const Frame::Method &frame)
return true; return true;
} }
if (frame.methodClass() == Frame::fcBasic) { if (frame.methodClass() == QAmqpFrame::fcBasic) {
switch(frame.id()) { switch(frame.id()) {
case bmConsumeOk: case bmConsumeOk:
consumeOk(frame); consumeOk(frame);
@ -76,9 +76,9 @@ bool QueuePrivate::_q_method(const Frame::Method &frame)
return false; 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); Q_ASSERT(frame.channel() == channelNumber);
if (frame.channel() != channelNumber) if (frame.channel() != channelNumber)
return; return;
@ -89,11 +89,11 @@ void QueuePrivate::_q_content(const Frame::Content &frame)
} }
currentMessage.d->leftSize = frame.bodySize(); currentMessage.d->leftSize = frame.bodySize();
Message::PropertyHash::ConstIterator it; QAmqpMessage::PropertyHash::ConstIterator it;
Message::PropertyHash::ConstIterator itEnd = frame.properties_.constEnd(); QAmqpMessage::PropertyHash::ConstIterator itEnd = frame.properties_.constEnd();
for (it = frame.properties_.constBegin(); it != itEnd; ++it) { for (it = frame.properties_.constBegin(); it != itEnd; ++it) {
Message::Property property = (it.key()); QAmqpMessage::Property property = (it.key());
if (property == Message::Headers) if (property == QAmqpMessage::Headers)
currentMessage.d->headers = (it.value()).toHash(); currentMessage.d->headers = (it.value()).toHash();
currentMessage.d->properties[property] = it.value(); 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); Q_ASSERT(frame.channel() == channelNumber);
if (frame.channel() != channelNumber) if (frame.channel() != channelNumber)
return; 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; qAmqpDebug() << "declared queue: " << name;
declared = true; declared = true;
QByteArray data = frame.arguments(); QByteArray data = frame.arguments();
QDataStream stream(&data, QIODevice::ReadOnly); QDataStream stream(&data, QIODevice::ReadOnly);
name = Frame::readAmqpField(stream, MetaType::ShortString).toString(); name = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString();
qint32 messageCount = 0, consumerCount = 0; qint32 messageCount = 0, consumerCount = 0;
stream >> messageCount >> consumerCount; stream >> messageCount >> consumerCount;
qAmqpDebug("message count %d\nConsumer count: %d", 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(); 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; qAmqpDebug() << "purged queue: " << name;
QByteArray data = frame.arguments(); QByteArray data = frame.arguments();
@ -156,9 +156,9 @@ void QueuePrivate::purgeOk(const Frame::Method &frame)
Q_EMIT q->purged(messageCount); 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; qAmqpDebug() << "deleted queue: " << name;
declared = false; declared = false;
@ -171,80 +171,80 @@ void QueuePrivate::deleteOk(const Frame::Method &frame)
Q_EMIT q->removed(); Q_EMIT q->removed();
} }
void QueuePrivate::bindOk(const Frame::Method &frame) void QAmqpQueuePrivate::bindOk(const QAmqpMethodFrame &frame)
{ {
Q_UNUSED(frame) Q_UNUSED(frame)
Q_Q(Queue); Q_Q(QAmqpQueue);
qAmqpDebug() << Q_FUNC_INFO << "bound to exchange"; qAmqpDebug() << Q_FUNC_INFO << "bound to exchange";
Q_EMIT q->bound(); Q_EMIT q->bound();
} }
void QueuePrivate::unbindOk(const Frame::Method &frame) void QAmqpQueuePrivate::unbindOk(const QAmqpMethodFrame &frame)
{ {
Q_UNUSED(frame) Q_UNUSED(frame)
Q_Q(Queue); Q_Q(QAmqpQueue);
qAmqpDebug() << Q_FUNC_INFO << "unbound from exchange"; qAmqpDebug() << Q_FUNC_INFO << "unbound from exchange";
Q_EMIT q->unbound(); Q_EMIT q->unbound();
} }
void QueuePrivate::getOk(const Frame::Method &frame) void QAmqpQueuePrivate::getOk(const QAmqpMethodFrame &frame)
{ {
QByteArray data = frame.arguments(); QByteArray data = frame.arguments();
QDataStream in(&data, QIODevice::ReadOnly); QDataStream in(&data, QIODevice::ReadOnly);
Message message; QAmqpMessage message;
message.d->deliveryTag = Frame::readAmqpField(in, MetaType::LongLongUint).toLongLong(); message.d->deliveryTag = QAmqpFrame::readAmqpField(in, QAmqpMetaType::LongLongUint).toLongLong();
message.d->redelivered = Frame::readAmqpField(in, MetaType::Boolean).toBool(); message.d->redelivered = QAmqpFrame::readAmqpField(in, QAmqpMetaType::Boolean).toBool();
message.d->exchangeName = Frame::readAmqpField(in, MetaType::ShortString).toString(); message.d->exchangeName = QAmqpFrame::readAmqpField(in, QAmqpMetaType::ShortString).toString();
message.d->routingKey = Frame::readAmqpField(in, MetaType::ShortString).toString(); message.d->routingKey = QAmqpFrame::readAmqpField(in, QAmqpMetaType::ShortString).toString();
currentMessage = message; 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; qAmqpDebug() << "consume ok: " << name;
QByteArray data = frame.arguments(); QByteArray data = frame.arguments();
QDataStream stream(&data, QIODevice::ReadOnly); 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)); qAmqpDebug("consumer tag = %s", qPrintable(consumerTag));
consuming = true; consuming = true;
Q_EMIT q->consuming(consumerTag); Q_EMIT q->consuming(consumerTag);
} }
void QueuePrivate::deliver(const Frame::Method &frame) void QAmqpQueuePrivate::deliver(const QAmqpMethodFrame &frame)
{ {
qAmqpDebug() << Q_FUNC_INFO; qAmqpDebug() << Q_FUNC_INFO;
QByteArray data = frame.arguments(); QByteArray data = frame.arguments();
QDataStream in(&data, QIODevice::ReadOnly); QDataStream in(&data, QIODevice::ReadOnly);
QString consumer = Frame::readAmqpField(in, MetaType::ShortString).toString(); QString consumer = QAmqpFrame::readAmqpField(in, QAmqpMetaType::ShortString).toString();
if (consumerTag != consumer) { if (consumerTag != consumer) {
qAmqpDebug() << Q_FUNC_INFO << "invalid consumer tag: " << consumer; qAmqpDebug() << Q_FUNC_INFO << "invalid consumer tag: " << consumer;
return; return;
} }
Message message; QAmqpMessage message;
message.d->deliveryTag = Frame::readAmqpField(in, MetaType::LongLongUint).toLongLong(); message.d->deliveryTag = QAmqpFrame::readAmqpField(in, QAmqpMetaType::LongLongUint).toLongLong();
message.d->redelivered = Frame::readAmqpField(in, MetaType::Boolean).toBool(); message.d->redelivered = QAmqpFrame::readAmqpField(in, QAmqpMetaType::Boolean).toBool();
message.d->exchangeName = Frame::readAmqpField(in, MetaType::ShortString).toString(); message.d->exchangeName = QAmqpFrame::readAmqpField(in, QAmqpMetaType::ShortString).toString();
message.d->routingKey = Frame::readAmqpField(in, MetaType::ShortString).toString(); message.d->routingKey = QAmqpFrame::readAmqpField(in, QAmqpMetaType::ShortString).toString();
currentMessage = message; currentMessage = message;
} }
void QueuePrivate::declare() void QAmqpQueuePrivate::declare()
{ {
Frame::Method frame(Frame::fcQueue, QueuePrivate::miDeclare); QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miDeclare);
frame.setChannel(channelNumber); frame.setChannel(channelNumber);
QByteArray arguments; QByteArray arguments;
QDataStream out(&arguments, QIODevice::WriteOnly); QDataStream out(&arguments, QIODevice::WriteOnly);
out << qint16(0); //reserved 1 out << qint16(0); //reserved 1
Frame::writeAmqpField(out, MetaType::ShortString, name); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, name);
out << qint8(options); out << qint8(options);
Frame::writeAmqpField(out, MetaType::Hash, Table()); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::Hash, QAmqpTable());
frame.setArguments(arguments); frame.setArguments(arguments);
sendFrame(frame); sendFrame(frame);
@ -253,13 +253,13 @@ void QueuePrivate::declare()
delayedDeclare = false; 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; qAmqpDebug() << Q_FUNC_INFO;
QByteArray data = frame.arguments(); QByteArray data = frame.arguments();
QDataStream in(&data, QIODevice::ReadOnly); QDataStream in(&data, QIODevice::ReadOnly);
QString consumer = Frame::readAmqpField(in, MetaType::ShortString).toString(); QString consumer = QAmqpFrame::readAmqpField(in, QAmqpMetaType::ShortString).toString();
if (consumerTag != consumer) { if (consumerTag != consumer) {
qAmqpDebug() << Q_FUNC_INFO << "invalid consumer tag: " << consumer; qAmqpDebug() << Q_FUNC_INFO << "invalid consumer tag: " << consumer;
return; return;
@ -271,20 +271,20 @@ void QueuePrivate::cancelOk(const Frame::Method &frame)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
Queue::Queue(int channelNumber, Client *parent) QAmqpQueue::QAmqpQueue(int channelNumber, QAmqpClient *parent)
: Channel(new QueuePrivate(this), parent) : QAmqpChannel(new QAmqpQueuePrivate(this), parent)
{ {
Q_D(Queue); Q_D(QAmqpQueue);
d->init(channelNumber, parent); d->init(channelNumber, parent);
} }
Queue::~Queue() QAmqpQueue::~QAmqpQueue()
{ {
} }
void Queue::channelOpened() void QAmqpQueue::channelOpened()
{ {
Q_D(Queue); Q_D(QAmqpQueue);
if (d->delayedDeclare) if (d->delayedDeclare)
d->declare(); 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; return d->options;
} }
void Queue::declare(int options) void QAmqpQueue::declare(int options)
{ {
Q_D(Queue); Q_D(QAmqpQueue);
d->options = options; d->options = options;
if (!d->opened) { if (!d->opened) {
@ -319,49 +319,49 @@ void Queue::declare(int options)
d->declare(); d->declare();
} }
void Queue::remove(int options) void QAmqpQueue::remove(int options)
{ {
Q_D(Queue); Q_D(QAmqpQueue);
if (!d->declared) { if (!d->declared) {
qAmqpDebug() << Q_FUNC_INFO << "trying to remove undeclared queue, aborting..."; qAmqpDebug() << Q_FUNC_INFO << "trying to remove undeclared queue, aborting...";
return; return;
} }
Frame::Method frame(Frame::fcQueue, QueuePrivate::miDelete); QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miDelete);
frame.setChannel(d->channelNumber); frame.setChannel(d->channelNumber);
QByteArray arguments; QByteArray arguments;
QDataStream out(&arguments, QIODevice::WriteOnly); QDataStream out(&arguments, QIODevice::WriteOnly);
out << qint16(0); //reserved 1 out << qint16(0); //reserved 1
Frame::writeAmqpField(out, MetaType::ShortString, d->name); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
out << qint8(options); out << qint8(options);
frame.setArguments(arguments); frame.setArguments(arguments);
d->sendFrame(frame); d->sendFrame(frame);
} }
void Queue::purge() void QAmqpQueue::purge()
{ {
Q_D(Queue); Q_D(QAmqpQueue);
if (!d->opened) if (!d->opened)
return; return;
Frame::Method frame(Frame::fcQueue, QueuePrivate::miPurge); QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miPurge);
frame.setChannel(d->channelNumber); frame.setChannel(d->channelNumber);
QByteArray arguments; QByteArray arguments;
QDataStream out(&arguments, QIODevice::WriteOnly); QDataStream out(&arguments, QIODevice::WriteOnly);
out << qint16(0); //reserved 1 out << qint16(0); //reserved 1
Frame::writeAmqpField(out, MetaType::ShortString, d->name); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
out << qint8(0); // no-wait out << qint8(0); // no-wait
frame.setArguments(arguments); frame.setArguments(arguments);
d->sendFrame(frame); d->sendFrame(frame);
} }
void Queue::bind(Exchange *exchange, const QString &key) void QAmqpQueue::bind(QAmqpExchange *exchange, const QString &key)
{ {
if (!exchange) { if (!exchange) {
qAmqpDebug() << Q_FUNC_INFO << "invalid exchange provided"; qAmqpDebug() << Q_FUNC_INFO << "invalid exchange provided";
@ -371,33 +371,33 @@ void Queue::bind(Exchange *exchange, const QString &key)
bind(exchange->name(), 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) { if (!d->opened) {
d->delayedBindings.append(QPair<QString,QString>(exchangeName, key)); d->delayedBindings.append(QPair<QString,QString>(exchangeName, key));
return; return;
} }
Frame::Method frame(Frame::fcQueue, QueuePrivate::miBind); QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miBind);
frame.setChannel(d->channelNumber); frame.setChannel(d->channelNumber);
QByteArray arguments; QByteArray arguments;
QDataStream out(&arguments, QIODevice::WriteOnly); QDataStream out(&arguments, QIODevice::WriteOnly);
out << qint16(0); // reserved 1 out << qint16(0); // reserved 1
Frame::writeAmqpField(out, MetaType::ShortString, d->name); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
Frame::writeAmqpField(out, MetaType::ShortString, exchangeName); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, exchangeName);
Frame::writeAmqpField(out, MetaType::ShortString, key); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, key);
out << qint8(0); // no-wait out << qint8(0); // no-wait
Frame::writeAmqpField(out, MetaType::Hash, Table()); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::Hash, QAmqpTable());
frame.setArguments(arguments); frame.setArguments(arguments);
d->sendFrame(frame); d->sendFrame(frame);
} }
void Queue::unbind(Exchange *exchange, const QString &key) void QAmqpQueue::unbind(QAmqpExchange *exchange, const QString &key)
{ {
if (!exchange) { if (!exchange) {
qAmqpDebug() << Q_FUNC_INFO << "invalid exchange provided"; qAmqpDebug() << Q_FUNC_INFO << "invalid exchange provided";
@ -407,32 +407,32 @@ void Queue::unbind(Exchange *exchange, const QString &key)
unbind(exchange->name(), 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) { if (!d->opened) {
qAmqpDebug() << Q_FUNC_INFO << "queue is not open"; qAmqpDebug() << Q_FUNC_INFO << "queue is not open";
return; return;
} }
Frame::Method frame(Frame::fcQueue, QueuePrivate::miUnbind); QAmqpMethodFrame frame(QAmqpFrame::fcQueue, QAmqpQueuePrivate::miUnbind);
frame.setChannel(d->channelNumber); frame.setChannel(d->channelNumber);
QByteArray arguments; QByteArray arguments;
QDataStream out(&arguments, QIODevice::WriteOnly); QDataStream out(&arguments, QIODevice::WriteOnly);
out << qint16(0); //reserved 1 out << qint16(0); //reserved 1
Frame::writeAmqpField(out, MetaType::ShortString, d->name); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
Frame::writeAmqpField(out, MetaType::ShortString, exchangeName); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, exchangeName);
Frame::writeAmqpField(out, MetaType::ShortString, key); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, key);
Frame::writeAmqpField(out, MetaType::Hash, Table()); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::Hash, QAmqpTable());
frame.setArguments(arguments); frame.setArguments(arguments);
d->sendFrame(frame); d->sendFrame(frame);
} }
bool Queue::consume(int options) bool QAmqpQueue::consume(int options)
{ {
Q_D(Queue); Q_D(QAmqpQueue);
if (!d->opened) { if (!d->opened) {
qAmqpDebug() << Q_FUNC_INFO << "queue is not open"; qAmqpDebug() << Q_FUNC_INFO << "queue is not open";
return false; return false;
@ -443,73 +443,73 @@ bool Queue::consume(int options)
return false; return false;
} }
Frame::Method frame(Frame::fcBasic, QueuePrivate::bmConsume); QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpQueuePrivate::bmConsume);
frame.setChannel(d->channelNumber); frame.setChannel(d->channelNumber);
QByteArray arguments; QByteArray arguments;
QDataStream out(&arguments, QIODevice::WriteOnly); QDataStream out(&arguments, QIODevice::WriteOnly);
out << qint16(0); //reserved 1 out << qint16(0); //reserved 1
Frame::writeAmqpField(out, MetaType::ShortString, d->name); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
Frame::writeAmqpField(out, MetaType::ShortString, d->consumerTag); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->consumerTag);
out << qint8(options); out << qint8(options);
Frame::writeAmqpField(out, MetaType::Hash, Table()); QAmqpFrame::writeAmqpField(out, QAmqpMetaType::Hash, QAmqpTable());
frame.setArguments(arguments); frame.setArguments(arguments);
d->sendFrame(frame); d->sendFrame(frame);
return true; return true;
} }
void Queue::setConsumerTag(const QString &consumerTag) void QAmqpQueue::setConsumerTag(const QString &consumerTag)
{ {
Q_D(Queue); Q_D(QAmqpQueue);
d->consumerTag = consumerTag; d->consumerTag = consumerTag;
} }
QString Queue::consumerTag() const QString QAmqpQueue::consumerTag() const
{ {
Q_D(const Queue); Q_D(const QAmqpQueue);
return d->consumerTag; return d->consumerTag;
} }
bool Queue::isConsuming() const bool QAmqpQueue::isConsuming() const
{ {
Q_D(const Queue); Q_D(const QAmqpQueue);
return d->consuming; return d->consuming;
} }
void Queue::get(bool noAck) void QAmqpQueue::get(bool noAck)
{ {
Q_D(Queue); Q_D(QAmqpQueue);
if (!d->opened) { if (!d->opened) {
qAmqpDebug() << Q_FUNC_INFO << "channel is not open"; qAmqpDebug() << Q_FUNC_INFO << "channel is not open";
return; return;
} }
Frame::Method frame(Frame::fcBasic, QueuePrivate::bmGet); QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpQueuePrivate::bmGet);
frame.setChannel(d->channelNumber); frame.setChannel(d->channelNumber);
QByteArray arguments; QByteArray arguments;
QDataStream out(&arguments, QIODevice::WriteOnly); QDataStream out(&arguments, QIODevice::WriteOnly);
out << qint16(0); //reserved 1 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 out << qint8(noAck ? 1 : 0); // no-ack
frame.setArguments(arguments); frame.setArguments(arguments);
d->sendFrame(frame); d->sendFrame(frame);
} }
void Queue::ack(const Message &message) void QAmqpQueue::ack(const QAmqpMessage &message)
{ {
Q_D(Queue); Q_D(QAmqpQueue);
if (!d->opened) { if (!d->opened) {
qAmqpDebug() << Q_FUNC_INFO << "channel is not open"; qAmqpDebug() << Q_FUNC_INFO << "channel is not open";
return; return;
} }
Frame::Method frame(Frame::fcBasic, QueuePrivate::bmAck); QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpQueuePrivate::bmAck);
frame.setChannel(d->channelNumber); frame.setChannel(d->channelNumber);
QByteArray arguments; QByteArray arguments;
@ -522,9 +522,9 @@ void Queue::ack(const Message &message)
d->sendFrame(frame); d->sendFrame(frame);
} }
bool Queue::cancel(bool noWait) bool QAmqpQueue::cancel(bool noWait)
{ {
Q_D(Queue); Q_D(QAmqpQueue);
if (!d->consuming) { if (!d->consuming) {
qAmqpDebug() << Q_FUNC_INFO << "not consuming!"; qAmqpDebug() << Q_FUNC_INFO << "not consuming!";
return false; return false;
@ -535,13 +535,13 @@ bool Queue::cancel(bool noWait)
return false; return false;
} }
Frame::Method frame(Frame::fcBasic, QueuePrivate::bmCancel); QAmqpMethodFrame frame(QAmqpFrame::fcBasic, QAmqpQueuePrivate::bmCancel);
frame.setChannel(d->channelNumber); frame.setChannel(d->channelNumber);
QByteArray arguments; QByteArray arguments;
QDataStream out(&arguments, QIODevice::WriteOnly); 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)); out << (noWait ? qint8(0x01) : qint8(0x0));
frame.setArguments(arguments); frame.setArguments(arguments);

View File

@ -7,14 +7,11 @@
#include "qamqpmessage.h" #include "qamqpmessage.h"
#include "qamqpglobal.h" #include "qamqpglobal.h"
namespace QAMQP class QAmqpClient;
{ class QAmqpClientPrivate;
class QAmqpExchange;
class Client; class QAmqpQueuePrivate;
class ClientPrivate; class QAMQP_EXPORT QAmqpQueue : public QAmqpChannel, public QQueue<QAmqpMessage>
class Exchange;
class QueuePrivate;
class QAMQP_EXPORT Queue : public Channel, public QQueue<Message>
{ {
Q_OBJECT Q_OBJECT
Q_ENUMS(QueueOptions) Q_ENUMS(QueueOptions)
@ -52,7 +49,7 @@ public:
}; };
Q_DECLARE_FLAGS(RemoveOptions, RemoveOption) Q_DECLARE_FLAGS(RemoveOptions, RemoveOption)
~Queue(); ~QAmqpQueue();
bool isConsuming() const; bool isConsuming() const;
void setConsumerTag(const QString &consumerTag); void setConsumerTag(const QString &consumerTag);
@ -61,16 +58,16 @@ public:
// AMQP Queue // AMQP Queue
void declare(int options = Durable|AutoDelete); void declare(int options = Durable|AutoDelete);
void bind(const QString &exchangeName, const QString &key); 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(const QString &exchangeName, const QString &key);
void unbind(Exchange *exchange, const QString &key); void unbind(QAmqpExchange *exchange, const QString &key);
void purge(); void purge();
void remove(int options = roIfUnused|roIfEmpty|roNoWait); void remove(int options = roIfUnused|roIfEmpty|roNoWait);
// AMQP Basic // AMQP Basic
bool consume(int options = NoOptions); bool consume(int options = NoOptions);
void get(bool noAck = true); void get(bool noAck = true);
void ack(const Message &message); void ack(const QAmqpMessage &message);
bool cancel(bool noWait = false); bool cancel(bool noWait = false);
Q_SIGNALS: Q_SIGNALS:
@ -91,14 +88,12 @@ protected:
virtual void channelClosed(); virtual void channelClosed();
private: private:
explicit Queue(int channelNumber = -1, Client *parent = 0); explicit QAmqpQueue(int channelNumber = -1, QAmqpClient *parent = 0);
Q_DISABLE_COPY(Queue) Q_DISABLE_COPY(QAmqpQueue)
Q_DECLARE_PRIVATE(Queue) Q_DECLARE_PRIVATE(QAmqpQueue)
friend class Client; friend class QAmqpClient;
}; };
} // namespace QAMQP
#endif // QAMQPQUEUE_H #endif // QAMQPQUEUE_H

View File

@ -6,12 +6,9 @@
#include "qamqpchannel_p.h" #include "qamqpchannel_p.h"
namespace QAMQP class QAmqpQueuePrivate: public QAmqpChannelPrivate,
{ public QAmqpContentFrameHandler,
public QAmqpContentBodyFrameHandler
class QueuePrivate: public ChannelPrivate,
public Frame::ContentHandler,
public Frame::ContentBodyHandler
{ {
public: public:
enum MethodId { enum MethodId {
@ -22,26 +19,26 @@ public:
METHOD_ID_ENUM(miDelete, 40) METHOD_ID_ENUM(miDelete, 40)
}; };
QueuePrivate(Queue *q); QAmqpQueuePrivate(QAmqpQueue *q);
~QueuePrivate(); ~QAmqpQueuePrivate();
void declare(); void declare();
virtual bool _q_method(const Frame::Method &frame); virtual bool _q_method(const QAmqpMethodFrame &frame);
// AMQP Queue method handlers // AMQP Queue method handlers
void declareOk(const Frame::Method &frame); void declareOk(const QAmqpMethodFrame &frame);
void deleteOk(const Frame::Method &frame); void deleteOk(const QAmqpMethodFrame &frame);
void purgeOk(const Frame::Method &frame); void purgeOk(const QAmqpMethodFrame &frame);
void bindOk(const Frame::Method &frame); void bindOk(const QAmqpMethodFrame &frame);
void unbindOk(const Frame::Method &frame); void unbindOk(const QAmqpMethodFrame &frame);
void consumeOk(const Frame::Method &frame); void consumeOk(const QAmqpMethodFrame &frame);
// AMQP Basic method handlers // AMQP Basic method handlers
virtual void _q_content(const Frame::Content &frame); virtual void _q_content(const QAmqpContentFrame &frame);
virtual void _q_body(const Frame::ContentBody &frame); virtual void _q_body(const QAmqpContentBodyFrame &frame);
void deliver(const Frame::Method &frame); void deliver(const QAmqpMethodFrame &frame);
void getOk(const Frame::Method &frame); void getOk(const QAmqpMethodFrame &frame);
void cancelOk(const Frame::Method &frame); void cancelOk(const QAmqpMethodFrame &frame);
QString type; QString type;
int options; int options;
@ -51,13 +48,11 @@ public:
QString consumerTag; QString consumerTag;
bool recievingMessage; bool recievingMessage;
Message currentMessage; QAmqpMessage currentMessage;
bool consuming; bool consuming;
Q_DECLARE_PUBLIC(Queue) Q_DECLARE_PUBLIC(QAmqpQueue)
}; };
} // namespace QAMQP
#endif // QAMQPQUEUE_P_H #endif // QAMQPQUEUE_P_H

View File

@ -5,7 +5,6 @@
#include "qamqpframe_p.h" #include "qamqpframe_p.h"
#include "qamqptable.h" #include "qamqptable.h"
using namespace QAMQP;
/* /*
* field value types according to: https://www.rabbitmq.com/amqp-0-9-1-errata.html * field value types according to: https://www.rabbitmq.com/amqp-0-9-1-errata.html
@ -29,47 +28,47 @@ V - Void
x - Byte array x - Byte array
*/ */
MetaType::ValueType valueTypeForOctet(qint8 octet) QAmqpMetaType::ValueType valueTypeForOctet(qint8 octet)
{ {
switch (octet) { switch (octet) {
case 't': return MetaType::Boolean; case 't': return QAmqpMetaType::Boolean;
case 'b': return MetaType::ShortShortInt; case 'b': return QAmqpMetaType::ShortShortInt;
case 's': return MetaType::ShortInt; case 's': return QAmqpMetaType::ShortInt;
case 'I': return MetaType::LongInt; case 'I': return QAmqpMetaType::LongInt;
case 'l': return MetaType::LongLongInt; case 'l': return QAmqpMetaType::LongLongInt;
case 'f': return MetaType::Float; case 'f': return QAmqpMetaType::Float;
case 'd': return MetaType::Double; case 'd': return QAmqpMetaType::Double;
case 'D': return MetaType::Decimal; case 'D': return QAmqpMetaType::Decimal;
case 'S': return MetaType::LongString; case 'S': return QAmqpMetaType::LongString;
case 'A': return MetaType::Array; case 'A': return QAmqpMetaType::Array;
case 'T': return MetaType::Timestamp; case 'T': return QAmqpMetaType::Timestamp;
case 'F': return MetaType::Hash; case 'F': return QAmqpMetaType::Hash;
case 'V': return MetaType::Void; case 'V': return QAmqpMetaType::Void;
case 'x': return MetaType::Bytes; case 'x': return QAmqpMetaType::Bytes;
default: default:
qAmqpDebug() << Q_FUNC_INFO << "invalid octet received: " << char(octet); 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) { switch (type) {
case MetaType::Boolean: return 't'; case QAmqpMetaType::Boolean: return 't';
case MetaType::ShortShortInt: return 'b'; case QAmqpMetaType::ShortShortInt: return 'b';
case MetaType::ShortInt: return 's'; case QAmqpMetaType::ShortInt: return 's';
case MetaType::LongInt: return 'I'; case QAmqpMetaType::LongInt: return 'I';
case MetaType::LongLongInt: return 'l'; case QAmqpMetaType::LongLongInt: return 'l';
case MetaType::Float: return 'f'; case QAmqpMetaType::Float: return 'f';
case MetaType::Double: return 'd'; case QAmqpMetaType::Double: return 'd';
case MetaType::Decimal: return 'D'; case QAmqpMetaType::Decimal: return 'D';
case MetaType::LongString: return 'S'; case QAmqpMetaType::LongString: return 'S';
case MetaType::Array: return 'A'; case QAmqpMetaType::Array: return 'A';
case MetaType::Timestamp: return 'T'; case QAmqpMetaType::Timestamp: return 'T';
case MetaType::Hash: return 'F'; case QAmqpMetaType::Hash: return 'F';
case MetaType::Void: return 'V'; case QAmqpMetaType::Void: return 'V';
case MetaType::Bytes: return 'x'; case QAmqpMetaType::Bytes: return 'x';
default: default:
qAmqpDebug() << Q_FUNC_INFO << "invalid type received: " << char(type); qAmqpDebug() << Q_FUNC_INFO << "invalid type received: " << char(type);
} }
@ -77,71 +76,71 @@ qint8 valueTypeToOctet(MetaType::ValueType type)
return 'V'; 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()) { switch (value.userType()) {
case QMetaType::Bool: case QMetaType::Bool:
type = MetaType::Boolean; type = QAmqpMetaType::Boolean;
break; break;
case QMetaType::QByteArray: case QMetaType::QByteArray:
type = MetaType::Bytes; type = QAmqpMetaType::Bytes;
break; break;
case QMetaType::Int: case QMetaType::Int:
{ {
int i = qAbs(value.toInt()); int i = qAbs(value.toInt());
if (i <= qint8(SCHAR_MAX)) { if (i <= qint8(SCHAR_MAX)) {
type = MetaType::ShortShortInt; type = QAmqpMetaType::ShortShortInt;
} else if (i <= qint16(SHRT_MAX)) { } else if (i <= qint16(SHRT_MAX)) {
type = MetaType::ShortInt; type = QAmqpMetaType::ShortInt;
} else { } else {
type = MetaType::LongInt; type = QAmqpMetaType::LongInt;
} }
} }
break; break;
case QMetaType::UShort: case QMetaType::UShort:
type = MetaType::ShortInt; type = QAmqpMetaType::ShortInt;
break; break;
case QMetaType::UInt: case QMetaType::UInt:
{ {
int i = value.toInt(); int i = value.toInt();
if (i <= qint8(SCHAR_MAX)) { if (i <= qint8(SCHAR_MAX)) {
type = MetaType::ShortShortInt; type = QAmqpMetaType::ShortShortInt;
} else if (i <= qint16(SHRT_MAX)) { } else if (i <= qint16(SHRT_MAX)) {
type = MetaType::ShortInt; type = QAmqpMetaType::ShortInt;
} else { } else {
type = MetaType::LongInt; type = QAmqpMetaType::LongInt;
} }
} }
break; break;
case QMetaType::LongLong: case QMetaType::LongLong:
case QMetaType::ULongLong: case QMetaType::ULongLong:
type = MetaType::LongLongInt; type = QAmqpMetaType::LongLongInt;
break; break;
case QMetaType::QString: case QMetaType::QString:
type = MetaType::LongString; type = QAmqpMetaType::LongString;
break; break;
case QMetaType::QDateTime: case QMetaType::QDateTime:
type = MetaType::Timestamp; type = QAmqpMetaType::Timestamp;
break; break;
case QMetaType::Double: case QMetaType::Double:
type = value.toDouble() > FLT_MAX ? MetaType::Double : MetaType::Float; type = value.toDouble() > FLT_MAX ? QAmqpMetaType::Double : QAmqpMetaType::Float;
break; break;
case QMetaType::QVariantHash: case QMetaType::QVariantHash:
type = MetaType::Hash; type = QAmqpMetaType::Hash;
break; break;
case QMetaType::QVariantList: case QMetaType::QVariantList:
type = MetaType::Array; type = QAmqpMetaType::Array;
break; break;
case QMetaType::Void: case QMetaType::Void:
type = MetaType::Void; type = QAmqpMetaType::Void;
break; break;
default: default:
if (value.userType() == qMetaTypeId<QAMQP::Decimal>()) { if (value.userType() == qMetaTypeId<QAMQP::Decimal>()) {
type = MetaType::Decimal; type = QAmqpMetaType::Decimal;
break; break;
} else if (!value.isValid()) { } else if (!value.isValid()) {
type = MetaType::Void; type = QAmqpMetaType::Void;
break; break;
} }
@ -154,33 +153,33 @@ void Table::writeFieldValue(QDataStream &stream, const QVariant &value)
writeFieldValue(stream, type, 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) { switch (type) {
case MetaType::Boolean: case QAmqpMetaType::Boolean:
case MetaType::ShortShortUint: case QAmqpMetaType::ShortShortUint:
case MetaType::ShortUint: case QAmqpMetaType::ShortUint:
case MetaType::LongUint: case QAmqpMetaType::LongUint:
case MetaType::LongLongUint: case QAmqpMetaType::LongLongUint:
case MetaType::ShortString: case QAmqpMetaType::ShortString:
case MetaType::LongString: case QAmqpMetaType::LongString:
case MetaType::Timestamp: case QAmqpMetaType::Timestamp:
case MetaType::Hash: case QAmqpMetaType::Hash:
return Frame::writeAmqpField(stream, type, value); return QAmqpFrame::writeAmqpField(stream, type, value);
case MetaType::ShortShortInt: case QAmqpMetaType::ShortShortInt:
stream << qint8(value.toInt()); stream << qint8(value.toInt());
break; break;
case MetaType::ShortInt: case QAmqpMetaType::ShortInt:
stream << qint16(value.toInt()); stream << qint16(value.toInt());
break; break;
case MetaType::LongInt: case QAmqpMetaType::LongInt:
stream << qint32(value.toInt()); stream << qint32(value.toInt());
break; break;
case MetaType::LongLongInt: case QAmqpMetaType::LongLongInt:
stream << qlonglong(value.toLongLong()); stream << qlonglong(value.toLongLong());
break; break;
case MetaType::Float: case QAmqpMetaType::Float:
{ {
float g = value.toFloat(); float g = value.toFloat();
QDataStream::FloatingPointPrecision oldPrecision = stream.floatingPointPrecision(); QDataStream::FloatingPointPrecision oldPrecision = stream.floatingPointPrecision();
@ -189,7 +188,7 @@ void Table::writeFieldValue(QDataStream &stream, MetaType::ValueType type, const
stream.setFloatingPointPrecision(oldPrecision); stream.setFloatingPointPrecision(oldPrecision);
} }
break; break;
case MetaType::Double: case QAmqpMetaType::Double:
{ {
double g = value.toDouble(); double g = value.toDouble();
QDataStream::FloatingPointPrecision oldPrecision = stream.floatingPointPrecision(); QDataStream::FloatingPointPrecision oldPrecision = stream.floatingPointPrecision();
@ -198,14 +197,14 @@ void Table::writeFieldValue(QDataStream &stream, MetaType::ValueType type, const
stream.setFloatingPointPrecision(oldPrecision); stream.setFloatingPointPrecision(oldPrecision);
} }
break; break;
case MetaType::Decimal: case QAmqpMetaType::Decimal:
{ {
QAMQP::Decimal v(value.value<QAMQP::Decimal>()); QAMQP::Decimal v(value.value<QAMQP::Decimal>());
stream << v.scale; stream << v.scale;
stream << v.value; stream << v.value;
} }
break; break;
case MetaType::Array: case QAmqpMetaType::Array:
{ {
QByteArray buffer; QByteArray buffer;
QDataStream arrayStream(&buffer, QIODevice::WriteOnly); QDataStream arrayStream(&buffer, QIODevice::WriteOnly);
@ -220,14 +219,14 @@ void Table::writeFieldValue(QDataStream &stream, MetaType::ValueType type, const
} }
} }
break; break;
case MetaType::Bytes: case QAmqpMetaType::Bytes:
{ {
QByteArray ba = value.toByteArray(); QByteArray ba = value.toByteArray();
stream << quint32(ba.length()); stream << quint32(ba.length());
stream.writeRawData(ba.data(), ba.length()); stream.writeRawData(ba.data(), ba.length());
} }
break; break;
case MetaType::Void: case QAmqpMetaType::Void:
stream << qint32(0); stream << qint32(0);
break; 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) { switch (type) {
case MetaType::Boolean: case QAmqpMetaType::Boolean:
case MetaType::ShortShortUint: case QAmqpMetaType::ShortShortUint:
case MetaType::ShortUint: case QAmqpMetaType::ShortUint:
case MetaType::LongUint: case QAmqpMetaType::LongUint:
case MetaType::LongLongUint: case QAmqpMetaType::LongLongUint:
case MetaType::ShortString: case QAmqpMetaType::ShortString:
case MetaType::LongString: case QAmqpMetaType::LongString:
case MetaType::Timestamp: case QAmqpMetaType::Timestamp:
case MetaType::Hash: case QAmqpMetaType::Hash:
return Frame::readAmqpField(stream, type); return QAmqpFrame::readAmqpField(stream, type);
case MetaType::ShortShortInt: case QAmqpMetaType::ShortShortInt:
{ {
char octet; char octet;
stream.readRawData(&octet, sizeof(octet)); stream.readRawData(&octet, sizeof(octet));
return QVariant::fromValue<int>(octet); return QVariant::fromValue<int>(octet);
} }
case MetaType::ShortInt: case QAmqpMetaType::ShortInt:
{ {
qint16 tmp_value = 0; qint16 tmp_value = 0;
stream >> tmp_value; stream >> tmp_value;
return QVariant::fromValue<int>(tmp_value); return QVariant::fromValue<int>(tmp_value);
} }
case MetaType::LongInt: case QAmqpMetaType::LongInt:
{ {
qint32 tmp_value = 0; qint32 tmp_value = 0;
stream >> tmp_value; stream >> tmp_value;
return QVariant::fromValue<int>(tmp_value); return QVariant::fromValue<int>(tmp_value);
} }
case MetaType::LongLongInt: case QAmqpMetaType::LongLongInt:
{ {
qlonglong v = 0 ; qlonglong v = 0 ;
stream >> v; stream >> v;
return v; return v;
} }
case MetaType::Float: case QAmqpMetaType::Float:
{ {
float tmp_value; float tmp_value;
QDataStream::FloatingPointPrecision precision = stream.floatingPointPrecision(); QDataStream::FloatingPointPrecision precision = stream.floatingPointPrecision();
@ -283,7 +282,7 @@ QVariant Table::readFieldValue(QDataStream &stream, MetaType::ValueType type)
stream.setFloatingPointPrecision(precision); stream.setFloatingPointPrecision(precision);
return QVariant::fromValue<float>(tmp_value); return QVariant::fromValue<float>(tmp_value);
} }
case MetaType::Double: case QAmqpMetaType::Double:
{ {
double tmp_value; double tmp_value;
QDataStream::FloatingPointPrecision precision = stream.floatingPointPrecision(); QDataStream::FloatingPointPrecision precision = stream.floatingPointPrecision();
@ -292,14 +291,14 @@ QVariant Table::readFieldValue(QDataStream &stream, MetaType::ValueType type)
stream.setFloatingPointPrecision(precision); stream.setFloatingPointPrecision(precision);
return QVariant::fromValue<double>(tmp_value); return QVariant::fromValue<double>(tmp_value);
} }
case MetaType::Decimal: case QAmqpMetaType::Decimal:
{ {
QAMQP::Decimal v; QAMQP::Decimal v;
stream >> v.scale; stream >> v.scale;
stream >> v.value; stream >> v.value;
return QVariant::fromValue<QAMQP::Decimal>(v); return QVariant::fromValue<QAMQP::Decimal>(v);
} }
case MetaType::Array: case QAmqpMetaType::Array:
{ {
QByteArray data; QByteArray data;
quint32 size = 0; quint32 size = 0;
@ -317,7 +316,7 @@ QVariant Table::readFieldValue(QDataStream &stream, MetaType::ValueType type)
return result; return result;
} }
case MetaType::Bytes: case QAmqpMetaType::Bytes:
{ {
QByteArray bytes; QByteArray bytes;
quint32 length = 0; quint32 length = 0;
@ -326,7 +325,7 @@ QVariant Table::readFieldValue(QDataStream &stream, MetaType::ValueType type)
stream.readRawData(bytes.data(), bytes.size()); stream.readRawData(bytes.data(), bytes.size());
return bytes; return bytes;
} }
case MetaType::Void: case QAmqpMetaType::Void:
break; break;
default: default:
qAmqpDebug() << Q_FUNC_INFO << "unhandled type: " << type; qAmqpDebug() << Q_FUNC_INFO << "unhandled type: " << type;
@ -335,15 +334,15 @@ QVariant Table::readFieldValue(QDataStream &stream, MetaType::ValueType type)
return QVariant(); return QVariant();
} }
QDataStream &operator<<(QDataStream &stream, const Table &table) QDataStream &operator<<(QDataStream &stream, const QAmqpTable &table)
{ {
QByteArray data; QByteArray data;
QDataStream s(&data, QIODevice::WriteOnly); QDataStream s(&data, QIODevice::WriteOnly);
Table::ConstIterator it; QAmqpTable::ConstIterator it;
Table::ConstIterator itEnd = table.constEnd(); QAmqpTable::ConstIterator itEnd = table.constEnd();
for (it = table.constBegin(); it != itEnd; ++it) { for (it = table.constBegin(); it != itEnd; ++it) {
Table::writeFieldValue(s, MetaType::ShortString, it.key()); QAmqpTable::writeFieldValue(s, QAmqpMetaType::ShortString, it.key());
Table::writeFieldValue(s, it.value()); QAmqpTable::writeFieldValue(s, it.value());
} }
if (data.isEmpty()) { if (data.isEmpty()) {
@ -355,16 +354,16 @@ QDataStream &operator<<(QDataStream &stream, const Table &table)
return stream; return stream;
} }
QDataStream &operator>>(QDataStream &stream, Table &table) QDataStream &operator>>(QDataStream &stream, QAmqpTable &table)
{ {
QByteArray data; QByteArray data;
stream >> data; stream >> data;
QDataStream tableStream(&data, QIODevice::ReadOnly); QDataStream tableStream(&data, QIODevice::ReadOnly);
while (!tableStream.atEnd()) { while (!tableStream.atEnd()) {
qint8 octet = 0; qint8 octet = 0;
QString field = Frame::readAmqpField(tableStream, MetaType::ShortString).toString(); QString field = QAmqpFrame::readAmqpField(tableStream, QAmqpMetaType::ShortString).toString();
tableStream >> octet; tableStream >> octet;
table[field] = Table::readFieldValue(tableStream, valueTypeForOctet(octet)); table[field] = QAmqpTable::readFieldValue(tableStream, valueTypeForOctet(octet));
} }
return stream; return stream;

View File

@ -5,26 +5,22 @@
#include "qamqpglobal.h" #include "qamqpglobal.h"
namespace QAMQP { class QAMQP_EXPORT QAmqpTable : public QVariantHash
class QAMQP_EXPORT Table : public QVariantHash
{ {
public: public:
Table() {} QAmqpTable() {}
inline Table(const QVariantHash &variantHash) inline QAmqpTable(const QVariantHash &variantHash)
: QVariantHash(variantHash) : QVariantHash(variantHash)
{ {
} }
static void writeFieldValue(QDataStream &stream, const QVariant &value); static void writeFieldValue(QDataStream &stream, const QVariant &value);
static void writeFieldValue(QDataStream &stream, MetaType::ValueType type, const QVariant &value); static void writeFieldValue(QDataStream &stream, QAmqpMetaType::ValueType type, const QVariant &value);
static QVariant readFieldValue(QDataStream &stream, MetaType::ValueType type); static QVariant readFieldValue(QDataStream &stream, QAmqpMetaType::ValueType type);
}; };
} // namespace QAMQP QAMQP_EXPORT QDataStream &operator<<(QDataStream &, const QAmqpTable &table);
QAMQP_EXPORT QDataStream &operator>>(QDataStream &, QAmqpTable &table);
QAMQP_EXPORT QDataStream &operator<<(QDataStream &, const QAMQP::Table &table); Q_DECLARE_METATYPE(QAmqpTable)
QAMQP_EXPORT QDataStream &operator>>(QDataStream &, QAMQP::Table &table);
Q_DECLARE_METATYPE(QAMQP::Table)
#endif // QAMQPTABLE_H #endif // QAMQPTABLE_H

View File

@ -6,7 +6,6 @@
#include "qamqpclient.h" #include "qamqpclient.h"
#include "qamqpexchange.h" #include "qamqpexchange.h"
#include "qamqpqueue.h" #include "qamqpqueue.h"
using namespace QAMQP;
class tst_QAMQPChannel : public TestCase class tst_QAMQPChannel : public TestCase
{ {
@ -20,13 +19,13 @@ private Q_SLOTS:
void sharedChannel(); void sharedChannel();
private: private:
QScopedPointer<Client> client; QScopedPointer<QAmqpClient> client;
}; };
void tst_QAMQPChannel::init() void tst_QAMQPChannel::init()
{ {
client.reset(new Client); client.reset(new QAmqpClient);
client->connectToHost(); client->connectToHost();
QVERIFY(waitForSignal(client.data(), SIGNAL(connected()))); QVERIFY(waitForSignal(client.data(), SIGNAL(connected())));
} }
@ -42,19 +41,19 @@ void tst_QAMQPChannel::cleanup()
void tst_QAMQPChannel::close() void tst_QAMQPChannel::close()
{ {
// exchange // exchange
Exchange *exchange = client->createExchange("test-close-channel"); QAmqpExchange *exchange = client->createExchange("test-close-channel");
QVERIFY(waitForSignal(exchange, SIGNAL(opened()))); QVERIFY(waitForSignal(exchange, SIGNAL(opened())));
exchange->declare(Exchange::Direct); exchange->declare(QAmqpExchange::Direct);
QVERIFY(waitForSignal(exchange, SIGNAL(declared()))); QVERIFY(waitForSignal(exchange, SIGNAL(declared())));
exchange->close(); exchange->close();
QVERIFY(waitForSignal(exchange, SIGNAL(closed()))); QVERIFY(waitForSignal(exchange, SIGNAL(closed())));
exchange->reopen(); exchange->reopen();
QVERIFY(waitForSignal(exchange, SIGNAL(opened()))); QVERIFY(waitForSignal(exchange, SIGNAL(opened())));
exchange->remove(Exchange::roForce); exchange->remove(QAmqpExchange::roForce);
QVERIFY(waitForSignal(exchange, SIGNAL(removed()))); QVERIFY(waitForSignal(exchange, SIGNAL(removed())));
// queue // queue
Queue *queue = client->createQueue("test-close-channel"); QAmqpQueue *queue = client->createQueue("test-close-channel");
QVERIFY(waitForSignal(queue, SIGNAL(opened()))); QVERIFY(waitForSignal(queue, SIGNAL(opened())));
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
queue->close(); queue->close();
@ -63,7 +62,7 @@ void tst_QAMQPChannel::close()
void tst_QAMQPChannel::resume() void tst_QAMQPChannel::resume()
{ {
Queue *queue = client->createQueue("test-resume"); QAmqpQueue *queue = client->createQueue("test-resume");
QVERIFY(waitForSignal(queue, SIGNAL(opened()))); QVERIFY(waitForSignal(queue, SIGNAL(opened())));
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
@ -74,13 +73,13 @@ void tst_QAMQPChannel::resume()
void tst_QAMQPChannel::sharedChannel() void tst_QAMQPChannel::sharedChannel()
{ {
QString routingKey = "test-shared-channel"; QString routingKey = "test-shared-channel";
Queue *queue = client->createQueue(routingKey); QAmqpQueue *queue = client->createQueue(routingKey);
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
Exchange *defaultExchange = client->createExchange("", queue->channelNumber()); QAmqpExchange *defaultExchange = client->createExchange("", queue->channelNumber());
defaultExchange->publish("first message", routingKey); defaultExchange->publish("first message", routingKey);
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived()))); QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
Message message = queue->dequeue(); QAmqpMessage message = queue->dequeue();
verifyStandardMessageHeaders(message, routingKey); verifyStandardMessageHeaders(message, routingKey);
QCOMPARE(message.payload(), QByteArray("first message")); QCOMPARE(message.payload(), QByteArray("first message"));
} }

View File

@ -6,7 +6,6 @@
#include "qamqpclient_p.h" #include "qamqpclient_p.h"
#include "qamqpauthenticator.h" #include "qamqpauthenticator.h"
using namespace QAMQP;
class tst_QAMQPClient : public TestCase class tst_QAMQPClient : public TestCase
{ {
Q_OBJECT Q_OBJECT
@ -28,7 +27,7 @@ private:
void tst_QAMQPClient::connect() void tst_QAMQPClient::connect()
{ {
Client client; QAmqpClient client;
client.connectToHost(); client.connectToHost();
QVERIFY(waitForSignal(&client, SIGNAL(connected()))); QVERIFY(waitForSignal(&client, SIGNAL(connected())));
@ -45,7 +44,7 @@ void tst_QAMQPClient::connect()
void tst_QAMQPClient::connectProperties() void tst_QAMQPClient::connectProperties()
{ {
Client client; QAmqpClient client;
client.setHost("localhost"); client.setHost("localhost");
client.setPort(5672); client.setPort(5672);
client.setVirtualHost("/"); client.setVirtualHost("/");
@ -60,7 +59,7 @@ void tst_QAMQPClient::connectProperties()
void tst_QAMQPClient::connectHostAddress() void tst_QAMQPClient::connectHostAddress()
{ {
Client client; QAmqpClient client;
client.connectToHost(QHostAddress::LocalHost, 5672); client.connectToHost(QHostAddress::LocalHost, 5672);
QVERIFY(waitForSignal(&client, SIGNAL(connected()))); QVERIFY(waitForSignal(&client, SIGNAL(connected())));
client.disconnectFromHost(); client.disconnectFromHost();
@ -69,14 +68,14 @@ void tst_QAMQPClient::connectHostAddress()
void tst_QAMQPClient::connectDisconnect() void tst_QAMQPClient::connectDisconnect()
{ {
Client client; QAmqpClient client;
client.connectToHost(); client.connectToHost();
QVERIFY(waitForSignal(&client, SIGNAL(connected()))); QVERIFY(waitForSignal(&client, SIGNAL(connected())));
client.disconnectFromHost(); client.disconnectFromHost();
QVERIFY(waitForSignal(&client, SIGNAL(disconnected()))); QVERIFY(waitForSignal(&client, SIGNAL(disconnected())));
} }
class InvalidAuthenticator : public Authenticator class InvalidAuthenticator : public QAmqpAuthenticator
{ {
public: public:
virtual QString type() const { return "CRAZYAUTH"; } virtual QString type() const { return "CRAZYAUTH"; }
@ -87,7 +86,7 @@ public:
void tst_QAMQPClient::invalidAuthenticationMechanism() void tst_QAMQPClient::invalidAuthenticationMechanism()
{ {
Client client; QAmqpClient client;
client.setAuth(new InvalidAuthenticator); client.setAuth(new InvalidAuthenticator);
client.connectToHost(); client.connectToHost();
QVERIFY(waitForSignal(&client, SIGNAL(disconnected()))); QVERIFY(waitForSignal(&client, SIGNAL(disconnected())));
@ -98,7 +97,7 @@ void tst_QAMQPClient::autoReconnect()
// TODO: this is a fairly crude way of testing this, research // TODO: this is a fairly crude way of testing this, research
// better alternatives // better alternatives
Client client; QAmqpClient client;
client.setAutoReconnect(true); client.setAutoReconnect(true);
client.connectToHost(); client.connectToHost();
QVERIFY(waitForSignal(&client, SIGNAL(connected()))); QVERIFY(waitForSignal(&client, SIGNAL(connected())));
@ -110,7 +109,7 @@ void tst_QAMQPClient::autoReconnect()
void tst_QAMQPClient::tune() void tst_QAMQPClient::tune()
{ {
Client client; QAmqpClient client;
client.setChannelMax(15); client.setChannelMax(15);
client.setFrameMax(5000); client.setFrameMax(5000);
client.setHeartbeatDelay(600); client.setHeartbeatDelay(600);
@ -163,15 +162,15 @@ void tst_QAMQPClient::validateUri()
QFETCH(quint16, expectedPort); QFETCH(quint16, expectedPort);
QFETCH(QString, expectedVirtualHost); QFETCH(QString, expectedVirtualHost);
ClientPrivate clientPrivate(0); QAmqpClientPrivate clientPrivate(0);
// fake init // fake init
clientPrivate.authenticator = QSharedPointer<Authenticator>( clientPrivate.authenticator = QSharedPointer<QAmqpAuthenticator>(
new AMQPlainAuthenticator(QString::fromLatin1(AMQP_LOGIN), QString::fromLatin1(AMQP_PSWD))); new QAmqpPlainAuthenticator(QString::fromLatin1(AMQP_LOGIN), QString::fromLatin1(AMQP_PSWD)));
// test parsing // test parsing
clientPrivate.parseConnectionString(uri); clientPrivate.parseConnectionString(uri);
AMQPlainAuthenticator *auth = QAmqpPlainAuthenticator *auth =
static_cast<AMQPlainAuthenticator*>(clientPrivate.authenticator.data()); static_cast<QAmqpPlainAuthenticator*>(clientPrivate.authenticator.data());
QCOMPARE(auth->login(), expectedUsername); QCOMPARE(auth->login(), expectedUsername);
QCOMPARE(auth->password(), expectedPassword); QCOMPARE(auth->password(), expectedPassword);

View File

@ -7,7 +7,6 @@
#include "qamqpexchange.h" #include "qamqpexchange.h"
#include "qamqpqueue.h" #include "qamqpqueue.h"
using namespace QAMQP;
class tst_QAMQPExchange : public TestCase class tst_QAMQPExchange : public TestCase
{ {
Q_OBJECT Q_OBJECT
@ -26,13 +25,13 @@ private Q_SLOTS:
void invalidImmediateRouting(); void invalidImmediateRouting();
private: private:
QScopedPointer<Client> client; QScopedPointer<QAmqpClient> client;
}; };
void tst_QAMQPExchange::init() void tst_QAMQPExchange::init()
{ {
client.reset(new Client); client.reset(new QAmqpClient);
client->connectToHost(); client->connectToHost();
QVERIFY(waitForSignal(client.data(), SIGNAL(connected()))); QVERIFY(waitForSignal(client.data(), SIGNAL(connected())));
} }
@ -47,55 +46,55 @@ void tst_QAMQPExchange::cleanup()
void tst_QAMQPExchange::standardTypes_data() void tst_QAMQPExchange::standardTypes_data()
{ {
QTest::addColumn<Exchange::ExchangeType>("type"); QTest::addColumn<QAmqpExchange::ExchangeType>("type");
QTest::addColumn<bool>("delayedDeclaration"); QTest::addColumn<bool>("delayedDeclaration");
QTest::newRow("direct") << Exchange::Direct << false; QTest::newRow("direct") << QAmqpExchange::Direct << false;
QTest::newRow("direct-delayed") << Exchange::Direct << true; QTest::newRow("direct-delayed") << QAmqpExchange::Direct << true;
QTest::newRow("fanout") << Exchange::FanOut << false; QTest::newRow("fanout") << QAmqpExchange::FanOut << false;
QTest::newRow("fanout-delayed") << Exchange::FanOut << true; QTest::newRow("fanout-delayed") << QAmqpExchange::FanOut << true;
QTest::newRow("topic") << Exchange::Topic << false; QTest::newRow("topic") << QAmqpExchange::Topic << false;
QTest::newRow("topic-delayed") << Exchange::Topic << true; QTest::newRow("topic-delayed") << QAmqpExchange::Topic << true;
QTest::newRow("headers") << Exchange::Headers << false; QTest::newRow("headers") << QAmqpExchange::Headers << false;
QTest::newRow("headers-delayed") << Exchange::Headers << true; QTest::newRow("headers-delayed") << QAmqpExchange::Headers << true;
} }
void tst_QAMQPExchange::standardTypes() void tst_QAMQPExchange::standardTypes()
{ {
QFETCH(Exchange::ExchangeType, type); QFETCH(QAmqpExchange::ExchangeType, type);
QFETCH(bool, delayedDeclaration); QFETCH(bool, delayedDeclaration);
Exchange *exchange = client->createExchange("test"); QAmqpExchange *exchange = client->createExchange("test");
if (!delayedDeclaration) if (!delayedDeclaration)
QVERIFY(waitForSignal(exchange, SIGNAL(opened()))); QVERIFY(waitForSignal(exchange, SIGNAL(opened())));
exchange->declare(type); exchange->declare(type);
QVERIFY(waitForSignal(exchange, SIGNAL(declared()))); QVERIFY(waitForSignal(exchange, SIGNAL(declared())));
exchange->remove(Exchange::roForce); exchange->remove(QAmqpExchange::roForce);
QVERIFY(waitForSignal(exchange, SIGNAL(removed()))); QVERIFY(waitForSignal(exchange, SIGNAL(removed())));
} }
void tst_QAMQPExchange::invalidStandardDeclaration_data() void tst_QAMQPExchange::invalidStandardDeclaration_data()
{ {
QTest::addColumn<QString>("exchangeName"); QTest::addColumn<QString>("exchangeName");
QTest::addColumn<Exchange::ExchangeType>("type"); QTest::addColumn<QAmqpExchange::ExchangeType>("type");
QTest::addColumn<QAMQP::Error>("error"); QTest::addColumn<QAMQP::Error>("error");
QTest::newRow("amq.direct") << "amq.direct" << Exchange::Direct << QAMQP::PreconditionFailedError; QTest::newRow("amq.direct") << "amq.direct" << QAmqpExchange::Direct << QAMQP::PreconditionFailedError;
QTest::newRow("amq.fanout") << "amq.fanout" << Exchange::FanOut << QAMQP::PreconditionFailedError; QTest::newRow("amq.fanout") << "amq.fanout" << QAmqpExchange::FanOut << QAMQP::PreconditionFailedError;
QTest::newRow("amq.headers") << "amq.headers" << Exchange::Headers << QAMQP::PreconditionFailedError; QTest::newRow("amq.headers") << "amq.headers" << QAmqpExchange::Headers << QAMQP::PreconditionFailedError;
QTest::newRow("amq.match") << "amq.match" << Exchange::Headers << QAMQP::PreconditionFailedError; QTest::newRow("amq.match") << "amq.match" << QAmqpExchange::Headers << QAMQP::PreconditionFailedError;
QTest::newRow("amq.topic") << "amq.topic" << Exchange::Topic << QAMQP::PreconditionFailedError; QTest::newRow("amq.topic") << "amq.topic" << QAmqpExchange::Topic << QAMQP::PreconditionFailedError;
QTest::newRow("amq.reserved") << "amq.reserved" << Exchange::Direct << QAMQP::AccessRefusedError; QTest::newRow("amq.reserved") << "amq.reserved" << QAmqpExchange::Direct << QAMQP::AccessRefusedError;
} }
void tst_QAMQPExchange::invalidStandardDeclaration() void tst_QAMQPExchange::invalidStandardDeclaration()
{ {
QFETCH(QString, exchangeName); QFETCH(QString, exchangeName);
QFETCH(Exchange::ExchangeType, type); QFETCH(QAmqpExchange::ExchangeType, type);
QFETCH(QAMQP::Error, error); QFETCH(QAMQP::Error, error);
Exchange *exchange = client->createExchange(exchangeName); QAmqpExchange *exchange = client->createExchange(exchangeName);
exchange->declare(type); exchange->declare(type);
QVERIFY(waitForSignal(exchange, SIGNAL(error(QAMQP::Error)))); QVERIFY(waitForSignal(exchange, SIGNAL(error(QAMQP::Error))));
QCOMPARE(exchange->error(), error); QCOMPARE(exchange->error(), error);
@ -103,7 +102,7 @@ void tst_QAMQPExchange::invalidStandardDeclaration()
void tst_QAMQPExchange::invalidDeclaration() void tst_QAMQPExchange::invalidDeclaration()
{ {
Exchange *exchange = client->createExchange("test-invalid-declaration"); QAmqpExchange *exchange = client->createExchange("test-invalid-declaration");
exchange->declare("invalidExchangeType"); exchange->declare("invalidExchangeType");
QVERIFY(waitForSignal(client.data(), SIGNAL(error(QAMQP::Error)))); QVERIFY(waitForSignal(client.data(), SIGNAL(error(QAMQP::Error))));
QCOMPARE(client->error(), QAMQP::CommandInvalidError); QCOMPARE(client->error(), QAMQP::CommandInvalidError);
@ -111,12 +110,12 @@ void tst_QAMQPExchange::invalidDeclaration()
void tst_QAMQPExchange::invalidRedeclaration() void tst_QAMQPExchange::invalidRedeclaration()
{ {
Exchange *exchange = client->createExchange("test-invalid-redeclaration"); QAmqpExchange *exchange = client->createExchange("test-invalid-redeclaration");
exchange->declare(Exchange::Direct); exchange->declare(QAmqpExchange::Direct);
QVERIFY(waitForSignal(exchange, SIGNAL(declared()))); QVERIFY(waitForSignal(exchange, SIGNAL(declared())));
Exchange *redeclared = client->createExchange("test-invalid-redeclaration"); QAmqpExchange *redeclared = client->createExchange("test-invalid-redeclaration");
redeclared->declare(Exchange::FanOut); redeclared->declare(QAmqpExchange::FanOut);
QVERIFY(waitForSignal(redeclared, SIGNAL(error(QAMQP::Error)))); QVERIFY(waitForSignal(redeclared, SIGNAL(error(QAMQP::Error))));
// this is per spec: // this is per spec:
@ -132,38 +131,38 @@ void tst_QAMQPExchange::invalidRedeclaration()
void tst_QAMQPExchange::removeIfUnused() void tst_QAMQPExchange::removeIfUnused()
{ {
Exchange *exchange = client->createExchange("test-if-unused-exchange"); QAmqpExchange *exchange = client->createExchange("test-if-unused-exchange");
exchange->declare(Exchange::Direct, Exchange::AutoDelete); exchange->declare(QAmqpExchange::Direct, QAmqpExchange::AutoDelete);
QVERIFY(waitForSignal(exchange, SIGNAL(declared()))); QVERIFY(waitForSignal(exchange, SIGNAL(declared())));
Queue *queue = client->createQueue("test-if-unused-queue"); QAmqpQueue *queue = client->createQueue("test-if-unused-queue");
queue->declare(); queue->declare();
QVERIFY(waitForSignal(queue, SIGNAL(declared()))); QVERIFY(waitForSignal(queue, SIGNAL(declared())));
queue->bind("test-if-unused-exchange", "testRoutingKey"); queue->bind("test-if-unused-exchange", "testRoutingKey");
QVERIFY(waitForSignal(queue, SIGNAL(bound()))); QVERIFY(waitForSignal(queue, SIGNAL(bound())));
exchange->remove(Exchange::roIfUnused); exchange->remove(QAmqpExchange::roIfUnused);
QVERIFY(waitForSignal(exchange, SIGNAL(error(QAMQP::Error)))); QVERIFY(waitForSignal(exchange, SIGNAL(error(QAMQP::Error))));
QCOMPARE(exchange->error(), QAMQP::PreconditionFailedError); QCOMPARE(exchange->error(), QAMQP::PreconditionFailedError);
QVERIFY(!exchange->errorString().isEmpty()); QVERIFY(!exchange->errorString().isEmpty());
// cleanup // cleanup
queue->remove(Queue::roForce); queue->remove(QAmqpQueue::roForce);
QVERIFY(waitForSignal(queue, SIGNAL(removed()))); QVERIFY(waitForSignal(queue, SIGNAL(removed())));
} }
void tst_QAMQPExchange::invalidMandatoryRouting() void tst_QAMQPExchange::invalidMandatoryRouting()
{ {
Exchange *defaultExchange = client->createExchange(); QAmqpExchange *defaultExchange = client->createExchange();
defaultExchange->publish("some message", "unroutable-key", Message::PropertyHash(), Exchange::poMandatory); defaultExchange->publish("some message", "unroutable-key", QAmqpMessage::PropertyHash(), QAmqpExchange::poMandatory);
QVERIFY(waitForSignal(defaultExchange, SIGNAL(error(QAMQP::Error)))); QVERIFY(waitForSignal(defaultExchange, SIGNAL(error(QAMQP::Error))));
QCOMPARE(defaultExchange->error(), QAMQP::UnroutableKey); QCOMPARE(defaultExchange->error(), QAMQP::UnroutableKey);
} }
void tst_QAMQPExchange::invalidImmediateRouting() void tst_QAMQPExchange::invalidImmediateRouting()
{ {
Exchange *defaultExchange = client->createExchange(); QAmqpExchange *defaultExchange = client->createExchange();
defaultExchange->publish("some message", "unroutable-key", Message::PropertyHash(), Exchange::poImmediate); defaultExchange->publish("some message", "unroutable-key", QAmqpMessage::PropertyHash(), QAmqpExchange::poImmediate);
QVERIFY(waitForSignal(client.data(), SIGNAL(error(QAMQP::Error)))); QVERIFY(waitForSignal(client.data(), SIGNAL(error(QAMQP::Error))));
QCOMPARE(client->error(), QAMQP::NotImplementedError); QCOMPARE(client->error(), QAMQP::NotImplementedError);
} }

View File

@ -9,7 +9,6 @@
#include "qamqpqueue.h" #include "qamqpqueue.h"
#include "qamqpexchange.h" #include "qamqpexchange.h"
using namespace QAMQP;
class tst_QAMQPQueue : public TestCase class tst_QAMQPQueue : public TestCase
{ {
Q_OBJECT Q_OBJECT
@ -49,13 +48,13 @@ private Q_SLOTS:
void emptyMessage(); void emptyMessage();
private: private:
QScopedPointer<Client> client; QScopedPointer<QAmqpClient> client;
}; };
void tst_QAMQPQueue::init() void tst_QAMQPQueue::init()
{ {
client.reset(new Client); client.reset(new QAmqpClient);
client->connectToHost(); client->connectToHost();
QVERIFY(waitForSignal(client.data(), SIGNAL(connected()))); QVERIFY(waitForSignal(client.data(), SIGNAL(connected())));
} }
@ -70,13 +69,13 @@ void tst_QAMQPQueue::cleanup()
void tst_QAMQPQueue::defaultExchange() void tst_QAMQPQueue::defaultExchange()
{ {
Queue *queue = client->createQueue("test-default-exchange"); QAmqpQueue *queue = client->createQueue("test-default-exchange");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
Exchange *defaultExchange = client->createExchange(); QAmqpExchange *defaultExchange = client->createExchange();
defaultExchange->publish("first message", "test-default-exchange"); defaultExchange->publish("first message", "test-default-exchange");
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived()))); QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
Message message = queue->dequeue(); QAmqpMessage message = queue->dequeue();
verifyStandardMessageHeaders(message, "test-default-exchange"); verifyStandardMessageHeaders(message, "test-default-exchange");
QCOMPARE(message.payload(), QByteArray("first message")); QCOMPARE(message.payload(), QByteArray("first message"));
} }
@ -106,7 +105,7 @@ void tst_QAMQPQueue::standardExchanges()
QString queueName = QString("test-%1").arg(exchange); QString queueName = QString("test-%1").arg(exchange);
QString routingKey = QString("testRoutingKey-%1").arg(exchange); QString routingKey = QString("testRoutingKey-%1").arg(exchange);
Queue *queue = client->createQueue(queueName); QAmqpQueue *queue = client->createQueue(queueName);
if (!delayedDeclaration) if (!delayedDeclaration)
QVERIFY(waitForSignal(queue, SIGNAL(opened()))); QVERIFY(waitForSignal(queue, SIGNAL(opened())));
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
@ -114,10 +113,10 @@ void tst_QAMQPQueue::standardExchanges()
queue->bind(exchange, routingKey); queue->bind(exchange, routingKey);
QVERIFY(waitForSignal(queue, SIGNAL(bound()))); QVERIFY(waitForSignal(queue, SIGNAL(bound())));
Exchange *defaultExchange = client->createExchange(exchange); QAmqpExchange *defaultExchange = client->createExchange(exchange);
defaultExchange->publish("test message", routingKey); defaultExchange->publish("test message", routingKey);
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived()))); QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
Message message = queue->dequeue(); QAmqpMessage message = queue->dequeue();
verifyStandardMessageHeaders(message, routingKey, exchange); verifyStandardMessageHeaders(message, routingKey, exchange);
QCOMPARE(message.payload(), QByteArray("test message")); QCOMPARE(message.payload(), QByteArray("test message"));
} }
@ -140,7 +139,7 @@ void tst_QAMQPQueue::invalidDeclaration()
QFETCH(QString, queueName); QFETCH(QString, queueName);
QFETCH(QAMQP::Error, error); QFETCH(QAMQP::Error, error);
Queue *queue = client->createQueue(queueName); QAmqpQueue *queue = client->createQueue(queueName);
queue->declare(); queue->declare();
QVERIFY(waitForSignal(queue, SIGNAL(error(QAMQP::Error)))); QVERIFY(waitForSignal(queue, SIGNAL(error(QAMQP::Error))));
QCOMPARE(queue->error(), error); QCOMPARE(queue->error(), error);
@ -148,7 +147,7 @@ void tst_QAMQPQueue::invalidDeclaration()
void tst_QAMQPQueue::invalidBind() void tst_QAMQPQueue::invalidBind()
{ {
Queue *queue = client->createQueue("test-invalid-bind"); QAmqpQueue *queue = client->createQueue("test-invalid-bind");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
queue->bind("non-existant-exchange", "routingKey"); queue->bind("non-existant-exchange", "routingKey");
@ -158,23 +157,23 @@ void tst_QAMQPQueue::invalidBind()
void tst_QAMQPQueue::unnamed() void tst_QAMQPQueue::unnamed()
{ {
Queue *queue = client->createQueue(); QAmqpQueue *queue = client->createQueue();
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
QVERIFY(!queue->name().isEmpty()); QVERIFY(!queue->name().isEmpty());
} }
void tst_QAMQPQueue::exclusiveAccess() void tst_QAMQPQueue::exclusiveAccess()
{ {
Queue *queue = client->createQueue("test-exclusive-queue"); QAmqpQueue *queue = client->createQueue("test-exclusive-queue");
queue->declare(Queue::Exclusive); queue->declare(QAmqpQueue::Exclusive);
QVERIFY(waitForSignal(queue, SIGNAL(declared()))); QVERIFY(waitForSignal(queue, SIGNAL(declared())));
QVERIFY(queue->options() & Queue::Exclusive); QVERIFY(queue->options() & QAmqpQueue::Exclusive);
Client secondClient; QAmqpClient secondClient;
secondClient.connectToHost(); secondClient.connectToHost();
QVERIFY(waitForSignal(&secondClient, SIGNAL(connected()))); QVERIFY(waitForSignal(&secondClient, SIGNAL(connected())));
Queue *passiveQueue = secondClient.createQueue("test-exclusive-queue"); QAmqpQueue *passiveQueue = secondClient.createQueue("test-exclusive-queue");
passiveQueue->declare(Queue::Passive); passiveQueue->declare(QAmqpQueue::Passive);
QVERIFY(waitForSignal(passiveQueue, SIGNAL(error(QAMQP::Error)))); QVERIFY(waitForSignal(passiveQueue, SIGNAL(error(QAMQP::Error))));
QCOMPARE(passiveQueue->error(), QAMQP::ResourceLockedError); QCOMPARE(passiveQueue->error(), QAMQP::ResourceLockedError);
@ -184,20 +183,20 @@ void tst_QAMQPQueue::exclusiveAccess()
void tst_QAMQPQueue::exclusiveRemoval() void tst_QAMQPQueue::exclusiveRemoval()
{ {
Queue *queue = client->createQueue("test-exclusive-queue"); QAmqpQueue *queue = client->createQueue("test-exclusive-queue");
queue->declare(Queue::Exclusive); queue->declare(QAmqpQueue::Exclusive);
QVERIFY(waitForSignal(queue, SIGNAL(declared()))); QVERIFY(waitForSignal(queue, SIGNAL(declared())));
QVERIFY(queue->options() & Queue::Exclusive); QVERIFY(queue->options() & QAmqpQueue::Exclusive);
client.data()->disconnectFromHost(); client.data()->disconnectFromHost();
QVERIFY(waitForSignal(client.data(), SIGNAL(disconnected()))); QVERIFY(waitForSignal(client.data(), SIGNAL(disconnected())));
// create a new client and try to access the queue that should // create a new client and try to access the queue that should
// no longer exist // no longer exist
Client secondClient; QAmqpClient secondClient;
secondClient.connectToHost(); secondClient.connectToHost();
QVERIFY(waitForSignal(&secondClient, SIGNAL(connected()))); QVERIFY(waitForSignal(&secondClient, SIGNAL(connected())));
Queue *passiveQueue = secondClient.createQueue("test-exclusive-queue"); QAmqpQueue *passiveQueue = secondClient.createQueue("test-exclusive-queue");
passiveQueue->declare(Queue::Passive); passiveQueue->declare(QAmqpQueue::Passive);
QVERIFY(waitForSignal(passiveQueue, SIGNAL(error(QAMQP::Error)))); QVERIFY(waitForSignal(passiveQueue, SIGNAL(error(QAMQP::Error))));
QCOMPARE(passiveQueue->error(), QAMQP::NotFoundError); QCOMPARE(passiveQueue->error(), QAMQP::NotFoundError);
secondClient.disconnectFromHost(); secondClient.disconnectFromHost();
@ -206,27 +205,27 @@ void tst_QAMQPQueue::exclusiveRemoval()
void tst_QAMQPQueue::notFound() void tst_QAMQPQueue::notFound()
{ {
Queue *queue = client->createQueue("test-not-found"); QAmqpQueue *queue = client->createQueue("test-not-found");
queue->declare(Queue::Passive); queue->declare(QAmqpQueue::Passive);
QVERIFY(waitForSignal(queue, SIGNAL(error(QAMQP::Error)))); QVERIFY(waitForSignal(queue, SIGNAL(error(QAMQP::Error))));
QCOMPARE(queue->error(), QAMQP::NotFoundError); QCOMPARE(queue->error(), QAMQP::NotFoundError);
} }
void tst_QAMQPQueue::remove() void tst_QAMQPQueue::remove()
{ {
Queue *queue = client->createQueue("test-remove"); QAmqpQueue *queue = client->createQueue("test-remove");
queue->declare(); queue->declare();
QVERIFY(waitForSignal(queue, SIGNAL(declared()))); QVERIFY(waitForSignal(queue, SIGNAL(declared())));
queue->remove(Queue::roIfEmpty|Queue::roIfUnused); queue->remove(QAmqpQueue::roIfEmpty|QAmqpQueue::roIfUnused);
QVERIFY(waitForSignal(queue, SIGNAL(removed()))); QVERIFY(waitForSignal(queue, SIGNAL(removed())));
} }
void tst_QAMQPQueue::removeIfUnused() void tst_QAMQPQueue::removeIfUnused()
{ {
Queue *queue = client->createQueue("test-remove-if-unused"); QAmqpQueue *queue = client->createQueue("test-remove-if-unused");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
queue->remove(Queue::roIfUnused); queue->remove(QAmqpQueue::roIfUnused);
QVERIFY(waitForSignal(queue, SIGNAL(error(QAMQP::Error)))); QVERIFY(waitForSignal(queue, SIGNAL(error(QAMQP::Error))));
QCOMPARE(queue->error(), QAMQP::PreconditionFailedError); QCOMPARE(queue->error(), QAMQP::PreconditionFailedError);
QVERIFY(!queue->errorString().isEmpty()); QVERIFY(!queue->errorString().isEmpty());
@ -235,25 +234,25 @@ void tst_QAMQPQueue::removeIfUnused()
void tst_QAMQPQueue::removeIfEmpty() void tst_QAMQPQueue::removeIfEmpty()
{ {
// declare the queue and send messages to it // declare the queue and send messages to it
Queue *queue = client->createQueue("test-remove-if-empty"); QAmqpQueue *queue = client->createQueue("test-remove-if-empty");
queue->declare(Queue::Durable); queue->declare(QAmqpQueue::Durable);
QVERIFY(waitForSignal(queue, SIGNAL(declared()))); 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"); defaultExchange->publish("first message", "test-remove-if-empty");
// create a second client and try to delete the queue // create a second client and try to delete the queue
{ {
Client secondClient; QAmqpClient secondClient;
secondClient.connectToHost(); secondClient.connectToHost();
QVERIFY(waitForSignal(&secondClient, SIGNAL(connected()))); QVERIFY(waitForSignal(&secondClient, SIGNAL(connected())));
Queue *testDeleteQueue = secondClient.createQueue("test-remove-if-empty"); QAmqpQueue *testDeleteQueue = secondClient.createQueue("test-remove-if-empty");
testDeleteQueue->declare(Queue::Passive); testDeleteQueue->declare(QAmqpQueue::Passive);
QVERIFY(waitForSignal(testDeleteQueue, SIGNAL(declared()))); 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)))); QVERIFY(waitForSignal(testDeleteQueue, SIGNAL(error(QAMQP::Error))));
QCOMPARE(testDeleteQueue->error(), QAMQP::PreconditionFailedError); QCOMPARE(testDeleteQueue->error(), QAMQP::PreconditionFailedError);
QVERIFY(!testDeleteQueue->errorString().isEmpty()); QVERIFY(!testDeleteQueue->errorString().isEmpty());
@ -263,13 +262,13 @@ void tst_QAMQPQueue::removeIfEmpty()
} }
// clean up queue // clean up queue
queue->remove(Queue::roForce); queue->remove(QAmqpQueue::roForce);
QVERIFY(waitForSignal(queue, SIGNAL(removed()))); QVERIFY(waitForSignal(queue, SIGNAL(removed())));
} }
void tst_QAMQPQueue::bindUnbind() void tst_QAMQPQueue::bindUnbind()
{ {
Queue *queue = client->createQueue("test-bind-unbind"); QAmqpQueue *queue = client->createQueue("test-bind-unbind");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
queue->bind("amq.topic", "routingKey"); queue->bind("amq.topic", "routingKey");
@ -277,8 +276,8 @@ void tst_QAMQPQueue::bindUnbind()
queue->unbind("amq.topic", "routingKey"); queue->unbind("amq.topic", "routingKey");
QVERIFY(waitForSignal(queue, SIGNAL(unbound()))); QVERIFY(waitForSignal(queue, SIGNAL(unbound())));
Exchange *amqTopic = client->createExchange("amq.topic"); QAmqpExchange *amqTopic = client->createExchange("amq.topic");
amqTopic->declare(Exchange::Direct, Exchange::Passive); amqTopic->declare(QAmqpExchange::Direct, QAmqpExchange::Passive);
QVERIFY(waitForSignal(amqTopic, SIGNAL(declared()))); QVERIFY(waitForSignal(amqTopic, SIGNAL(declared())));
queue->bind(amqTopic, "routingKey"); queue->bind(amqTopic, "routingKey");
QVERIFY(waitForSignal(queue, SIGNAL(bound()))); QVERIFY(waitForSignal(queue, SIGNAL(bound())));
@ -290,7 +289,7 @@ void tst_QAMQPQueue::delayedBind()
{ {
client->disconnectFromHost(); client->disconnectFromHost();
QVERIFY(waitForSignal(client.data(), SIGNAL(disconnected()))); QVERIFY(waitForSignal(client.data(), SIGNAL(disconnected())));
Queue *queue = client->createQueue("test-delayed-bind"); QAmqpQueue *queue = client->createQueue("test-delayed-bind");
queue->declare(); queue->declare();
queue->bind("amq.topic", "routingKey"); queue->bind("amq.topic", "routingKey");
@ -300,31 +299,31 @@ void tst_QAMQPQueue::delayedBind()
QVERIFY(waitForSignal(queue, SIGNAL(bound()))); QVERIFY(waitForSignal(queue, SIGNAL(bound())));
// clean up queue // clean up queue
queue->remove(Queue::roForce); queue->remove(QAmqpQueue::roForce);
QVERIFY(waitForSignal(queue, SIGNAL(removed()))); QVERIFY(waitForSignal(queue, SIGNAL(removed())));
} }
void tst_QAMQPQueue::purge() void tst_QAMQPQueue::purge()
{ {
Queue *queue = client->createQueue("test-purge"); QAmqpQueue *queue = client->createQueue("test-purge");
queue->declare(Queue::Durable); queue->declare(QAmqpQueue::Durable);
QVERIFY(waitForSignal(queue, SIGNAL(declared()))); 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("first message", "test-purge");
defaultExchange->publish("second message", "test-purge"); defaultExchange->publish("second message", "test-purge");
defaultExchange->publish("third message", "test-purge"); defaultExchange->publish("third message", "test-purge");
// create second client to listen to messages and attempt purge // create second client to listen to messages and attempt purge
{ {
Client secondClient; QAmqpClient secondClient;
secondClient.connectToHost(); secondClient.connectToHost();
QVERIFY(waitForSignal(&secondClient, SIGNAL(connected()))); QVERIFY(waitForSignal(&secondClient, SIGNAL(connected())));
Queue *testPurgeQueue = secondClient.createQueue("test-purge"); QAmqpQueue *testPurgeQueue = secondClient.createQueue("test-purge");
testPurgeQueue->declare(Queue::Passive); testPurgeQueue->declare(QAmqpQueue::Passive);
QVERIFY(waitForSignal(testPurgeQueue, SIGNAL(declared()))); QVERIFY(waitForSignal(testPurgeQueue, SIGNAL(declared())));
QVERIFY(testPurgeQueue->options() & Queue::Passive); QVERIFY(testPurgeQueue->options() & QAmqpQueue::Passive);
QSignalSpy spy(testPurgeQueue, SIGNAL(purged(int))); QSignalSpy spy(testPurgeQueue, SIGNAL(purged(int)));
testPurgeQueue->purge(); testPurgeQueue->purge();
@ -339,20 +338,20 @@ void tst_QAMQPQueue::purge()
} }
// clean up queue // clean up queue
queue->remove(Queue::roForce); queue->remove(QAmqpQueue::roForce);
QVERIFY(waitForSignal(queue, SIGNAL(removed()))); QVERIFY(waitForSignal(queue, SIGNAL(removed())));
} }
void tst_QAMQPQueue::canOnlyStartConsumingOnce() void tst_QAMQPQueue::canOnlyStartConsumingOnce()
{ {
Queue *queue = client->createQueue("test-single-consumer"); QAmqpQueue *queue = client->createQueue("test-single-consumer");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
QCOMPARE(queue->consume(), false); QCOMPARE(queue->consume(), false);
} }
void tst_QAMQPQueue::cancel() void tst_QAMQPQueue::cancel()
{ {
Queue *queue = client->createQueue("test-cancel"); QAmqpQueue *queue = client->createQueue("test-cancel");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
QString consumerTag = queue->consumerTag(); QString consumerTag = queue->consumerTag();
@ -366,19 +365,19 @@ void tst_QAMQPQueue::cancel()
void tst_QAMQPQueue::invalidCancelBecauseNotConsuming() 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(); queue->declare();
QVERIFY(waitForSignal(queue, SIGNAL(declared()))); QVERIFY(waitForSignal(queue, SIGNAL(declared())));
QCOMPARE(queue->cancel(), false); QCOMPARE(queue->cancel(), false);
// clean up queue // clean up queue
queue->remove(Queue::roForce); queue->remove(QAmqpQueue::roForce);
QVERIFY(waitForSignal(queue, SIGNAL(removed()))); QVERIFY(waitForSignal(queue, SIGNAL(removed())));
} }
void tst_QAMQPQueue::invalidCancelBecauseInvalidConsumerTag() 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); declareQueueAndVerifyConsuming(queue);
queue->setConsumerTag(QString()); queue->setConsumerTag(QString());
QCOMPARE(queue->cancel(), false); QCOMPARE(queue->cancel(), false);
@ -386,7 +385,7 @@ void tst_QAMQPQueue::invalidCancelBecauseInvalidConsumerTag()
void tst_QAMQPQueue::getEmpty() void tst_QAMQPQueue::getEmpty()
{ {
Queue *queue = client->createQueue("test-get-empty"); QAmqpQueue *queue = client->createQueue("test-get-empty");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
queue->get(); queue->get();
@ -395,12 +394,12 @@ void tst_QAMQPQueue::getEmpty()
void tst_QAMQPQueue::get() void tst_QAMQPQueue::get()
{ {
Queue *queue = client->createQueue("test-get"); QAmqpQueue *queue = client->createQueue("test-get");
queue->declare(); queue->declare();
QVERIFY(waitForSignal(queue, SIGNAL(declared()))); QVERIFY(waitForSignal(queue, SIGNAL(declared())));
const int messageCount = 200; const int messageCount = 200;
Exchange *defaultExchange = client->createExchange(); QAmqpExchange *defaultExchange = client->createExchange();
for (int i = 0; i < messageCount; ++i) { for (int i = 0; i < messageCount; ++i) {
QString expected = QString("message %1").arg(i); QString expected = QString("message %1").arg(i);
defaultExchange->publish(expected, "test-get"); defaultExchange->publish(expected, "test-get");
@ -417,7 +416,7 @@ void tst_QAMQPQueue::get()
continue; continue;
} }
Message message = queue->dequeue(); QAmqpMessage message = queue->dequeue();
verifyStandardMessageHeaders(message, "test-get"); verifyStandardMessageHeaders(message, "test-get");
QCOMPARE(message.payload(), expected.toUtf8()); QCOMPARE(message.payload(), expected.toUtf8());
queue->ack(message); queue->ack(message);
@ -427,31 +426,31 @@ void tst_QAMQPQueue::get()
QVERIFY(waitForSignal(queue, SIGNAL(empty()))); QVERIFY(waitForSignal(queue, SIGNAL(empty())));
// clean up queue // clean up queue
queue->remove(Queue::roForce); queue->remove(QAmqpQueue::roForce);
QVERIFY(waitForSignal(queue, SIGNAL(removed()))); QVERIFY(waitForSignal(queue, SIGNAL(removed())));
} }
void tst_QAMQPQueue::verifyContentEncodingIssue33() void tst_QAMQPQueue::verifyContentEncodingIssue33()
{ {
Queue *queue = client->createQueue("test-issue-33"); QAmqpQueue *queue = client->createQueue("test-issue-33");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
Exchange *defaultExchange = client->createExchange(); QAmqpExchange *defaultExchange = client->createExchange();
Message::PropertyHash properties; QAmqpMessage::PropertyHash properties;
properties.insert(Message::ContentEncoding, "fakeContentEncoding"); properties.insert(QAmqpMessage::ContentEncoding, "fakeContentEncoding");
defaultExchange->publish("some data", "test-issue-33", properties); defaultExchange->publish("some data", "test-issue-33", properties);
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived()))); QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
Message message = queue->dequeue(); QAmqpMessage message = queue->dequeue();
verifyStandardMessageHeaders(message, "test-issue-33"); verifyStandardMessageHeaders(message, "test-issue-33");
QVERIFY(message.hasProperty(Message::ContentEncoding)); QVERIFY(message.hasProperty(QAmqpMessage::ContentEncoding));
QString contentType = message.property(Message::ContentEncoding).toString(); QString contentType = message.property(QAmqpMessage::ContentEncoding).toString();
QCOMPARE(contentType, QLatin1String("fakeContentEncoding")); QCOMPARE(contentType, QLatin1String("fakeContentEncoding"));
} }
void tst_QAMQPQueue::defineQos() void tst_QAMQPQueue::defineQos()
{ {
Queue *queue = client->createQueue("test-define-qos"); QAmqpQueue *queue = client->createQueue("test-define-qos");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
queue->qos(10); queue->qos(10);
@ -460,13 +459,13 @@ void tst_QAMQPQueue::defineQos()
QCOMPARE(queue->prefetchSize(), 0); QCOMPARE(queue->prefetchSize(), 0);
// clean up queue // clean up queue
queue->remove(Queue::roForce); queue->remove(QAmqpQueue::roForce);
QVERIFY(waitForSignal(queue, SIGNAL(removed()))); QVERIFY(waitForSignal(queue, SIGNAL(removed())));
} }
void tst_QAMQPQueue::invalidQos() void tst_QAMQPQueue::invalidQos()
{ {
Queue *queue = client->createQueue("test-invalid-define-qos"); QAmqpQueue *queue = client->createQueue("test-invalid-define-qos");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
queue->qos(10, 10); queue->qos(10, 10);
@ -476,7 +475,7 @@ void tst_QAMQPQueue::invalidQos()
void tst_QAMQPQueue::qos() void tst_QAMQPQueue::qos()
{ {
Queue *queue = client->createQueue("test-qos"); QAmqpQueue *queue = client->createQueue("test-qos");
queue->declare(); queue->declare();
QVERIFY(waitForSignal(queue, SIGNAL(declared()))); QVERIFY(waitForSignal(queue, SIGNAL(declared())));
@ -489,7 +488,7 @@ void tst_QAMQPQueue::qos()
// load up the queue // load up the queue
const int messageCount = 10; const int messageCount = 10;
Exchange *defaultExchange = client->createExchange(); QAmqpExchange *defaultExchange = client->createExchange();
for (int i = 0; i < messageCount; ++i) { for (int i = 0; i < messageCount; ++i) {
QString message = QString("message %1").arg(i); QString message = QString("message %1").arg(i);
defaultExchange->publish(message, "test-qos"); defaultExchange->publish(message, "test-qos");
@ -499,7 +498,7 @@ void tst_QAMQPQueue::qos()
int messageReceivedCount = 0; int messageReceivedCount = 0;
while (!queue->isEmpty()) { while (!queue->isEmpty()) {
QString expected = QString("message %1").arg(messageReceivedCount); QString expected = QString("message %1").arg(messageReceivedCount);
Message message = queue->dequeue(); QAmqpMessage message = queue->dequeue();
verifyStandardMessageHeaders(message, "test-qos"); verifyStandardMessageHeaders(message, "test-qos");
QCOMPARE(message.payload(), expected.toUtf8()); QCOMPARE(message.payload(), expected.toUtf8());
queue->ack(message); queue->ack(message);
@ -515,7 +514,7 @@ void tst_QAMQPQueue::qos()
void tst_QAMQPQueue::invalidRoutingKey() void tst_QAMQPQueue::invalidRoutingKey()
{ {
QString routingKey = QString("%1").arg('1', 256, QLatin1Char('0')); QString routingKey = QString("%1").arg('1', 256, QLatin1Char('0'));
Queue *queue = client->createQueue(routingKey); QAmqpQueue *queue = client->createQueue(routingKey);
queue->declare(); queue->declare();
QVERIFY(waitForSignal(client.data(), SIGNAL(error(QAMQP::Error)))); QVERIFY(waitForSignal(client.data(), SIGNAL(error(QAMQP::Error))));
QCOMPARE(client->error(), QAMQP::FrameError); QCOMPARE(client->error(), QAMQP::FrameError);
@ -523,7 +522,7 @@ void tst_QAMQPQueue::invalidRoutingKey()
void tst_QAMQPQueue::tableFieldDataTypes() void tst_QAMQPQueue::tableFieldDataTypes()
{ {
Queue *queue = client->createQueue("test-table-field-data-types"); QAmqpQueue *queue = client->createQueue("test-table-field-data-types");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
QAMQP::Decimal decimal; QAMQP::Decimal decimal;
@ -531,7 +530,7 @@ void tst_QAMQPQueue::tableFieldDataTypes()
decimal.value = 12345; decimal.value = 12345;
QVariant decimalVariant = QVariant::fromValue<QAMQP::Decimal>(decimal); QVariant decimalVariant = QVariant::fromValue<QAMQP::Decimal>(decimal);
Table nestedTable; QAmqpTable nestedTable;
nestedTable.insert("boolean", true); nestedTable.insert("boolean", true);
nestedTable.insert("long-int", qint32(-65536)); nestedTable.insert("long-int", qint32(-65536));
@ -541,7 +540,7 @@ void tst_QAMQPQueue::tableFieldDataTypes()
QDateTime timestamp = QDateTime::currentDateTime(); QDateTime timestamp = QDateTime::currentDateTime();
Table headers; QAmqpTable headers;
headers.insert("boolean", true); headers.insert("boolean", true);
headers.insert("short-short-int", qint8(-15)); headers.insert("short-short-int", qint8(-15));
headers.insert("short-short-uint", quint8(15)); headers.insert("short-short-uint", quint8(15));
@ -561,11 +560,11 @@ void tst_QAMQPQueue::tableFieldDataTypes()
headers.insert("array", array); headers.insert("array", array);
headers.insert("bytes", QByteArray("abcdefg1234567")); headers.insert("bytes", QByteArray("abcdefg1234567"));
Exchange *defaultExchange = client->createExchange(); QAmqpExchange *defaultExchange = client->createExchange();
defaultExchange->publish("dummy", "test-table-field-data-types", "text.plain", headers); defaultExchange->publish("dummy", "test-table-field-data-types", "text.plain", headers);
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived()))); QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
Message message = queue->dequeue(); QAmqpMessage message = queue->dequeue();
QCOMPARE(message.header("boolean").toBool(), true); QCOMPARE(message.header("boolean").toBool(), true);
QCOMPARE(qint8(message.header("short-short-int").toInt()), qint8(-15)); 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")); QCOMPARE(message.header("bytes").toByteArray(), QByteArray("abcdefg1234567"));
QVERIFY(message.hasHeader("nested-table")); QVERIFY(message.hasHeader("nested-table"));
Table compareTable(message.header("nested-table").toHash()); QAmqpTable compareTable(message.header("nested-table").toHash());
foreach (QString key, nestedTable.keys()) { foreach (QString key, nestedTable.keys()) {
QVERIFY(compareTable.contains(key)); QVERIFY(compareTable.contains(key));
QCOMPARE(nestedTable.value(key), compareTable.value(key)); QCOMPARE(nestedTable.value(key), compareTable.value(key));
@ -601,55 +600,55 @@ void tst_QAMQPQueue::tableFieldDataTypes()
void tst_QAMQPQueue::messageProperties() void tst_QAMQPQueue::messageProperties()
{ {
Queue *queue = client->createQueue("test-message-properties"); QAmqpQueue *queue = client->createQueue("test-message-properties");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
QDateTime timestamp = QDateTime::currentDateTime(); QDateTime timestamp = QDateTime::currentDateTime();
Message::PropertyHash properties; QAmqpMessage::PropertyHash properties;
properties.insert(Message::ContentType, "some-content-type"); properties.insert(QAmqpMessage::ContentType, "some-content-type");
properties.insert(Message::ContentEncoding, "some-content-encoding"); properties.insert(QAmqpMessage::ContentEncoding, "some-content-encoding");
properties.insert(Message::DeliveryMode, 2); properties.insert(QAmqpMessage::DeliveryMode, 2);
properties.insert(Message::Priority, 5); properties.insert(QAmqpMessage::Priority, 5);
properties.insert(Message::CorrelationId, 42); properties.insert(QAmqpMessage::CorrelationId, 42);
properties.insert(Message::ReplyTo, "another-queue"); properties.insert(QAmqpMessage::ReplyTo, "another-queue");
properties.insert(Message::MessageId, "some-message-id"); properties.insert(QAmqpMessage::MessageId, "some-message-id");
properties.insert(Message::Expiration, "60000"); properties.insert(QAmqpMessage::Expiration, "60000");
properties.insert(Message::Timestamp, timestamp); properties.insert(QAmqpMessage::Timestamp, timestamp);
properties.insert(Message::Type, "some-message-type"); properties.insert(QAmqpMessage::Type, "some-message-type");
properties.insert(Message::UserId, "guest"); properties.insert(QAmqpMessage::UserId, "guest");
properties.insert(Message::AppId, "some-app-id"); properties.insert(QAmqpMessage::AppId, "some-app-id");
properties.insert(Message::ClusterID, "some-cluster-id"); properties.insert(QAmqpMessage::ClusterID, "some-cluster-id");
Exchange *defaultExchange = client->createExchange(); QAmqpExchange *defaultExchange = client->createExchange();
defaultExchange->publish("dummy", "test-message-properties", properties); defaultExchange->publish("dummy", "test-message-properties", properties);
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived()))); 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(QAmqpMessage::ContentType).toString(), QLatin1String("some-content-type"));
QCOMPARE(message.property(Message::ContentEncoding).toString(), QLatin1String("some-content-encoding")); QCOMPARE(message.property(QAmqpMessage::ContentEncoding).toString(), QLatin1String("some-content-encoding"));
QCOMPARE(message.property(Message::DeliveryMode).toInt(), 2); QCOMPARE(message.property(QAmqpMessage::DeliveryMode).toInt(), 2);
QCOMPARE(message.property(Message::Priority).toInt(), 5); QCOMPARE(message.property(QAmqpMessage::Priority).toInt(), 5);
QCOMPARE(message.property(Message::CorrelationId).toInt(), 42); QCOMPARE(message.property(QAmqpMessage::CorrelationId).toInt(), 42);
QCOMPARE(message.property(Message::ReplyTo).toString(), QLatin1String("another-queue")); QCOMPARE(message.property(QAmqpMessage::ReplyTo).toString(), QLatin1String("another-queue"));
QCOMPARE(message.property(Message::MessageId).toString(), QLatin1String("some-message-id")); QCOMPARE(message.property(QAmqpMessage::MessageId).toString(), QLatin1String("some-message-id"));
QCOMPARE(message.property(Message::Expiration).toString(), QLatin1String("60000")); QCOMPARE(message.property(QAmqpMessage::Expiration).toString(), QLatin1String("60000"));
QCOMPARE(message.property(Message::Timestamp).toDateTime(), timestamp); QCOMPARE(message.property(QAmqpMessage::Timestamp).toDateTime(), timestamp);
QCOMPARE(message.property(Message::Type).toString(), QLatin1String("some-message-type")); QCOMPARE(message.property(QAmqpMessage::Type).toString(), QLatin1String("some-message-type"));
QCOMPARE(message.property(Message::UserId).toString(), QLatin1String("guest")); QCOMPARE(message.property(QAmqpMessage::UserId).toString(), QLatin1String("guest"));
QCOMPARE(message.property(Message::AppId).toString(), QLatin1String("some-app-id")); QCOMPARE(message.property(QAmqpMessage::AppId).toString(), QLatin1String("some-app-id"));
QCOMPARE(message.property(Message::ClusterID).toString(), QLatin1String("some-cluster-id")); QCOMPARE(message.property(QAmqpMessage::ClusterID).toString(), QLatin1String("some-cluster-id"));
} }
void tst_QAMQPQueue::emptyMessage() void tst_QAMQPQueue::emptyMessage()
{ {
Queue *queue = client->createQueue("test-issue-43"); QAmqpQueue *queue = client->createQueue("test-issue-43");
declareQueueAndVerifyConsuming(queue); declareQueueAndVerifyConsuming(queue);
Exchange *defaultExchange = client->createExchange(); QAmqpExchange *defaultExchange = client->createExchange();
defaultExchange->publish("", "test-issue-43"); defaultExchange->publish("", "test-issue-43");
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived()))); QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
Message message = queue->dequeue(); QAmqpMessage message = queue->dequeue();
verifyStandardMessageHeaders(message, "test-issue-43"); verifyStandardMessageHeaders(message, "test-issue-43");
QVERIFY(message.payload().isEmpty()); QVERIFY(message.payload().isEmpty());
} }

View File

@ -6,8 +6,6 @@
#include "qamqpqueue.h" #include "qamqpqueue.h"
namespace QAMQP {
class TestCase : public QObject class TestCase : public QObject
{ {
public: public:
@ -26,7 +24,7 @@ protected:
return !QTestEventLoop::instance().timeout(); return !QTestEventLoop::instance().timeout();
} }
void declareQueueAndVerifyConsuming(Queue *queue) void declareQueueAndVerifyConsuming(QAmqpQueue *queue)
{ {
queue->declare(); queue->declare();
QVERIFY(waitForSignal(queue, SIGNAL(declared()))); QVERIFY(waitForSignal(queue, SIGNAL(declared())));
@ -39,7 +37,7 @@ protected:
QCOMPARE(arguments.at(0).toString(), queue->consumerTag()); 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(""), const QString &exchangeName = QLatin1String(""),
bool redelivered = false) bool redelivered = false)
{ {
@ -47,9 +45,6 @@ protected:
QCOMPARE(message.exchangeName(), exchangeName); QCOMPARE(message.exchangeName(), exchangeName);
QCOMPARE(message.isRedelivered(), redelivered); QCOMPARE(message.isRedelivered(), redelivered);
} }
}; };
} // namespace QAMQP
#endif // QAMQPTESTCASE_H #endif // QAMQPTESTCASE_H

View File

@ -4,7 +4,6 @@
#include "qamqpclient.h" #include "qamqpclient.h"
#include "qamqpexchange.h" #include "qamqpexchange.h"
#include "qamqpqueue.h" #include "qamqpqueue.h"
using namespace QAMQP;
class Receiver : public QObject class Receiver : public QObject
{ {
@ -20,32 +19,32 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void clientConnected() { void clientConnected() {
Queue *queue = m_client.createQueue("hello"); QAmqpQueue *queue = m_client.createQueue("hello");
connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared())); connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared()));
queue->declare(); queue->declare();
} }
void queueDeclared() { void queueDeclared() {
Queue *queue = qobject_cast<Queue*>(sender()); QAmqpQueue *queue = qobject_cast<QAmqpQueue*>(sender());
if (!queue) if (!queue)
return; return;
connect(queue, SIGNAL(messageReceived()), this, SLOT(messageReceived())); connect(queue, SIGNAL(messageReceived()), this, SLOT(messageReceived()));
queue->consume(Queue::coNoAck); queue->consume(QAmqpQueue::coNoAck);
qDebug() << " [*] Waiting for messages. To exit press CTRL+C"; qDebug() << " [*] Waiting for messages. To exit press CTRL+C";
} }
void messageReceived() { void messageReceived() {
Queue *queue = qobject_cast<Queue*>(sender()); QAmqpQueue *queue = qobject_cast<QAmqpQueue*>(sender());
if (!queue) if (!queue)
return; return;
Message message = queue->dequeue(); QAmqpMessage message = queue->dequeue();
qDebug() << " [x] Received " << message.payload(); qDebug() << " [x] Received " << message.payload();
} }
private: private:
Client m_client; QAmqpClient m_client;
}; };

View File

@ -5,7 +5,6 @@
#include "qamqpclient.h" #include "qamqpclient.h"
#include "qamqpexchange.h" #include "qamqpexchange.h"
#include "qamqpqueue.h" #include "qamqpqueue.h"
using namespace QAMQP;
class Sender : public QObject class Sender : public QObject
{ {
@ -22,23 +21,23 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void clientConnected() { void clientConnected() {
Queue *queue = m_client.createQueue("hello"); QAmqpQueue *queue = m_client.createQueue("hello");
connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared())); connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared()));
queue->declare(); queue->declare();
} }
void queueDeclared() { void queueDeclared() {
Queue *queue = qobject_cast<Queue*>(sender()); QAmqpQueue *queue = qobject_cast<QAmqpQueue*>(sender());
if (!queue) if (!queue)
return; return;
Exchange *defaultExchange = m_client.createExchange(); QAmqpExchange *defaultExchange = m_client.createExchange();
defaultExchange->publish("Hello World!", "hello"); defaultExchange->publish("Hello World!", "hello");
qDebug() << " [x] Sent 'Hello World!'"; qDebug() << " [x] Sent 'Hello World!'";
m_client.disconnectFromHost(); m_client.disconnectFromHost();
} }
private: private:
Client m_client; QAmqpClient m_client;
}; };

View File

@ -5,7 +5,6 @@
#include "qamqpclient.h" #include "qamqpclient.h"
#include "qamqpexchange.h" #include "qamqpexchange.h"
#include "qamqpqueue.h" #include "qamqpqueue.h"
using namespace QAMQP;
class LogEmitter : public QObject class LogEmitter : public QObject
{ {
@ -22,13 +21,13 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void clientConnected() { void clientConnected() {
Exchange *exchange = m_client.createExchange("logs"); QAmqpExchange *exchange = m_client.createExchange("logs");
connect(exchange, SIGNAL(declared()), this, SLOT(exchangeDeclared())); connect(exchange, SIGNAL(declared()), this, SLOT(exchangeDeclared()));
exchange->declare(Exchange::FanOut); exchange->declare(QAmqpExchange::FanOut);
} }
void exchangeDeclared() { void exchangeDeclared() {
Exchange *exchange = qobject_cast<Exchange*>(sender()); QAmqpExchange *exchange = qobject_cast<QAmqpExchange*>(sender());
if (!exchange) if (!exchange)
return; return;
@ -43,7 +42,7 @@ private Q_SLOTS:
} }
private: private:
Client m_client; QAmqpClient m_client;
}; };

View File

@ -5,7 +5,6 @@
#include "qamqpclient.h" #include "qamqpclient.h"
#include "qamqpexchange.h" #include "qamqpexchange.h"
#include "qamqpqueue.h" #include "qamqpqueue.h"
using namespace QAMQP;
class LogReceiver : public QObject class LogReceiver : public QObject
{ {
@ -21,21 +20,21 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void clientConnected() { void clientConnected() {
Exchange *exchange = m_client.createExchange("logs"); QAmqpExchange *exchange = m_client.createExchange("logs");
connect(exchange, SIGNAL(declared()), this, SLOT(exchangeDeclared())); connect(exchange, SIGNAL(declared()), this, SLOT(exchangeDeclared()));
exchange->declare(Exchange::FanOut); exchange->declare(QAmqpExchange::FanOut);
} }
void exchangeDeclared() { void exchangeDeclared() {
Queue *temporaryQueue = m_client.createQueue(); QAmqpQueue *temporaryQueue = m_client.createQueue();
connect(temporaryQueue, SIGNAL(declared()), this, SLOT(queueDeclared())); connect(temporaryQueue, SIGNAL(declared()), this, SLOT(queueDeclared()));
connect(temporaryQueue, SIGNAL(bound()), this, SLOT(queueBound())); connect(temporaryQueue, SIGNAL(bound()), this, SLOT(queueBound()));
connect(temporaryQueue, SIGNAL(messageReceived()), this, SLOT(messageReceived())); connect(temporaryQueue, SIGNAL(messageReceived()), this, SLOT(messageReceived()));
temporaryQueue->declare(Queue::Exclusive); temporaryQueue->declare(QAmqpQueue::Exclusive);
} }
void queueDeclared() { void queueDeclared() {
Queue *temporaryQueue = qobject_cast<Queue*>(sender()); QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
if (!temporaryQueue) if (!temporaryQueue)
return; return;
@ -43,25 +42,25 @@ private Q_SLOTS:
} }
void queueBound() { void queueBound() {
Queue *temporaryQueue = qobject_cast<Queue*>(sender()); QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
if (!temporaryQueue) if (!temporaryQueue)
return; return;
qDebug() << " [*] Waiting for logs. To exit press CTRL+C"; qDebug() << " [*] Waiting for logs. To exit press CTRL+C";
temporaryQueue->consume(Queue::coNoAck); temporaryQueue->consume(QAmqpQueue::coNoAck);
} }
void messageReceived() { void messageReceived() {
Queue *temporaryQueue = qobject_cast<Queue*>(sender()); QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
if (!temporaryQueue) if (!temporaryQueue)
return; return;
Message message = temporaryQueue->dequeue(); QAmqpMessage message = temporaryQueue->dequeue();
qDebug() << " [x] " << message.payload(); qDebug() << " [x] " << message.payload();
} }
private: private:
Client m_client; QAmqpClient m_client;
}; };

View File

@ -5,7 +5,6 @@
#include "qamqpclient.h" #include "qamqpclient.h"
#include "qamqpexchange.h" #include "qamqpexchange.h"
#include "qamqpqueue.h" #include "qamqpqueue.h"
using namespace QAMQP;
class DirectLogEmitter : public QObject class DirectLogEmitter : public QObject
{ {
@ -22,13 +21,13 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void clientConnected() { 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())); connect(direct_logs, SIGNAL(declared()), this, SLOT(exchangeDeclared()));
direct_logs->declare(Exchange::Direct); direct_logs->declare(QAmqpExchange::Direct);
} }
void exchangeDeclared() { void exchangeDeclared() {
Exchange *direct_logs = qobject_cast<Exchange*>(sender()); QAmqpExchange *direct_logs = qobject_cast<QAmqpExchange*>(sender());
if (!direct_logs) if (!direct_logs)
return; return;
@ -50,7 +49,7 @@ private Q_SLOTS:
} }
private: private:
Client m_client; QAmqpClient m_client;
}; };

View File

@ -5,7 +5,6 @@
#include "qamqpclient.h" #include "qamqpclient.h"
#include "qamqpexchange.h" #include "qamqpexchange.h"
#include "qamqpqueue.h" #include "qamqpqueue.h"
using namespace QAMQP;
class DirectLogReceiver : public QObject class DirectLogReceiver : public QObject
{ {
@ -22,25 +21,25 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void clientConnected() { void clientConnected() {
Exchange *exchange = m_client.createExchange("direct_logs"); QAmqpExchange *exchange = m_client.createExchange("direct_logs");
connect(exchange, SIGNAL(declared()), this, SLOT(exchangeDeclared())); connect(exchange, SIGNAL(declared()), this, SLOT(exchangeDeclared()));
exchange->declare(Exchange::Direct); exchange->declare(QAmqpExchange::Direct);
} }
void exchangeDeclared() { void exchangeDeclared() {
Queue *temporaryQueue = m_client.createQueue(); QAmqpQueue *temporaryQueue = m_client.createQueue();
connect(temporaryQueue, SIGNAL(declared()), this, SLOT(queueDeclared())); connect(temporaryQueue, SIGNAL(declared()), this, SLOT(queueDeclared()));
connect(temporaryQueue, SIGNAL(messageReceived()), this, SLOT(messageReceived())); connect(temporaryQueue, SIGNAL(messageReceived()), this, SLOT(messageReceived()));
temporaryQueue->declare(Queue::Exclusive); temporaryQueue->declare(QAmqpQueue::Exclusive);
} }
void queueDeclared() { void queueDeclared() {
Queue *temporaryQueue = qobject_cast<Queue*>(sender()); QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
if (!temporaryQueue) if (!temporaryQueue)
return; return;
// start consuming // start consuming
temporaryQueue->consume(Queue::coNoAck); temporaryQueue->consume(QAmqpQueue::coNoAck);
foreach (QString severity, m_severities) foreach (QString severity, m_severities)
temporaryQueue->bind("direct_logs", severity); temporaryQueue->bind("direct_logs", severity);
@ -48,16 +47,16 @@ private Q_SLOTS:
} }
void messageReceived() { void messageReceived() {
Queue *temporaryQueue = qobject_cast<Queue*>(sender()); QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
if (!temporaryQueue) if (!temporaryQueue)
return; return;
Message message = temporaryQueue->dequeue(); QAmqpMessage message = temporaryQueue->dequeue();
qDebug() << " [x] " << message.routingKey() << ":" << message.payload(); qDebug() << " [x] " << message.routingKey() << ":" << message.payload();
} }
private: private:
Client m_client; QAmqpClient m_client;
QStringList m_severities; QStringList m_severities;
}; };

View File

@ -5,7 +5,6 @@
#include "qamqpclient.h" #include "qamqpclient.h"
#include "qamqpexchange.h" #include "qamqpexchange.h"
#include "qamqpqueue.h" #include "qamqpqueue.h"
using namespace QAMQP;
class TopicLogEmitter : public QObject class TopicLogEmitter : public QObject
{ {
@ -22,13 +21,13 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void clientConnected() { 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())); connect(topic_logs, SIGNAL(declared()), this, SLOT(exchangeDeclared()));
topic_logs->declare(Exchange::Topic); topic_logs->declare(QAmqpExchange::Topic);
} }
void exchangeDeclared() { void exchangeDeclared() {
Exchange *topic_logs = qobject_cast<Exchange*>(sender()); QAmqpExchange *topic_logs = qobject_cast<QAmqpExchange*>(sender());
if (!topic_logs) if (!topic_logs)
return; return;
@ -50,7 +49,7 @@ private Q_SLOTS:
} }
private: private:
Client m_client; QAmqpClient m_client;
}; };

View File

@ -5,7 +5,6 @@
#include "qamqpclient.h" #include "qamqpclient.h"
#include "qamqpexchange.h" #include "qamqpexchange.h"
#include "qamqpqueue.h" #include "qamqpqueue.h"
using namespace QAMQP;
class TopicLogReceiver : public QObject class TopicLogReceiver : public QObject
{ {
@ -22,21 +21,21 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void clientConnected() { 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())); connect(topic_logs, SIGNAL(declared()), this, SLOT(exchangeDeclared()));
topic_logs->declare(Exchange::Topic); topic_logs->declare(QAmqpExchange::Topic);
} }
void exchangeDeclared() { void exchangeDeclared() {
Queue *temporaryQueue = m_client.createQueue(); QAmqpQueue *temporaryQueue = m_client.createQueue();
connect(temporaryQueue, SIGNAL(declared()), this, SLOT(queueDeclared())); connect(temporaryQueue, SIGNAL(declared()), this, SLOT(queueDeclared()));
connect(temporaryQueue, SIGNAL(bound()), this, SLOT(queueBound())); connect(temporaryQueue, SIGNAL(bound()), this, SLOT(queueBound()));
connect(temporaryQueue, SIGNAL(messageReceived()), this, SLOT(messageReceived())); connect(temporaryQueue, SIGNAL(messageReceived()), this, SLOT(messageReceived()));
temporaryQueue->declare(Queue::Exclusive); temporaryQueue->declare(QAmqpQueue::Exclusive);
} }
void queueDeclared() { void queueDeclared() {
Queue *temporaryQueue = qobject_cast<Queue*>(sender()); QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
if (!temporaryQueue) if (!temporaryQueue)
return; return;
@ -46,23 +45,23 @@ private Q_SLOTS:
} }
void queueBound() { void queueBound() {
Queue *temporaryQueue = qobject_cast<Queue*>(sender()); QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
if (!temporaryQueue) if (!temporaryQueue)
return; return;
temporaryQueue->consume(Queue::coNoAck); temporaryQueue->consume(QAmqpQueue::coNoAck);
} }
void messageReceived() { void messageReceived() {
Queue *temporaryQueue = qobject_cast<Queue*>(sender()); QAmqpQueue *temporaryQueue = qobject_cast<QAmqpQueue*>(sender());
if (!temporaryQueue) if (!temporaryQueue)
return; return;
Message message = temporaryQueue->dequeue(); QAmqpMessage message = temporaryQueue->dequeue();
qDebug() << " [x] " << message.routingKey() << ":" << message.payload(); qDebug() << " [x] " << message.routingKey() << ":" << message.payload();
} }
private: private:
Client m_client; QAmqpClient m_client;
QStringList m_bindingKeys; QStringList m_bindingKeys;
}; };

View File

@ -5,7 +5,6 @@
#include "qamqpclient.h" #include "qamqpclient.h"
#include "qamqpexchange.h" #include "qamqpexchange.h"
#include "qamqpqueue.h" #include "qamqpqueue.h"
using namespace QAMQP;
class TaskCreator : public QObject class TaskCreator : public QObject
{ {
@ -22,19 +21,19 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void clientConnected() { void clientConnected() {
Queue *queue = m_client.createQueue("task_queue"); QAmqpQueue *queue = m_client.createQueue("task_queue");
connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared())); connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared()));
queue->declare(); queue->declare();
} }
void queueDeclared() { void queueDeclared() {
Queue *queue = qobject_cast<Queue*>(sender()); QAmqpQueue *queue = qobject_cast<QAmqpQueue*>(sender());
if (!queue) if (!queue)
return; return;
Exchange *defaultExchange = m_client.createExchange(); QAmqpExchange *defaultExchange = m_client.createExchange();
Message::PropertyHash properties; QAmqpMessage::PropertyHash properties;
properties[Message::DeliveryMode] = "2"; // make message persistent properties[QAmqpMessage::DeliveryMode] = "2"; // make message persistent
QString message; QString message;
if (qApp->arguments().size() < 2) if (qApp->arguments().size() < 2)
@ -48,7 +47,7 @@ private Q_SLOTS:
} }
private: private:
Client m_client; QAmqpClient m_client;
}; };

View File

@ -4,7 +4,6 @@
#include "qamqpclient.h" #include "qamqpclient.h"
#include "qamqpqueue.h" #include "qamqpqueue.h"
using namespace QAMQP;
class Worker : public QObject class Worker : public QObject
{ {
@ -46,9 +45,9 @@ private Q_SLOTS:
} }
private: private:
Client m_client; QAmqpClient m_client;
Queue *m_queue; QAmqpQueue *m_queue;
Message m_currentMessage; QAmqpMessage m_currentMessage;
}; };