moved declare/remove from private to main class
This commit is contained in:
parent
10ca783442
commit
5bd2ebbde8
|
|
@ -24,13 +24,12 @@ void Exchange::onOpen()
|
|||
{
|
||||
Q_D(Exchange);
|
||||
if (d->delayedDeclare)
|
||||
d->declare();
|
||||
declare();
|
||||
}
|
||||
|
||||
void Exchange::onClose()
|
||||
{
|
||||
Q_D(Exchange);
|
||||
d->remove(true, true);
|
||||
remove(true, true);
|
||||
}
|
||||
|
||||
Exchange::ExchangeOptions Exchange::option() const
|
||||
|
|
@ -45,19 +44,60 @@ QString Exchange::type() const
|
|||
return d->type;
|
||||
}
|
||||
|
||||
void Exchange::declare(const QString &type, ExchangeOptions option , const Frame::TableField &arg)
|
||||
void Exchange::declare(const QString &type, ExchangeOptions options , const Frame::TableField &args)
|
||||
{
|
||||
Q_D(Exchange);
|
||||
d->options = option;
|
||||
d->type = type;
|
||||
d->arguments = arg;
|
||||
d->declare();
|
||||
d->options = options;
|
||||
d->arguments = args;
|
||||
|
||||
if (!d->opened) {
|
||||
d->delayedDeclare = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (d->name.isEmpty()) {
|
||||
qDebug() << Q_FUNC_INFO << "attempting to declare an unnamed exchange, aborting...";
|
||||
return;
|
||||
}
|
||||
|
||||
Frame::Method frame(Frame::fcExchange, ExchangePrivate::miDeclare);
|
||||
frame.setChannel(d->number);
|
||||
|
||||
QByteArray arguments;
|
||||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
stream << qint16(0); //reserver 1
|
||||
Frame::writeField('s', stream, d->name);
|
||||
Frame::writeField('s', stream, d->type);
|
||||
|
||||
stream << qint8(d->options);
|
||||
Frame::writeField('F', stream, d->arguments);
|
||||
|
||||
frame.setArguments(arguments);
|
||||
d->sendFrame(frame);
|
||||
d->delayedDeclare = false;
|
||||
}
|
||||
|
||||
void Exchange::remove(bool ifUnused, bool noWait)
|
||||
{
|
||||
Q_D(Exchange);
|
||||
d->remove(ifUnused, noWait);
|
||||
Frame::Method frame(Frame::fcExchange, ExchangePrivate::miDelete);
|
||||
frame.setChannel(d->number);
|
||||
|
||||
QByteArray arguments;
|
||||
QDataStream stream(&arguments, QIODevice::WriteOnly);
|
||||
|
||||
stream << qint16(0); //reserver 1
|
||||
Frame::writeField('s', stream, d->name);
|
||||
|
||||
qint8 flag = 0;
|
||||
flag |= (ifUnused ? 0x1 : 0);
|
||||
flag |= (noWait ? 0x2 : 0);
|
||||
stream << flag; //reserver 1
|
||||
|
||||
frame.setArguments(arguments);
|
||||
d->sendFrame(frame);
|
||||
}
|
||||
|
||||
void Exchange::bind(Queue *queue)
|
||||
|
|
@ -153,53 +193,6 @@ void ExchangePrivate::deleteOk(const Frame::Method &frame)
|
|||
QMetaObject::invokeMethod(q, "removed");
|
||||
}
|
||||
|
||||
void ExchangePrivate::declare()
|
||||
{
|
||||
if (!opened) {
|
||||
delayedDeclare = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
|
||||
Frame::Method frame(Frame::fcExchange, miDeclare);
|
||||
frame.setChannel(number);
|
||||
QByteArray arguments_;
|
||||
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
||||
|
||||
stream << qint16(0); //reserver 1
|
||||
Frame::writeField('s', stream, name);
|
||||
Frame::writeField('s', stream, type);
|
||||
stream << qint8(options);
|
||||
Frame::writeField('F', stream, ExchangePrivate::arguments);
|
||||
|
||||
frame.setArguments(arguments_);
|
||||
sendFrame(frame);
|
||||
delayedDeclare = false;
|
||||
}
|
||||
|
||||
void ExchangePrivate::remove(bool ifUnused, bool noWait)
|
||||
{
|
||||
Frame::Method frame(Frame::fcExchange, miDelete);
|
||||
frame.setChannel(number);
|
||||
QByteArray arguments_;
|
||||
QDataStream stream(&arguments_, QIODevice::WriteOnly);
|
||||
|
||||
stream << qint16(0); //reserver 1
|
||||
Frame::writeField('s', stream, name);
|
||||
|
||||
qint8 flag = 0;
|
||||
|
||||
flag |= (ifUnused ? 0x1 : 0);
|
||||
flag |= (noWait ? 0x2 : 0);
|
||||
|
||||
stream << flag; //reserver 1
|
||||
|
||||
frame.setArguments(arguments_);
|
||||
sendFrame(frame);
|
||||
}
|
||||
|
||||
void ExchangePrivate::publish(const QByteArray &message, const QString &key,
|
||||
const QString &mimeType, const QVariantHash &headers,
|
||||
const Exchange::MessageProperties &prop)
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ public:
|
|||
ExchangeOptions option() const;
|
||||
|
||||
void declare(const QString &type = QLatin1String("direct"),
|
||||
ExchangeOptions option = NoOptions,
|
||||
const Frame::TableField &arg = Frame::TableField());
|
||||
ExchangeOptions options = NoOptions,
|
||||
const Frame::TableField &args = Frame::TableField());
|
||||
void remove(bool ifUnused = true, bool noWait = true);
|
||||
|
||||
void bind(Queue *queue);
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
#include "amqp_channel_p.h"
|
||||
|
||||
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
|
|
@ -19,24 +17,20 @@ public:
|
|||
ExchangePrivate(Exchange *q);
|
||||
~ExchangePrivate();
|
||||
|
||||
void declare();
|
||||
void remove(bool ifUnused = true, bool noWait = true);
|
||||
|
||||
void declareOk(const Frame::Method &frame);
|
||||
void deleteOk(const Frame::Method &frame);
|
||||
|
||||
void publish(const QByteArray &message, const QString &key,
|
||||
const QString &mimeType = QLatin1String("text/plain"),
|
||||
const QVariantHash &headers = QVariantHash(),
|
||||
const Exchange::MessageProperties &properties = Exchange::MessageProperties());
|
||||
|
||||
// method handler related
|
||||
virtual void _q_disconnected();
|
||||
virtual bool _q_method(const Frame::Method &frame);
|
||||
void declareOk(const Frame::Method &frame);
|
||||
void deleteOk(const Frame::Method &frame);
|
||||
|
||||
QString type;
|
||||
Exchange::ExchangeOptions options;
|
||||
Frame::TableField arguments;
|
||||
|
||||
bool _q_method(const Frame::Method &frame);
|
||||
void _q_disconnected();
|
||||
|
||||
bool delayedDeclare;
|
||||
bool declared;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
#include <QQueue>
|
||||
#include "amqp_channel_p.h"
|
||||
|
||||
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue