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)
|
2014-06-10 07:27:24 +08:00
|
|
|
Q_PROPERTY(qint16 channelMax READ channelMax WRITE setChannelMax)
|
|
|
|
|
Q_PROPERTY(qint32 frameMax READ frameMax WRITE setFrameMax)
|
|
|
|
|
Q_PROPERTY(qint16 heartbeatDelay READ heartbeatDelay() WRITE setHeartbeatDelay)
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
public:
|
2014-06-27 01:31:25 +08:00
|
|
|
explicit Client(QObject *parent = 0);
|
2014-05-29 00:25:28 +08:00
|
|
|
~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-10 07:27:24 +08:00
|
|
|
qint16 channelMax() const;
|
|
|
|
|
void setChannelMax(qint16 channelMax);
|
|
|
|
|
|
|
|
|
|
qint32 frameMax() const;
|
|
|
|
|
void setFrameMax(qint32 frameMax);
|
|
|
|
|
|
|
|
|
|
qint16 heartbeatDelay() const;
|
|
|
|
|
void setHeartbeatDelay(qint16 delay);
|
|
|
|
|
|
2014-06-06 09:31:24 +08:00
|
|
|
void addCustomProperty(const QString &name, const QString &value);
|
|
|
|
|
QString customProperty(const QString &name) const;
|
|
|
|
|
|
2014-06-12 01:44:30 +08:00
|
|
|
Error error() const;
|
2014-06-07 00:10:51 +08:00
|
|
|
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-06-27 01:31:25 +08:00
|
|
|
void connectToHost(const QString &uri = QString());
|
2014-06-10 07:27:24 +08:00
|
|
|
void connectToHost(const QHostAddress &address, quint16 port = AMQP_PORT);
|
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-12 03:49:05 +08:00
|
|
|
void error(QAMQP::Error 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())
|
2014-06-12 01:44:30 +08:00
|
|
|
Q_PRIVATE_SLOT(d_func(), void _q_socketDisconnected())
|
2014-06-04 04:11:30 +08:00
|
|
|
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__
|