use Q_Q/Q_D from Qt rather than P_Q/P_D, style cleanups for Qt coding style
delete exception-related code, as Qt does not officially support them anymore
This commit is contained in:
parent
387af4038e
commit
c069b063d3
|
|
@ -1,386 +1,380 @@
|
||||||
#include "amqp.h"
|
#include "amqp.h"
|
||||||
#include "amqp_p.h"
|
#include "amqp_p.h"
|
||||||
|
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include "amqp_exchange.h"
|
#include "amqp_exchange.h"
|
||||||
#include "amqp_exchange_p.h"
|
#include "amqp_exchange_p.h"
|
||||||
#include "amqp_queue.h"
|
#include "amqp_queue.h"
|
||||||
#include "amqp_queue_p.h"
|
#include "amqp_queue_p.h"
|
||||||
#include "amqp_authenticator.h"
|
#include "amqp_connection_p.h"
|
||||||
|
#include "amqp_authenticator.h"
|
||||||
using namespace QAMQP;
|
|
||||||
|
using namespace QAMQP;
|
||||||
namespace QAMQP
|
|
||||||
{
|
namespace QAMQP
|
||||||
struct ClientExceptionCleaner
|
{
|
||||||
{
|
struct ClientExceptionCleaner
|
||||||
/* this cleans up when the constructor throws an exception */
|
{
|
||||||
static inline void cleanup(Client *that, ClientPrivate *d)
|
/* this cleans up when the constructor throws an exception */
|
||||||
{
|
static inline void cleanup(Client *that, ClientPrivate *d)
|
||||||
#ifdef QT_NO_EXCEPTIONS
|
{
|
||||||
Q_UNUSED(that);
|
#ifdef QT_NO_EXCEPTIONS
|
||||||
Q_UNUSED(d);
|
Q_UNUSED(that);
|
||||||
#else
|
Q_UNUSED(d);
|
||||||
Q_UNUSED(that);
|
#else
|
||||||
Q_UNUSED(d);
|
Q_UNUSED(that);
|
||||||
#endif
|
Q_UNUSED(d);
|
||||||
}
|
#endif
|
||||||
};
|
}
|
||||||
}
|
};
|
||||||
|
}
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
ClientPrivate::ClientPrivate( Client * q ) :
|
|
||||||
port(AMQPPORT)
|
ClientPrivate::ClientPrivate(Client * q)
|
||||||
, host(QString::fromLatin1(AMQPHOST))
|
: port(AMQPPORT),
|
||||||
, virtualHost(QString::fromLatin1(AMQPVHOST))
|
host(QString::fromLatin1(AMQPHOST)),
|
||||||
, pq_ptr(q)
|
virtualHost(QString::fromLatin1(AMQPVHOST)),
|
||||||
{
|
q_ptr(q)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClientPrivate::~ClientPrivate()
|
||||||
ClientPrivate::~ClientPrivate()
|
{
|
||||||
{
|
}
|
||||||
|
|
||||||
}
|
void ClientPrivate::init(QObject *parent)
|
||||||
|
{
|
||||||
void ClientPrivate::init(QObject * parent)
|
Q_Q(QAMQP::Client);
|
||||||
{
|
q->setParent(parent);
|
||||||
pq_func()->setParent(parent);
|
if (!network_)
|
||||||
if(!network_)
|
network_ = new QAMQP::Network(q);
|
||||||
{
|
|
||||||
network_ = new QAMQP::Network(pq_func());
|
if (!connection_)
|
||||||
}
|
connection_ = new QAMQP::Connection(q);
|
||||||
|
network_->setMethodHandlerConnection(connection_);
|
||||||
if(!connection_)
|
|
||||||
{
|
setAuth(new AMQPlainAuthenticator(QString::fromLatin1(AMQPLOGIN), QString::fromLatin1(AMQPPSWD)));
|
||||||
connection_ = new QAMQP::Connection(pq_func());
|
|
||||||
}
|
QObject::connect(connection_, SIGNAL(connected()), q, SIGNAL(connected()));
|
||||||
|
QObject::connect(connection_, SIGNAL(disconnected()), q, SIGNAL(disconnected()));
|
||||||
network_->setMethodHandlerConnection(connection_);
|
}
|
||||||
|
|
||||||
setAuth(new AMQPlainAuthenticator(QString::fromLatin1(AMQPLOGIN), QString::fromLatin1(AMQPPSWD)));
|
void ClientPrivate::init(QObject *parent, const QUrl &connectionString)
|
||||||
|
{
|
||||||
QObject::connect(connection_, SIGNAL(connected()), pq_func(), SIGNAL(connected()));
|
init(parent);
|
||||||
QObject::connect(connection_, SIGNAL(disconnected()), pq_func(), SIGNAL(disconnected()));
|
parseConnectionString(connectionString);
|
||||||
}
|
connect();
|
||||||
|
}
|
||||||
void ClientPrivate::init(QObject * parent, const QUrl & con)
|
|
||||||
{
|
void ClientPrivate::setAuth(Authenticator *auth)
|
||||||
init(parent);
|
{
|
||||||
parseCnnString(con);
|
auth_ = QSharedPointer<Authenticator>(auth);
|
||||||
ClientPrivate::connect();
|
}
|
||||||
}
|
|
||||||
|
void ClientPrivate::printConnect() const
|
||||||
|
{
|
||||||
void ClientPrivate::setAuth( Authenticator* auth )
|
QTextStream stream(stdout);
|
||||||
{
|
stream << "port = " << port << endl;
|
||||||
auth_ = QSharedPointer<Authenticator>(auth);
|
stream << "host = " << host << endl;
|
||||||
}
|
stream << "vhost = " << virtualHost << endl;
|
||||||
|
|
||||||
|
if (auth_ && auth_->type() == QLatin1String("AMQPLAIN")) {
|
||||||
void ClientPrivate::printConnect() const
|
QSharedPointer<AMQPlainAuthenticator> a = auth_.staticCast<AMQPlainAuthenticator>();
|
||||||
{
|
stream << "user = " << a->login() << endl;
|
||||||
QTextStream stream(stdout);
|
stream << "passw = " << a->password() << endl;
|
||||||
stream << "port = " << port << endl;
|
}
|
||||||
stream << "host = " << host << endl;
|
}
|
||||||
stream << "vhost = " << virtualHost << endl;
|
|
||||||
|
void ClientPrivate::connect()
|
||||||
if(auth_ && auth_->type() == "AMQPLAIN")
|
{
|
||||||
{
|
sockConnect();
|
||||||
QSharedPointer<AMQPlainAuthenticator> a = auth_.staticCast<AMQPlainAuthenticator>();
|
login();
|
||||||
stream << "user = " << a->login() << endl;
|
}
|
||||||
stream << "passw = " << a->password() << endl;
|
|
||||||
}
|
void ClientPrivate::parseConnectionString(const QUrl &connectionString)
|
||||||
|
{
|
||||||
}
|
Q_Q(QAMQP::Client);
|
||||||
|
if (connectionString.scheme() != AMQPSCHEME &&
|
||||||
void ClientPrivate::connect()
|
connectionString.scheme() != AMQPSSCHEME) {
|
||||||
{
|
qDebug() << Q_FUNC_INFO << "invalid scheme: " << connectionString.scheme();
|
||||||
ClientPrivate::sockConnect();
|
return;
|
||||||
ClientPrivate::login();
|
}
|
||||||
}
|
|
||||||
|
q->setSsl(connectionString.scheme() == AMQPSSCHEME);
|
||||||
void ClientPrivate::parseCnnString( const QUrl & con )
|
q->setPassword(connectionString.password());
|
||||||
{
|
q->setUser(connectionString.userName());
|
||||||
P_Q(QAMQP::Client);
|
q->setPort(connectionString.port(AMQPPORT));
|
||||||
if(con.scheme() == AMQPSCHEME || con.scheme() == AMQPSSCHEME )
|
q->setHost(connectionString.host());
|
||||||
{
|
q->setVirtualHost(connectionString.path());
|
||||||
q->setSsl(con.scheme() == AMQPSSCHEME);
|
}
|
||||||
q->setPassword(con.password());
|
|
||||||
q->setUser(con.userName());
|
void ClientPrivate::sockConnect()
|
||||||
q->setPort(con.port(AMQPPORT));
|
{
|
||||||
q->setHost(con.host());
|
if (network_->state() != QAbstractSocket::UnconnectedState)
|
||||||
q->setVirtualHost(con.path());
|
disconnect();
|
||||||
}
|
network_->connectTo(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPrivate::sockConnect()
|
void ClientPrivate::login()
|
||||||
{
|
{
|
||||||
if(network_->state() != QAbstractSocket::UnconnectedState )
|
}
|
||||||
{
|
|
||||||
disconnect();
|
Exchange *ClientPrivate::createExchange(int channelNumber, const QString &name)
|
||||||
}
|
{
|
||||||
network_->connectTo(host, port);
|
Q_Q(QAMQP::Client);
|
||||||
}
|
Exchange * exchange_ = new Exchange(channelNumber, q);
|
||||||
|
|
||||||
void ClientPrivate::login()
|
network_->addMethodHandlerForChannel(exchange_->channelNumber(), exchange_);
|
||||||
{
|
|
||||||
|
QObject::connect(connection_, SIGNAL(connected()), exchange_, SLOT(_q_open()));
|
||||||
}
|
exchange_->d_func()->open();
|
||||||
|
QObject::connect(q, SIGNAL(disconnected()), exchange_, SLOT(_q_disconnected()));
|
||||||
Exchange * ClientPrivate::createExchange(int channelNumber, const QString &name )
|
exchange_->setName(name);
|
||||||
{
|
|
||||||
Exchange * exchange_ = new Exchange(channelNumber, pq_func());
|
return exchange_;
|
||||||
|
}
|
||||||
network_->addMethodHandlerForChannel(exchange_->channelNumber(), exchange_);
|
|
||||||
|
Queue *ClientPrivate::createQueue(int channelNumber, const QString &name )
|
||||||
QObject::connect(connection_, SIGNAL(connected()), exchange_, SLOT(_q_open()));
|
{
|
||||||
exchange_->pd_func()->open();
|
Q_Q(QAMQP::Client);
|
||||||
QObject::connect(pq_func(), SIGNAL(disconnected()), exchange_, SLOT(_q_disconnected()));
|
Queue *queue_ = new Queue(channelNumber, q);
|
||||||
exchange_->setName(name);
|
|
||||||
|
network_->addMethodHandlerForChannel(queue_->channelNumber(), queue_);
|
||||||
return exchange_;
|
network_->addContentHandlerForChannel(queue_->channelNumber(), queue_);
|
||||||
}
|
network_->addContentBodyHandlerForChannel(queue_->channelNumber(), queue_);
|
||||||
|
|
||||||
Queue * ClientPrivate::createQueue(int channelNumber, const QString &name )
|
QObject::connect(connection_, SIGNAL(connected()), queue_, SLOT(_q_open()));
|
||||||
{
|
queue_->d_func()->open();
|
||||||
Queue * queue_ = new Queue(channelNumber, pq_func());
|
QObject::connect(q, SIGNAL(disconnected()), queue_, SLOT(_q_disconnected()));
|
||||||
|
queue_->setName(name);
|
||||||
network_->addMethodHandlerForChannel(queue_->channelNumber(), queue_);
|
|
||||||
network_->addContentHandlerForChannel(queue_->channelNumber(), queue_);
|
return queue_;
|
||||||
network_->addContentBodyHandlerForChannel(queue_->channelNumber(), queue_);
|
}
|
||||||
|
|
||||||
QObject::connect(connection_, SIGNAL(connected()), queue_, SLOT(_q_open()));
|
void ClientPrivate::disconnect()
|
||||||
queue_->pd_func()->open();
|
{
|
||||||
QObject::connect(pq_func(), SIGNAL(disconnected()), queue_, SLOT(_q_disconnected()));
|
Q_Q(QAMQP::Client);
|
||||||
queue_->setName(name);
|
if (network_->state() != QAbstractSocket::UnconnectedState) {
|
||||||
|
network_->disconnect();
|
||||||
return queue_;
|
connection_->d_func()->connected = false;
|
||||||
}
|
Q_EMIT q->disconnected();
|
||||||
|
}
|
||||||
|
}
|
||||||
void ClientPrivate::disconnect()
|
|
||||||
{
|
//////////////////////////////////////////////////////////////////////////
|
||||||
P_Q(QAMQP::Client);
|
|
||||||
Q_UNUSED(q);
|
QAMQP::Client::Client(QObject *parent)
|
||||||
if(network_->state() != QAbstractSocket::UnconnectedState)
|
: QObject(parent),
|
||||||
{
|
d_ptr(new ClientPrivate(this))
|
||||||
network_->QAMQP::Network::disconnect();
|
{
|
||||||
connection_->pd_func()->connected = false;
|
d_ptr->init(parent);
|
||||||
emit pq_func()->disconnected();
|
}
|
||||||
}
|
|
||||||
}
|
QAMQP::Client::Client(const QUrl & connectionString, QObject * parent)
|
||||||
|
: d_ptr(new ClientPrivate(this))
|
||||||
|
{
|
||||||
//////////////////////////////////////////////////////////////////////////
|
d_ptr->init(parent, connectionString);
|
||||||
|
}
|
||||||
|
|
||||||
QAMQP::Client::Client( QObject * parent /*= 0*/ )
|
QAMQP::Client::~Client()
|
||||||
: pd_ptr(new ClientPrivate(this))
|
{
|
||||||
{
|
}
|
||||||
QT_TRY {
|
|
||||||
pd_func()->init(parent);
|
quint16 QAMQP::Client::port() const
|
||||||
} QT_CATCH(...) {
|
{
|
||||||
ClientExceptionCleaner::cleanup(this, pd_func());
|
Q_D(const QAMQP::Client);
|
||||||
QT_RETHROW;
|
return d->port;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void QAMQP::Client::setPort(quint16 port)
|
||||||
QAMQP::Client::Client( const QUrl & connectionString, QObject * parent /*= 0*/ )
|
{
|
||||||
: pd_ptr(new ClientPrivate(this))
|
Q_D(QAMQP::Client);
|
||||||
{
|
d->port = port;
|
||||||
QT_TRY {
|
}
|
||||||
pd_func()->init(parent, connectionString);
|
|
||||||
} QT_CATCH(...) {
|
QString QAMQP::Client::host() const
|
||||||
ClientExceptionCleaner::cleanup(this, pd_func());
|
{
|
||||||
QT_RETHROW;
|
Q_D(const QAMQP::Client);
|
||||||
}
|
return d->host;
|
||||||
}
|
}
|
||||||
|
|
||||||
QAMQP::Client::~Client()
|
void QAMQP::Client::setHost( const QString & host )
|
||||||
{
|
{
|
||||||
QT_TRY {
|
Q_D(QAMQP::Client);
|
||||||
QEvent e(QEvent::Destroy);
|
d->host = host;
|
||||||
QCoreApplication::sendEvent(this, &e);
|
}
|
||||||
} QT_CATCH(const std::exception&) {
|
|
||||||
// if this fails we can't do anything about it but at least we are not allowed to throw.
|
QString QAMQP::Client::virtualHost() const
|
||||||
}
|
{
|
||||||
}
|
Q_D(const QAMQP::Client);
|
||||||
|
return d->virtualHost;
|
||||||
quint32 QAMQP::Client::port() const
|
}
|
||||||
{
|
|
||||||
return pd_func()->port;
|
void QAMQP::Client::setVirtualHost(const QString &virtualHost)
|
||||||
}
|
{
|
||||||
|
Q_D(QAMQP::Client);
|
||||||
void QAMQP::Client::setPort( quint32 port )
|
d->virtualHost = virtualHost;
|
||||||
{
|
}
|
||||||
pd_func()->port = port;
|
|
||||||
}
|
QString QAMQP::Client::user() const
|
||||||
|
{
|
||||||
QString QAMQP::Client::host() const
|
Q_D(const QAMQP::Client);
|
||||||
{
|
const Authenticator * auth = d->auth_.data();
|
||||||
return pd_func()->host;
|
if (auth && auth->type() == QLatin1String("AMQPLAIN")) {
|
||||||
}
|
const AMQPlainAuthenticator * a = static_cast<const AMQPlainAuthenticator *>(auth);
|
||||||
|
return a->login();
|
||||||
void QAMQP::Client::setHost( const QString & host )
|
}
|
||||||
{
|
|
||||||
pd_func()->host = host;
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QAMQP::Client::virtualHost() const
|
void QAMQP::Client::setUser(const QString &user)
|
||||||
{
|
{
|
||||||
return pd_func()->virtualHost;
|
Q_D(const QAMQP::Client);
|
||||||
}
|
Authenticator * auth = d->auth_.data();
|
||||||
|
if (auth && auth->type() == QLatin1String("AMQPLAIN")) {
|
||||||
void QAMQP::Client::setVirtualHost( const QString & virtualHost )
|
AMQPlainAuthenticator * a = static_cast<AMQPlainAuthenticator *>(auth);
|
||||||
{
|
a->setLogin(user);
|
||||||
pd_func()->virtualHost = virtualHost;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QAMQP::Client::user() const
|
QString QAMQP::Client::password() const
|
||||||
{
|
{
|
||||||
const Authenticator * auth = pd_func()->auth_.data();
|
Q_D(const QAMQP::Client);
|
||||||
|
const Authenticator * auth = d->auth_.data();
|
||||||
if(auth && auth->type() == "AMQPLAIN")
|
if (auth && auth->type() == "AMQPLAIN") {
|
||||||
{
|
const AMQPlainAuthenticator * a = static_cast<const AMQPlainAuthenticator *>(auth);
|
||||||
const AMQPlainAuthenticator * a = static_cast<const AMQPlainAuthenticator *>(auth);
|
return a->password();
|
||||||
return a->login();
|
}
|
||||||
}
|
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QAMQP::Client::setUser( const QString & user )
|
void QAMQP::Client::setPassword(const QString &password)
|
||||||
{
|
{
|
||||||
Authenticator * auth = pd_func()->auth_.data();
|
Q_D(QAMQP::Client);
|
||||||
|
Authenticator *auth = d->auth_.data();
|
||||||
if(auth && auth->type() == "AMQPLAIN")
|
if (auth && auth->type() == QLatin1String("AMQPLAIN")) {
|
||||||
{
|
AMQPlainAuthenticator * a = static_cast<AMQPlainAuthenticator *>(auth);
|
||||||
AMQPlainAuthenticator * a = static_cast<AMQPlainAuthenticator *>(auth);
|
a->setPassword(password);
|
||||||
a->setLogin(user);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void QAMQP::Client::printConnect() const
|
||||||
QString QAMQP::Client::password() const
|
{
|
||||||
{
|
#ifdef _DEBUG
|
||||||
const Authenticator * auth = pd_func()->auth_.data();
|
Q_D(const QAMQP::Client);
|
||||||
|
d->printConnect();
|
||||||
if(auth && auth->type() == "AMQPLAIN")
|
#endif // _DEBUG
|
||||||
{
|
}
|
||||||
const AMQPlainAuthenticator * a = static_cast<const AMQPlainAuthenticator *>(auth);
|
|
||||||
return a->password();
|
void QAMQP::Client::closeChannel()
|
||||||
}
|
{
|
||||||
return QString();
|
}
|
||||||
}
|
|
||||||
|
Exchange *QAMQP::Client::createExchange(int channelNumber)
|
||||||
void QAMQP::Client::setPassword( const QString & password )
|
{
|
||||||
{
|
Q_D(QAMQP::Client);
|
||||||
Authenticator * auth = pd_func()->auth_.data();
|
return d->createExchange(channelNumber, QString());
|
||||||
|
}
|
||||||
if(auth && auth->type() == "AMQPLAIN")
|
|
||||||
{
|
Exchange *QAMQP::Client::createExchange( const QString &name, int channelNumber )
|
||||||
AMQPlainAuthenticator * a = static_cast<AMQPlainAuthenticator *>(auth);
|
{
|
||||||
a->setPassword(password);
|
Q_D(QAMQP::Client);
|
||||||
}
|
return d->createExchange(channelNumber, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QAMQP::Client::printConnect() const
|
Queue *QAMQP::Client::createQueue(int channelNumber)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
Q_D(QAMQP::Client);
|
||||||
pd_func()->printConnect();
|
return d->createQueue(channelNumber, QString());
|
||||||
#endif // _DEBUG
|
}
|
||||||
}
|
|
||||||
|
Queue *QAMQP::Client::createQueue( const QString &name, int channelNumber )
|
||||||
void QAMQP::Client::closeChannel()
|
{
|
||||||
{
|
Q_D(QAMQP::Client);
|
||||||
|
return d->createQueue(channelNumber, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Exchange * QAMQP::Client::createExchange(int channelNumber)
|
void QAMQP::Client::open()
|
||||||
{
|
{
|
||||||
return pd_func()->createExchange(channelNumber, QString());
|
Q_D(QAMQP::Client);
|
||||||
}
|
return d->connect();
|
||||||
|
}
|
||||||
Exchange * QAMQP::Client::createExchange( const QString &name, int channelNumber )
|
|
||||||
{
|
void QAMQP::Client::open(const QUrl &connectionString)
|
||||||
return pd_func()->createExchange(channelNumber, name);
|
{
|
||||||
}
|
Q_D(QAMQP::Client);
|
||||||
|
d->parseConnectionString(connectionString);
|
||||||
Queue * QAMQP::Client::createQueue(int channelNumber)
|
open();
|
||||||
{
|
}
|
||||||
return pd_func()->createQueue(channelNumber, QString());
|
|
||||||
}
|
void QAMQP::Client::close()
|
||||||
|
{
|
||||||
Queue * QAMQP::Client::createQueue( const QString &name, int channelNumber )
|
Q_D(QAMQP::Client);
|
||||||
{
|
return d->disconnect();
|
||||||
return pd_func()->createQueue(channelNumber, name);
|
}
|
||||||
}
|
|
||||||
|
void QAMQP::Client::reopen()
|
||||||
void QAMQP::Client::open()
|
{
|
||||||
{
|
Q_D(QAMQP::Client);
|
||||||
return pd_func()->connect();
|
d->disconnect();
|
||||||
}
|
d->connect();
|
||||||
|
}
|
||||||
void QAMQP::Client::open( const QUrl & connectionString )
|
|
||||||
{
|
void QAMQP::Client::setAuth(Authenticator *auth)
|
||||||
pd_func()->parseCnnString(connectionString);
|
{
|
||||||
open();
|
Q_D(QAMQP::Client);
|
||||||
}
|
d->setAuth(auth);
|
||||||
|
}
|
||||||
void QAMQP::Client::close()
|
|
||||||
{
|
Authenticator *QAMQP::Client::auth() const
|
||||||
return pd_func()->disconnect();
|
{
|
||||||
}
|
Q_D(const QAMQP::Client);
|
||||||
|
return d->auth_.data();
|
||||||
void QAMQP::Client::reopen()
|
}
|
||||||
{
|
|
||||||
pd_func()->disconnect();
|
bool QAMQP::Client::isSsl() const
|
||||||
pd_func()->connect();
|
{
|
||||||
}
|
Q_D(const QAMQP::Client);
|
||||||
|
return d->network_->isSsl();
|
||||||
void QAMQP::Client::setAuth( Authenticator * auth )
|
}
|
||||||
{
|
|
||||||
pd_func()->setAuth(auth);
|
void QAMQP::Client::setSsl(bool value)
|
||||||
}
|
{
|
||||||
|
Q_D(QAMQP::Client);
|
||||||
Authenticator * QAMQP::Client::auth() const
|
d->network_->setSsl(value);
|
||||||
{
|
}
|
||||||
return pd_func()->auth_.data();
|
|
||||||
}
|
bool QAMQP::Client::autoReconnect() const
|
||||||
|
{
|
||||||
bool QAMQP::Client::isSsl() const
|
Q_D(const QAMQP::Client);
|
||||||
{
|
return d->network_->autoReconnect();
|
||||||
return pd_func()->network_->isSsl();
|
}
|
||||||
}
|
|
||||||
|
void QAMQP::Client::setAutoReconnect(bool value)
|
||||||
void QAMQP::Client::setSsl( bool value )
|
{
|
||||||
{
|
Q_D(QAMQP::Client);
|
||||||
pd_func()->network_->setSsl(value);
|
d->network_->setAutoReconnect(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QAMQP::Client::autoReconnect() const
|
bool QAMQP::Client::isConnected() const
|
||||||
{
|
{
|
||||||
return pd_func()->network_->autoReconnect();
|
Q_D(const QAMQP::Client);
|
||||||
}
|
return d->connection_->isConnected();
|
||||||
|
}
|
||||||
void QAMQP::Client::setAutoReconnect( bool value )
|
|
||||||
{
|
void QAMQP::Client::addCustomProperty(const QString &name, const QString &value)
|
||||||
pd_func()->network_->setAutoReconnect(value);
|
{
|
||||||
}
|
Q_D(QAMQP::Client);
|
||||||
|
return d->connection_->addCustomProperty(name, value);
|
||||||
bool QAMQP::Client::isConnected() const
|
}
|
||||||
{
|
|
||||||
return pd_func()->connection_->isConnected();
|
QString QAMQP::Client::customProperty(const QString &name) const
|
||||||
}
|
{
|
||||||
|
Q_D(const QAMQP::Client);
|
||||||
void QAMQP::Client::addCustomProperty( const QString & name, const QString & value )
|
return d->connection_->customProperty(name);
|
||||||
{
|
}
|
||||||
return pd_func()->connection_->addCustomProperty(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QAMQP::Client::customProperty( const QString & name ) const
|
|
||||||
{
|
|
||||||
return pd_func()->connection_->customProperty(name);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
190
src/qamqp/amqp.h
190
src/qamqp/amqp.h
|
|
@ -1,97 +1,93 @@
|
||||||
#ifndef qamqp_amqp_h__
|
#ifndef QAMQP_H
|
||||||
#define qamqp_amqp_h__
|
#define QAMQP_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include "amqp_global.h"
|
|
||||||
|
#include "amqp_global.h"
|
||||||
namespace QAMQP
|
|
||||||
{
|
namespace QAMQP
|
||||||
class Exchange;
|
{
|
||||||
class Queue;
|
|
||||||
class ClientPrivate;
|
class Exchange;
|
||||||
class Authenticator;
|
class Queue;
|
||||||
class ConnectionPrivate;
|
class ClientPrivate;
|
||||||
class Client : public QObject
|
class Authenticator;
|
||||||
{
|
class ConnectionPrivate;
|
||||||
Q_OBJECT
|
class Client : public QObject
|
||||||
|
{
|
||||||
Q_PROPERTY(quint32 port READ port WRITE setPort);
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString host READ host WRITE setHost);
|
Q_PROPERTY(quint32 port READ port WRITE setPort)
|
||||||
Q_PROPERTY(QString virtualHost READ virtualHost WRITE setVirtualHost);
|
Q_PROPERTY(QString host READ host WRITE setHost)
|
||||||
Q_PROPERTY(QString user READ user WRITE setUser);
|
Q_PROPERTY(QString virtualHost READ virtualHost WRITE setVirtualHost)
|
||||||
Q_PROPERTY(QString password READ password WRITE setPassword);
|
Q_PROPERTY(QString user READ user WRITE setUser)
|
||||||
Q_PROPERTY(bool ssl READ isSsl WRITE setSsl);
|
Q_PROPERTY(QString password READ password WRITE setPassword)
|
||||||
Q_PROPERTY(bool autoReconnect READ autoReconnect WRITE setAutoReconnect);
|
Q_PROPERTY(bool ssl READ isSsl WRITE setSsl)
|
||||||
Q_PROPERTY(bool connected READ isConnected );
|
Q_PROPERTY(bool autoReconnect READ autoReconnect WRITE setAutoReconnect)
|
||||||
|
Q_PROPERTY(bool connected READ isConnected )
|
||||||
Q_DISABLE_COPY(Client)
|
|
||||||
|
public:
|
||||||
P_DECLARE_PRIVATE(QAMQP::Client)
|
Client(QObject *parent = 0);
|
||||||
|
Client(const QUrl &connectionString, QObject *parent = 0);
|
||||||
friend class ConnectionPrivate;
|
~Client();
|
||||||
friend class ChannelPrivate;
|
|
||||||
|
void printConnect() const;
|
||||||
public:
|
void closeChannel();
|
||||||
Client(QObject * parent = 0);
|
|
||||||
Client(const QUrl & connectionString, QObject * parent = 0);
|
void addCustomProperty(const QString &name, const QString &value);
|
||||||
~Client();
|
QString customProperty(const QString &name) const;
|
||||||
|
|
||||||
void printConnect() const;
|
Exchange *createExchange(int channelNumber = -1);
|
||||||
void closeChannel();
|
Exchange *createExchange(const QString &name, int channelNumber = -1);
|
||||||
|
|
||||||
void addCustomProperty(const QString & name, const QString & value);
|
Queue *createQueue(int channelNumber = -1);
|
||||||
QString customProperty(const QString & name) const;
|
Queue *createQueue(const QString &name, int channelNumber = -1);
|
||||||
|
|
||||||
Exchange * createExchange(int channelNumber = -1);
|
quint16 port() const;
|
||||||
Exchange * createExchange(const QString &name, int channelNumber = -1);
|
void setPort(quint16 port);
|
||||||
|
|
||||||
Queue * createQueue(int channelNumber = -1);
|
QString host() const;
|
||||||
Queue * createQueue(const QString &name, int channelNumber = -1);
|
void setHost(const QString &host);
|
||||||
|
|
||||||
quint32 port() const;
|
QString virtualHost() const;
|
||||||
void setPort(quint32 port);
|
void setVirtualHost(const QString &virtualHost);
|
||||||
|
|
||||||
QString host() const;
|
QString user() const;
|
||||||
void setHost(const QString & host);
|
void setUser(const QString &user);
|
||||||
|
|
||||||
QString virtualHost() const;
|
QString password() const;
|
||||||
void setVirtualHost(const QString & virtualHost);
|
void setPassword(const QString &password);
|
||||||
|
|
||||||
QString user() const;
|
void setAuth(Authenticator *auth);
|
||||||
void setUser(const QString & user);
|
Authenticator *auth() const;
|
||||||
|
|
||||||
QString password() const;
|
void open();
|
||||||
void setPassword(const QString & password);
|
void open(const QUrl &connectionString);
|
||||||
|
void close();
|
||||||
void setAuth(Authenticator * auth);
|
void reopen();
|
||||||
Authenticator * auth() const;
|
|
||||||
void open();
|
bool isSsl() const;
|
||||||
void open(const QUrl & connectionString);
|
void setSsl(bool value);
|
||||||
void close();
|
|
||||||
void reopen();
|
bool autoReconnect() const;
|
||||||
|
void setAutoReconnect(bool value);
|
||||||
bool isSsl() const;
|
|
||||||
void setSsl(bool value);
|
bool isConnected() const;
|
||||||
|
|
||||||
bool autoReconnect() const;
|
signals:
|
||||||
void setAutoReconnect(bool value);
|
void connected();
|
||||||
|
void disconnected();
|
||||||
bool isConnected() const;
|
|
||||||
|
private:
|
||||||
signals:
|
Q_DISABLE_COPY(Client)
|
||||||
void connected();
|
Q_DECLARE_PRIVATE(QAMQP::Client)
|
||||||
void disconnected();
|
QScopedPointer<ClientPrivate> d_ptr;
|
||||||
|
|
||||||
|
friend class ConnectionPrivate;
|
||||||
protected:
|
friend class ChannelPrivate;
|
||||||
ClientPrivate * const pd_ptr;
|
friend struct ClientExceptionCleaner;
|
||||||
|
};
|
||||||
private:
|
|
||||||
friend struct ClientExceptionCleaner;
|
} // namespace QAMQP
|
||||||
|
|
||||||
//void chanalConnect();
|
#endif // QAMQP
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // qamqp_amqp_h__
|
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,48 @@
|
||||||
#include "amqp_authenticator.h"
|
#include "amqp_authenticator.h"
|
||||||
#include "amqp_frame.h"
|
#include "amqp_frame.h"
|
||||||
|
|
||||||
QString QAMQP::AMQPlainAuthenticator::login() const
|
using namespace QAMQP;
|
||||||
{
|
|
||||||
return login_;
|
AMQPlainAuthenticator::AMQPlainAuthenticator(const QString &l, const QString &p)
|
||||||
}
|
: login_(l),
|
||||||
|
password_(p)
|
||||||
QString QAMQP::AMQPlainAuthenticator::password() const
|
{
|
||||||
{
|
}
|
||||||
return password_;
|
|
||||||
}
|
AMQPlainAuthenticator::~AMQPlainAuthenticator()
|
||||||
|
{
|
||||||
QAMQP::AMQPlainAuthenticator::AMQPlainAuthenticator( const QString & l /*= QString()*/, const QString & p /*= QString()*/ )
|
}
|
||||||
{
|
|
||||||
login_ = l;
|
QString AMQPlainAuthenticator::login() const
|
||||||
password_ = p;
|
{
|
||||||
}
|
return login_;
|
||||||
|
}
|
||||||
QAMQP::AMQPlainAuthenticator::~AMQPlainAuthenticator()
|
|
||||||
{
|
QString AMQPlainAuthenticator::password() const
|
||||||
|
{
|
||||||
}
|
return password_;
|
||||||
|
}
|
||||||
QString QAMQP::AMQPlainAuthenticator::type() const
|
|
||||||
{
|
QString AMQPlainAuthenticator::type() const
|
||||||
return "AMQPLAIN";
|
{
|
||||||
}
|
return "AMQPLAIN";
|
||||||
|
}
|
||||||
void QAMQP::AMQPlainAuthenticator::setLogin( const QString& l )
|
|
||||||
{
|
void AMQPlainAuthenticator::setLogin(const QString &l)
|
||||||
login_ = l;
|
{
|
||||||
}
|
login_ = l;
|
||||||
|
}
|
||||||
void QAMQP::AMQPlainAuthenticator::setPassword( const QString &p )
|
|
||||||
{
|
void AMQPlainAuthenticator::setPassword(const QString &p)
|
||||||
password_ = p;
|
{
|
||||||
}
|
password_ = p;
|
||||||
|
}
|
||||||
void QAMQP::AMQPlainAuthenticator::write( QDataStream & out )
|
|
||||||
{
|
void AMQPlainAuthenticator::write(QDataStream &out)
|
||||||
QAMQP::Frame::writeField('s', out, type());
|
{
|
||||||
QAMQP::Frame::TableField response;
|
QAMQP::Frame::writeField('s', out, type());
|
||||||
response["LOGIN"] = login_;
|
QAMQP::Frame::TableField response;
|
||||||
response["PASSWORD"] = password_;
|
response["LOGIN"] = login_;
|
||||||
QAMQP::Frame::serialize(out, response);
|
response["PASSWORD"] = password_;
|
||||||
}
|
QAMQP::Frame::serialize(out, response);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,42 @@
|
||||||
#ifndef amqp_authenticator_h__
|
#ifndef amqp_authenticator_h__
|
||||||
#define amqp_authenticator_h__
|
#define amqp_authenticator_h__
|
||||||
|
|
||||||
#include "amqp_global.h"
|
#include <QString>
|
||||||
#include <QString>
|
#include <QDataStream>
|
||||||
#include <QDataStream>
|
|
||||||
|
#include "amqp_global.h"
|
||||||
namespace QAMQP
|
|
||||||
{
|
namespace QAMQP
|
||||||
class Authenticator
|
{
|
||||||
{
|
|
||||||
public:
|
class Authenticator
|
||||||
virtual ~Authenticator(){};
|
{
|
||||||
virtual QString type() const = 0;
|
public:
|
||||||
virtual void write(QDataStream & out) = 0;
|
virtual ~Authenticator() {}
|
||||||
};
|
virtual QString type() const = 0;
|
||||||
|
virtual void write(QDataStream &out) = 0;
|
||||||
class AMQPlainAuthenticator : public Authenticator
|
};
|
||||||
{
|
|
||||||
QString login_, password_;
|
class AMQPlainAuthenticator : public Authenticator
|
||||||
public:
|
{
|
||||||
AMQPlainAuthenticator(const QString & login = QString(), const QString & password = QString());
|
public:
|
||||||
virtual ~AMQPlainAuthenticator();
|
AMQPlainAuthenticator(const QString &login = QString(), const QString &password = QString());
|
||||||
QString login() const;
|
virtual ~AMQPlainAuthenticator();
|
||||||
void setLogin(const QString& l);
|
|
||||||
QString password() const;
|
QString login() const;
|
||||||
void setPassword(const QString &p);
|
void setLogin(const QString &l);
|
||||||
virtual QString type() const;
|
|
||||||
virtual void write(QDataStream & out);
|
QString password() const;
|
||||||
};
|
void setPassword(const QString &p);
|
||||||
|
|
||||||
}
|
virtual QString type() const;
|
||||||
#endif // amqp_authenticator_h__
|
virtual void write(QDataStream &out);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString login_;
|
||||||
|
QString password_;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // amqp_authenticator_h__
|
||||||
|
|
|
||||||
|
|
@ -1,320 +1,293 @@
|
||||||
#include "amqp_channel.h"
|
#include "amqp_channel.h"
|
||||||
#include "amqp_channel_p.h"
|
#include "amqp_channel_p.h"
|
||||||
|
#include "amqp_connection_p.h"
|
||||||
#include "amqp.h"
|
|
||||||
#include "amqp_p.h"
|
#include "amqp.h"
|
||||||
|
#include "amqp_p.h"
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QDebug>
|
#include <QCoreApplication>
|
||||||
#include <QDataStream>
|
#include <QDebug>
|
||||||
|
#include <QDataStream>
|
||||||
using namespace QAMQP;
|
|
||||||
|
using namespace QAMQP;
|
||||||
namespace QAMQP
|
|
||||||
{
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int ChannelPrivate::nextChannelNumber_ = 0;
|
|
||||||
struct ChannelExceptionCleaner
|
QAMQP::Channel::Channel(int channelNumber, Client *parent)
|
||||||
{
|
: QObject(parent),
|
||||||
/* this cleans up when the constructor throws an exception */
|
d_ptr(new ChannelPrivate(this))
|
||||||
static inline void cleanup(Channel *that, ChannelPrivate *d)
|
{
|
||||||
{
|
Q_D(QAMQP::Channel);
|
||||||
#ifdef QT_NO_EXCEPTIONS
|
d->init(channelNumber, parent);
|
||||||
Q_UNUSED(that);
|
}
|
||||||
Q_UNUSED(d);
|
|
||||||
#else
|
QAMQP::Channel::Channel(ChannelPrivate *dd, Client *parent)
|
||||||
Q_UNUSED(that);
|
: QObject(parent),
|
||||||
Q_UNUSED(d);
|
d_ptr(dd)
|
||||||
#endif
|
{
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
QAMQP::Channel::~Channel()
|
||||||
|
{
|
||||||
|
}
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
void QAMQP::Channel::closeChannel()
|
||||||
QAMQP::Channel::Channel(int channelNumber /*= -1*/, Client * parent /*= 0*/ )
|
{
|
||||||
: pd_ptr(new ChannelPrivate(this))
|
Q_D(QAMQP::Channel);
|
||||||
{
|
d->needOpen = true;
|
||||||
QT_TRY {
|
if (d->opened)
|
||||||
pd_func()->init(channelNumber, parent);
|
d->close(0, QString(), 0,0);
|
||||||
} QT_CATCH(...) {
|
|
||||||
ChannelExceptionCleaner::cleanup(this, pd_func());
|
}
|
||||||
QT_RETHROW;
|
|
||||||
}
|
void QAMQP::Channel::reopen()
|
||||||
}
|
{
|
||||||
|
Q_D(QAMQP::Channel);
|
||||||
QAMQP::Channel::Channel( ChannelPrivate * d )
|
closeChannel();
|
||||||
: pd_ptr(d)
|
d->open();
|
||||||
{
|
}
|
||||||
|
|
||||||
}
|
QString QAMQP::Channel::name() const
|
||||||
|
{
|
||||||
QAMQP::Channel::~Channel()
|
Q_D(const QAMQP::Channel);
|
||||||
{
|
return d->name;
|
||||||
|
}
|
||||||
QT_TRY {
|
|
||||||
QEvent e(QEvent::Destroy);
|
int QAMQP::Channel::channelNumber() const
|
||||||
QCoreApplication::sendEvent(this, &e);
|
{
|
||||||
} QT_CATCH(const std::exception&) {
|
Q_D(const QAMQP::Channel);
|
||||||
// if this fails we can't do anything about it but at least we are not allowed to throw.
|
return d->number;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void QAMQP::Channel::setName(const QString &name)
|
||||||
void QAMQP::Channel::closeChannel()
|
{
|
||||||
{
|
Q_D(QAMQP::Channel);
|
||||||
P_D(Channel);
|
d->name = name;
|
||||||
d->needOpen = true;
|
}
|
||||||
if(d->opened)
|
|
||||||
d->close(0, QString(), 0,0);
|
void QAMQP::Channel::stateChanged(int state)
|
||||||
|
{
|
||||||
}
|
switch(ChannelPrivate::State(state)) {
|
||||||
|
case ChannelPrivate::csOpened:
|
||||||
void QAMQP::Channel::reopen()
|
emit opened();
|
||||||
{
|
break;
|
||||||
closeChannel();
|
case ChannelPrivate::csClosed:
|
||||||
pd_func()->open();
|
emit closed();
|
||||||
}
|
break;
|
||||||
|
case ChannelPrivate::csIdle:
|
||||||
QString QAMQP::Channel::name()
|
emit flowChanged(false);
|
||||||
{
|
break;
|
||||||
return pd_func()->name;
|
case ChannelPrivate::csRunning:
|
||||||
}
|
emit flowChanged(true);
|
||||||
|
break;
|
||||||
int QAMQP::Channel::channelNumber()
|
}
|
||||||
{
|
}
|
||||||
return pd_func()->number;
|
|
||||||
}
|
void QAMQP::Channel::_q_method(const Frame::Method &frame)
|
||||||
|
{
|
||||||
void QAMQP::Channel::setName( const QString &name )
|
Q_D(QAMQP::Channel);
|
||||||
{
|
d->_q_method(frame);
|
||||||
pd_func()->name = name;
|
}
|
||||||
}
|
|
||||||
|
bool QAMQP::Channel::isOpened() const
|
||||||
void QAMQP::Channel::stateChanged( int state )
|
{
|
||||||
{
|
Q_D(const QAMQP::Channel);
|
||||||
switch(ChannelPrivate::State(state))
|
return d->opened;
|
||||||
{
|
}
|
||||||
case ChannelPrivate::csOpened:
|
|
||||||
emit opened();
|
void QAMQP::Channel::onOpen()
|
||||||
break;
|
{
|
||||||
case ChannelPrivate::csClosed:
|
}
|
||||||
emit closed();
|
|
||||||
break;
|
void QAMQP::Channel::onClose()
|
||||||
case ChannelPrivate::csIdle:
|
{
|
||||||
emit flowChanged(false);
|
}
|
||||||
break;
|
|
||||||
case ChannelPrivate::csRunning:
|
void QAMQP::Channel::setQOS(qint32 prefetchSize, quint16 prefetchCount)
|
||||||
emit flowChanged(true);
|
{
|
||||||
break;
|
Q_D(QAMQP::Channel);
|
||||||
}
|
d->setQOS(prefetchSize, prefetchCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QAMQP::Channel::_q_method(const Frame::Method &frame)
|
//////////////////////////////////////////////////////////////////////////
|
||||||
{
|
|
||||||
pd_func()->_q_method(frame);
|
int ChannelPrivate::nextChannelNumber_ = 0;
|
||||||
}
|
ChannelPrivate::ChannelPrivate(Channel * q)
|
||||||
|
: number(0),
|
||||||
bool QAMQP::Channel::isOpened() const
|
opened(false),
|
||||||
{
|
needOpen(true),
|
||||||
return pd_func()->opened;
|
q_ptr(q)
|
||||||
}
|
{
|
||||||
|
}
|
||||||
void QAMQP::Channel::onOpen()
|
|
||||||
{
|
ChannelPrivate::~ChannelPrivate()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QAMQP::Channel::onClose()
|
void ChannelPrivate::init(int channelNumber, Client *parent)
|
||||||
{
|
{
|
||||||
|
Q_Q(QAMQP::Channel);
|
||||||
}
|
needOpen = channelNumber == -1 ? true : false;
|
||||||
|
number = channelNumber == -1 ? ++nextChannelNumber_ : channelNumber;
|
||||||
void QAMQP::Channel::setQOS( qint32 prefetchSize, quint16 prefetchCount )
|
nextChannelNumber_ = qMax(channelNumber, (nextChannelNumber_ + 1));
|
||||||
{
|
q->setParent(parent);
|
||||||
pd_func()->setQOS(prefetchSize, prefetchCount);
|
client_ = parent;
|
||||||
}
|
}
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
ChannelPrivate::ChannelPrivate(Channel * q)
|
bool ChannelPrivate::_q_method(const QAMQP::Frame::Method &frame)
|
||||||
: number(0)
|
{
|
||||||
, opened(false)
|
Q_ASSERT(frame.channel() == number);
|
||||||
, needOpen(true)
|
if (frame.channel() != number)
|
||||||
, pq_ptr(q)
|
return true;
|
||||||
{
|
|
||||||
|
if (frame.methodClass() != QAMQP::Frame::fcChannel)
|
||||||
}
|
return false;
|
||||||
|
|
||||||
ChannelPrivate::~ChannelPrivate()
|
qDebug("Channel#%d:", number);
|
||||||
{
|
|
||||||
|
switch (frame.id()) {
|
||||||
}
|
case miOpenOk:
|
||||||
|
openOk(frame);
|
||||||
void ChannelPrivate::init(int channelNumber, Client * parent)
|
break;
|
||||||
{
|
case miFlow:
|
||||||
needOpen = channelNumber == -1 ? true : false;
|
flow(frame);
|
||||||
number = channelNumber == -1 ? ++nextChannelNumber_ : channelNumber;
|
break;
|
||||||
nextChannelNumber_ = qMax(channelNumber, (nextChannelNumber_ + 1));
|
case miFlowOk:
|
||||||
pq_func()->setParent(parent);
|
flowOk(frame);
|
||||||
client_ = parent;
|
break;
|
||||||
}
|
case miClose:
|
||||||
|
close(frame);
|
||||||
|
break;
|
||||||
bool ChannelPrivate::_q_method( const QAMQP::Frame::Method & frame )
|
case miCloseOk:
|
||||||
{
|
closeOk(frame);
|
||||||
Q_ASSERT(frame.channel() == number);
|
break;
|
||||||
if(frame.channel() != number )
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
if(frame.methodClass() != QAMQP::Frame::fcChannel)
|
|
||||||
return false;
|
void ChannelPrivate::_q_open()
|
||||||
|
{
|
||||||
qDebug("Channel#%d:", number);
|
open();
|
||||||
|
}
|
||||||
switch(frame.id())
|
|
||||||
{
|
|
||||||
case miOpenOk:
|
void ChannelPrivate::sendFrame(const QAMQP::Frame::Base &frame)
|
||||||
openOk(frame);
|
{
|
||||||
break;
|
if (client_) {
|
||||||
case miFlow:
|
client_->d_func()->network_->sendFrame(frame);
|
||||||
flow(frame);
|
}
|
||||||
break;
|
}
|
||||||
case miFlowOk:
|
|
||||||
flowOk(frame);
|
void ChannelPrivate::open()
|
||||||
break;
|
{
|
||||||
case miClose:
|
if (!needOpen || opened)
|
||||||
close(frame);
|
return;
|
||||||
break;
|
|
||||||
case miCloseOk:
|
if (!client_->d_func()->connection_->isConnected())
|
||||||
closeOk(frame);
|
return;
|
||||||
break;
|
|
||||||
}
|
qDebug("Open channel #%d", number);
|
||||||
return true;
|
QAMQP::Frame::Method frame(QAMQP::Frame::fcChannel, miOpen);
|
||||||
}
|
frame.setChannel(number);
|
||||||
|
QByteArray arguments_;
|
||||||
void ChannelPrivate::_q_open()
|
arguments_.resize(1);
|
||||||
{
|
arguments_[0] = 0;
|
||||||
open();
|
frame.setArguments(arguments_);
|
||||||
}
|
sendFrame(frame);
|
||||||
|
}
|
||||||
|
|
||||||
void ChannelPrivate::sendFrame( const QAMQP::Frame::Base & frame )
|
void ChannelPrivate::flow()
|
||||||
{
|
{
|
||||||
if(client_)
|
}
|
||||||
{
|
|
||||||
client_->pd_func()->network_->sendFrame(frame);
|
void ChannelPrivate::flow(const QAMQP::Frame::Method &frame)
|
||||||
}
|
{
|
||||||
}
|
Q_UNUSED(frame);
|
||||||
|
}
|
||||||
|
|
||||||
void ChannelPrivate::open()
|
void ChannelPrivate::flowOk()
|
||||||
{
|
{
|
||||||
if(!needOpen || opened)
|
}
|
||||||
return;
|
|
||||||
|
void ChannelPrivate::flowOk(const QAMQP::Frame::Method &frame)
|
||||||
if(!client_->pd_func()->connection_->isConnected())
|
{
|
||||||
return;
|
Q_UNUSED(frame);
|
||||||
qDebug("Open channel #%d", number);
|
}
|
||||||
QAMQP::Frame::Method frame(QAMQP::Frame::fcChannel, miOpen);
|
|
||||||
frame.setChannel(number);
|
void ChannelPrivate::close(int code, const QString &text, int classId, int methodId)
|
||||||
QByteArray arguments_;
|
{
|
||||||
arguments_.resize(1);
|
QAMQP::Frame::Method frame(QAMQP::Frame::fcChannel, miClose);
|
||||||
arguments_[0] = 0;
|
QByteArray arguments_;
|
||||||
frame.setArguments(arguments_);
|
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
||||||
sendFrame(frame);
|
|
||||||
}
|
QAMQP::Frame::writeField('s',stream, client_->virtualHost());
|
||||||
|
|
||||||
|
stream << qint16(code);
|
||||||
void ChannelPrivate::flow()
|
QAMQP::Frame::writeField('s', stream, text);
|
||||||
{
|
stream << qint16(classId);
|
||||||
|
stream << qint16(methodId);
|
||||||
}
|
|
||||||
|
frame.setArguments(arguments_);
|
||||||
void ChannelPrivate::flow( const QAMQP::Frame::Method & frame )
|
client_->d_func()->network_->sendFrame(frame);
|
||||||
{
|
}
|
||||||
Q_UNUSED(frame);
|
|
||||||
}
|
void ChannelPrivate::close(const QAMQP::Frame::Method &frame)
|
||||||
|
{
|
||||||
void ChannelPrivate::flowOk()
|
Q_Q(QAMQP::Channel);
|
||||||
{
|
q->stateChanged(csClosed);
|
||||||
|
|
||||||
}
|
qDebug(">> CLOSE");
|
||||||
|
QByteArray data = frame.arguments();
|
||||||
void ChannelPrivate::flowOk( const QAMQP::Frame::Method & frame )
|
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||||
{
|
qint16 code_ = 0, classId, methodId;
|
||||||
Q_UNUSED(frame);
|
stream >> code_;
|
||||||
}
|
QString text(QAMQP::Frame::readField('s', stream).toString());
|
||||||
|
stream >> classId;
|
||||||
void ChannelPrivate::close(int code, const QString & text, int classId, int methodId)
|
stream >> methodId;
|
||||||
{
|
|
||||||
QAMQP::Frame::Method frame(QAMQP::Frame::fcChannel, miClose);
|
qDebug(">> code: %d", code_);
|
||||||
QByteArray arguments_;
|
qDebug(">> text: %s", qPrintable(text));
|
||||||
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
qDebug(">> class-id: %d", classId);
|
||||||
|
qDebug(">> method-id: %d", methodId);
|
||||||
QAMQP::Frame::writeField('s',stream, client_->virtualHost());
|
}
|
||||||
|
|
||||||
stream << qint16(code);
|
void ChannelPrivate::closeOk()
|
||||||
QAMQP::Frame::writeField('s', stream, text);
|
{
|
||||||
stream << qint16(classId);
|
QAMQP::Frame::Method frame(QAMQP::Frame::fcChannel, miCloseOk);
|
||||||
stream << qint16(methodId);
|
sendFrame(frame);
|
||||||
|
}
|
||||||
frame.setArguments(arguments_);
|
|
||||||
client_->pd_func()->network_->sendFrame(frame);
|
void ChannelPrivate::closeOk(const QAMQP::Frame::Method &frame)
|
||||||
}
|
{
|
||||||
|
Q_UNUSED(frame)
|
||||||
void ChannelPrivate::close( const QAMQP::Frame::Method & frame )
|
Q_Q(QAMQP::Channel);
|
||||||
{
|
|
||||||
pq_func()->stateChanged(csClosed);
|
q->stateChanged(csClosed);
|
||||||
|
q->onClose();
|
||||||
qDebug(">> CLOSE");
|
opened = false;
|
||||||
QByteArray data = frame.arguments();
|
}
|
||||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
|
||||||
qint16 code_ = 0, classId, methodId;
|
void ChannelPrivate::openOk(const QAMQP::Frame::Method &frame)
|
||||||
stream >> code_;
|
{
|
||||||
QString text(QAMQP::Frame::readField('s', stream).toString());
|
Q_UNUSED(frame)
|
||||||
stream >> classId;
|
Q_Q(QAMQP::Channel);
|
||||||
stream >> methodId;
|
|
||||||
|
qDebug(">> OpenOK");
|
||||||
qDebug(">> code: %d", code_);
|
opened = true;
|
||||||
qDebug(">> text: %s", qPrintable(text));
|
q->stateChanged(csOpened);
|
||||||
qDebug(">> class-id: %d", classId);
|
q->onOpen();
|
||||||
qDebug(">> method-id: %d", methodId);
|
}
|
||||||
|
|
||||||
}
|
void ChannelPrivate::setQOS(qint32 prefetchSize, quint16 prefetchCount)
|
||||||
|
{
|
||||||
void ChannelPrivate::closeOk()
|
client_->d_func()->connection_->d_func()->setQOS(prefetchSize, prefetchCount, number, false);
|
||||||
{
|
}
|
||||||
QAMQP::Frame::Method frame(QAMQP::Frame::fcChannel, miCloseOk);
|
|
||||||
sendFrame(frame);
|
void ChannelPrivate::_q_disconnected()
|
||||||
}
|
{
|
||||||
|
nextChannelNumber_ = 0;
|
||||||
void ChannelPrivate::closeOk( const QAMQP::Frame::Method & frame )
|
opened = false;
|
||||||
{
|
}
|
||||||
Q_UNUSED(frame);
|
|
||||||
P_Q(Channel);
|
#include "moc_amqp_channel.cpp"
|
||||||
q->stateChanged(csClosed);
|
|
||||||
q->onClose();
|
|
||||||
opened = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChannelPrivate::openOk( const QAMQP::Frame::Method & frame )
|
|
||||||
{
|
|
||||||
Q_UNUSED(frame);
|
|
||||||
P_Q(Channel);
|
|
||||||
qDebug(">> OpenOK");
|
|
||||||
opened = true;
|
|
||||||
q->stateChanged(csOpened);
|
|
||||||
q->onOpen();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChannelPrivate::setQOS( qint32 prefetchSize, quint16 prefetchCount )
|
|
||||||
{
|
|
||||||
client_->pd_func()->connection_->pd_func()->setQOS(prefetchSize, prefetchCount, number, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ChannelPrivate::_q_disconnected()
|
|
||||||
{
|
|
||||||
nextChannelNumber_ = 0;
|
|
||||||
opened = false;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,60 +1,58 @@
|
||||||
#ifndef amqp_channel_h__
|
#ifndef amqp_channel_h__
|
||||||
#define amqp_channel_h__
|
#define amqp_channel_h__
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "amqp_global.h"
|
#include "amqp_global.h"
|
||||||
#include "amqp_frame.h"
|
#include "amqp_frame.h"
|
||||||
|
|
||||||
namespace QAMQP
|
namespace QAMQP
|
||||||
{
|
{
|
||||||
class ChannelPrivate;
|
|
||||||
class Client;
|
class Client;
|
||||||
class Channel : public QObject, public Frame::MethodHandler
|
class ChannelPrivate;
|
||||||
{
|
class Channel : public QObject, public Frame::MethodHandler
|
||||||
Q_OBJECT
|
{
|
||||||
|
Q_OBJECT
|
||||||
Q_PROPERTY(int number READ channelNumber);
|
Q_PROPERTY(int number READ channelNumber)
|
||||||
Q_PROPERTY(QString name READ name WRITE setName);
|
Q_PROPERTY(QString name READ name WRITE setName)
|
||||||
|
|
||||||
P_DECLARE_PRIVATE(QAMQP::Channel)
|
public:
|
||||||
Q_DISABLE_COPY(Channel)
|
~Channel();
|
||||||
public:
|
|
||||||
~Channel();
|
void closeChannel();
|
||||||
|
void reopen();
|
||||||
void closeChannel();
|
|
||||||
void reopen();
|
QString name() const;
|
||||||
|
int channelNumber() const;
|
||||||
QString name();
|
|
||||||
int channelNumber();
|
void setName(const QString &name);
|
||||||
|
void setQOS(qint32 prefetchSize, quint16 prefetchCount);
|
||||||
void setName(const QString &name);
|
bool isOpened() const;
|
||||||
void setQOS(qint32 prefetchSize, quint16 prefetchCount);
|
|
||||||
bool isOpened() const;
|
signals:
|
||||||
|
void opened();
|
||||||
signals:
|
void closed();
|
||||||
void opened();
|
void flowChanged(bool enabled);
|
||||||
void closed();
|
|
||||||
void flowChanged(bool enabled);
|
protected:
|
||||||
|
Q_DISABLE_COPY(Channel)
|
||||||
protected:
|
Q_DECLARE_PRIVATE(QAMQP::Channel)
|
||||||
Channel(int channelNumber = -1, Client * parent = 0);
|
|
||||||
Channel(ChannelPrivate * d);
|
Channel(int channelNumber = -1, Client *parent = 0);
|
||||||
virtual void onOpen();
|
Channel(ChannelPrivate *dd, Client *parent = 0);
|
||||||
virtual void onClose();
|
QScopedPointer<ChannelPrivate> d_ptr;
|
||||||
|
|
||||||
ChannelPrivate * const pd_ptr;
|
Q_PRIVATE_SLOT(d_func(), void _q_open())
|
||||||
|
Q_PRIVATE_SLOT(d_func(), void _q_disconnected())
|
||||||
private:
|
|
||||||
void stateChanged(int state);
|
virtual void onOpen();
|
||||||
friend class ClientPrivate;
|
virtual void onClose();
|
||||||
void _q_method(const QAMQP::Frame::Method & frame);
|
void stateChanged(int state);
|
||||||
|
void _q_method(const QAMQP::Frame::Method &frame);
|
||||||
Q_PRIVATE_SLOT(pd_func(), void _q_open())
|
|
||||||
Q_PRIVATE_SLOT(pd_func(), void _q_disconnected())
|
friend class ClientPrivate;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
}
|
||||||
#ifdef QAMQP_P_INCLUDE
|
|
||||||
# include "amqp_channel_p.h"
|
#endif
|
||||||
#endif
|
|
||||||
#endif // amqp_channel_h__
|
|
||||||
|
|
|
||||||
|
|
@ -1,85 +1,85 @@
|
||||||
#ifndef amqp_channel_p_h__
|
#ifndef amqp_channel_p_h__
|
||||||
#define amqp_channel_p_h__
|
#define amqp_channel_p_h__
|
||||||
|
|
||||||
#include "amqp_global.h"
|
#include "amqp_global.h"
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
||||||
|
|
||||||
namespace QAMQP
|
namespace QAMQP
|
||||||
{
|
{
|
||||||
class Client;
|
class Client;
|
||||||
class ClientPrivate;
|
class ClientPrivate;
|
||||||
class ChannelPrivate
|
class ChannelPrivate
|
||||||
{
|
{
|
||||||
P_DECLARE_PUBLIC(QAMQP::Channel)
|
public:
|
||||||
public:
|
enum MethodId {
|
||||||
enum MethodId
|
METHOD_ID_ENUM(miOpen, 10),
|
||||||
{
|
METHOD_ID_ENUM(miFlow, 20),
|
||||||
METHOD_ID_ENUM(miOpen, 10),
|
METHOD_ID_ENUM(miClose, 40)
|
||||||
METHOD_ID_ENUM(miFlow, 20),
|
};
|
||||||
METHOD_ID_ENUM(miClose, 40)
|
|
||||||
};
|
enum State {
|
||||||
|
csOpened,
|
||||||
enum State {
|
csClosed,
|
||||||
csOpened,
|
csIdle,
|
||||||
csClosed,
|
csRunning
|
||||||
csIdle,
|
};
|
||||||
csRunning
|
|
||||||
};
|
enum BasicMethod
|
||||||
|
{
|
||||||
enum BasicMethod
|
METHOD_ID_ENUM(bmQos, 10),
|
||||||
{
|
METHOD_ID_ENUM(bmConsume, 20),
|
||||||
METHOD_ID_ENUM(bmQos, 10),
|
METHOD_ID_ENUM(bmCancel, 30),
|
||||||
METHOD_ID_ENUM(bmConsume, 20),
|
bmPublish = 40,
|
||||||
METHOD_ID_ENUM(bmCancel, 30),
|
bmReturn = 50,
|
||||||
bmPublish = 40,
|
bmDeliver = 60,
|
||||||
bmReturn = 50,
|
METHOD_ID_ENUM(bmGet, 70),
|
||||||
bmDeliver = 60,
|
bmGetEmpty = 72,
|
||||||
METHOD_ID_ENUM(bmGet, 70),
|
bmAck = 80,
|
||||||
bmGetEmpty = 72,
|
bmReject = 90,
|
||||||
bmAck = 80,
|
bmRecoverAsync = 100,
|
||||||
bmReject = 90,
|
METHOD_ID_ENUM(bmRecover, 110)
|
||||||
bmRecoverAsync = 100,
|
};
|
||||||
METHOD_ID_ENUM(bmRecover, 110)
|
|
||||||
};
|
ChannelPrivate(Channel * q);
|
||||||
|
virtual ~ChannelPrivate();
|
||||||
ChannelPrivate(Channel * q);
|
|
||||||
virtual ~ChannelPrivate();
|
void init(int channelNumber, Client *parent);
|
||||||
|
|
||||||
void init(int channelNumber, Client * parent);
|
void open();
|
||||||
|
void flow();
|
||||||
void open();
|
void flowOk();
|
||||||
void flow();
|
void close(int code, const QString &text, int classId, int methodId);
|
||||||
void flowOk();
|
void closeOk();
|
||||||
void close(int code, const QString & text, int classId, int methodId);
|
|
||||||
void closeOk();
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
void openOk(const QAMQP::Frame::Method &frame);
|
||||||
|
void flow(const QAMQP::Frame::Method &frame);
|
||||||
void openOk(const QAMQP::Frame::Method & frame);
|
void flowOk(const QAMQP::Frame::Method &frame);
|
||||||
void flow(const QAMQP::Frame::Method & frame);
|
void close(const QAMQP::Frame::Method &frame);
|
||||||
void flowOk(const QAMQP::Frame::Method & frame);
|
void closeOk(const QAMQP::Frame::Method &frame);
|
||||||
void close(const QAMQP::Frame::Method & frame);
|
|
||||||
void closeOk(const QAMQP::Frame::Method & frame);
|
virtual bool _q_method(const QAMQP::Frame::Method &frame);
|
||||||
|
virtual void _q_disconnected();
|
||||||
virtual bool _q_method(const QAMQP::Frame::Method & frame);
|
void _q_open();
|
||||||
virtual void _q_disconnected();
|
|
||||||
void _q_open();
|
void setQOS(qint32 prefetchSize, quint16 prefetchCount);
|
||||||
|
void sendFrame(const QAMQP::Frame::Base &frame);
|
||||||
void setQOS(qint32 prefetchSize, quint16 prefetchCount);
|
|
||||||
void sendFrame(const QAMQP::Frame::Base & frame);
|
QPointer<Client> client_;
|
||||||
|
|
||||||
QPointer<Client> client_;
|
QString name;
|
||||||
|
int number;
|
||||||
QString name;
|
|
||||||
int number;
|
static int nextChannelNumber_;
|
||||||
|
bool opened;
|
||||||
static int nextChannelNumber_;
|
bool needOpen;
|
||||||
bool opened;
|
|
||||||
bool needOpen;
|
Q_DECLARE_PUBLIC(QAMQP::Channel)
|
||||||
|
Channel * const q_ptr;
|
||||||
Channel * const pq_ptr;
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
#endif // amqp_channel_p_h__
|
#endif // amqp_channel_p_h__
|
||||||
|
|
|
||||||
|
|
@ -1,397 +1,369 @@
|
||||||
#include "amqp_connection.h"
|
#include "amqp_connection.h"
|
||||||
#include "amqp_connection_p.h"
|
#include "amqp_connection_p.h"
|
||||||
#include "amqp.h"
|
#include "amqp.h"
|
||||||
#include "amqp_p.h"
|
#include "amqp_p.h"
|
||||||
#include "amqp_frame.h"
|
#include "amqp_frame.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
using namespace QAMQP;
|
using namespace QAMQP;
|
||||||
|
|
||||||
namespace QAMQP
|
ConnectionPrivate::ConnectionPrivate(Connection * q)
|
||||||
{
|
: closed_(false),
|
||||||
struct ConnectionExceptionCleaner
|
connected(false),
|
||||||
{
|
q_ptr(q)
|
||||||
/* this cleans up when the constructor throws an exception */
|
{
|
||||||
static inline void cleanup(Connection *that, ConnectionPrivate *d)
|
}
|
||||||
{
|
|
||||||
#ifdef QT_NO_EXCEPTIONS
|
ConnectionPrivate::~ConnectionPrivate()
|
||||||
Q_UNUSED(that);
|
{
|
||||||
Q_UNUSED(d);
|
}
|
||||||
#else
|
|
||||||
Q_UNUSED(that);
|
void ConnectionPrivate::init(Client * parent)
|
||||||
Q_UNUSED(d);
|
{
|
||||||
#endif
|
Q_Q(QAMQP::Connection);
|
||||||
}
|
q->setParent(parent);
|
||||||
};
|
client_ = parent;
|
||||||
|
heartbeatTimer_ = new QTimer(parent);
|
||||||
|
QObject::connect(heartbeatTimer_, SIGNAL(timeout()), q, SLOT(_q_heartbeat()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
void ConnectionPrivate::startOk()
|
||||||
//////////////////////////////////////////////////////////////////////////
|
{
|
||||||
|
QAMQP::Frame::Method frame(QAMQP::Frame::fcConnection, miStartOk);
|
||||||
|
QByteArray arguments_;
|
||||||
ConnectionPrivate::ConnectionPrivate( Connection * q)
|
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
||||||
: closed_(false)
|
|
||||||
, connected(false)
|
QAMQP::Frame::TableField clientProperties;
|
||||||
, pq_ptr(q)
|
clientProperties["version"] = QString(QAMQP_VERSION);
|
||||||
{
|
clientProperties["platform"] = QString("Qt %1").arg(qVersion());
|
||||||
|
clientProperties["product"] = QString("QAMQP");
|
||||||
}
|
clientProperties.unite(customProperty);
|
||||||
|
QAMQP::Frame::serialize(stream, clientProperties);
|
||||||
ConnectionPrivate::~ConnectionPrivate()
|
|
||||||
{
|
client_->d_func()->auth_->write(stream);
|
||||||
|
QAMQP::Frame::writeField('s', stream, "en_US");
|
||||||
}
|
frame.setArguments(arguments_);
|
||||||
|
client_->d_func()->network_->sendFrame(frame);
|
||||||
void ConnectionPrivate::init(Client * parent)
|
}
|
||||||
{
|
|
||||||
pq_func()->setParent(parent);
|
void ConnectionPrivate::secureOk()
|
||||||
client_ = parent;
|
{
|
||||||
heartbeatTimer_ = new QTimer(parent);
|
}
|
||||||
QObject::connect(heartbeatTimer_, SIGNAL(timeout()),
|
|
||||||
pq_func(), SLOT(_q_heartbeat()));
|
void ConnectionPrivate::tuneOk()
|
||||||
}
|
{
|
||||||
|
QAMQP::Frame::Method frame(QAMQP::Frame::fcConnection, miTuneOk);
|
||||||
void ConnectionPrivate::startOk()
|
QByteArray arguments_;
|
||||||
{
|
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
||||||
QAMQP::Frame::Method frame(QAMQP::Frame::fcConnection, miStartOk);
|
|
||||||
QByteArray arguments_;
|
stream << qint16(0); //channel_max
|
||||||
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
stream << qint32(FRAME_MAX); //frame_max
|
||||||
|
stream << qint16(heartbeatTimer_->interval() / 1000); //heartbeat
|
||||||
QAMQP::Frame::TableField clientProperties;
|
|
||||||
clientProperties["version"] = QString(QAMQP_VERSION);
|
frame.setArguments(arguments_);
|
||||||
clientProperties["platform"] = QString("Qt %1").arg(qVersion());
|
client_->d_func()->network_->sendFrame(frame);
|
||||||
clientProperties["product"] = QString("QAMQP");
|
}
|
||||||
clientProperties.unite(customProperty);
|
|
||||||
QAMQP::Frame::serialize(stream, clientProperties);
|
void ConnectionPrivate::open()
|
||||||
|
{
|
||||||
client_->pd_func()->auth_->write(stream);
|
QAMQP::Frame::Method frame(QAMQP::Frame::fcConnection, miOpen);
|
||||||
|
QByteArray arguments_;
|
||||||
QAMQP::Frame::writeField('s', stream, "en_US");
|
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
||||||
|
|
||||||
frame.setArguments(arguments_);
|
QAMQP::Frame::writeField('s',stream, client_->virtualHost());
|
||||||
|
|
||||||
client_->pd_func()->network_->sendFrame(frame);
|
stream << qint8(0);
|
||||||
}
|
stream << qint8(0);
|
||||||
|
|
||||||
void ConnectionPrivate::secureOk()
|
frame.setArguments(arguments_);
|
||||||
{
|
client_->d_func()->network_->sendFrame(frame);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
void ConnectionPrivate::start(const QAMQP::Frame::Method &frame)
|
||||||
|
{
|
||||||
void ConnectionPrivate::tuneOk()
|
qDebug(">> Start");
|
||||||
{
|
QByteArray data = frame.arguments();
|
||||||
QAMQP::Frame::Method frame(QAMQP::Frame::fcConnection, miTuneOk);
|
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||||
QByteArray arguments_;
|
quint8 version_major = 0;
|
||||||
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
quint8 version_minor = 0;
|
||||||
|
|
||||||
stream << qint16(0); //channel_max
|
stream >> version_major >> version_minor;
|
||||||
stream << qint32(FRAME_MAX); //frame_max
|
|
||||||
stream << qint16(heartbeatTimer_->interval() / 1000); //heartbeat
|
QAMQP::Frame::TableField table;
|
||||||
|
QAMQP::Frame::deserialize(stream, table);
|
||||||
frame.setArguments(arguments_);
|
|
||||||
client_->pd_func()->network_->sendFrame(frame);
|
QString mechanisms = QAMQP::Frame::readField('S', stream).toString();
|
||||||
}
|
QString locales = QAMQP::Frame::readField('S', stream).toString();
|
||||||
|
|
||||||
void ConnectionPrivate::open()
|
qDebug(">> version_major: %d", version_major);
|
||||||
{
|
qDebug(">> version_minor: %d", version_minor);
|
||||||
QAMQP::Frame::Method frame(QAMQP::Frame::fcConnection, miOpen);
|
|
||||||
QByteArray arguments_;
|
QAMQP::Frame::print(table);
|
||||||
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
|
||||||
|
qDebug(">> mechanisms: %s", qPrintable(mechanisms));
|
||||||
QAMQP::Frame::writeField('s',stream, client_->virtualHost());
|
qDebug(">> locales: %s", qPrintable(locales));
|
||||||
|
|
||||||
stream << qint8(0);
|
startOk();
|
||||||
stream << qint8(0);
|
}
|
||||||
|
|
||||||
frame.setArguments(arguments_);
|
void ConnectionPrivate::secure(const QAMQP::Frame::Method &frame)
|
||||||
client_->pd_func()->network_->sendFrame(frame);
|
{
|
||||||
}
|
Q_UNUSED(frame)
|
||||||
|
}
|
||||||
void ConnectionPrivate::start( const QAMQP::Frame::Method & frame )
|
|
||||||
{
|
void ConnectionPrivate::tune(const QAMQP::Frame::Method &frame)
|
||||||
qDebug(">> Start");
|
{
|
||||||
QByteArray data = frame.arguments();
|
qDebug(">> Tune");
|
||||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
QByteArray data = frame.arguments();
|
||||||
quint8 version_major = 0;
|
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||||
quint8 version_minor = 0;
|
|
||||||
|
qint16 channel_max = 0,
|
||||||
stream >> version_major >> version_minor;
|
heartbeat = 0;
|
||||||
|
qint32 frame_max = 0;
|
||||||
QAMQP::Frame::TableField table;
|
|
||||||
QAMQP::Frame::deserialize(stream, table);
|
stream >> channel_max;
|
||||||
|
stream >> frame_max;
|
||||||
QString mechanisms = QAMQP::Frame::readField('S', stream).toString();
|
stream >> heartbeat;
|
||||||
QString locales = QAMQP::Frame::readField('S', stream).toString();
|
|
||||||
|
qDebug(">> channel_max: %d", channel_max);
|
||||||
qDebug(">> version_major: %d", version_major);
|
qDebug(">> frame_max: %d", frame_max);
|
||||||
qDebug(">> version_minor: %d", version_minor);
|
qDebug(">> heartbeat: %d", heartbeat);
|
||||||
|
|
||||||
QAMQP::Frame::print(table);
|
if (heartbeatTimer_) {
|
||||||
|
heartbeatTimer_->setInterval(heartbeat * 1000);
|
||||||
qDebug(">> mechanisms: %s", qPrintable(mechanisms));
|
if (heartbeatTimer_->interval())
|
||||||
qDebug(">> locales: %s", qPrintable(locales));
|
heartbeatTimer_->start();
|
||||||
|
else
|
||||||
startOk();
|
heartbeatTimer_->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionPrivate::secure( const QAMQP::Frame::Method & frame )
|
tuneOk();
|
||||||
{
|
open();
|
||||||
Q_UNUSED(frame);
|
}
|
||||||
}
|
|
||||||
|
void ConnectionPrivate::openOk(const QAMQP::Frame::Method &frame)
|
||||||
void ConnectionPrivate::tune( const QAMQP::Frame::Method & frame )
|
{
|
||||||
{
|
Q_UNUSED(frame)
|
||||||
qDebug(">> Tune");
|
Q_Q(QAMQP::Connection);
|
||||||
QByteArray data = frame.arguments();
|
|
||||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
qDebug(">> OpenOK");
|
||||||
|
connected = true;
|
||||||
qint16 channel_max = 0,
|
q->openOk();
|
||||||
heartbeat = 0;
|
}
|
||||||
qint32 frame_max = 0;
|
|
||||||
|
void ConnectionPrivate::close(const QAMQP::Frame::Method &frame)
|
||||||
stream >> channel_max;
|
{
|
||||||
stream >> frame_max;
|
Q_Q(QAMQP::Connection);
|
||||||
stream >> heartbeat;
|
|
||||||
|
qDebug(">> CLOSE");
|
||||||
qDebug(">> channel_max: %d", channel_max);
|
QByteArray data = frame.arguments();
|
||||||
qDebug(">> frame_max: %d", frame_max);
|
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||||
qDebug(">> heartbeat: %d", heartbeat);
|
qint16 code_ = 0, classId, methodId;
|
||||||
|
stream >> code_;
|
||||||
if(heartbeatTimer_)
|
QString text(QAMQP::Frame::readField('s', stream).toString());
|
||||||
{
|
stream >> classId;
|
||||||
heartbeatTimer_->setInterval(heartbeat * 1000);
|
stream >> methodId;
|
||||||
if(heartbeatTimer_->interval())
|
|
||||||
{
|
qDebug(">> code: %d", code_);
|
||||||
heartbeatTimer_->start();
|
qDebug(">> text: %s", qPrintable(text));
|
||||||
} else {
|
qDebug(">> class-id: %d", classId);
|
||||||
heartbeatTimer_->stop();
|
qDebug(">> method-id: %d", methodId);
|
||||||
}
|
connected = false;
|
||||||
}
|
client_->d_func()->network_->error(QAbstractSocket::RemoteHostClosedError);
|
||||||
tuneOk();
|
QMetaObject::invokeMethod(q, "disconnected");
|
||||||
open();
|
}
|
||||||
}
|
|
||||||
|
void ConnectionPrivate::close(int code, const QString &text, int classId, int methodId)
|
||||||
void ConnectionPrivate::openOk( const QAMQP::Frame::Method & frame )
|
{
|
||||||
{
|
QAMQP::Frame::Method frame(QAMQP::Frame::fcConnection, miClose);
|
||||||
Q_UNUSED(frame);
|
QByteArray arguments_;
|
||||||
qDebug(">> OpenOK");
|
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
||||||
connected = true;
|
|
||||||
pq_func()->openOk();
|
QAMQP::Frame::writeField('s',stream, client_->virtualHost());
|
||||||
}
|
|
||||||
|
stream << qint16(code);
|
||||||
void ConnectionPrivate::close( const QAMQP::Frame::Method & frame )
|
QAMQP::Frame::writeField('s', stream, text);
|
||||||
{
|
stream << qint16(classId);
|
||||||
qDebug(">> CLOSE");
|
stream << qint16(methodId);
|
||||||
QByteArray data = frame.arguments();
|
|
||||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
frame.setArguments(arguments_);
|
||||||
qint16 code_ = 0, classId, methodId;
|
client_->d_func()->network_->sendFrame(frame);
|
||||||
stream >> code_;
|
}
|
||||||
QString text(QAMQP::Frame::readField('s', stream).toString());
|
|
||||||
stream >> classId;
|
void ConnectionPrivate::closeOk()
|
||||||
stream >> methodId;
|
{
|
||||||
|
QAMQP::Frame::Method frame(QAMQP::Frame::fcConnection, miCloseOk);
|
||||||
qDebug(">> code: %d", code_);
|
connected = false;
|
||||||
qDebug(">> text: %s", qPrintable(text));
|
client_->d_func()->network_->sendFrame(frame);
|
||||||
qDebug(">> class-id: %d", classId);
|
|
||||||
qDebug(">> method-id: %d", methodId);
|
}
|
||||||
connected = false;
|
|
||||||
client_->pd_func()->network_->error(QAbstractSocket::RemoteHostClosedError);
|
void ConnectionPrivate::closeOk(const QAMQP::Frame::Method &frame)
|
||||||
QMetaObject::invokeMethod(pq_func(), "disconnected");
|
{
|
||||||
}
|
Q_UNUSED(frame)
|
||||||
|
Q_Q(QAMQP::Connection);
|
||||||
void ConnectionPrivate::close(int code, const QString & text, int classId, int methodId)
|
|
||||||
{
|
connected = false;
|
||||||
QAMQP::Frame::Method frame(QAMQP::Frame::fcConnection, miClose);
|
QMetaObject::invokeMethod(q, "disconnected");
|
||||||
QByteArray arguments_;
|
if (heartbeatTimer_)
|
||||||
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
heartbeatTimer_->stop();
|
||||||
|
}
|
||||||
QAMQP::Frame::writeField('s',stream, client_->virtualHost());
|
|
||||||
|
|
||||||
stream << qint16(code);
|
void ConnectionPrivate::setQOS(qint32 prefetchSize, quint16 prefetchCount, int channel, bool global)
|
||||||
QAMQP::Frame::writeField('s', stream, text);
|
{
|
||||||
stream << qint16(classId);
|
QAMQP::Frame::Method frame(QAMQP::Frame::fcBasic, 10);
|
||||||
stream << qint16(methodId);
|
frame.setChannel(channel);
|
||||||
|
QByteArray arguments_;
|
||||||
frame.setArguments(arguments_);
|
QDataStream out(&arguments_, QIODevice::WriteOnly);
|
||||||
client_->pd_func()->network_->sendFrame(frame);
|
|
||||||
}
|
out << prefetchSize;
|
||||||
|
out << prefetchCount;
|
||||||
void ConnectionPrivate::closeOk()
|
out << qint8(global ? 1 : 0);
|
||||||
{
|
|
||||||
QAMQP::Frame::Method frame(QAMQP::Frame::fcConnection, miCloseOk);
|
frame.setArguments(arguments_);
|
||||||
connected = false;
|
client_->d_func()->network_->sendFrame(frame);
|
||||||
client_->pd_func()->network_->sendFrame(frame);
|
}
|
||||||
|
|
||||||
}
|
bool ConnectionPrivate::_q_method(const QAMQP::Frame::Method &frame)
|
||||||
|
{
|
||||||
void ConnectionPrivate::closeOk( const QAMQP::Frame::Method & )
|
Q_ASSERT(frame.methodClass() == QAMQP::Frame::fcConnection);
|
||||||
{
|
if (frame.methodClass() != QAMQP::Frame::fcConnection)
|
||||||
connected = false;
|
return true;
|
||||||
QMetaObject::invokeMethod(pq_func(), "disconnected");
|
|
||||||
if(heartbeatTimer_)
|
qDebug() << "Connection:";
|
||||||
{
|
|
||||||
heartbeatTimer_->stop();
|
if (closed_) {
|
||||||
}
|
if (frame.id() == miCloseOk)
|
||||||
}
|
closeOk(frame);
|
||||||
|
|
||||||
|
return true;
|
||||||
void ConnectionPrivate::setQOS( qint32 prefetchSize, quint16 prefetchCount, int channel, bool global )
|
}
|
||||||
{
|
|
||||||
QAMQP::Frame::Method frame(QAMQP::Frame::fcBasic, 10);
|
switch (MethodId(frame.id())) {
|
||||||
frame.setChannel(channel);
|
case miStart:
|
||||||
QByteArray arguments_;
|
start(frame);
|
||||||
QDataStream out(&arguments_, QIODevice::WriteOnly);
|
break;
|
||||||
|
case miSecure:
|
||||||
out << prefetchSize;
|
secure(frame);
|
||||||
out << prefetchCount;
|
break;
|
||||||
out << qint8(global ? 1 : 0);
|
case miTune:
|
||||||
|
tune(frame);
|
||||||
frame.setArguments(arguments_);
|
break;
|
||||||
client_->pd_func()->network_->sendFrame(frame);
|
case miOpenOk:
|
||||||
}
|
openOk(frame);
|
||||||
|
break;
|
||||||
bool ConnectionPrivate::_q_method( const QAMQP::Frame::Method & frame )
|
case miClose:
|
||||||
{
|
close(frame);
|
||||||
Q_ASSERT(frame.methodClass() == QAMQP::Frame::fcConnection);
|
break;
|
||||||
if(frame.methodClass() != QAMQP::Frame::fcConnection)
|
case miCloseOk:
|
||||||
return true;
|
closeOk(frame);
|
||||||
|
break;
|
||||||
qDebug() << "Connection:";
|
default:
|
||||||
|
qWarning("Unknown method-id %d", frame.id());
|
||||||
if (closed_)
|
return false;
|
||||||
{
|
}
|
||||||
if( frame.id() == miCloseOk)
|
|
||||||
closeOk(frame);
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
|
void ConnectionPrivate::_q_heartbeat()
|
||||||
switch(MethodId(frame.id()))
|
{
|
||||||
{
|
QAMQP::Frame::Heartbeat frame;
|
||||||
case miStart:
|
client_->d_func()->network_->sendFrame(frame);
|
||||||
start(frame);
|
}
|
||||||
break;
|
|
||||||
case miSecure:
|
//////////////////////////////////////////////////////////////////////////
|
||||||
secure(frame);
|
|
||||||
break;
|
Connection::Connection(Client *parent)
|
||||||
case miTune:
|
: QObject(parent),
|
||||||
tune(frame);
|
d_ptr(new ConnectionPrivate(this))
|
||||||
break;
|
{
|
||||||
case miOpenOk:
|
Q_D(QAMQP::Connection);
|
||||||
openOk(frame);
|
d->init(parent);
|
||||||
break;
|
}
|
||||||
case miClose:
|
|
||||||
close(frame);
|
Connection::~Connection()
|
||||||
break;
|
{
|
||||||
case miCloseOk:
|
}
|
||||||
closeOk(frame);
|
|
||||||
break;
|
void Connection::startOk()
|
||||||
default:
|
{
|
||||||
qWarning("Unknown method-id %d", frame.id());
|
Q_D(QAMQP::Connection);
|
||||||
return false;
|
d->startOk();
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
void Connection::secureOk()
|
||||||
|
{
|
||||||
void ConnectionPrivate::_q_heartbeat()
|
Q_D(QAMQP::Connection);
|
||||||
{
|
d->secureOk();
|
||||||
QAMQP::Frame::Heartbeat frame;
|
}
|
||||||
client_->pd_func()->network_->sendFrame(frame);
|
|
||||||
}
|
void Connection::tuneOk()
|
||||||
|
{
|
||||||
//////////////////////////////////////////////////////////////////////////
|
Q_D(QAMQP::Connection);
|
||||||
|
d->tuneOk();
|
||||||
Connection::Connection( Client * parent /*= 0*/ )
|
}
|
||||||
: pd_ptr(new ConnectionPrivate(this))
|
|
||||||
{
|
void Connection::open()
|
||||||
QT_TRY {
|
{
|
||||||
pd_func()->init(parent);
|
Q_D(QAMQP::Connection);
|
||||||
} QT_CATCH(...) {
|
d->open();
|
||||||
ConnectionExceptionCleaner::cleanup(this, pd_func());
|
}
|
||||||
QT_RETHROW;
|
|
||||||
}
|
void Connection::close(int code, const QString &text, int classId , int methodId)
|
||||||
}
|
{
|
||||||
|
Q_D(QAMQP::Connection);
|
||||||
Connection::~Connection()
|
d->close(code, text, classId, methodId);
|
||||||
{
|
}
|
||||||
QT_TRY {
|
|
||||||
QEvent e(QEvent::Destroy);
|
void Connection::closeOk()
|
||||||
QCoreApplication::sendEvent(this, &e);
|
{
|
||||||
} QT_CATCH(const std::exception&) {
|
Q_D(QAMQP::Connection);
|
||||||
// if this fails we can't do anything about it but at least we are not allowed to throw.
|
d->closeOk();
|
||||||
}
|
Q_EMIT disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::startOk()
|
void Connection::openOk()
|
||||||
{
|
{
|
||||||
pd_func()->startOk();
|
Q_EMIT connected();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::secureOk()
|
void Connection::_q_method(const QAMQP::Frame::Method &frame)
|
||||||
{
|
{
|
||||||
pd_func()->secureOk();
|
Q_D(QAMQP::Connection);
|
||||||
}
|
d->_q_method(frame);
|
||||||
|
}
|
||||||
void Connection::tuneOk()
|
|
||||||
{
|
bool Connection::isConnected() const
|
||||||
pd_func()->tuneOk();
|
{
|
||||||
}
|
Q_D(const QAMQP::Connection);
|
||||||
|
return d->connected;
|
||||||
void Connection::open()
|
}
|
||||||
{
|
|
||||||
pd_func()->open();
|
void Connection::setQOS(qint32 prefetchSize, quint16 prefetchCount)
|
||||||
}
|
{
|
||||||
|
Q_D(QAMQP::Connection);
|
||||||
void Connection::close(int code, const QString & text, int classId , int methodId)
|
d->setQOS(prefetchSize, prefetchCount, 0, true);
|
||||||
{
|
}
|
||||||
pd_func()->close(code, text, classId, methodId);
|
|
||||||
}
|
void Connection::addCustomProperty(const QString &name, const QString &value)
|
||||||
|
{
|
||||||
void Connection::closeOk()
|
Q_D(QAMQP::Connection);
|
||||||
{
|
d->customProperty[name] = value;
|
||||||
pd_func()->closeOk();
|
}
|
||||||
emit disconnect();
|
|
||||||
}
|
QString Connection::customProperty(const QString &name) const
|
||||||
|
{
|
||||||
void Connection::openOk()
|
Q_D(const QAMQP::Connection);
|
||||||
{
|
if (d->customProperty.contains(name))
|
||||||
emit connected();
|
return d->customProperty.value(name).toString();
|
||||||
}
|
return QString();
|
||||||
|
}
|
||||||
void Connection::_q_method(const QAMQP::Frame::Method & frame)
|
|
||||||
{
|
#include "moc_amqp_connection.cpp"
|
||||||
pd_func()->_q_method(frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Connection::isConnected() const
|
|
||||||
{
|
|
||||||
return pd_func()->connected;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Connection::setQOS( qint32 prefetchSize, quint16 prefetchCount )
|
|
||||||
{
|
|
||||||
pd_func()->setQOS(prefetchSize, prefetchCount, 0, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Connection::addCustomProperty( const QString & name, const QString & value )
|
|
||||||
{
|
|
||||||
pd_func()->customProperty[name] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Connection::customProperty( const QString & name ) const
|
|
||||||
{
|
|
||||||
if(pd_func()->customProperty.contains(name))
|
|
||||||
{
|
|
||||||
return pd_func()->customProperty.value(name).toString();
|
|
||||||
}
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,59 +1,56 @@
|
||||||
#ifndef amqp_connection_h__
|
#ifndef amqp_connection_h__
|
||||||
#define amqp_connection_h__
|
#define amqp_connection_h__
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "amqp_frame.h"
|
#include "amqp_frame.h"
|
||||||
#include "amqp_global.h"
|
#include "amqp_global.h"
|
||||||
|
|
||||||
namespace QAMQP
|
namespace QAMQP
|
||||||
{
|
{
|
||||||
class ConnectionPrivate;
|
|
||||||
class ChannelPrivate;
|
class Client;
|
||||||
class ClientPrivate;
|
class ClientPrivate;
|
||||||
class Client;
|
class ChannelPrivate;
|
||||||
class Connection : public QObject, public Frame::MethodHandler
|
class ConnectionPrivate;
|
||||||
{
|
class Connection : public QObject, public Frame::MethodHandler
|
||||||
Q_OBJECT
|
{
|
||||||
P_DECLARE_PRIVATE(QAMQP::Connection)
|
Q_OBJECT
|
||||||
Q_DISABLE_COPY(Connection)
|
public:
|
||||||
Connection(Client * parent = 0);
|
virtual ~Connection();
|
||||||
public:
|
|
||||||
~Connection();
|
void addCustomProperty(const QString &name, const QString &value);
|
||||||
|
QString customProperty(const QString &name) const;
|
||||||
|
|
||||||
void addCustomProperty(const QString & name, const QString & value);
|
void startOk();
|
||||||
QString customProperty(const QString & name) const;
|
void secureOk();
|
||||||
|
void tuneOk();
|
||||||
void startOk();
|
void open();
|
||||||
void secureOk();
|
void close(int code, const QString &text, int classId = 0, int methodId = 0);
|
||||||
void tuneOk();
|
void closeOk();
|
||||||
void open();
|
|
||||||
void close(int code, const QString & text, int classId = 0, int methodId = 0);
|
bool isConnected() const;
|
||||||
void closeOk();
|
|
||||||
|
void setQOS(qint32 prefetchSize, quint16 prefetchCount);
|
||||||
bool isConnected() const;
|
|
||||||
|
Q_SIGNALS:
|
||||||
void setQOS(qint32 prefetchSize, quint16 prefetchCount);
|
void disconnected();
|
||||||
|
void connected();
|
||||||
Q_SIGNALS:
|
|
||||||
void disconnected();
|
private:
|
||||||
void connected();
|
Q_DISABLE_COPY(Connection)
|
||||||
protected:
|
Q_DECLARE_PRIVATE(Connection)
|
||||||
ConnectionPrivate * const pd_ptr;
|
QScopedPointer<ConnectionPrivate> d_ptr;
|
||||||
|
|
||||||
private:
|
Connection(Client * parent = 0);
|
||||||
void openOk();
|
|
||||||
friend class ClientPrivate;
|
void openOk();
|
||||||
friend class ChannelPrivate;
|
friend class ClientPrivate;
|
||||||
|
friend class ChannelPrivate;
|
||||||
void _q_method(const QAMQP::Frame::Method & frame);
|
|
||||||
Q_PRIVATE_SLOT(pd_func(), void _q_heartbeat());
|
void _q_method(const QAMQP::Frame::Method &frame);
|
||||||
};
|
Q_PRIVATE_SLOT(d_func(), void _q_heartbeat())
|
||||||
}
|
};
|
||||||
|
|
||||||
// Include private header so MOC won't complain
|
}
|
||||||
#ifdef QAMQP_P_INCLUDE
|
|
||||||
# include "amqp_connection_p.h"
|
#endif // amqp_connection_h__
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // amqp_connection_h__
|
|
||||||
|
|
|
||||||
|
|
@ -1,59 +1,62 @@
|
||||||
#ifndef amqp_connection_p_h__
|
#ifndef amqp_connection_p_h__
|
||||||
#define amqp_connection_p_h__
|
#define amqp_connection_p_h__
|
||||||
|
|
||||||
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
||||||
|
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
namespace QAMQP
|
namespace QAMQP
|
||||||
{
|
{
|
||||||
class Client;
|
class Client;
|
||||||
class ClientPrivate;
|
class ClientPrivate;
|
||||||
class ConnectionPrivate
|
class Connection;
|
||||||
{
|
class ConnectionPrivate
|
||||||
P_DECLARE_PUBLIC(QAMQP::Connection)
|
{
|
||||||
public:
|
public:
|
||||||
enum MethodId
|
enum MethodId {
|
||||||
{
|
METHOD_ID_ENUM(miStart, 10),
|
||||||
METHOD_ID_ENUM(miStart, 10),
|
METHOD_ID_ENUM(miSecure, 20),
|
||||||
METHOD_ID_ENUM(miSecure, 20),
|
METHOD_ID_ENUM(miTune, 30),
|
||||||
METHOD_ID_ENUM(miTune, 30),
|
METHOD_ID_ENUM(miOpen, 40),
|
||||||
METHOD_ID_ENUM(miOpen, 40),
|
METHOD_ID_ENUM(miClose, 50)
|
||||||
METHOD_ID_ENUM(miClose, 50)
|
};
|
||||||
};
|
|
||||||
|
ConnectionPrivate(Connection *q);
|
||||||
ConnectionPrivate(Connection * q);
|
~ConnectionPrivate();
|
||||||
~ConnectionPrivate();
|
|
||||||
void init(Client * parent);
|
void init(Client *parent);
|
||||||
void startOk();
|
void startOk();
|
||||||
void secureOk();
|
void secureOk();
|
||||||
void tuneOk();
|
void tuneOk();
|
||||||
void open();
|
void open();
|
||||||
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 closeOk();
|
void closeOk();
|
||||||
|
|
||||||
void start(const QAMQP::Frame::Method & frame);
|
void start(const QAMQP::Frame::Method &frame);
|
||||||
void secure(const QAMQP::Frame::Method & frame);
|
void secure(const QAMQP::Frame::Method &frame);
|
||||||
void tune(const QAMQP::Frame::Method & frame);
|
void tune(const QAMQP::Frame::Method &frame);
|
||||||
void openOk(const QAMQP::Frame::Method & frame);
|
void openOk(const QAMQP::Frame::Method &frame);
|
||||||
void close(const QAMQP::Frame::Method & frame);
|
void close(const QAMQP::Frame::Method &frame);
|
||||||
void closeOk(const QAMQP::Frame::Method & frame);
|
void closeOk(const QAMQP::Frame::Method &frame);
|
||||||
bool _q_method(const QAMQP::Frame::Method & frame);
|
|
||||||
void _q_heartbeat();
|
bool _q_method(const QAMQP::Frame::Method &frame);
|
||||||
|
void _q_heartbeat();
|
||||||
void setQOS(qint32 prefetchSize, quint16 prefetchCount, int channel, bool global);
|
|
||||||
|
void setQOS(qint32 prefetchSize, quint16 prefetchCount, int channel, bool global);
|
||||||
QPointer<Client> client_;
|
|
||||||
bool closed_;
|
QPointer<Client> client_;
|
||||||
bool connected;
|
bool closed_;
|
||||||
QPointer<QTimer> heartbeatTimer_;
|
bool connected;
|
||||||
|
QPointer<QTimer> heartbeatTimer_;
|
||||||
Connection * const pq_ptr;
|
|
||||||
|
QAMQP::Frame::TableField customProperty;
|
||||||
QAMQP::Frame::TableField customProperty;
|
|
||||||
|
Q_DECLARE_PUBLIC(QAMQP::Connection)
|
||||||
};
|
Connection * const q_ptr;
|
||||||
}
|
};
|
||||||
#endif // amqp_connection_p_h__
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // amqp_connection_p_h__
|
||||||
|
|
|
||||||
|
|
@ -1,276 +1,252 @@
|
||||||
#include "amqp_exchange.h"
|
#include "amqp_exchange.h"
|
||||||
#include "amqp_exchange_p.h"
|
#include "amqp_exchange_p.h"
|
||||||
#include "amqp_queue.h"
|
#include "amqp_queue.h"
|
||||||
|
|
||||||
using namespace QAMQP;
|
using namespace QAMQP;
|
||||||
using namespace QAMQP::Frame;
|
using namespace QAMQP::Frame;
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
|
|
||||||
|
Exchange::Exchange(int channelNumber, Client *parent)
|
||||||
namespace QAMQP
|
: Channel(new ExchangePrivate(this), parent)
|
||||||
{
|
{
|
||||||
struct ExchangeExceptionCleaner
|
Q_D(QAMQP::Exchange);
|
||||||
{
|
d->init(channelNumber, parent);
|
||||||
/* this cleans up when the constructor throws an exception */
|
}
|
||||||
static inline void cleanup(Exchange *that, ExchangePrivate *d)
|
|
||||||
{
|
Exchange::~Exchange()
|
||||||
#ifdef QT_NO_EXCEPTIONS
|
{
|
||||||
Q_UNUSED(that);
|
remove();
|
||||||
Q_UNUSED(d);
|
}
|
||||||
#else
|
|
||||||
Q_UNUSED(that);
|
void Exchange::onOpen()
|
||||||
Q_UNUSED(d);
|
{
|
||||||
#endif
|
Q_D(QAMQP::Exchange);
|
||||||
}
|
if (d->delayedDeclare)
|
||||||
};
|
d->declare();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
void Exchange::onClose()
|
||||||
|
{
|
||||||
Exchange::Exchange(int channelNumber, Client * parent /*= 0*/ )
|
Q_D(QAMQP::Exchange);
|
||||||
: Channel(new ExchangePrivate(this))
|
d->remove(true, true);
|
||||||
{
|
}
|
||||||
QT_TRY {
|
|
||||||
pd_func()->init(channelNumber, parent);
|
Exchange::ExchangeOptions Exchange::option() const
|
||||||
} QT_CATCH(...) {
|
{
|
||||||
ExchangeExceptionCleaner::cleanup(this, pd_func());
|
Q_D(const QAMQP::Exchange);
|
||||||
QT_RETHROW;
|
return d->options;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
QString Exchange::type() const
|
||||||
Exchange::~Exchange()
|
{
|
||||||
{
|
Q_D(const QAMQP::Exchange);
|
||||||
remove();
|
return d->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Exchange::onOpen()
|
void Exchange::declare(const QString &type, ExchangeOptions option , const TableField &arg)
|
||||||
{
|
{
|
||||||
P_D(Exchange);
|
Q_D(QAMQP::Exchange);
|
||||||
if(d->delayedDeclare)
|
d->options = option;
|
||||||
{
|
d->type = type;
|
||||||
d->declare();
|
d->arguments = arg;
|
||||||
}
|
d->declare();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Exchange::onClose()
|
void Exchange::remove(bool ifUnused, bool noWait)
|
||||||
{
|
{
|
||||||
pd_func()->remove(true, true);
|
Q_D(QAMQP::Exchange);
|
||||||
}
|
d->remove(ifUnused, noWait);
|
||||||
|
}
|
||||||
Exchange::ExchangeOptions Exchange::option() const
|
|
||||||
{
|
void Exchange::bind(QAMQP::Queue *queue)
|
||||||
return pd_func()->options;
|
{
|
||||||
}
|
Q_D(QAMQP::Exchange);
|
||||||
|
queue->bind(this, d->name);
|
||||||
QString Exchange::type() const
|
}
|
||||||
{
|
|
||||||
return pd_func()->type;
|
void Exchange::bind(const QString &queueName)
|
||||||
}
|
{
|
||||||
|
Q_UNUSED(queueName);
|
||||||
|
qWarning("Not implemented");
|
||||||
void Exchange::declare(const QString &type, ExchangeOptions option , const TableField & arg)
|
}
|
||||||
{
|
|
||||||
P_D(Exchange);
|
void Exchange::bind(const QString &queueName, const QString &key)
|
||||||
d->options = option;
|
{
|
||||||
d->type = type;
|
Q_UNUSED(queueName);
|
||||||
d->arguments = arg;
|
Q_UNUSED(key);
|
||||||
d->declare();
|
qWarning("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Exchange::remove( bool ifUnused /*= true*/, bool noWait /*= true*/ )
|
void Exchange::publish(const QString &message, const QString &key, const MessageProperties &prop)
|
||||||
{
|
{
|
||||||
pd_func()->remove(ifUnused, noWait);
|
Q_D(QAMQP::Exchange);
|
||||||
}
|
d->publish(message.toUtf8(), key, QLatin1String("text.plain"), QVariantHash(), prop);
|
||||||
|
}
|
||||||
|
|
||||||
void Exchange::bind( QAMQP::Queue * queue )
|
void Exchange::publish(const QByteArray &message, const QString &key,
|
||||||
{
|
const QString &mimeType, const MessageProperties &prop)
|
||||||
queue->bind(this, pd_func()->name);
|
{
|
||||||
}
|
Q_D(QAMQP::Exchange);
|
||||||
|
d->publish(message, key, mimeType, QVariantHash(), prop);
|
||||||
void Exchange::bind( const QString & queueName )
|
}
|
||||||
{
|
|
||||||
Q_UNUSED(queueName);
|
void Exchange::publish(const QByteArray &message, const QString &key,
|
||||||
qWarning("Not implement");
|
const QVariantHash &headers, const QString &mimeType,
|
||||||
}
|
const MessageProperties &prop)
|
||||||
|
{
|
||||||
void Exchange::bind( const QString & queueName, const QString &key )
|
Q_D(QAMQP::Exchange);
|
||||||
{
|
d->publish(message, key, mimeType, headers, prop);
|
||||||
Q_UNUSED(queueName);
|
}
|
||||||
Q_UNUSED(key);
|
|
||||||
qWarning("Not implement");
|
//////////////////////////////////////////////////////////////////////////
|
||||||
}
|
|
||||||
|
ExchangePrivate::ExchangePrivate(Exchange * q)
|
||||||
void Exchange::publish( const QString & message, const QString & key, const MessageProperties &prop )
|
: ChannelPrivate(q),
|
||||||
{
|
delayedDeclare(false),
|
||||||
pd_func()->publish(message.toUtf8(), key, QString::fromLatin1("text.plain"), QVariantHash(), prop);
|
declared(false)
|
||||||
}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void Exchange::publish( const QByteArray & message, const QString & key, const QString &mimeType, const MessageProperties &prop )
|
ExchangePrivate::~ExchangePrivate()
|
||||||
{
|
{
|
||||||
pd_func()->publish(message, key, mimeType, QVariantHash(), prop);
|
}
|
||||||
}
|
|
||||||
|
bool ExchangePrivate::_q_method(const QAMQP::Frame::Method &frame)
|
||||||
void Exchange::publish( const QByteArray & message, const QString & key, const QVariantHash &headers, const QString &mimeType, const MessageProperties &prop )
|
{
|
||||||
{
|
if (ChannelPrivate::_q_method(frame))
|
||||||
pd_func()->publish(message, key, mimeType, headers, prop);
|
return true;
|
||||||
}
|
|
||||||
|
if (frame.methodClass() != QAMQP::Frame::fcExchange)
|
||||||
//////////////////////////////////////////////////////////////////////////
|
return false;
|
||||||
|
|
||||||
|
switch(frame.id()) {
|
||||||
ExchangePrivate::ExchangePrivate(Exchange * q)
|
case miDeclareOk:
|
||||||
:ChannelPrivate(q)
|
declareOk(frame);
|
||||||
, delayedDeclare(false)
|
break;
|
||||||
, declared(false)
|
case miDelete:
|
||||||
{
|
deleteOk(frame);
|
||||||
}
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
ExchangePrivate::~ExchangePrivate()
|
}
|
||||||
{
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExchangePrivate::declareOk(const QAMQP::Frame::Method &frame)
|
||||||
bool ExchangePrivate::_q_method( const QAMQP::Frame::Method & frame )
|
{
|
||||||
{
|
Q_UNUSED(frame)
|
||||||
if(ChannelPrivate::_q_method(frame))
|
Q_Q(QAMQP::Exchange);
|
||||||
return true;
|
qDebug() << "Declared exchange: " << name;
|
||||||
|
declared = true;
|
||||||
if(frame.methodClass() != QAMQP::Frame::fcExchange)
|
QMetaObject::invokeMethod(q, "declared");
|
||||||
return false;
|
}
|
||||||
|
|
||||||
switch(frame.id())
|
void ExchangePrivate::deleteOk(const QAMQP::Frame::Method &frame)
|
||||||
{
|
{
|
||||||
case miDeclareOk:
|
Q_UNUSED(frame)
|
||||||
declareOk(frame);
|
Q_Q(QAMQP::Exchange);
|
||||||
break;
|
qDebug() << "Deleted exchange: " << name;
|
||||||
case miDelete:
|
declared = false;
|
||||||
deleteOk(frame);
|
QMetaObject::invokeMethod(q, "removed");
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
break;
|
void ExchangePrivate::declare()
|
||||||
}
|
{
|
||||||
return true;
|
if (!opened) {
|
||||||
}
|
delayedDeclare = true;
|
||||||
|
return;
|
||||||
void ExchangePrivate::declareOk( const QAMQP::Frame::Method & )
|
}
|
||||||
{
|
|
||||||
qDebug() << "Declared exchange: " << name;
|
if (name.isEmpty())
|
||||||
declared = true;
|
return;
|
||||||
QMetaObject::invokeMethod(pq_func(), "declared");
|
|
||||||
}
|
QAMQP::Frame::Method frame(QAMQP::Frame::fcExchange, miDeclare);
|
||||||
|
frame.setChannel(number);
|
||||||
void ExchangePrivate::deleteOk( const QAMQP::Frame::Method & )
|
QByteArray arguments_;
|
||||||
{
|
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
||||||
qDebug() << "Deleted exchange: " << name;
|
|
||||||
declared = false;
|
stream << qint16(0); //reserver 1
|
||||||
QMetaObject::invokeMethod(pq_func(), "removed");
|
writeField('s', stream, name);
|
||||||
}
|
writeField('s', stream, type);
|
||||||
|
stream << qint8(options);
|
||||||
void ExchangePrivate::declare( )
|
writeField('F', stream, ExchangePrivate::arguments);
|
||||||
{
|
|
||||||
if(!opened)
|
frame.setArguments(arguments_);
|
||||||
{
|
sendFrame(frame);
|
||||||
delayedDeclare = true;
|
delayedDeclare = false;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
void ExchangePrivate::remove(bool ifUnused, bool noWait)
|
||||||
if(name.isEmpty())
|
{
|
||||||
return;
|
QAMQP::Frame::Method frame(QAMQP::Frame::fcExchange, miDelete);
|
||||||
|
frame.setChannel(number);
|
||||||
QAMQP::Frame::Method frame(QAMQP::Frame::fcExchange, miDeclare);
|
QByteArray arguments_;
|
||||||
frame.setChannel(number);
|
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
||||||
QByteArray arguments_;
|
|
||||||
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
stream << qint16(0); //reserver 1
|
||||||
|
writeField('s', stream, name);
|
||||||
stream << qint16(0); //reserver 1
|
|
||||||
writeField('s', stream, name);
|
qint8 flag = 0;
|
||||||
writeField('s', stream, type);
|
|
||||||
stream << qint8(options);
|
flag |= (ifUnused ? 0x1 : 0);
|
||||||
writeField('F', stream, ExchangePrivate::arguments);
|
flag |= (noWait ? 0x2 : 0);
|
||||||
|
|
||||||
frame.setArguments(arguments_);
|
stream << flag; //reserver 1
|
||||||
sendFrame(frame);
|
|
||||||
delayedDeclare = false;
|
frame.setArguments(arguments_);
|
||||||
}
|
sendFrame(frame);
|
||||||
|
}
|
||||||
void ExchangePrivate::remove( bool ifUnused /*= true*/, bool noWait /*= true*/ )
|
|
||||||
{
|
void ExchangePrivate::publish(const QByteArray &message, const QString &key,
|
||||||
QAMQP::Frame::Method frame(QAMQP::Frame::fcExchange, miDelete);
|
const QString &mimeType, const QVariantHash & headers,
|
||||||
frame.setChannel(number);
|
const Exchange::MessageProperties &prop)
|
||||||
QByteArray arguments_;
|
{
|
||||||
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
QAMQP::Frame::Method frame(QAMQP::Frame::fcBasic, bmPublish);
|
||||||
|
frame.setChannel(number);
|
||||||
stream << qint16(0); //reserver 1
|
QByteArray arguments_;
|
||||||
writeField('s', stream, name);
|
QDataStream out(&arguments_, QIODevice::WriteOnly);
|
||||||
|
|
||||||
qint8 flag = 0;
|
out << qint16(0); //reserver 1
|
||||||
|
writeField('s', out, name);
|
||||||
flag |= (ifUnused ? 0x1 : 0);
|
writeField('s', out, key);
|
||||||
flag |= (noWait ? 0x2 : 0);
|
out << qint8(0);
|
||||||
|
|
||||||
stream << flag; //reserver 1
|
frame.setArguments(arguments_);
|
||||||
|
sendFrame(frame);
|
||||||
frame.setArguments(arguments_);
|
|
||||||
sendFrame(frame);
|
QAMQP::Frame::Content content(QAMQP::Frame::fcBasic);
|
||||||
}
|
content.setChannel(number);
|
||||||
|
content.setProperty(Content::cpContentType, mimeType);
|
||||||
void ExchangePrivate::publish( const QByteArray & message, const QString & key, const QString &mimeType /*= QString::fromLatin1("text/plain")*/, const QVariantHash & headers, const Exchange::MessageProperties & prop )
|
content.setProperty(Content::cpContentEncoding, "utf-8");
|
||||||
{
|
content.setProperty(Content::cpHeaders, headers);
|
||||||
QAMQP::Frame::Method frame(QAMQP::Frame::fcBasic, bmPublish);
|
content.setProperty(Content::cpMessageId, "0");
|
||||||
frame.setChannel(number);
|
|
||||||
QByteArray arguments_;
|
Exchange::MessageProperties::ConstIterator i;
|
||||||
QDataStream out(&arguments_, QIODevice::WriteOnly);
|
|
||||||
|
for (i = prop.begin(); i != prop.end(); ++i)
|
||||||
out << qint16(0); //reserver 1
|
content.setProperty(i.key(), i.value());
|
||||||
writeField('s', out, name);
|
|
||||||
writeField('s', out, key);
|
content.setBody(message);
|
||||||
out << qint8(0);
|
sendFrame(content);
|
||||||
|
|
||||||
frame.setArguments(arguments_);
|
int fullSize = message.size();
|
||||||
sendFrame(frame);
|
for (int sended_ = 0; sended_ < fullSize; sended_+= (FRAME_MAX - 7)) {
|
||||||
|
QAMQP::Frame::ContentBody body;
|
||||||
|
QByteArray partition_ = message.mid(sended_, (FRAME_MAX - 7));
|
||||||
QAMQP::Frame::Content content(QAMQP::Frame::fcBasic);
|
body.setChannel(number);
|
||||||
content.setChannel(number);
|
body.setBody(partition_);
|
||||||
content.setProperty(Content::cpContentType, mimeType);
|
sendFrame(body);
|
||||||
content.setProperty(Content::cpContentEncoding, "utf-8");
|
}
|
||||||
content.setProperty(Content::cpHeaders, headers);
|
}
|
||||||
content.setProperty(Content::cpMessageId, "0");
|
|
||||||
|
void ExchangePrivate::_q_disconnected()
|
||||||
Exchange::MessageProperties::ConstIterator i;
|
{
|
||||||
|
ChannelPrivate::_q_disconnected();
|
||||||
for(i = prop.begin(); i != prop.end(); ++i)
|
qDebug() << "Exchange " << name << " disconnected";
|
||||||
{
|
delayedDeclare = false;
|
||||||
content.setProperty(i.key(), i.value());
|
declared = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
content.setBody(message);
|
|
||||||
sendFrame(content);
|
|
||||||
|
|
||||||
int fullSize = message.size();
|
|
||||||
for (int sended_ = 0; sended_ < fullSize; sended_+= (FRAME_MAX - 7))
|
|
||||||
{
|
|
||||||
QAMQP::Frame::ContentBody body;
|
|
||||||
QByteArray partition_ = message.mid(sended_, (FRAME_MAX - 7));
|
|
||||||
body.setChannel(number);
|
|
||||||
body.setBody(partition_);
|
|
||||||
sendFrame(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ExchangePrivate::_q_disconnected()
|
|
||||||
{
|
|
||||||
ChannelPrivate::_q_disconnected();
|
|
||||||
qDebug() << "Exchange " << name << " disconnected";
|
|
||||||
delayedDeclare = false;
|
|
||||||
declared = false;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,64 +1,76 @@
|
||||||
#ifndef amqp_exchange_h__
|
#ifndef amqp_exchange_h__
|
||||||
#define amqp_exchange_h__
|
#define amqp_exchange_h__
|
||||||
|
|
||||||
#include "amqp_channel.h"
|
#include "amqp_channel.h"
|
||||||
namespace QAMQP
|
|
||||||
{
|
namespace QAMQP
|
||||||
class Client;
|
{
|
||||||
class Queue;
|
|
||||||
class ClientPrivate;
|
using namespace QAMQP::Frame;
|
||||||
class ExchangePrivate;
|
|
||||||
|
class Client;
|
||||||
using namespace QAMQP::Frame;
|
class Queue;
|
||||||
class Exchange : public Channel
|
class ClientPrivate;
|
||||||
{
|
class ExchangePrivate;
|
||||||
Q_OBJECT;
|
class Exchange : public Channel
|
||||||
Exchange(int channelNumber = -1, Client * parent = 0);
|
{
|
||||||
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString type READ type);
|
Q_PROPERTY(QString type READ type)
|
||||||
Q_PROPERTY(ExchangeOptions option READ option );
|
Q_PROPERTY(ExchangeOptions option READ option)
|
||||||
|
Q_ENUMS(ExchangeOption)
|
||||||
P_DECLARE_PRIVATE(QAMQP::Exchange)
|
|
||||||
Q_DISABLE_COPY(Exchange);
|
public:
|
||||||
friend class ClientPrivate;
|
enum ExchangeOption {
|
||||||
protected:
|
NoOptions = 0x0,
|
||||||
void onOpen();
|
Passive = 0x01,
|
||||||
void onClose();
|
Durable = 0x02,
|
||||||
|
AutoDelete = 0x4,
|
||||||
public:
|
Internal = 0x8,
|
||||||
|
NoWait = 0x10
|
||||||
enum ExchangeOption {
|
};
|
||||||
NoOptions = 0x0,
|
Q_DECLARE_FLAGS(ExchangeOptions, ExchangeOption)
|
||||||
Passive = 0x01,
|
|
||||||
Durable = 0x02,
|
typedef QHash<QAMQP::Frame::Content::Property, QVariant> MessageProperties;
|
||||||
AutoDelete = 0x4,
|
|
||||||
Internal = 0x8,
|
virtual ~Exchange();
|
||||||
NoWait = 0x10
|
|
||||||
};
|
QString type() const;
|
||||||
Q_DECLARE_FLAGS(ExchangeOptions, ExchangeOption)
|
ExchangeOptions option() const;
|
||||||
|
|
||||||
typedef QHash<QAMQP::Frame::Content::Property, QVariant> MessageProperties;
|
void declare(const QString &type = QLatin1String("direct"),
|
||||||
|
ExchangeOptions option = NoOptions,
|
||||||
~Exchange();
|
const TableField &arg = TableField());
|
||||||
|
void remove(bool ifUnused = true, bool noWait = true);
|
||||||
QString type() const;
|
|
||||||
ExchangeOptions option() const;
|
void bind(QAMQP::Queue *queue);
|
||||||
|
void bind(const QString &queueName);
|
||||||
void declare(const QString &type = QString::fromLatin1("direct"), ExchangeOptions option = NoOptions, const TableField & arg = TableField());
|
void bind(const QString &queueName, const QString &key);
|
||||||
void remove(bool ifUnused = true, bool noWait = true);
|
|
||||||
|
void publish(const QString &message, const QString &key,
|
||||||
void bind(QAMQP::Queue * queue);
|
const MessageProperties &property = MessageProperties());
|
||||||
void bind(const QString & queueName);
|
void publish(const QByteArray &message, const QString &key,
|
||||||
void bind(const QString & queueName, const QString &key);
|
const QString &mimeType, const MessageProperties &property = MessageProperties());
|
||||||
|
void publish(const QByteArray &message, const QString &key, const QVariantHash &headers,
|
||||||
void publish(const QString & message, const QString & key, const MessageProperties &property = MessageProperties() );
|
const QString &mimeType, const MessageProperties &property = MessageProperties());
|
||||||
void publish(const QByteArray & message, const QString & key, const QString &mimeType, const MessageProperties &property = MessageProperties());
|
|
||||||
void publish(const QByteArray & message, const QString & key, const QVariantHash &headers, const QString &mimeType, const MessageProperties &property = MessageProperties());
|
Q_SIGNALS:
|
||||||
|
void declared();
|
||||||
Q_SIGNALS:
|
void removed();
|
||||||
void declared();
|
|
||||||
void removed();
|
protected:
|
||||||
};
|
void onOpen();
|
||||||
}
|
void onClose();
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QAMQP::Exchange::ExchangeOptions)
|
|
||||||
#endif // amqp_exchange_h__
|
private:
|
||||||
|
Q_DISABLE_COPY(Exchange)
|
||||||
|
Q_DECLARE_PRIVATE(QAMQP::Exchange)
|
||||||
|
Exchange(int channelNumber = -1, Client * parent = 0);
|
||||||
|
friend class ClientPrivate;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(QAMQP::Exchange::ExchangeOptions)
|
||||||
|
|
||||||
|
#endif // amqp_exchange_h__
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,44 @@
|
||||||
#include "amqp_channel_p.h"
|
#include "amqp_channel_p.h"
|
||||||
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
|
||||||
|
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
||||||
namespace QAMQP
|
|
||||||
{
|
namespace QAMQP
|
||||||
using namespace QAMQP::Frame;
|
{
|
||||||
class ExchangePrivate: public ChannelPrivate
|
|
||||||
{
|
using namespace QAMQP::Frame;
|
||||||
P_DECLARE_PUBLIC(QAMQP::Exchange)
|
class ExchangePrivate: public ChannelPrivate
|
||||||
public:
|
{
|
||||||
|
public:
|
||||||
enum MethodId
|
enum MethodId {
|
||||||
{
|
METHOD_ID_ENUM(miDeclare, 10),
|
||||||
METHOD_ID_ENUM(miDeclare, 10),
|
METHOD_ID_ENUM(miDelete, 20)
|
||||||
METHOD_ID_ENUM(miDelete, 20)
|
};
|
||||||
};
|
|
||||||
|
ExchangePrivate(Exchange * q);
|
||||||
ExchangePrivate(Exchange * q);
|
~ExchangePrivate();
|
||||||
~ExchangePrivate();
|
|
||||||
|
void declare();
|
||||||
void declare();
|
void remove(bool ifUnused = true, bool noWait = true);
|
||||||
void remove(bool ifUnused = true, bool noWait = true);
|
|
||||||
|
void declareOk(const QAMQP::Frame::Method &frame);
|
||||||
void declareOk(const QAMQP::Frame::Method & frame);
|
void deleteOk(const QAMQP::Frame::Method &frame);
|
||||||
void deleteOk(const QAMQP::Frame::Method & frame);
|
|
||||||
|
void publish(const QByteArray &message, const QString &key,
|
||||||
void publish(const QByteArray & message, const QString & key, const QString &mimeType = QString::fromLatin1("text/plain"), const QVariantHash & headers = QVariantHash(), const Exchange::MessageProperties & properties = Exchange::MessageProperties());
|
const QString &mimeType = QLatin1String("text/plain"),
|
||||||
|
const QVariantHash &headers = QVariantHash(),
|
||||||
QString type;
|
const Exchange::MessageProperties &properties = Exchange::MessageProperties());
|
||||||
Exchange::ExchangeOptions options;
|
|
||||||
TableField arguments;
|
QString type;
|
||||||
|
Exchange::ExchangeOptions options;
|
||||||
bool _q_method(const QAMQP::Frame::Method & frame);
|
TableField arguments;
|
||||||
void _q_disconnected();
|
|
||||||
|
bool _q_method(const QAMQP::Frame::Method &frame);
|
||||||
bool delayedDeclare;
|
void _q_disconnected();
|
||||||
bool declared;
|
|
||||||
|
bool delayedDeclare;
|
||||||
};
|
bool declared;
|
||||||
}
|
|
||||||
|
Q_DECLARE_PUBLIC(QAMQP::Exchange)
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,421 +1,421 @@
|
||||||
#ifndef amqp_frame_h__
|
#ifndef amqp_frame_h__
|
||||||
#define amqp_frame_h__
|
#define amqp_frame_h__
|
||||||
|
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#define AMQP_BASIC_CONTENT_TYPE_FLAG (1 << 15)
|
#define AMQP_BASIC_CONTENT_TYPE_FLAG (1 << 15)
|
||||||
#define AMQP_BASIC_CONTENT_ENCODING_FLAG (1 << 7)
|
#define AMQP_BASIC_CONTENT_ENCODING_FLAG (1 << 7)
|
||||||
#define AMQP_BASIC_HEADERS_FLAG (1 << 13)
|
#define AMQP_BASIC_HEADERS_FLAG (1 << 13)
|
||||||
#define AMQP_BASIC_DELIVERY_MODE_FLAG (1 << 12)
|
#define AMQP_BASIC_DELIVERY_MODE_FLAG (1 << 12)
|
||||||
#define AMQP_BASIC_PRIORITY_FLAG (1 << 11)
|
#define AMQP_BASIC_PRIORITY_FLAG (1 << 11)
|
||||||
#define AMQP_BASIC_CORRELATION_ID_FLAG (1 << 10)
|
#define AMQP_BASIC_CORRELATION_ID_FLAG (1 << 10)
|
||||||
#define AMQP_BASIC_REPLY_TO_FLAG (1 << 9)
|
#define AMQP_BASIC_REPLY_TO_FLAG (1 << 9)
|
||||||
#define AMQP_BASIC_EXPIRATION_FLAG (1 << 8)
|
#define AMQP_BASIC_EXPIRATION_FLAG (1 << 8)
|
||||||
#define AMQP_BASIC_MESSAGE_ID_FLAG (1 << 14)
|
#define AMQP_BASIC_MESSAGE_ID_FLAG (1 << 14)
|
||||||
#define AMQP_BASIC_TIMESTAMP_FLAG (1 << 6)
|
#define AMQP_BASIC_TIMESTAMP_FLAG (1 << 6)
|
||||||
#define AMQP_BASIC_TYPE_FLAG (1 << 5)
|
#define AMQP_BASIC_TYPE_FLAG (1 << 5)
|
||||||
#define AMQP_BASIC_USER_ID_FLAG (1 << 4)
|
#define AMQP_BASIC_USER_ID_FLAG (1 << 4)
|
||||||
#define AMQP_BASIC_APP_ID_FLAG (1 << 3)
|
#define AMQP_BASIC_APP_ID_FLAG (1 << 3)
|
||||||
#define AMQP_BASIC_CLUSTER_ID_FLAG (1 << 2)
|
#define AMQP_BASIC_CLUSTER_ID_FLAG (1 << 2)
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
Library namespace
|
* Library namespace
|
||||||
@namespace QAMQP
|
* @namespace QAMQP
|
||||||
*/
|
*/
|
||||||
namespace QAMQP
|
namespace QAMQP
|
||||||
{
|
{
|
||||||
class QueuePrivate;
|
|
||||||
/*!
|
class QueuePrivate;
|
||||||
Frame namespace
|
|
||||||
@namespace Frame
|
namespace Frame
|
||||||
*/
|
{
|
||||||
namespace Frame
|
typedef quint16 channel_t;
|
||||||
{
|
|
||||||
typedef quint16 channel_t;
|
/*
|
||||||
/*!
|
* @brief Header size in bytes
|
||||||
@brief Header size in bytes
|
*/
|
||||||
*/
|
static const qint64 HEADER_SIZE = 7;
|
||||||
static const qint64 HEADER_SIZE = 7;
|
|
||||||
/*!
|
/*
|
||||||
@brief Frame end indicator size in bytes
|
* @brief Frame end indicator size in bytes
|
||||||
*/
|
*/
|
||||||
static const qint64 FRAME_END_SIZE = 1;
|
static const qint64 FRAME_END_SIZE = 1;
|
||||||
|
|
||||||
/*!
|
/*
|
||||||
@brief Frame end marker
|
* @brief Frame end marker
|
||||||
*/
|
*/
|
||||||
static const quint8 FRAME_END = 0xCE;
|
static const quint8 FRAME_END = 0xCE;
|
||||||
|
|
||||||
/*!
|
/*
|
||||||
@brief Frame type
|
* @brief Frame type
|
||||||
*/
|
*/
|
||||||
enum Type
|
enum Type
|
||||||
{
|
{
|
||||||
ftMethod = 1, /*!< Used define method frame */
|
ftMethod = 1, /*!< Used define method frame */
|
||||||
ftHeader = 2, /*!< Used define content header frame */
|
ftHeader = 2, /*!< Used define content header frame */
|
||||||
ftBody = 3, /*!< Used define content body frame */
|
ftBody = 3, /*!< Used define content body frame */
|
||||||
ftHeartbeat = 8 /*!< Used define heartbeat frame */
|
ftHeartbeat = 8 /*!< Used define heartbeat frame */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*
|
||||||
@brief Frame method class
|
* @brief Frame method class
|
||||||
@enum MethodClass
|
* @enum MethodClass
|
||||||
*/
|
*/
|
||||||
enum MethodClass
|
enum MethodClass
|
||||||
{
|
{
|
||||||
fcConnection = 10, /*!< Define class of methods related to connection */
|
fcConnection = 10, // Define class of methods related to connection
|
||||||
fcChannel = 20, /*!< Define class of methods related to channel */
|
fcChannel = 20, // Define class of methods related to channel
|
||||||
fcExchange = 40, /*!< Define class of methods related to exchange */
|
fcExchange = 40, // Define class of methods related to exchange
|
||||||
fcQueue = 50, /*!< Define class of methods related to queue */
|
fcQueue = 50, // Define class of methods related to queue
|
||||||
fcBasic = 60, /*!< Define class of methods related to basic command */
|
fcBasic = 60, // Define class of methods related to basic command
|
||||||
fcTx = 90,
|
fcTx = 90,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct decimal
|
struct decimal
|
||||||
{
|
{
|
||||||
qint8 scale;
|
qint8 scale;
|
||||||
quint32 value;
|
quint32 value;
|
||||||
|
};
|
||||||
};
|
|
||||||
|
/*
|
||||||
/*!
|
* @brief Definition implementation of TableField type
|
||||||
@brief Definition implementation of TableField type
|
* @detailed Define implementation TableField type in builtin Qt types. Key contains field name, value contains field data.
|
||||||
@detailed Define implementation TableField type in builtin Qt types. Key contains field name, value contains field data.
|
* It can by any type witch support serialization in AMQP types.
|
||||||
It can by any type witch support serialization in AMQP types.
|
*/
|
||||||
*/
|
typedef QHash<QString, QVariant> TableField;
|
||||||
typedef QHash<QString, QVariant> TableField;
|
|
||||||
|
QDataStream & serialize( QDataStream & stream, const QAMQP::Frame::TableField & f );
|
||||||
QDataStream & serialize( QDataStream & stream, const QAMQP::Frame::TableField & f );
|
QDataStream & deserialize( QDataStream & stream, QAMQP::Frame::TableField & f );
|
||||||
QDataStream & deserialize( QDataStream & stream, QAMQP::Frame::TableField & f );
|
QVariant readField( qint8 valueType, QDataStream &s );
|
||||||
QVariant readField( qint8 valueType, QDataStream &s );
|
void writeField( QDataStream &s, const QVariant & value );
|
||||||
void writeField( QDataStream &s, const QVariant & value );
|
void writeField( qint8 valueType, QDataStream &s, const QVariant & value, bool withType = false );
|
||||||
void writeField( qint8 valueType, QDataStream &s, const QVariant & value, bool withType = false );
|
void print( const QAMQP::Frame::TableField & f );
|
||||||
void print( const QAMQP::Frame::TableField & f );
|
|
||||||
|
/*
|
||||||
/*!
|
* @brief Base class for any frames.
|
||||||
@brief Base class for any frames.
|
* @detailed Implement main methods for serialize and deserialize raw frame data.
|
||||||
@detailed Implement main methods for serialize and deserialize raw frame data.
|
* All frames start with a 7-octet header composed of a type field (octet), a channel field (short integer) and a
|
||||||
All frames start with a 7-octet header composed of a type field (octet), a channel field (short integer) and a
|
* size field (long integer):
|
||||||
size field (long integer):
|
* @code Frame struct
|
||||||
@code Frame struct
|
* 0 1 3 7 size+7 size+8
|
||||||
0 1 3 7 size+7 size+8
|
* +------+---------+---------+ +-------------+ +-----------+
|
||||||
+------+---------+---------+ +-------------+ +-----------+
|
* | type | channel | size | | payload | | frame-end |
|
||||||
| type | channel | size | | payload | | frame-end |
|
* +------+---------+---------+ +-------------+ +-----------+
|
||||||
+------+---------+---------+ +-------------+ +-----------+
|
* @endcode
|
||||||
@endcode
|
* octet short long 'size' octets octet
|
||||||
octet short long 'size' octets octet
|
*/
|
||||||
*/
|
class Base
|
||||||
class Base
|
{
|
||||||
{
|
public:
|
||||||
public:
|
/*
|
||||||
/*!
|
* Base class constructor.
|
||||||
Base class constructor.
|
* @detailed Construct frame class for sending.
|
||||||
@detailed Construct frame class for sending.
|
* @param type Define type of constructed frame.
|
||||||
@param type Define type of constructed frame.
|
*/
|
||||||
*/
|
Base(Type type);
|
||||||
Base(Type type);
|
|
||||||
|
/*
|
||||||
/*!
|
* Base class constructor.
|
||||||
Base class constructor.
|
* @detailed Construct frame class from received raw data.
|
||||||
@detailed Construct frame class from received raw data.
|
* @param raw Data stream for reading source data.
|
||||||
@param raw Data stream for reading source data.
|
*/
|
||||||
*/
|
Base(QDataStream& raw);
|
||||||
Base(QDataStream& raw);
|
|
||||||
|
/*
|
||||||
/*!
|
* Base class virtual destructor
|
||||||
Base class virtual destructor
|
*/
|
||||||
*/
|
virtual ~Base();
|
||||||
virtual ~Base();
|
|
||||||
|
/*
|
||||||
/*!
|
* Frame type
|
||||||
Frame type
|
* @detailed Return type of current frame.
|
||||||
@detailed Return type of current frame.
|
*/
|
||||||
*/
|
Type type() const;
|
||||||
Type type() const;
|
|
||||||
|
/*
|
||||||
/*!
|
* Set number of associated channel.
|
||||||
Set number of associated channel.
|
* @param channel Number of channel.
|
||||||
@param channel Number of channel.
|
* @sa channel()
|
||||||
@sa channel()
|
*/
|
||||||
*/
|
void setChannel(qint16 channel);
|
||||||
void setChannel(qint16 channel);
|
|
||||||
|
/*
|
||||||
/*!
|
* Return number of associated channel.
|
||||||
Return number of associated channel.
|
* @sa setChannel()
|
||||||
@sa setChannel()
|
*/
|
||||||
*/
|
qint16 channel() const;
|
||||||
qint16 channel() const;
|
|
||||||
|
/*
|
||||||
/*!
|
* Return size of frame.
|
||||||
Return size of frame.
|
*/
|
||||||
*/
|
virtual qint32 size() const;
|
||||||
virtual qint32 size() const;
|
|
||||||
|
/*
|
||||||
/*!
|
* Output frame to stream.
|
||||||
Output frame to stream.
|
* @param stream Stream for serilize frame.
|
||||||
@param stream Stream for serilize frame.
|
*/
|
||||||
*/
|
void toStream(QDataStream &stream) const;
|
||||||
void toStream(QDataStream & stream) const;
|
|
||||||
|
protected:
|
||||||
protected:
|
void writeHeader(QDataStream &stream) const;
|
||||||
void writeHeader(QDataStream & stream) const;
|
virtual void writePayload(QDataStream &stream) const;
|
||||||
virtual void writePayload(QDataStream & stream) const;
|
void writeEnd(QDataStream &stream) const;
|
||||||
void writeEnd(QDataStream & stream) const;
|
|
||||||
|
void readHeader(QDataStream &stream);
|
||||||
void readHeader(QDataStream & stream);
|
virtual void readPayload(QDataStream &stream);
|
||||||
virtual void readPayload(QDataStream & stream);
|
void readEnd(QDataStream &stream);
|
||||||
void readEnd(QDataStream & stream);
|
|
||||||
|
qint32 size_;
|
||||||
qint32 size_;
|
|
||||||
private:
|
private:
|
||||||
qint8 type_;
|
qint8 type_;
|
||||||
|
qint16 channel_;
|
||||||
qint16 channel_;
|
|
||||||
|
};
|
||||||
};
|
|
||||||
|
/*
|
||||||
/*!
|
* @brief Class for working with method frames.
|
||||||
@brief Class for working with method frames.
|
* @detailed Implement main methods for serialize and deserialize raw method frame data.
|
||||||
@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
|
||||||
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:
|
||||||
with identifier numbers for the class and method:
|
* @code Frame struct
|
||||||
@code Frame struct
|
* 0 2 4
|
||||||
0 2 4
|
* +----------+-----------+-------------- - -
|
||||||
+----------+-----------+-------------- - -
|
* | class-id | method-id | arguments...
|
||||||
| class-id | method-id | arguments...
|
* +----------+-----------+-------------- - -
|
||||||
+----------+-----------+-------------- - -
|
* short short ...
|
||||||
short short ...
|
* @endcode
|
||||||
@endcode
|
*/
|
||||||
*/
|
class Method : public Base
|
||||||
class Method : public Base
|
{
|
||||||
{
|
public:
|
||||||
public:
|
/*
|
||||||
/*!
|
* Method class constructor.
|
||||||
Method class constructor.
|
* @detailed Construct frame class for sending.
|
||||||
@detailed Construct frame class for sending.
|
*/
|
||||||
*/
|
Method();
|
||||||
Method();
|
|
||||||
|
/*
|
||||||
/*!
|
* Method class constructor.
|
||||||
Method class constructor.
|
* @detailed Construct frame class for sending.
|
||||||
@detailed Construct frame class for sending.
|
* @param methodClass Define method class id of constructed frame.
|
||||||
@param methodClass Define method class id of constructed frame.
|
* @param id Define method id of constructed frame.
|
||||||
@param id Define method id of constructed frame.
|
*/
|
||||||
*/
|
Method(MethodClass methodClass, qint16 id);
|
||||||
Method(MethodClass methodClass, qint16 id);
|
|
||||||
|
/*
|
||||||
/*!
|
* Method class constructor.
|
||||||
Method class constructor.
|
* @detailed Construct frame class from received raw data.
|
||||||
@detailed Construct frame class from received raw data.
|
* @param raw Data stream for reading source data.
|
||||||
@param raw Data stream for reading source data.
|
*/
|
||||||
*/
|
Method(QDataStream &raw);
|
||||||
Method(QDataStream& raw);
|
|
||||||
|
/*
|
||||||
/*!
|
* Method class type.
|
||||||
Method class type.
|
*/
|
||||||
*/
|
MethodClass methodClass() const;
|
||||||
MethodClass methodClass() const;
|
|
||||||
|
/*
|
||||||
/*!
|
* Method id.
|
||||||
Method id.
|
*/
|
||||||
*/
|
qint16 id() const;
|
||||||
qint16 id() const;
|
qint32 size() const;
|
||||||
qint32 size() const;
|
|
||||||
|
/*
|
||||||
/*!
|
* Set arguments for method.
|
||||||
Set arguments for method.
|
* @param data Serialized method arguments.
|
||||||
@param data Serialized method arguments.
|
* @sa arguments
|
||||||
@sa arguments
|
*/
|
||||||
*/
|
void setArguments(const QByteArray &data);
|
||||||
void setArguments(const QByteArray & data);
|
|
||||||
|
/*
|
||||||
/*!
|
* Return arguments for method.
|
||||||
Return arguments for method.
|
* @sa setArguments
|
||||||
@sa setArguments
|
*/
|
||||||
*/
|
QByteArray arguments() const;
|
||||||
QByteArray arguments() const;
|
|
||||||
|
protected:
|
||||||
protected:
|
void writePayload(QDataStream & stream) const;
|
||||||
void writePayload(QDataStream & stream) const;
|
void readPayload(QDataStream & stream);
|
||||||
void readPayload(QDataStream & stream);
|
short methodClass_;
|
||||||
short methodClass_;
|
qint16 id_;
|
||||||
qint16 id_;
|
QByteArray arguments_;
|
||||||
QByteArray arguments_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*
|
||||||
@brief Class for working with content frames.
|
* @brief Class for working with content frames.
|
||||||
@detailed Implement main methods for serialize and deserialize raw content frame data.
|
* @detailed Implement main methods for serialize and deserialize raw content frame data.
|
||||||
A content header payload has this format:
|
* A content header payload has this format:
|
||||||
@code Frame struct
|
* @code Frame struct
|
||||||
+----------+--------+-----------+----------------+------------- - -
|
* +----------+--------+-----------+----------------+------------- - -
|
||||||
| class-id | weight | body size | property flags | property list...
|
* | class-id | weight | body size | property flags | property list...
|
||||||
+----------+--------+-----------+----------------+------------- - -
|
* +----------+--------+-----------+----------------+------------- - -
|
||||||
short short long long short remainder...
|
* short short long long short remainder...
|
||||||
@endcode
|
* @endcode
|
||||||
|
*
|
||||||
| Property | Description |
|
* | Property | Description |
|
||||||
| ---------- | ----------- |
|
* | ---------- | ----------- |
|
||||||
|cpContentType | MIME content type |
|
* |cpContentType | MIME content type |
|
||||||
| ocpContentEncoding | MIME content encoding |
|
* | ocpContentEncoding | MIME content encoding |
|
||||||
| cpHeaders | message header field table |
|
* | cpHeaders | message header field table |
|
||||||
| cpDeliveryMode| nonpersistent (1) or persistent (2) |
|
* | cpDeliveryMode| nonpersistent (1) or persistent (2) |
|
||||||
| cpPriority | message priority, 0 to 9 |
|
* | cpPriority | message priority, 0 to 9 |
|
||||||
| cpCorrelationId | application correlation identifier |
|
* | cpCorrelationId | application correlation identifier |
|
||||||
| cpReplyTo | address to reply to |
|
* | cpReplyTo | address to reply to |
|
||||||
| cpExpiration | message expiration specification |
|
* | cpExpiration | message expiration specification |
|
||||||
| cpMessageId | application message identifier |
|
* | cpMessageId | application message identifier |
|
||||||
| cpTimestamp | message timestamp |
|
* | cpTimestamp | message timestamp |
|
||||||
| cpType | message type name |
|
* | cpType | message type name |
|
||||||
| cpUserId | creating user id |
|
* | cpUserId | creating user id |
|
||||||
| cpAppId | creating application id |
|
* | cpAppId | creating application id |
|
||||||
| cpClusterID| cluster ID |
|
* | cpClusterID| cluster ID |
|
||||||
|
*
|
||||||
Default property:
|
* Default property:
|
||||||
@sa setProperty
|
* @sa setProperty
|
||||||
@sa property
|
* @sa property
|
||||||
|
*/
|
||||||
*/
|
class Content : public Base
|
||||||
class Content : public Base
|
{
|
||||||
{
|
friend class QAMQP::QueuePrivate;
|
||||||
friend class QAMQP::QueuePrivate;
|
|
||||||
public:
|
public:
|
||||||
|
/*
|
||||||
/*! Default content frame property
|
* Default content frame property
|
||||||
|
*/
|
||||||
*/
|
enum Property
|
||||||
enum Property
|
{
|
||||||
{
|
cpContentType = AMQP_BASIC_CONTENT_TYPE_FLAG,
|
||||||
cpContentType = AMQP_BASIC_CONTENT_TYPE_FLAG,
|
cpContentEncoding = AMQP_BASIC_CONTENT_ENCODING_FLAG,
|
||||||
cpContentEncoding = AMQP_BASIC_CONTENT_ENCODING_FLAG,
|
cpHeaders = AMQP_BASIC_HEADERS_FLAG,
|
||||||
cpHeaders = AMQP_BASIC_HEADERS_FLAG,
|
cpDeliveryMode = AMQP_BASIC_DELIVERY_MODE_FLAG,
|
||||||
cpDeliveryMode = AMQP_BASIC_DELIVERY_MODE_FLAG,
|
cpPriority = AMQP_BASIC_PRIORITY_FLAG,
|
||||||
cpPriority = AMQP_BASIC_PRIORITY_FLAG,
|
cpCorrelationId = AMQP_BASIC_CORRELATION_ID_FLAG,
|
||||||
cpCorrelationId = AMQP_BASIC_CORRELATION_ID_FLAG,
|
cpReplyTo = AMQP_BASIC_REPLY_TO_FLAG,
|
||||||
cpReplyTo = AMQP_BASIC_REPLY_TO_FLAG,
|
cpExpiration = AMQP_BASIC_EXPIRATION_FLAG,
|
||||||
cpExpiration = AMQP_BASIC_EXPIRATION_FLAG,
|
cpMessageId = AMQP_BASIC_MESSAGE_ID_FLAG,
|
||||||
cpMessageId = AMQP_BASIC_MESSAGE_ID_FLAG,
|
cpTimestamp = AMQP_BASIC_TIMESTAMP_FLAG,
|
||||||
cpTimestamp = AMQP_BASIC_TIMESTAMP_FLAG,
|
cpType = AMQP_BASIC_TYPE_FLAG,
|
||||||
cpType = AMQP_BASIC_TYPE_FLAG,
|
cpUserId = AMQP_BASIC_USER_ID_FLAG,
|
||||||
cpUserId = AMQP_BASIC_USER_ID_FLAG,
|
cpAppId = AMQP_BASIC_APP_ID_FLAG,
|
||||||
cpAppId = AMQP_BASIC_APP_ID_FLAG,
|
cpClusterID = AMQP_BASIC_CLUSTER_ID_FLAG
|
||||||
cpClusterID = AMQP_BASIC_CLUSTER_ID_FLAG
|
};
|
||||||
};
|
Q_DECLARE_FLAGS(Properties, Property)
|
||||||
Q_DECLARE_FLAGS(Properties, Property);
|
|
||||||
|
/*
|
||||||
/*!
|
* Content class constructor.
|
||||||
Content class constructor.
|
* @detailed Construct frame content header class for sending.
|
||||||
@detailed Construct frame content header class for sending.
|
*/
|
||||||
*/
|
Content();
|
||||||
Content();
|
|
||||||
|
/*
|
||||||
/*!
|
* Content class constructor.
|
||||||
Content class constructor.
|
* @detailed Construct frame content header class for sending.
|
||||||
@detailed Construct frame content header class for sending.
|
* @param methodClass Define method class id of constructed frame.
|
||||||
@param methodClass Define method class id of constructed frame.
|
*/
|
||||||
*/
|
Content(MethodClass methodClass);
|
||||||
Content(MethodClass methodClass);
|
|
||||||
|
/*
|
||||||
/*!
|
* Content class constructor.
|
||||||
Content class constructor.
|
* @detailed Construct frame content header class for sending.
|
||||||
@detailed Construct frame content header class for sending.
|
* @param raw Data stream for reading source data.
|
||||||
@param raw Data stream for reading source data.
|
*/
|
||||||
*/
|
Content(QDataStream &raw);
|
||||||
Content(QDataStream& raw);
|
|
||||||
|
/*
|
||||||
/*!
|
* Method class type.
|
||||||
Method class type.
|
*/
|
||||||
*/
|
MethodClass methodClass() const;
|
||||||
MethodClass methodClass() const;
|
qint32 size() const;
|
||||||
qint32 size() const;
|
|
||||||
|
/*
|
||||||
/*!
|
* Set default content header property
|
||||||
Set default content header property
|
* @param prop Any default content header property
|
||||||
@param prop Any default content header property
|
* @param value Associated data
|
||||||
@param value Associated data
|
*/
|
||||||
*/
|
void setProperty(Property prop, const QVariant &value);
|
||||||
void setProperty(Property prop, const QVariant & value);
|
|
||||||
|
/*
|
||||||
/*!
|
* Return associated with property value
|
||||||
Return associated with property value
|
* @param prop Any default content header property
|
||||||
@param prop Any default content header property
|
*/
|
||||||
*/
|
QVariant property(Property prop) const;
|
||||||
QVariant property(Property prop) const;
|
|
||||||
|
void setBody(const QByteArray &data);
|
||||||
|
QByteArray body() const;
|
||||||
void setBody(const QByteArray & data);
|
qlonglong bodySize() const;
|
||||||
QByteArray body() const;
|
|
||||||
qlonglong bodySize() const;
|
protected:
|
||||||
|
void writePayload(QDataStream &stream) const;
|
||||||
protected:
|
void readPayload(QDataStream &stream);
|
||||||
void writePayload(QDataStream & stream) const;
|
short methodClass_;
|
||||||
void readPayload(QDataStream & stream);
|
qint16 id_;
|
||||||
short methodClass_;
|
QByteArray body_;
|
||||||
qint16 id_;
|
mutable QByteArray buffer_;
|
||||||
QByteArray body_;
|
QHash<int, QVariant> properties_;
|
||||||
mutable QByteArray buffer_;
|
qlonglong bodySize_;
|
||||||
QHash<int, QVariant> properties_;
|
};
|
||||||
qlonglong bodySize_;
|
|
||||||
};
|
class ContentBody : public Base
|
||||||
|
{
|
||||||
class ContentBody : public Base
|
public:
|
||||||
{
|
ContentBody();
|
||||||
public:
|
ContentBody(QDataStream &raw);
|
||||||
ContentBody();
|
|
||||||
ContentBody(QDataStream& raw);
|
void setBody(const QByteArray &data);
|
||||||
void setBody(const QByteArray & data);
|
QByteArray body() const;
|
||||||
QByteArray body() const;
|
|
||||||
qint32 size() const;
|
qint32 size() const;
|
||||||
protected:
|
protected:
|
||||||
void writePayload(QDataStream & stream) const;
|
void writePayload(QDataStream &stream) const;
|
||||||
void readPayload(QDataStream & stream);
|
void readPayload(QDataStream &stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray body_;
|
QByteArray body_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*
|
||||||
@brief Class for working with heartbeat frames.
|
* @brief Class for working with heartbeat frames.
|
||||||
@detailed Implement frame for heartbeat send.
|
* @detailed Implement frame for heartbeat send.
|
||||||
*/
|
*/
|
||||||
class Heartbeat : public Base
|
class Heartbeat : public Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*!
|
/*
|
||||||
Heartbeat class constructor.
|
* Heartbeat class constructor.
|
||||||
@detailed Construct frame class for sending.
|
* @detailed Construct frame class for sending.
|
||||||
*/
|
*/
|
||||||
Heartbeat();
|
Heartbeat();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void writePayload(QDataStream & stream) const;
|
void writePayload(QDataStream &stream) const;
|
||||||
void readPayload(QDataStream & stream);
|
void readPayload(QDataStream &stream);
|
||||||
};
|
};
|
||||||
|
|
||||||
class MethodHandler
|
class MethodHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void _q_method(const QAMQP::Frame::Method & frame) = 0;
|
virtual void _q_method(const QAMQP::Frame::Method &frame) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ContentHandler
|
class ContentHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void _q_content(const QAMQP::Frame::Content & frame) = 0;
|
virtual void _q_content(const QAMQP::Frame::Content & frame) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ContentBodyHandler
|
class ContentBodyHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void _q_body(const QAMQP::Frame::ContentBody & frame) = 0;
|
virtual void _q_body(const QAMQP::Frame::ContentBody & frame) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QAMQP::Frame::decimal);
|
Q_DECLARE_METATYPE(QAMQP::Frame::decimal)
|
||||||
Q_DECLARE_METATYPE(QAMQP::Frame::TableField);
|
Q_DECLARE_METATYPE(QAMQP::Frame::TableField)
|
||||||
|
|
||||||
#endif // amqp_frame_h__
|
#endif // amqp_frame_h__
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,18 @@
|
||||||
#ifndef qamqp_global_h__
|
#ifndef qamqp_global_h__
|
||||||
#define qamqp_global_h__
|
#define qamqp_global_h__
|
||||||
|
|
||||||
#include <QtCore/qglobal.h>
|
#define QAMQP_P_INCLUDE
|
||||||
|
#define AMQPSCHEME "amqp"
|
||||||
#define QAMQP_P_INCLUDE
|
#define AMQPSSCHEME "amqps"
|
||||||
#define AMQPSCHEME "amqp"
|
#define AMQPPORT 5672
|
||||||
#define AMQPSSCHEME "amqps"
|
#define AMQPHOST "localhost"
|
||||||
#define AMQPPORT 5672
|
#define AMQPVHOST "/"
|
||||||
#define AMQPHOST "localhost"
|
#define AMQPLOGIN "guest"
|
||||||
#define AMQPVHOST "/"
|
#define AMQPPSWD "guest"
|
||||||
#define AMQPLOGIN "guest"
|
#define FRAME_MAX 131072
|
||||||
#define AMQPPSWD "guest"
|
|
||||||
#define FRAME_MAX 131072
|
#define QAMQP_VERSION "0.2.0"
|
||||||
|
|
||||||
#define QAMQP_VERSION "0.2.0"
|
#define AMQP_CONNECTION_FORCED 320
|
||||||
|
|
||||||
|
#endif // qamqp_global_h__
|
||||||
|
|
||||||
#define AMQP_CONNECTION_FORCED 320
|
|
||||||
|
|
||||||
#define P_DECLARE_PRIVATE(Class) \
|
|
||||||
friend class Class##Private; \
|
|
||||||
inline Class##Private* pd_func() { return reinterpret_cast<Class##Private *>(this->pd_ptr); } \
|
|
||||||
inline const Class##Private* pd_func() const { return reinterpret_cast<const Class##Private *>(this->pd_ptr); }
|
|
||||||
|
|
||||||
|
|
||||||
#define P_DECLARE_PUBLIC(Class) \
|
|
||||||
inline Class* pq_func() { return static_cast<Class *>(this->pq_ptr); } \
|
|
||||||
inline const Class* pq_func() const { return static_cast<const Class *>(this->pq_ptr); } \
|
|
||||||
friend class Class;
|
|
||||||
|
|
||||||
|
|
||||||
#define P_D(Class) Class##Private * const d = this->pd_func()
|
|
||||||
#define P_Q(Class) Class * const q = this->pq_func()
|
|
||||||
|
|
||||||
#endif // qamqp_global_h__
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
#include "amqp_message.h"
|
||||||
|
|
||||||
|
using namespace QAMQP;
|
||||||
|
|
||||||
|
Message::Message()
|
||||||
|
{
|
||||||
|
qDebug("Message create");
|
||||||
|
leftSize = 0;
|
||||||
|
deliveryTag = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Message::~Message()
|
||||||
|
{
|
||||||
|
qDebug("Message release");
|
||||||
|
}
|
||||||
|
|
@ -1,33 +1,28 @@
|
||||||
#include "amqp_frame.h"
|
#include "amqp_frame.h"
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
namespace QAMQP
|
namespace QAMQP
|
||||||
{
|
{
|
||||||
struct Message
|
|
||||||
{
|
struct Message
|
||||||
Message()
|
{
|
||||||
{
|
Message();
|
||||||
qDebug("Message create");
|
virtual ~Message();
|
||||||
leftSize = 0;
|
|
||||||
deliveryTag = 0;
|
typedef QAMQP::Frame::Content::Property MessageProperty;
|
||||||
}
|
Q_DECLARE_FLAGS(MessageProperties, MessageProperty)
|
||||||
~Message()
|
|
||||||
{
|
qlonglong deliveryTag;
|
||||||
qDebug("Message release");
|
QByteArray payload;
|
||||||
}
|
QHash<MessageProperty, QVariant> property;
|
||||||
typedef QAMQP::Frame::Content::Property MessageProperty;
|
QAMQP::Frame::TableField headers;
|
||||||
Q_DECLARE_FLAGS(MessageProperties, MessageProperty);
|
QString routeKey;
|
||||||
|
QString exchangeName;
|
||||||
qlonglong deliveryTag;
|
int leftSize;
|
||||||
QByteArray payload;
|
};
|
||||||
QHash<MessageProperty, QVariant> property;
|
|
||||||
QAMQP::Frame::TableField headers;
|
typedef QSharedPointer<QAMQP::Message> MessagePtr;
|
||||||
QString routeKey;
|
|
||||||
QString exchangeName;
|
}
|
||||||
int leftSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef QSharedPointer<QAMQP::Message> MessagePtr;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,276 +1,243 @@
|
||||||
#include "amqp_network.h"
|
#include "amqp_network.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QtEndian>
|
#include <QtEndian>
|
||||||
|
|
||||||
QAMQP::Network::Network( QObject * parent /*= 0*/ ):QObject(parent)
|
QAMQP::Network::Network( QObject * parent)
|
||||||
{
|
: QObject(parent)
|
||||||
qRegisterMetaType<QAMQP::Frame::Method>("QAMQP::Frame::Method");
|
{
|
||||||
|
qRegisterMetaType<QAMQP::Frame::Method>("QAMQP::Frame::Method");
|
||||||
buffer_.reserve(Frame::HEADER_SIZE);
|
|
||||||
timeOut_ = 1000;
|
buffer_.reserve(Frame::HEADER_SIZE);
|
||||||
connect_ = false;
|
timeOut_ = 1000;
|
||||||
|
connect_ = false;
|
||||||
initSocket(false);
|
|
||||||
}
|
initSocket(false);
|
||||||
|
}
|
||||||
QAMQP::Network::~Network()
|
|
||||||
{
|
QAMQP::Network::~Network()
|
||||||
disconnect();
|
{
|
||||||
}
|
disconnect();
|
||||||
|
}
|
||||||
void QAMQP::Network::connectTo( const QString & host, quint32 port )
|
|
||||||
{
|
void QAMQP::Network::connectTo(const QString & host, quint16 port)
|
||||||
if(!socket_)
|
{
|
||||||
{
|
if(!socket_) {
|
||||||
qWarning("AMQP: Socket didn't create.");
|
qWarning("AMQP: Socket didn't create.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString h(host);
|
|
||||||
int p(port);
|
QString h(host);
|
||||||
connect_ = true;
|
int p(port);
|
||||||
if(host.isEmpty())
|
connect_ = true;
|
||||||
h = lastHost_ ;
|
if (host.isEmpty())
|
||||||
if(port == 0)
|
h = lastHost_ ;
|
||||||
p = lastPort_;
|
if (port == 0)
|
||||||
|
p = lastPort_;
|
||||||
if (isSsl())
|
|
||||||
{
|
if (isSsl()) {
|
||||||
#ifndef QT_NO_SSL
|
#ifndef QT_NO_SSL
|
||||||
static_cast<QSslSocket *>(socket_.data())->connectToHostEncrypted(h, p);
|
static_cast<QSslSocket *>(socket_.data())->connectToHostEncrypted(h, p);
|
||||||
#else
|
#else
|
||||||
qWarning("AMQP: You library has builded with QT_NO_SSL option.");
|
qWarning("AMQP: You library has builded with QT_NO_SSL option.");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
socket_->connectToHost(h, p);
|
socket_->connectToHost(h, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastHost_ = h;
|
lastHost_ = h;
|
||||||
lastPort_ = p;
|
lastPort_ = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QAMQP::Network::disconnect()
|
void QAMQP::Network::disconnect()
|
||||||
{
|
{
|
||||||
connect_ = false;
|
connect_ = false;
|
||||||
if(socket_)
|
if (socket_)
|
||||||
socket_->close();
|
socket_->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QAMQP::Network::error( QAbstractSocket::SocketError socketError )
|
void QAMQP::Network::error(QAbstractSocket::SocketError socketError)
|
||||||
{
|
{
|
||||||
if(timeOut_ == 0)
|
if (timeOut_ == 0) {
|
||||||
{
|
timeOut_ = 1000;
|
||||||
timeOut_ = 1000;
|
} else {
|
||||||
} else {
|
if (timeOut_ < 120000)
|
||||||
if(timeOut_ < 120000)
|
timeOut_ *= 5;
|
||||||
{
|
}
|
||||||
timeOut_ *= 5;
|
|
||||||
}
|
switch(socketError) {
|
||||||
}
|
case QAbstractSocket::ConnectionRefusedError:
|
||||||
|
case QAbstractSocket::RemoteHostClosedError:
|
||||||
Q_UNUSED(socketError);
|
case QAbstractSocket::SocketTimeoutError:
|
||||||
switch(socketError)
|
case QAbstractSocket::NetworkError:
|
||||||
{
|
case QAbstractSocket::ProxyConnectionClosedError:
|
||||||
case QAbstractSocket::ConnectionRefusedError:
|
case QAbstractSocket::ProxyConnectionRefusedError:
|
||||||
case QAbstractSocket::RemoteHostClosedError:
|
case QAbstractSocket::ProxyConnectionTimeoutError:
|
||||||
case QAbstractSocket::SocketTimeoutError:
|
|
||||||
case QAbstractSocket::NetworkError:
|
default:
|
||||||
case QAbstractSocket::ProxyConnectionClosedError:
|
qWarning() << "AMQP: Socket Error: " << socket_->errorString();
|
||||||
case QAbstractSocket::ProxyConnectionRefusedError:
|
break;
|
||||||
case QAbstractSocket::ProxyConnectionTimeoutError:
|
}
|
||||||
|
|
||||||
default:
|
if (autoReconnect_ && connect_)
|
||||||
qWarning() << "AMQP: Socket Error: " << socket_->errorString();
|
QTimer::singleShot(timeOut_, this, SLOT(connectTo()));
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
void QAMQP::Network::readyRead()
|
||||||
if( autoReconnect_ && connect_ )
|
{
|
||||||
{
|
while (socket_->bytesAvailable() >= Frame::HEADER_SIZE) {
|
||||||
QTimer::singleShot(timeOut_, this, SLOT(connectTo()));
|
char *headerData = buffer_.data();
|
||||||
}
|
socket_->peek(headerData, Frame::HEADER_SIZE);
|
||||||
|
const quint32 payloadSize = qFromBigEndian<quint32>(*(quint32*)&headerData[3]);
|
||||||
}
|
const qint64 readSize = Frame::HEADER_SIZE+payloadSize+Frame::FRAME_END_SIZE;
|
||||||
|
|
||||||
void QAMQP::Network::readyRead()
|
if (socket_->bytesAvailable() >= readSize) {
|
||||||
{
|
buffer_.resize(readSize);
|
||||||
while(socket_->bytesAvailable() >= Frame::HEADER_SIZE)
|
socket_->read(buffer_.data(), readSize);
|
||||||
{
|
const char* bufferData = buffer_.constData();
|
||||||
char* headerData = buffer_.data();
|
const quint8 type = *(quint8*)&bufferData[0];
|
||||||
socket_->peek(headerData, Frame::HEADER_SIZE);
|
const quint8 magic = *(quint8*)&bufferData[Frame::HEADER_SIZE+payloadSize];
|
||||||
const quint32 payloadSize = qFromBigEndian<quint32>(*(quint32*)&headerData[3]);
|
if (magic != QAMQP::Frame::FRAME_END)
|
||||||
const qint64 readSize = Frame::HEADER_SIZE+payloadSize+Frame::FRAME_END_SIZE;
|
qWarning() << "Wrong end frame";
|
||||||
if(socket_->bytesAvailable() >= readSize)
|
|
||||||
{
|
QDataStream streamB(&buffer_, QIODevice::ReadOnly);
|
||||||
buffer_.resize(readSize);
|
switch(QAMQP::Frame::Type(type)) {
|
||||||
socket_->read(buffer_.data(), readSize);
|
case QAMQP::Frame::ftMethod:
|
||||||
const char* bufferData = buffer_.constData();
|
{
|
||||||
const quint8 type = *(quint8*)&bufferData[0];
|
QAMQP::Frame::Method frame(streamB);
|
||||||
const quint8 magic = *(quint8*)&bufferData[Frame::HEADER_SIZE+payloadSize];
|
if (frame.methodClass() == QAMQP::Frame::fcConnection) {
|
||||||
if(magic != QAMQP::Frame::FRAME_END)
|
m_pMethodHandlerConnection->_q_method(frame);
|
||||||
{
|
} else {
|
||||||
qWarning() << "Wrong end frame";
|
foreach(Frame::MethodHandler* pMethodHandler, m_methodHandlersByChannel[frame.channel()])
|
||||||
}
|
pMethodHandler->_q_method(frame);
|
||||||
|
}
|
||||||
QDataStream streamB(&buffer_, QIODevice::ReadOnly);
|
}
|
||||||
switch(QAMQP::Frame::Type(type))
|
break;
|
||||||
{
|
case QAMQP::Frame::ftHeader:
|
||||||
case QAMQP::Frame::ftMethod:
|
{
|
||||||
{
|
QAMQP::Frame::Content frame(streamB);
|
||||||
QAMQP::Frame::Method frame(streamB);
|
foreach(Frame::ContentHandler* pMethodHandler, m_contentHandlerByChannel[frame.channel()])
|
||||||
if(frame.methodClass() == QAMQP::Frame::fcConnection)
|
pMethodHandler->_q_content(frame);
|
||||||
{
|
}
|
||||||
m_pMethodHandlerConnection->_q_method(frame);
|
break;
|
||||||
}
|
case QAMQP::Frame::ftBody:
|
||||||
else
|
{
|
||||||
{
|
QAMQP::Frame::ContentBody frame(streamB);
|
||||||
foreach(Frame::MethodHandler* pMethodHandler, m_methodHandlersByChannel[frame.channel()])
|
foreach(Frame::ContentBodyHandler* pMethodHandler, m_bodyHandlersByChannel[frame.channel()])
|
||||||
{
|
pMethodHandler->_q_body(frame);
|
||||||
pMethodHandler->_q_method(frame);
|
}
|
||||||
}
|
break;
|
||||||
}
|
case QAMQP::Frame::ftHeartbeat:
|
||||||
}
|
qDebug("AMQP: Heartbeat");
|
||||||
break;
|
break;
|
||||||
case QAMQP::Frame::ftHeader:
|
default:
|
||||||
{
|
qWarning() << "AMQP: Unknown frame type: " << type;
|
||||||
QAMQP::Frame::Content frame(streamB);
|
}
|
||||||
foreach(Frame::ContentHandler* pMethodHandler, m_contentHandlerByChannel[frame.channel()])
|
} else {
|
||||||
{
|
break;
|
||||||
pMethodHandler->_q_content(frame);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case QAMQP::Frame::ftBody:
|
void QAMQP::Network::sendFrame(const QAMQP::Frame::Base &frame)
|
||||||
{
|
{
|
||||||
QAMQP::Frame::ContentBody frame(streamB);
|
if (socket_->state() == QAbstractSocket::ConnectedState) {
|
||||||
foreach(Frame::ContentBodyHandler* pMethodHandler, m_bodyHandlersByChannel[frame.channel()])
|
QDataStream stream(socket_);
|
||||||
{
|
frame.toStream(stream);
|
||||||
pMethodHandler->_q_body(frame);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
bool QAMQP::Network::isSsl() const
|
||||||
case QAMQP::Frame::ftHeartbeat:
|
{
|
||||||
{
|
if (socket_)
|
||||||
qDebug("AMQP: Heartbeat");
|
return QString(socket_->metaObject()->className()).compare("QSslSocket", Qt::CaseInsensitive) == 0;
|
||||||
}
|
return false;
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
qWarning() << "AMQP: Unknown frame type: " << type;
|
void QAMQP::Network::setSsl(bool value)
|
||||||
}
|
{
|
||||||
}
|
initSocket(value);
|
||||||
else
|
}
|
||||||
{
|
|
||||||
break;
|
void QAMQP::Network::initSocket(bool ssl)
|
||||||
}
|
{
|
||||||
}
|
if (socket_) {
|
||||||
}
|
socket_->deleteLater();
|
||||||
|
socket_ = 0;
|
||||||
void QAMQP::Network::sendFrame( const QAMQP::Frame::Base & frame )
|
}
|
||||||
{
|
|
||||||
if(socket_->state() == QAbstractSocket::ConnectedState)
|
if (ssl) {
|
||||||
{
|
#ifndef QT_NO_SSL
|
||||||
QDataStream stream(socket_);
|
socket_ = new QSslSocket(this);
|
||||||
frame.toStream(stream);
|
QSslSocket * ssl_= static_cast<QSslSocket*> (socket_.data());
|
||||||
}
|
ssl_->setProtocol(QSsl::AnyProtocol);
|
||||||
}
|
connect(socket_, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors()));
|
||||||
|
connect(socket_, SIGNAL(connected()), this, SLOT(conectionReady()));
|
||||||
bool QAMQP::Network::isSsl() const
|
#else
|
||||||
{
|
qWarning("AMQP: You library has builded with QT_NO_SSL option.");
|
||||||
if(socket_)
|
#endif
|
||||||
{
|
} else {
|
||||||
return QString(socket_->metaObject()->className()).compare( "QSslSocket", Qt::CaseInsensitive) == 0;
|
socket_ = new QTcpSocket(this);
|
||||||
}
|
connect(socket_, SIGNAL(connected()), this, SLOT(conectionReady()));
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
if (socket_) {
|
||||||
void QAMQP::Network::setSsl( bool value )
|
connect(socket_, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
|
||||||
{
|
connect(socket_, SIGNAL(readyRead()), this, SLOT(readyRead()));
|
||||||
initSocket(value);
|
connect(socket_, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||||
}
|
this, SLOT(error(QAbstractSocket::SocketError)));
|
||||||
|
}
|
||||||
void QAMQP::Network::initSocket( bool ssl /*= false*/ )
|
}
|
||||||
{
|
|
||||||
if(socket_)
|
void QAMQP::Network::sslErrors()
|
||||||
delete socket_;
|
{
|
||||||
|
#ifndef QT_NO_SSL
|
||||||
if(ssl)
|
static_cast<QSslSocket*>(socket_.data())->ignoreSslErrors();
|
||||||
{
|
#endif
|
||||||
#ifndef QT_NO_SSL
|
}
|
||||||
socket_ = new QSslSocket(this);
|
|
||||||
QSslSocket * ssl_= static_cast<QSslSocket*> (socket_.data());
|
void QAMQP::Network::conectionReady()
|
||||||
ssl_->setProtocol(QSsl::AnyProtocol);
|
{
|
||||||
connect(socket_, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors()));
|
Q_EMIT connected();
|
||||||
|
timeOut_ = 0;
|
||||||
connect(socket_, SIGNAL(connected()), this, SLOT(conectionReady()));
|
|
||||||
#else
|
char header_[8] = {'A', 'M', 'Q', 'P', 0,0,9,1};
|
||||||
qWarning("AMQP: You library has builded with QT_NO_SSL option.");
|
socket_->write(header_, 8);
|
||||||
#endif
|
}
|
||||||
} else {
|
|
||||||
socket_ = new QTcpSocket(this);
|
bool QAMQP::Network::autoReconnect() const
|
||||||
connect(socket_, SIGNAL(connected()), this, SLOT(conectionReady()));
|
{
|
||||||
}
|
return autoReconnect_;
|
||||||
|
}
|
||||||
if(socket_)
|
|
||||||
{
|
void QAMQP::Network::setAutoReconnect(bool value)
|
||||||
connect(socket_, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
|
{
|
||||||
connect(socket_, SIGNAL(readyRead()), this, SLOT(readyRead()));
|
autoReconnect_ = value;
|
||||||
connect(socket_, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError)));
|
}
|
||||||
}
|
|
||||||
}
|
QAbstractSocket::SocketState QAMQP::Network::state() const
|
||||||
|
{
|
||||||
|
if (socket_)
|
||||||
void QAMQP::Network::sslErrors( )
|
return socket_->state();
|
||||||
{
|
return QAbstractSocket::UnconnectedState;
|
||||||
#ifndef QT_NO_SSL
|
}
|
||||||
static_cast<QSslSocket*>(socket_.data())->ignoreSslErrors();
|
|
||||||
#endif
|
void QAMQP::Network::setMethodHandlerConnection(Frame::MethodHandler *pMethodHandlerConnection)
|
||||||
}
|
{
|
||||||
|
m_pMethodHandlerConnection = pMethodHandlerConnection;
|
||||||
|
}
|
||||||
void QAMQP::Network::conectionReady()
|
|
||||||
{
|
void QAMQP::Network::addMethodHandlerForChannel(Channel channel, Frame::MethodHandler *pHandler)
|
||||||
emit connected();
|
{
|
||||||
timeOut_ = 0;
|
m_methodHandlersByChannel[channel].append(pHandler);
|
||||||
char header_[8] = {'A', 'M', 'Q', 'P', 0,0,9,1};
|
}
|
||||||
socket_->write(header_, 8);
|
|
||||||
}
|
void QAMQP::Network::addContentHandlerForChannel(Channel channel, Frame::ContentHandler *pHandler)
|
||||||
|
{
|
||||||
bool QAMQP::Network::autoReconnect() const
|
m_contentHandlerByChannel[channel].append(pHandler);
|
||||||
{
|
}
|
||||||
return autoReconnect_;
|
|
||||||
}
|
void QAMQP::Network::addContentBodyHandlerForChannel(Channel channel, Frame::ContentBodyHandler *pHandler)
|
||||||
|
{
|
||||||
void QAMQP::Network::setAutoReconnect( bool value )
|
m_bodyHandlersByChannel[channel].append(pHandler);
|
||||||
{
|
}
|
||||||
autoReconnect_ = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
QAbstractSocket::SocketState QAMQP::Network::state() const
|
|
||||||
{
|
|
||||||
if(socket_)
|
|
||||||
{
|
|
||||||
return socket_->state();
|
|
||||||
} else {
|
|
||||||
return QAbstractSocket::UnconnectedState;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void QAMQP::Network::setMethodHandlerConnection(Frame::MethodHandler* pMethodHandlerConnection)
|
|
||||||
{
|
|
||||||
m_pMethodHandlerConnection = pMethodHandlerConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QAMQP::Network::addMethodHandlerForChannel(Channel channel, Frame::MethodHandler* pHandler)
|
|
||||||
{
|
|
||||||
m_methodHandlersByChannel[channel].append(pHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QAMQP::Network::addContentHandlerForChannel(Channel channel, Frame::ContentHandler* pHandler)
|
|
||||||
{
|
|
||||||
m_contentHandlerByChannel[channel].append(pHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QAMQP::Network::addContentBodyHandlerForChannel(Channel channel, Frame::ContentBodyHandler* pHandler)
|
|
||||||
{
|
|
||||||
m_bodyHandlersByChannel[channel].append(pHandler);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,77 +1,76 @@
|
||||||
#ifndef amqp_network_h__
|
#ifndef amqp_network_h__
|
||||||
#define amqp_network_h__
|
#define amqp_network_h__
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#ifndef QT_NO_SSL
|
#ifndef QT_NO_SSL
|
||||||
#include <QSslSocket>
|
# include <QSslSocket>
|
||||||
#endif
|
#endif
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
|
|
||||||
#include "amqp_frame.h"
|
#include "amqp_frame.h"
|
||||||
|
|
||||||
namespace QAMQP
|
namespace QAMQP
|
||||||
{
|
{
|
||||||
class Network : public QObject
|
|
||||||
{
|
class Network : public QObject
|
||||||
Q_OBJECT
|
{
|
||||||
Q_DISABLE_COPY(Network)
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
typedef qint16 Channel;
|
Network(QObject *parent = 0);
|
||||||
|
~Network();
|
||||||
Network(QObject * parent = 0);
|
|
||||||
~Network();
|
void disconnect();
|
||||||
|
void sendFrame();
|
||||||
void disconnect();
|
|
||||||
void sendFrame();
|
void sendFrame(const QAMQP::Frame::Base &frame);
|
||||||
|
|
||||||
void sendFrame(const QAMQP::Frame::Base & frame);
|
bool isSsl() const;
|
||||||
|
void setSsl(bool value);
|
||||||
bool isSsl() const;
|
|
||||||
void setSsl(bool value);
|
bool autoReconnect() const;
|
||||||
|
void setAutoReconnect(bool value);
|
||||||
bool autoReconnect() const;
|
|
||||||
void setAutoReconnect(bool value);
|
QAbstractSocket::SocketState state() const;
|
||||||
|
|
||||||
QAbstractSocket::SocketState state() const;
|
typedef qint16 Channel;
|
||||||
|
void setMethodHandlerConnection(Frame::MethodHandler *pMethodHandlerConnection);
|
||||||
void setMethodHandlerConnection(Frame::MethodHandler* pMethodHandlerConnection);
|
void addMethodHandlerForChannel(Channel channel, Frame::MethodHandler *pHandler);
|
||||||
void addMethodHandlerForChannel(Channel channel, Frame::MethodHandler* pHandler);
|
void addContentHandlerForChannel(Channel channel, Frame::ContentHandler *pHandler);
|
||||||
void addContentHandlerForChannel(Channel channel, Frame::ContentHandler* pHandler);
|
void addContentBodyHandlerForChannel(Channel channel, Frame::ContentBodyHandler *pHandler);
|
||||||
void addContentBodyHandlerForChannel(Channel channel, Frame::ContentBodyHandler* pHandler);
|
|
||||||
|
public slots:
|
||||||
public slots:
|
void connectTo(const QString &host = QString(), quint16 port = 0);
|
||||||
void connectTo(const QString & host = QString(), quint32 port = 0);
|
void error(QAbstractSocket::SocketError socketError);
|
||||||
void error( QAbstractSocket::SocketError socketError );
|
|
||||||
|
Q_SIGNALS:
|
||||||
signals:
|
void connected();
|
||||||
void connected();
|
void disconnected();
|
||||||
void disconnected();
|
|
||||||
|
private Q_SLOTS:
|
||||||
private slots:
|
void readyRead();
|
||||||
void readyRead();
|
void sslErrors();
|
||||||
|
void conectionReady();
|
||||||
void sslErrors ( );
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(Network)
|
||||||
void conectionReady();
|
|
||||||
|
void initSocket(bool ssl = false);
|
||||||
private:
|
QPointer<QTcpSocket> socket_;
|
||||||
void initSocket(bool ssl = false);
|
QByteArray buffer_;
|
||||||
QPointer<QTcpSocket> socket_;
|
QString lastHost_;
|
||||||
QByteArray buffer_;
|
int lastPort_;
|
||||||
QString lastHost_;
|
bool autoReconnect_;
|
||||||
int lastPort_;
|
int timeOut_;
|
||||||
bool autoReconnect_;
|
bool connect_;
|
||||||
int timeOut_;
|
|
||||||
bool connect_;
|
Frame::MethodHandler *m_pMethodHandlerConnection;
|
||||||
|
|
||||||
Frame::MethodHandler* m_pMethodHandlerConnection;
|
QHash<Channel, QList<Frame::MethodHandler*> > m_methodHandlersByChannel;
|
||||||
|
QHash<Channel, QList<Frame::ContentHandler*> > m_contentHandlerByChannel;
|
||||||
QHash<Channel, QList<Frame::MethodHandler*> > m_methodHandlersByChannel;
|
QHash<Channel, QList<Frame::ContentBodyHandler*> > m_bodyHandlersByChannel;
|
||||||
QHash<Channel, QList<Frame::ContentHandler*> > m_contentHandlerByChannel;
|
};
|
||||||
QHash<Channel, QList<Frame::ContentBodyHandler*> > m_bodyHandlersByChannel;
|
|
||||||
};
|
}
|
||||||
}
|
#endif // amqp_network_h__
|
||||||
#endif // amqp_network_h__
|
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,51 @@
|
||||||
#ifndef qamqp_amqp_p_h__
|
#ifndef QAMQP_P_H
|
||||||
#define qamqp_amqp_p_h__
|
#define QAMQP_P_H
|
||||||
|
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
#include "amqp_global.h"
|
#include "amqp_global.h"
|
||||||
#include "amqp_network.h"
|
#include "amqp_network.h"
|
||||||
#include "amqp_connection.h"
|
#include "amqp_connection.h"
|
||||||
#include "amqp_authenticator.h"
|
#include "amqp_authenticator.h"
|
||||||
|
|
||||||
namespace QAMQP
|
namespace QAMQP
|
||||||
{
|
{
|
||||||
class ClientPrivate
|
|
||||||
{
|
class Queue;
|
||||||
P_DECLARE_PUBLIC(QAMQP::Client)
|
class Exchange;
|
||||||
|
class ClientPrivate
|
||||||
public:
|
{
|
||||||
ClientPrivate(Client * q ) ;
|
public:
|
||||||
~ClientPrivate();
|
ClientPrivate(Client *q);
|
||||||
|
~ClientPrivate();
|
||||||
|
|
||||||
void init(QObject * parent);
|
void init(QObject *parent);
|
||||||
void init(QObject * parent, const QUrl & connectionString);
|
void init(QObject *parent, const QUrl &connectionString);
|
||||||
void printConnect() const;
|
|
||||||
void connect();
|
void printConnect() const;
|
||||||
void disconnect();
|
void connect();
|
||||||
void parseCnnString( const QUrl & connectionString);
|
void disconnect();
|
||||||
void sockConnect();
|
void parseConnectionString( const QUrl &connectionString);
|
||||||
void login();
|
void sockConnect();
|
||||||
void setAuth(Authenticator* auth);
|
void login();
|
||||||
Exchange * createExchange(int channelNumber, const QString &name);
|
void setAuth(Authenticator* auth);
|
||||||
Queue * createQueue(int channelNumber, const QString &name);
|
Exchange *createExchange(int channelNumber, const QString &name);
|
||||||
|
Queue *createQueue(int channelNumber, const QString &name);
|
||||||
quint32 port;
|
|
||||||
QString host;
|
quint32 port;
|
||||||
QString virtualHost;
|
QString host;
|
||||||
|
QString virtualHost;
|
||||||
QPointer<QAMQP::Network> network_;
|
|
||||||
QPointer<QAMQP::Connection> connection_;
|
QPointer<QAMQP::Network> network_;
|
||||||
QSharedPointer<Authenticator> auth_;
|
QPointer<QAMQP::Connection> connection_;
|
||||||
|
QSharedPointer<Authenticator> auth_;
|
||||||
bool isSSl() const;
|
|
||||||
|
bool isSSl() const;
|
||||||
|
|
||||||
|
Client * const q_ptr;
|
||||||
Client * const pq_ptr;
|
Q_DECLARE_PUBLIC(QAMQP::Client)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif // amqp_p_h__
|
#endif // amqp_p_h__
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,91 +1,95 @@
|
||||||
#ifndef amqp_queue_h__
|
#ifndef amqp_queue_h__
|
||||||
#define amqp_queue_h__
|
#define amqp_queue_h__
|
||||||
|
|
||||||
#include "amqp_channel.h"
|
#include "amqp_channel.h"
|
||||||
#include "amqp_message.h"
|
#include "amqp_message.h"
|
||||||
|
|
||||||
namespace QAMQP
|
namespace QAMQP
|
||||||
{
|
{
|
||||||
class Client;
|
|
||||||
class ClientPrivate;
|
class Client;
|
||||||
class Exchange;
|
class ClientPrivate;
|
||||||
class QueuePrivate;
|
class Exchange;
|
||||||
class Queue : public Channel, public Frame::ContentHandler, public Frame::ContentBodyHandler
|
class QueuePrivate;
|
||||||
{
|
class Queue : public Channel, public Frame::ContentHandler, public Frame::ContentBodyHandler
|
||||||
Q_OBJECT
|
{
|
||||||
Queue(int channelNumber = -1, Client * parent = 0);
|
Q_OBJECT
|
||||||
|
Q_ENUMS(QueueOptions)
|
||||||
Q_PROPERTY(QueueOptions option READ option );
|
Q_PROPERTY(QueueOptions option READ option)
|
||||||
Q_PROPERTY(QString consumerTag READ consumerTag WRITE setConsumerTag)
|
Q_PROPERTY(QString consumerTag READ consumerTag WRITE setConsumerTag)
|
||||||
Q_PROPERTY(bool noAck READ noAck WRITE setNoAck)
|
Q_PROPERTY(bool noAck READ noAck WRITE setNoAck)
|
||||||
|
|
||||||
P_DECLARE_PRIVATE(QAMQP::Queue)
|
public:
|
||||||
Q_DISABLE_COPY(Queue);
|
enum QueueOption {
|
||||||
friend class ClientPrivate;
|
NoOptions = 0x0,
|
||||||
|
Passive = 0x01,
|
||||||
protected:
|
Durable = 0x02,
|
||||||
void onOpen();
|
Exclusive = 0x4,
|
||||||
void onClose();
|
AutoDelete = 0x8,
|
||||||
|
NoWait = 0x10
|
||||||
public:
|
};
|
||||||
enum QueueOption {
|
Q_DECLARE_FLAGS(QueueOptions, QueueOption)
|
||||||
NoOptions = 0x0,
|
|
||||||
Passive = 0x01,
|
enum ConsumeOption {
|
||||||
Durable = 0x02,
|
coNoLocal = 0x1,
|
||||||
Exclusive = 0x4,
|
coNoAck = 0x02,
|
||||||
AutoDelete = 0x8,
|
coExclusive = 0x04,
|
||||||
NoWait = 0x10
|
coNoWait = 0x8
|
||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(QueueOptions, QueueOption)
|
Q_DECLARE_FLAGS(ConsumeOptions, ConsumeOption)
|
||||||
|
|
||||||
enum ConsumeOption {
|
~Queue();
|
||||||
coNoLocal = 0x1,
|
QueueOptions option() const;
|
||||||
coNoAck = 0x02,
|
|
||||||
coExclusive = 0x04,
|
void declare();
|
||||||
coNoWait = 0x8
|
void declare(const QString &name, QueueOptions options);
|
||||||
};
|
void remove(bool ifUnused = true, bool ifEmpty = true, bool noWait = true);
|
||||||
Q_DECLARE_FLAGS(ConsumeOptions, ConsumeOption)
|
|
||||||
|
void purge();
|
||||||
~Queue();
|
|
||||||
|
void bind(const QString & exchangeName, const QString & key);
|
||||||
QueueOptions option() const;
|
void bind(Exchange * exchange, const QString & key);
|
||||||
|
|
||||||
void declare();
|
void unbind(const QString & exchangeName, const QString & key);
|
||||||
void declare(const QString &name, QueueOptions options);
|
void unbind(Exchange * exchange, const QString & key);
|
||||||
void remove(bool ifUnused = true, bool ifEmpty = true, bool noWait = true);
|
|
||||||
|
MessagePtr getMessage();
|
||||||
void purge();
|
void get();
|
||||||
|
void ack(const MessagePtr & message);
|
||||||
void bind(const QString & exchangeName, const QString & key);
|
bool hasMessage() const;
|
||||||
void bind(Exchange * exchange, const QString & key);
|
void consume(ConsumeOptions options = ConsumeOptions(NoOptions));
|
||||||
|
void setConsumerTag(const QString &consumerTag);
|
||||||
void unbind(const QString & exchangeName, const QString & key);
|
QString consumerTag() const;
|
||||||
void unbind(Exchange * exchange, const QString & key);
|
|
||||||
|
void setNoAck(bool noAck);
|
||||||
MessagePtr getMessage();
|
bool noAck() const;
|
||||||
void get();
|
|
||||||
void ack(const MessagePtr & message);
|
Q_SIGNALS:
|
||||||
bool hasMessage() const;
|
void declared();
|
||||||
void consume(ConsumeOptions options = ConsumeOptions(NoOptions));
|
void binded(bool);
|
||||||
void setConsumerTag(const QString &consumerTag);
|
void removed();
|
||||||
QString consumerTag() const;
|
void messageReceived(QAMQP::Queue *pQueue);
|
||||||
|
void empty();
|
||||||
void setNoAck(bool noAck);
|
|
||||||
bool noAck() const;
|
protected:
|
||||||
|
void onOpen();
|
||||||
Q_SIGNALS:
|
void onClose();
|
||||||
void declared();
|
|
||||||
void binded(bool);
|
private:
|
||||||
void removed();
|
Queue(int channelNumber = -1, Client * parent = 0);
|
||||||
void messageReceived(QAMQP::Queue* pQueue);
|
|
||||||
void empty();
|
void _q_content(const QAMQP::Frame::Content & frame);
|
||||||
|
void _q_body(const QAMQP::Frame::ContentBody & frame);
|
||||||
private:
|
|
||||||
void _q_content(const QAMQP::Frame::Content & frame);
|
Q_DISABLE_COPY(Queue)
|
||||||
void _q_body(const QAMQP::Frame::ContentBody & frame);
|
Q_DECLARE_PRIVATE(QAMQP::Queue)
|
||||||
};
|
|
||||||
}
|
friend class ClientPrivate;
|
||||||
#ifdef QAMQP_P_INCLUDE
|
|
||||||
# include "amqp_queue_p.h"
|
};
|
||||||
#endif
|
|
||||||
#endif // amqp_queue_h__
|
}
|
||||||
|
#ifdef QAMQP_P_INCLUDE
|
||||||
|
# include "amqp_queue_p.h"
|
||||||
|
#endif
|
||||||
|
#endif // amqp_queue_h__
|
||||||
|
|
|
||||||
|
|
@ -1,70 +1,73 @@
|
||||||
#ifndef amqp_queue_p_h__
|
#ifndef amqp_queue_p_h__
|
||||||
#define amqp_queue_p_h__
|
#define amqp_queue_p_h__
|
||||||
|
|
||||||
#include "amqp_channel_p.h"
|
#include "amqp_channel_p.h"
|
||||||
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
||||||
#include <QQueue>
|
#include <QQueue>
|
||||||
|
|
||||||
namespace QAMQP
|
namespace QAMQP
|
||||||
{
|
{
|
||||||
using namespace QAMQP::Frame;
|
|
||||||
class QueuePrivate: public ChannelPrivate
|
using namespace QAMQP::Frame;
|
||||||
{
|
|
||||||
P_DECLARE_PUBLIC(QAMQP::Queue)
|
class QueuePrivate: public ChannelPrivate
|
||||||
public:
|
{
|
||||||
|
public:
|
||||||
enum MethodId
|
enum MethodId {
|
||||||
{
|
METHOD_ID_ENUM(miDeclare, 10),
|
||||||
METHOD_ID_ENUM(miDeclare, 10),
|
METHOD_ID_ENUM(miBind, 20),
|
||||||
METHOD_ID_ENUM(miBind, 20),
|
METHOD_ID_ENUM(miUnbind, 50),
|
||||||
METHOD_ID_ENUM(miUnbind, 50),
|
METHOD_ID_ENUM(miPurge, 30),
|
||||||
METHOD_ID_ENUM(miPurge, 30),
|
METHOD_ID_ENUM(miDelete, 40)
|
||||||
METHOD_ID_ENUM(miDelete, 40)
|
};
|
||||||
};
|
|
||||||
|
QueuePrivate(Queue *q);
|
||||||
QueuePrivate(Queue * q);
|
~QueuePrivate();
|
||||||
~QueuePrivate();
|
|
||||||
|
void declare();
|
||||||
void declare();
|
void remove(bool ifUnused = true, bool ifEmpty = true, bool noWait = true);
|
||||||
void remove(bool ifUnused = true, bool ifEmpty = true, bool noWait = true);
|
void purge();
|
||||||
void purge();
|
void bind(const QString &exchangeName, const QString &key);
|
||||||
void bind(const QString & exchangeName, const QString & key);
|
void unbind(const QString &exchangeName, const QString &key);
|
||||||
void unbind(const QString & exchangeName, const QString & key);
|
|
||||||
|
void declareOk(const QAMQP::Frame::Method &frame);
|
||||||
void declareOk(const QAMQP::Frame::Method & frame);
|
void deleteOk(const QAMQP::Frame::Method &frame);
|
||||||
void deleteOk(const QAMQP::Frame::Method & frame);
|
void bindOk(const QAMQP::Frame::Method &frame);
|
||||||
void bindOk(const QAMQP::Frame::Method & frame);
|
void unbindOk(const QAMQP::Frame::Method &frame);
|
||||||
void unbindOk(const QAMQP::Frame::Method & frame);
|
|
||||||
|
/************************************************************************/
|
||||||
/************************************************************************/
|
/* CLASS BASIC METHODS */
|
||||||
/* CLASS BASIC METHODS */
|
/************************************************************************/
|
||||||
/************************************************************************/
|
|
||||||
|
void consume(Queue::ConsumeOptions options);
|
||||||
void consume(Queue::ConsumeOptions options);
|
void consumeOk(const QAMQP::Frame::Method &frame);
|
||||||
void consumeOk(const QAMQP::Frame::Method & frame);
|
void deliver(const QAMQP::Frame::Method &frame);
|
||||||
void deliver(const QAMQP::Frame::Method & frame);
|
|
||||||
|
void get();
|
||||||
void get();
|
void getOk(const QAMQP::Frame::Method &frame);
|
||||||
void getOk(const QAMQP::Frame::Method & frame);
|
void ack(const MessagePtr &Message);
|
||||||
void ack(const MessagePtr & Message);
|
|
||||||
|
QString type;
|
||||||
QString type;
|
Queue::QueueOptions options;
|
||||||
Queue::QueueOptions options;
|
|
||||||
|
bool _q_method(const QAMQP::Frame::Method &frame);
|
||||||
bool _q_method(const QAMQP::Frame::Method & frame);
|
|
||||||
|
bool delayedDeclare;
|
||||||
bool delayedDeclare;
|
bool declared;
|
||||||
bool declared;
|
bool noAck;
|
||||||
bool noAck;
|
QString consumerTag;
|
||||||
QString consumerTag;
|
|
||||||
|
QQueue<QPair<QString, QString> > delayedBindings;
|
||||||
QQueue<QPair<QString, QString> > delayedBindings;
|
QQueue<QAMQP::MessagePtr> messages_;
|
||||||
QQueue<QAMQP::MessagePtr> messages_;
|
|
||||||
|
bool recievingMessage;
|
||||||
bool recievingMessage;
|
|
||||||
|
void _q_content(const QAMQP::Frame::Content &frame);
|
||||||
void _q_content(const QAMQP::Frame::Content & frame);
|
void _q_body(const QAMQP::Frame::ContentBody &frame);
|
||||||
void _q_body(const QAMQP::Frame::ContentBody & frame);
|
|
||||||
};
|
Q_DECLARE_PUBLIC(QAMQP::Queue)
|
||||||
}
|
|
||||||
#endif // amqp_queue_p_h__
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // amqp_queue_p_h__
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,29 @@
|
||||||
QT += network
|
QT += network
|
||||||
|
|
||||||
DEPENDPATH += $$PWD
|
DEPENDPATH += $$PWD
|
||||||
|
|
||||||
HEADERS += $$PWD/amqp.h \
|
HEADERS += $$PWD/amqp.h \
|
||||||
$$PWD/amqp_authenticator.h \
|
$$PWD/amqp_authenticator.h \
|
||||||
$$PWD/amqp_channel.h \
|
$$PWD/amqp_channel.h \
|
||||||
$$PWD/amqp_channel_p.h \
|
$$PWD/amqp_channel_p.h \
|
||||||
$$PWD/amqp_connection.h \
|
$$PWD/amqp_connection.h \
|
||||||
$$PWD/amqp_connection_p.h \
|
$$PWD/amqp_connection_p.h \
|
||||||
$$PWD/amqp_exchange.h \
|
$$PWD/amqp_exchange.h \
|
||||||
$$PWD/amqp_exchange_p.h \
|
$$PWD/amqp_exchange_p.h \
|
||||||
$$PWD/amqp_frame.h \
|
$$PWD/amqp_frame.h \
|
||||||
$$PWD/amqp_message.h \
|
$$PWD/amqp_message.h \
|
||||||
$$PWD/amqp_network.h \
|
$$PWD/amqp_network.h \
|
||||||
$$PWD/amqp_p.h \
|
$$PWD/amqp_p.h \
|
||||||
$$PWD/amqp_queue.h \
|
$$PWD/amqp_queue.h \
|
||||||
$$PWD/amqp_queue_p.h \
|
$$PWD/amqp_queue_p.h \
|
||||||
$$PWD/amqp_global.h \
|
$$PWD/amqp_global.h \
|
||||||
|
|
||||||
SOURCES += $$PWD/amqp.cpp \
|
SOURCES += $$PWD/amqp.cpp \
|
||||||
$$PWD/amqp_authenticator.cpp \
|
$$PWD/amqp_authenticator.cpp \
|
||||||
$$PWD/amqp_channel.cpp \
|
$$PWD/amqp_channel.cpp \
|
||||||
$$PWD/amqp_connection.cpp \
|
$$PWD/amqp_connection.cpp \
|
||||||
$$PWD/amqp_exchange.cpp \
|
$$PWD/amqp_exchange.cpp \
|
||||||
$$PWD/amqp_frame.cpp \
|
$$PWD/amqp_frame.cpp \
|
||||||
$$PWD/amqp_network.cpp \
|
$$PWD/amqp_message.cpp \
|
||||||
$$PWD/amqp_queue.cpp \
|
$$PWD/amqp_network.cpp \
|
||||||
|
$$PWD/amqp_queue.cpp \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue