2014-05-29 01:05:51 +08:00
|
|
|
#ifndef amqp_client_h__
|
|
|
|
|
#define amqp_client_h__
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QUrl>
|
2014-05-29 04:28:45 +08:00
|
|
|
#include <QHostAddress>
|
2014-05-29 00:25:28 +08:00
|
|
|
|
2014-06-06 09:31:24 +08:00
|
|
|
#ifndef QT_NO_SSL
|
|
|
|
|
#include <QSslConfiguration>
|
|
|
|
|
#include <QSslError>
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-05-29 03:33:15 +08:00
|
|
|
#include "amqp_global.h"
|
|
|
|
|
|
2014-05-29 00:25:28 +08:00
|
|
|
namespace QAMQP
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class Exchange;
|
|
|
|
|
class Queue;
|
|
|
|
|
class Authenticator;
|
2014-05-31 05:20:11 +08:00
|
|
|
class ClientPrivate;
|
2014-05-29 03:33:15 +08:00
|
|
|
class QAMQP_EXPORT Client : public QObject
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PROPERTY(quint32 port READ port WRITE setPort)
|
|
|
|
|
Q_PROPERTY(QString host READ host WRITE setHost)
|
|
|
|
|
Q_PROPERTY(QString virtualHost READ virtualHost WRITE setVirtualHost)
|
2014-06-06 09:31:24 +08:00
|
|
|
Q_PROPERTY(QString user READ username WRITE setUsername)
|
2014-05-29 00:25:28 +08:00
|
|
|
Q_PROPERTY(QString password READ password WRITE setPassword)
|
|
|
|
|
Q_PROPERTY(bool autoReconnect READ autoReconnect WRITE setAutoReconnect)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Client(QObject *parent = 0);
|
|
|
|
|
Client(const QUrl &connectionString, QObject *parent = 0);
|
|
|
|
|
~Client();
|
|
|
|
|
|
2014-06-06 09:31:24 +08:00
|
|
|
// properties
|
2014-05-29 00:25:28 +08:00
|
|
|
quint16 port() const;
|
|
|
|
|
void setPort(quint16 port);
|
|
|
|
|
|
|
|
|
|
QString host() const;
|
|
|
|
|
void setHost(const QString &host);
|
|
|
|
|
|
|
|
|
|
QString virtualHost() const;
|
|
|
|
|
void setVirtualHost(const QString &virtualHost);
|
|
|
|
|
|
2014-06-06 09:31:24 +08:00
|
|
|
QString username() const;
|
|
|
|
|
void setUsername(const QString &username);
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
QString password() const;
|
|
|
|
|
void setPassword(const QString &password);
|
|
|
|
|
|
|
|
|
|
void setAuth(Authenticator *auth);
|
|
|
|
|
Authenticator *auth() const;
|
|
|
|
|
|
|
|
|
|
bool autoReconnect() const;
|
|
|
|
|
void setAutoReconnect(bool value);
|
|
|
|
|
|
|
|
|
|
bool isConnected() const;
|
|
|
|
|
|
2014-06-06 09:31:24 +08:00
|
|
|
void addCustomProperty(const QString &name, const QString &value);
|
|
|
|
|
QString customProperty(const QString &name) const;
|
|
|
|
|
|
2014-06-07 00:10:51 +08:00
|
|
|
enum ConnectionError {
|
|
|
|
|
NoError = 0,
|
|
|
|
|
ConnectionForced = 320,
|
|
|
|
|
InvalidPath = 402,
|
|
|
|
|
FrameError = 501,
|
|
|
|
|
SyntaxError = 502,
|
|
|
|
|
CommandInvalid = 503,
|
|
|
|
|
ChannelError = 504,
|
|
|
|
|
UnexpectedFrame = 505,
|
|
|
|
|
ResourceError = 506,
|
|
|
|
|
NotAllowed = 530,
|
|
|
|
|
NotImplemented = 540,
|
|
|
|
|
InternalError = 541
|
|
|
|
|
};
|
|
|
|
|
ConnectionError error() const;
|
|
|
|
|
QString errorString() const;
|
|
|
|
|
|
2014-06-06 09:31:24 +08:00
|
|
|
// channels
|
|
|
|
|
Exchange *createExchange(int channelNumber = -1);
|
|
|
|
|
Exchange *createExchange(const QString &name, int channelNumber = -1);
|
|
|
|
|
|
|
|
|
|
Queue *createQueue(int channelNumber = -1);
|
|
|
|
|
Queue *createQueue(const QString &name, int channelNumber = -1);
|
|
|
|
|
|
|
|
|
|
// methods
|
2014-05-29 22:16:33 +08:00
|
|
|
void connectToHost(const QString &connectionString = QString());
|
2014-06-04 04:11:30 +08:00
|
|
|
void connectToHost(const QHostAddress &address, quint16 port = AMQPPORT);
|
2014-05-29 22:16:33 +08:00
|
|
|
void disconnectFromHost();
|
|
|
|
|
|
2014-05-29 04:28:45 +08:00
|
|
|
Q_SIGNALS:
|
2014-05-29 00:25:28 +08:00
|
|
|
void connected();
|
|
|
|
|
void disconnected();
|
2014-06-07 00:10:51 +08:00
|
|
|
void error(ConnectionError error);
|
2014-05-29 00:25:28 +08:00
|
|
|
|
2014-06-06 09:31:24 +08:00
|
|
|
protected:
|
|
|
|
|
Client(ClientPrivate *dd, QObject *parent = 0);
|
|
|
|
|
|
2014-05-29 00:25:28 +08:00
|
|
|
Q_DISABLE_COPY(Client)
|
2014-05-29 04:28:45 +08:00
|
|
|
Q_DECLARE_PRIVATE(Client)
|
2014-05-29 00:25:28 +08:00
|
|
|
QScopedPointer<ClientPrivate> d_ptr;
|
|
|
|
|
|
2014-06-06 09:31:24 +08:00
|
|
|
private:
|
2014-06-04 04:11:30 +08:00
|
|
|
Q_PRIVATE_SLOT(d_func(), void _q_socketConnected())
|
|
|
|
|
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_heartbeat())
|
2014-06-06 04:09:52 +08:00
|
|
|
Q_PRIVATE_SLOT(d_func(), void _q_connect())
|
|
|
|
|
Q_PRIVATE_SLOT(d_func(), void _q_disconnect())
|
2014-06-04 04:11:30 +08:00
|
|
|
|
2014-05-29 00:25:28 +08:00
|
|
|
friend class ChannelPrivate;
|
2014-05-29 22:16:33 +08:00
|
|
|
|
2014-05-29 00:25:28 +08:00
|
|
|
};
|
|
|
|
|
|
2014-06-06 09:31:24 +08:00
|
|
|
#ifndef QT_NO_SSL
|
|
|
|
|
class SslClientPrivate;
|
|
|
|
|
class SslClient : public Client
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
SslClient(QObject *parent = 0);
|
|
|
|
|
SslClient(const QUrl &connectionString, QObject *parent = 0);
|
|
|
|
|
~SslClient();
|
|
|
|
|
|
|
|
|
|
QSslConfiguration sslConfiguration() const;
|
|
|
|
|
void setSslConfiguration(const QSslConfiguration &config);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Q_DISABLE_COPY(SslClient)
|
|
|
|
|
Q_DECLARE_PRIVATE(SslClient)
|
|
|
|
|
|
|
|
|
|
Q_PRIVATE_SLOT(d_func(), void _q_sslErrors(const QList<QSslError> &errors))
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-05-29 00:25:28 +08:00
|
|
|
} // namespace QAMQP
|
|
|
|
|
|
2014-05-29 01:05:51 +08:00
|
|
|
#endif // amqp_client_h__
|