move error constants to global namespace

This commit is contained in:
Matt Broadstone 2014-06-11 13:44:30 -04:00
parent e1522771e3
commit 496e00abb9
10 changed files with 70 additions and 51 deletions

View File

@ -13,7 +13,7 @@ ChannelPrivate::ChannelPrivate(Channel *q)
: channelNumber(0), : channelNumber(0),
opened(false), opened(false),
needOpen(true), needOpen(true),
error(Channel::NoError), error(QAMQP::NoError),
q_ptr(q) q_ptr(q)
{ {
} }
@ -163,8 +163,8 @@ void ChannelPrivate::close(const Frame::Method &frame)
stream >> classId; stream >> classId;
stream >> methodId; stream >> methodId;
Channel::ChannelError checkError = static_cast<Channel::ChannelError>(code); Error checkError = static_cast<Error>(code);
if (checkError != Channel::NoError) { if (checkError != QAMQP::NoError) {
error = checkError; error = checkError;
errorString = qPrintable(text); errorString = qPrintable(text);
Q_EMIT q->error(error); Q_EMIT q->error(error);
@ -282,7 +282,7 @@ void Channel::setQOS(qint32 prefetchSize, quint16 prefetchCount)
d->setQOS(prefetchSize, prefetchCount); d->setQOS(prefetchSize, prefetchCount);
} }
Channel::ChannelError Channel::error() const Error Channel::error() const
{ {
Q_D(const Channel); Q_D(const Channel);
return d->error; return d->error;

View File

@ -24,16 +24,7 @@ public:
QString name() const; QString name() const;
void setName(const QString &name); void setName(const QString &name);
enum ChannelError { Error error() const;
NoError = 0,
ContentTooLargeError = 311,
NoConsumersError = 313,
AccessRefusedError = 403,
NotFoundError = 404,
ResourceLockedError = 405,
PreconditionFailedError = 406
};
ChannelError error() const;
QString errorString() const; QString errorString() const;
public Q_SLOTS: public Q_SLOTS:
@ -45,7 +36,7 @@ Q_SIGNALS:
void opened(); void opened();
void closed(); void closed();
void flowChanged(bool enabled); void flowChanged(bool enabled);
void error(ChannelError error); void error(QAMQP::Error error);
protected: protected:
virtual void channelOpened() = 0; virtual void channelOpened() = 0;

View File

@ -77,7 +77,7 @@ public:
bool opened; bool opened;
bool needOpen; bool needOpen;
Channel::ChannelError error; Error error;
QString errorString; QString errorString;
Q_DECLARE_PUBLIC(Channel) Q_DECLARE_PUBLIC(Channel)

View File

@ -25,7 +25,7 @@ ClientPrivate::ClientPrivate(Client *q)
channelMax(0), channelMax(0),
heartbeatDelay(0), heartbeatDelay(0),
frameMax(AMQP_FRAME_MAX), frameMax(AMQP_FRAME_MAX),
error(Client::NoError), error(QAMQP::NoError),
q_ptr(q) q_ptr(q)
{ {
} }
@ -55,6 +55,7 @@ void ClientPrivate::initSocket()
Q_Q(Client); Q_Q(Client);
socket = new QTcpSocket(q); socket = new QTcpSocket(q);
QObject::connect(socket, SIGNAL(connected()), q, SLOT(_q_socketConnected())); QObject::connect(socket, SIGNAL(connected()), q, SLOT(_q_socketConnected()));
QObject::connect(socket, SIGNAL(disconnected()), q, SLOT(_q_socketDisconnected()));
QObject::connect(socket, SIGNAL(readyRead()), q, SLOT(_q_readyRead())); QObject::connect(socket, SIGNAL(readyRead()), q, SLOT(_q_readyRead()));
QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
q, SLOT(_q_socketError(QAbstractSocket::SocketError))); q, SLOT(_q_socketError(QAbstractSocket::SocketError)));
@ -105,6 +106,16 @@ void ClientPrivate::_q_socketConnected()
socket->write(header, 8); socket->write(header, 8);
} }
void ClientPrivate::_q_socketDisconnected()
{
Q_Q(Client);
buffer.clear();
if (connected) {
connected = false;
Q_EMIT q->disconnected();
}
}
void ClientPrivate::_q_heartbeat() void ClientPrivate::_q_heartbeat()
{ {
Frame::Heartbeat frame; Frame::Heartbeat frame;
@ -131,10 +142,14 @@ void ClientPrivate::_q_socketError(QAbstractSocket::SocketError error)
case QAbstractSocket::ProxyConnectionTimeoutError: case QAbstractSocket::ProxyConnectionTimeoutError:
default: default:
qWarning() << "AMQP: Socket Error: " << socket->errorString(); qAmqpDebug() << "socket Error: " << socket->errorString();
break; break;
} }
// per spec, on any error we need to close the socket immediately
// and send no more data;
socket->close();
if (autoReconnect) { if (autoReconnect) {
QTimer::singleShot(timeout, q, SLOT(_q_connect())); QTimer::singleShot(timeout, q, SLOT(_q_connect()));
} }
@ -167,7 +182,7 @@ void ClientPrivate::_q_readyRead()
{ {
Frame::Method frame(streamB); Frame::Method frame(streamB);
if (frame.size() > frameMax) { if (frame.size() > frameMax) {
close(Client::FrameError, "frame size too large"); close(FrameError, "frame size too large");
return; return;
} }
@ -183,7 +198,7 @@ void ClientPrivate::_q_readyRead()
{ {
Frame::Content frame(streamB); Frame::Content frame(streamB);
if (frame.size() > frameMax) { if (frame.size() > frameMax) {
close(Client::FrameError, "frame size too large"); close(FrameError, "frame size too large");
return; return;
} }
@ -195,7 +210,7 @@ void ClientPrivate::_q_readyRead()
{ {
Frame::ContentBody frame(streamB); Frame::ContentBody frame(streamB);
if (frame.size() > frameMax) { if (frame.size() > frameMax) {
close(Client::FrameError, "frame size too large"); close(FrameError, "frame size too large");
return; return;
} }
@ -372,8 +387,8 @@ void ClientPrivate::close(const Frame::Method &frame)
stream >> classId; stream >> classId;
stream >> methodId; stream >> methodId;
Client::ConnectionError checkError = static_cast<Client::ConnectionError>(code); Error checkError = static_cast<Error>(code);
if (checkError != Client::NoError) { if (checkError != QAMQP::NoError) {
error = checkError; error = checkError;
errorString = qPrintable(text); errorString = qPrintable(text);
Q_EMIT q->error(error); Q_EMIT q->error(error);
@ -749,6 +764,7 @@ void SslClientPrivate::initSocket()
Q_Q(Client); Q_Q(Client);
QSslSocket *sslSocket = new QSslSocket(q); QSslSocket *sslSocket = new QSslSocket(q);
QObject::connect(sslSocket, SIGNAL(connected()), q, SLOT(_q_socketConnected())); QObject::connect(sslSocket, SIGNAL(connected()), q, SLOT(_q_socketConnected()));
QObject::connect(sslSocket, SIGNAL(disconnected()), q, SLOT(_q_socketDisconnected()));
QObject::connect(sslSocket, SIGNAL(readyRead()), q, SLOT(_q_readyRead())); QObject::connect(sslSocket, SIGNAL(readyRead()), q, SLOT(_q_readyRead()));
QObject::connect(sslSocket, SIGNAL(error(QAbstractSocket::SocketError)), QObject::connect(sslSocket, SIGNAL(error(QAbstractSocket::SocketError)),
q, SLOT(_q_socketError(QAbstractSocket::SocketError))); q, SLOT(_q_socketError(QAbstractSocket::SocketError)));

View File

@ -73,21 +73,7 @@ public:
void addCustomProperty(const QString &name, const QString &value); void addCustomProperty(const QString &name, const QString &value);
QString customProperty(const QString &name) const; QString customProperty(const QString &name) const;
enum ConnectionError { Error error() const;
NoError = 0,
ConnectionForcedError = 320,
InvalidPathError = 402,
FrameError = 501,
SyntaxError = 502,
CommandInvalidError = 503,
ChannelError = 504,
UnexpectedFrameError = 505,
ResourceError = 506,
NotAllowedError = 530,
NotImplementedError = 540,
InternalError = 541
};
ConnectionError error() const;
QString errorString() const; QString errorString() const;
// channels // channels
@ -105,7 +91,7 @@ public:
Q_SIGNALS: Q_SIGNALS:
void connected(); void connected();
void disconnected(); void disconnected();
void error(ConnectionError error); void error(Error error);
protected: protected:
Client(ClientPrivate *dd, QObject *parent = 0); Client(ClientPrivate *dd, QObject *parent = 0);
@ -116,6 +102,7 @@ protected:
private: private:
Q_PRIVATE_SLOT(d_func(), void _q_socketConnected()) Q_PRIVATE_SLOT(d_func(), void _q_socketConnected())
Q_PRIVATE_SLOT(d_func(), void _q_socketDisconnected())
Q_PRIVATE_SLOT(d_func(), void _q_readyRead()) Q_PRIVATE_SLOT(d_func(), void _q_readyRead())
Q_PRIVATE_SLOT(d_func(), void _q_socketError(QAbstractSocket::SocketError error)) Q_PRIVATE_SLOT(d_func(), void _q_socketError(QAbstractSocket::SocketError error))
Q_PRIVATE_SLOT(d_func(), void _q_heartbeat()) Q_PRIVATE_SLOT(d_func(), void _q_heartbeat())

View File

@ -42,6 +42,7 @@ public:
// private slots // private slots
void _q_socketConnected(); void _q_socketConnected();
void _q_socketDisconnected();
void _q_readyRead(); void _q_readyRead();
void _q_socketError(QAbstractSocket::SocketError error); void _q_socketError(QAbstractSocket::SocketError error);
void _q_heartbeat(); void _q_heartbeat();
@ -94,7 +95,7 @@ public:
qint16 heartbeatDelay; qint16 heartbeatDelay;
qint32 frameMax; qint32 frameMax;
Client::ConnectionError error; Error error;
QString errorString; QString errorString;
Client * const q_ptr; Client * const q_ptr;

View File

@ -28,4 +28,29 @@
#define qAmqpDebug if (qgetenv("QAMQP_DEBUG").isEmpty()); else qDebug #define qAmqpDebug if (qgetenv("QAMQP_DEBUG").isEmpty()); else qDebug
namespace QAMQP {
enum Error {
NoError = 0,
ContentTooLargeError = 311,
NoConsumersError = 313,
ConnectionForcedError = 320,
InvalidPathError = 402,
AccessRefusedError = 403,
NotFoundError = 404,
ResourceLockedError = 405,
PreconditionFailedError = 406,
FrameError = 501,
SyntaxError = 502,
CommandInvalidError = 503,
ChannelError = 504,
UnexpectedFrameError = 505,
ResourceError = 506,
NotAllowedError = 530,
NotImplementedError = 540,
InternalError = 541
};
} // namespace QAMQP
#endif // qamqp_global_h__ #endif // qamqp_global_h__

View File

@ -13,7 +13,6 @@ private Q_SLOTS:
void connect(); void connect();
void connectDisconnect(); void connectDisconnect();
void invalidAuthenticationMechanism(); void invalidAuthenticationMechanism();
void tune(); void tune();
private: private:

View File

@ -72,8 +72,8 @@ void tst_QAMQPExchange::removeIfUnused()
QVERIFY(waitForSignal(queue, SIGNAL(bound()))); QVERIFY(waitForSignal(queue, SIGNAL(bound())));
exchange->remove(Exchange::roIfUnused); exchange->remove(Exchange::roIfUnused);
QVERIFY(waitForSignal(exchange, SIGNAL(error(ChannelError)))); QVERIFY(waitForSignal(exchange, SIGNAL(error(QAMQP::Error))));
QCOMPARE(exchange->error(), Exchange::PreconditionFailedError); QCOMPARE(exchange->error(), QAMQP::PreconditionFailedError);
QVERIFY(!exchange->errorString().isEmpty()); QVERIFY(!exchange->errorString().isEmpty());
// cleanup // cleanup

View File

@ -116,8 +116,8 @@ void tst_QAMQPQueue::exclusiveAccess()
QVERIFY(waitForSignal(&secondClient, SIGNAL(connected()))); QVERIFY(waitForSignal(&secondClient, SIGNAL(connected())));
Queue *passiveQueue = secondClient.createQueue("test-exclusive-queue"); Queue *passiveQueue = secondClient.createQueue("test-exclusive-queue");
passiveQueue->declare(Queue::Passive); passiveQueue->declare(Queue::Passive);
QVERIFY(waitForSignal(passiveQueue, SIGNAL(error(ChannelError)))); QVERIFY(waitForSignal(passiveQueue, SIGNAL(error(QAMQP::Error))));
QCOMPARE(passiveQueue->error(), Channel::ResourceLockedError); QCOMPARE(passiveQueue->error(), QAMQP::ResourceLockedError);
secondClient.disconnectFromHost(); secondClient.disconnectFromHost();
QVERIFY(waitForSignal(&secondClient, SIGNAL(disconnected()))); QVERIFY(waitForSignal(&secondClient, SIGNAL(disconnected())));
@ -138,8 +138,8 @@ void tst_QAMQPQueue::exclusiveRemoval()
QVERIFY(waitForSignal(&secondClient, SIGNAL(connected()))); QVERIFY(waitForSignal(&secondClient, SIGNAL(connected())));
Queue *passiveQueue = secondClient.createQueue("test-exclusive-queue"); Queue *passiveQueue = secondClient.createQueue("test-exclusive-queue");
passiveQueue->declare(Queue::Passive); passiveQueue->declare(Queue::Passive);
QVERIFY(waitForSignal(passiveQueue, SIGNAL(error(ChannelError)))); QVERIFY(waitForSignal(passiveQueue, SIGNAL(error(QAMQP::Error))));
QCOMPARE(passiveQueue->error(), Channel::NotFoundError); QCOMPARE(passiveQueue->error(), QAMQP::NotFoundError);
secondClient.disconnectFromHost(); secondClient.disconnectFromHost();
QVERIFY(waitForSignal(&secondClient, SIGNAL(disconnected()))); QVERIFY(waitForSignal(&secondClient, SIGNAL(disconnected())));
} }
@ -161,8 +161,8 @@ void tst_QAMQPQueue::removeIfUnused()
queue->consume(); queue->consume();
queue->remove(Queue::roIfUnused); queue->remove(Queue::roIfUnused);
QVERIFY(waitForSignal(queue, SIGNAL(error(ChannelError)))); QVERIFY(waitForSignal(queue, SIGNAL(error(QAMQP::Error))));
QCOMPARE(queue->error(), Channel::PreconditionFailedError); QCOMPARE(queue->error(), QAMQP::PreconditionFailedError);
QVERIFY(!queue->errorString().isEmpty()); QVERIFY(!queue->errorString().isEmpty());
} }
@ -185,8 +185,8 @@ void tst_QAMQPQueue::removeIfEmpty()
QVERIFY(waitForSignal(testDeleteQueue, SIGNAL(declared()))); QVERIFY(waitForSignal(testDeleteQueue, SIGNAL(declared())));
testDeleteQueue->remove(Queue::roIfEmpty); testDeleteQueue->remove(Queue::roIfEmpty);
QVERIFY(waitForSignal(testDeleteQueue, SIGNAL(error(ChannelError)))); QVERIFY(waitForSignal(testDeleteQueue, SIGNAL(error(QAMQP::Error))));
QCOMPARE(testDeleteQueue->error(), Channel::PreconditionFailedError); QCOMPARE(testDeleteQueue->error(), QAMQP::PreconditionFailedError);
QVERIFY(!testDeleteQueue->errorString().isEmpty()); QVERIFY(!testDeleteQueue->errorString().isEmpty());
secondClient.disconnectFromHost(); secondClient.disconnectFromHost();