diff --git a/src/qamqp/amqp.cpp b/src/qamqp/amqp.cpp index e7e817a..ca105ec 100644 --- a/src/qamqp/amqp.cpp +++ b/src/qamqp/amqp.cpp @@ -3,7 +3,6 @@ #include #include -#include "qamqp_global.h" #include "amqp_exchange.h" #include "amqp_queue.h" #include "amqp_authenticator.h" @@ -27,8 +26,8 @@ struct QAMQP::ClientExceptionCleaner ////////////////////////////////////////////////////////////////////////// -ClientPrivate::ClientPrivate(int version ) - :QObjectPrivate(version) +ClientPrivate::ClientPrivate( Client * q ) : + pq_ptr(q) , port(AMQPPORT) , host(QString::fromLatin1(AMQPHOST)) , virtualHost(QString::fromLatin1(AMQPVHOST)) @@ -44,14 +43,14 @@ ClientPrivate::~ClientPrivate() void ClientPrivate::init(QObject * parent) { - q_func()->setParent(parent); + pq_func()->setParent(parent); if(!network_){ - network_ = new QAMQP::Network(q_func()); + network_ = new QAMQP::Network(pq_func()); } if(!connection_) { - connection_ = new QAMQP::Connection(q_func()); + connection_ = new QAMQP::Connection(pq_func()); } setAuth(new AMQPlainAuthenticator(QString::fromLatin1(AMQPLOGIN), QString::fromLatin1(AMQPPSWD))); @@ -98,7 +97,7 @@ void ClientPrivate::connect() void ClientPrivate::parseCnnString( const QUrl & con ) { - Q_Q(QAMQP::Client); + P_Q(QAMQP::Client); if(con.scheme() == AMQPSCHEME ) { q->setPassword(con.password()); @@ -122,7 +121,7 @@ void ClientPrivate::login() Exchange * ClientPrivate::createExchange(int channelNumber, const QString &name ) { - Exchange * exchange_ = new Exchange(channelNumber, q_func()); + Exchange * exchange_ = new Exchange(channelNumber, pq_func()); QObject::connect(network_, SIGNAL(method(const QAMQP::Frame::Method &)), exchange_, SLOT(_q_method(const QAMQP::Frame::Method &))); @@ -133,7 +132,7 @@ Exchange * ClientPrivate::createExchange(int channelNumber, const QString &name Queue * ClientPrivate::createQueue(int channelNumber, const QString &name ) { - Queue * queue_ = new Queue(channelNumber, q_func()); + Queue * queue_ = new Queue(channelNumber, pq_func()); QObject::connect(network_, SIGNAL(method(const QAMQP::Frame::Method &)), queue_, SLOT(_q_method(const QAMQP::Frame::Method &))); @@ -159,42 +158,29 @@ void ClientPrivate::disconnect() QAMQP::Client::Client( QObject * parent /*= 0*/ ) - : QObject(*new ClientPrivate, 0) + : pd_ptr(new ClientPrivate(this)) { QT_TRY { - d_func()->init(parent); + pd_func()->init(parent); } QT_CATCH(...) { - ClientExceptionCleaner::cleanup(this, d_func()); + ClientExceptionCleaner::cleanup(this, pd_func()); QT_RETHROW; } } QAMQP::Client::Client( const QUrl & connectionString, QObject * parent /*= 0*/ ) - : QObject(*new ClientPrivate, 0) + : pd_ptr(new ClientPrivate(this)) { QT_TRY { - d_func()->init(parent, connectionString); + pd_func()->init(parent, connectionString); } QT_CATCH(...) { - ClientExceptionCleaner::cleanup(this, d_func()); - QT_RETHROW; - } -} - -QAMQP::Client::Client(ClientPrivate &dd, QObject* parent, const QUrl & connectionString) - : QObject(dd, 0) -{ - Q_D(QAMQP::Client); - QT_TRY { - d->init(parent, connectionString); - } QT_CATCH(...) { - ClientExceptionCleaner::cleanup(this, d_func()); + ClientExceptionCleaner::cleanup(this, pd_func()); QT_RETHROW; } } QAMQP::Client::~Client() { - QObjectPrivate::clearGuards(this); QT_TRY { QEvent e(QEvent::Destroy); QCoreApplication::sendEvent(this, &e); @@ -205,37 +191,37 @@ QAMQP::Client::~Client() quint32 QAMQP::Client::port() const { - return d_func()->port; + return pd_func()->port; } void QAMQP::Client::setPort( quint32 port ) { - d_func()->port = port; + pd_func()->port = port; } QString QAMQP::Client::host() const { - return d_func()->host; + return pd_func()->host; } void QAMQP::Client::setHost( const QString & host ) { - d_func()->host = host; + pd_func()->host = host; } QString QAMQP::Client::virtualHost() const { - return d_func()->virtualHost; + return pd_func()->virtualHost; } void QAMQP::Client::setVirtualHost( const QString & virtualHost ) { - d_func()->virtualHost = virtualHost; + pd_func()->virtualHost = virtualHost; } QString QAMQP::Client::user() const { - const Authenticator * auth = d_func()->auth_.data(); + const Authenticator * auth = pd_func()->auth_.data(); if(auth && auth->type() == "AMQPLAIN") { @@ -247,7 +233,7 @@ QString QAMQP::Client::user() const void QAMQP::Client::setUser( const QString & user ) { - Authenticator * auth = d_func()->auth_.data(); + Authenticator * auth = pd_func()->auth_.data(); if(auth && auth->type() == "AMQPLAIN") { @@ -258,7 +244,7 @@ void QAMQP::Client::setUser( const QString & user ) QString QAMQP::Client::password() const { - const Authenticator * auth = d_func()->auth_.data(); + const Authenticator * auth = pd_func()->auth_.data(); if(auth && auth->type() == "AMQPLAIN") { @@ -270,7 +256,7 @@ QString QAMQP::Client::password() const void QAMQP::Client::setPassword( const QString & password ) { - Authenticator * auth = d_func()->auth_.data(); + Authenticator * auth = pd_func()->auth_.data(); if(auth && auth->type() == "AMQPLAIN") { @@ -282,7 +268,7 @@ void QAMQP::Client::setPassword( const QString & password ) void QAMQP::Client::printConnect() const { #ifdef _DEBUG - d_func()->printConnect(); + pd_func()->printConnect(); #endif // _DEBUG } @@ -293,52 +279,52 @@ void QAMQP::Client::closeChannel() Exchange * QAMQP::Client::createExchange(int channelNumber) { - return d_func()->createExchange(channelNumber, QString()); + return pd_func()->createExchange(channelNumber, QString()); } Exchange * QAMQP::Client::createExchange( const QString &name, int channelNumber ) { - return d_func()->createExchange(channelNumber, name); + return pd_func()->createExchange(channelNumber, name); } Queue * QAMQP::Client::createQueue(int channelNumber) { - return d_func()->createQueue(channelNumber, QString()); + return pd_func()->createQueue(channelNumber, QString()); } Queue * QAMQP::Client::createQueue( const QString &name, int channelNumber ) { - return d_func()->createQueue(channelNumber, name); + return pd_func()->createQueue(channelNumber, name); } void QAMQP::Client::open() { - return d_func()->connect(); + return pd_func()->connect(); } void QAMQP::Client::open( const QUrl & connectionString ) { - d_func()->parseCnnString(connectionString); + pd_func()->parseCnnString(connectionString); open(); } void QAMQP::Client::close() { - return d_func()->disconnect(); + return pd_func()->disconnect(); } void QAMQP::Client::reopen() { - d_func()->disconnect(); - d_func()->connect(); + pd_func()->disconnect(); + pd_func()->connect(); } void QAMQP::Client::setAuth( Authenticator * auth ) { - d_func()->setAuth(auth); + pd_func()->setAuth(auth); } Authenticator * QAMQP::Client::auth() const { - return d_func()->auth_.data(); + return pd_func()->auth_.data(); } \ No newline at end of file diff --git a/src/qamqp/amqp.h b/src/qamqp/amqp.h index 2ccf50b..b902b21 100644 --- a/src/qamqp/amqp.h +++ b/src/qamqp/amqp.h @@ -3,6 +3,7 @@ #include #include +#include "amqp_global.h" namespace QAMQP { @@ -21,8 +22,10 @@ namespace QAMQP Q_PROPERTY(QString user READ user WRITE setUser); Q_PROPERTY(QString password READ password WRITE setPassword); - Q_DECLARE_PRIVATE(QAMQP::Client) Q_DISABLE_COPY(Client) + + P_DECLARE_PRIVATE(QAMQP::Client) + friend class ConnectionPrivate; friend class ChannelPrivate; @@ -61,12 +64,12 @@ namespace QAMQP void open(const QUrl & connectionString); void close(); void reopen(); - protected: - Client(ClientPrivate &d, QObject* parent, const QUrl & connectionString); + ClientPrivate * const pd_ptr; private: friend struct ClientExceptionCleaner; + //void chanalConnect(); }; } diff --git a/src/qamqp/amqp_authenticator.h b/src/qamqp/amqp_authenticator.h index 4d46f9d..b882b33 100644 --- a/src/qamqp/amqp_authenticator.h +++ b/src/qamqp/amqp_authenticator.h @@ -1,7 +1,7 @@ #ifndef amqp_authenticator_h__ #define amqp_authenticator_h__ -#include "qamqp_global.h" +#include "amqp_global.h" #include #include diff --git a/src/qamqp/amqp_channel.cpp b/src/qamqp/amqp_channel.cpp index bba6560..5470928 100644 --- a/src/qamqp/amqp_channel.cpp +++ b/src/qamqp/amqp_channel.cpp @@ -33,31 +33,24 @@ namespace QAMQP ////////////////////////////////////////////////////////////////////////// QAMQP::Channel::Channel(int channelNumber /*= -1*/, Client * parent /*= 0*/ ) - : QObject(*new ChannelPrivate, 0) + : pd_ptr(new ChannelPrivate(this)) { QT_TRY { - d_func()->init(channelNumber, parent); + pd_func()->init(channelNumber, parent); } QT_CATCH(...) { - ChannelExceptionCleaner::cleanup(this, d_func()); + ChannelExceptionCleaner::cleanup(this, pd_func()); QT_RETHROW; } } -QAMQP::Channel::Channel( ChannelPrivate &dd, int channelNumber, Client* parent ) - : QObject(dd, 0) +QAMQP::Channel::Channel( ChannelPrivate * d ) + : pd_ptr(d) { - Q_D(QAMQP::Channel); - QT_TRY { - d->init(channelNumber, parent); - } QT_CATCH(...) { - ChannelExceptionCleaner::cleanup(this, d_func()); - QT_RETHROW; - } + } QAMQP::Channel::~Channel() { - QObjectPrivate::clearGuards(this); QT_TRY { QEvent e(QEvent::Destroy); @@ -69,7 +62,7 @@ QAMQP::Channel::~Channel() void QAMQP::Channel::closeChannel() { - Q_D(Channel); + P_D(Channel); d->needOpen = true; if(d->opened) d->close(0, QString(), 0,0); @@ -79,22 +72,22 @@ void QAMQP::Channel::closeChannel() void QAMQP::Channel::reopen() { closeChannel(); - d_func()->open(); + pd_func()->open(); } QString QAMQP::Channel::name() { - return d_func()->name; + return pd_func()->name; } int QAMQP::Channel::channelNumber() { - return d_func()->number; + return pd_func()->number; } void QAMQP::Channel::setName( const QString &name ) { - d_func()->name = name; + pd_func()->name = name; } void QAMQP::Channel::stateChanged( int state ) @@ -118,7 +111,7 @@ void QAMQP::Channel::stateChanged( int state ) bool QAMQP::Channel::isOpened() const { - return d_func()->opened; + return pd_func()->opened; } void QAMQP::Channel::onOpen() @@ -133,12 +126,12 @@ void QAMQP::Channel::onClose() void QAMQP::Channel::setQOS( qint32 prefetchSize, quint16 prefetchCount ) { - d_func()->setQOS(prefetchSize, prefetchCount); + pd_func()->setQOS(prefetchSize, prefetchCount); } ////////////////////////////////////////////////////////////////////////// -ChannelPrivate::ChannelPrivate(int version /* = QObjectPrivateVersion */) - :QObjectPrivate(version) +ChannelPrivate::ChannelPrivate(Channel * q) + :pq_ptr(q) , number(0) , opened(false) , needOpen(true) @@ -156,7 +149,7 @@ void ChannelPrivate::init(int channelNumber, Client * parent) needOpen = channelNumber == -1 ? true : false; number = channelNumber == -1 ? ++nextChannelNumber_ : channelNumber; nextChannelNumber_ = qMax(channelNumber, (nextChannelNumber_ + 1)); - q_func()->setParent(parent); + pq_func()->setParent(parent); client_ = parent; } @@ -200,7 +193,7 @@ void ChannelPrivate::_q_open() void ChannelPrivate::sendFrame( const QAMQP::Frame::Base & frame ) { - client_->d_func()->network_->sendFrame(frame); + client_->pd_func()->network_->sendFrame(frame); } @@ -209,7 +202,7 @@ void ChannelPrivate::open() if(!needOpen) return; - if(!client_->d_func()->connection_->isConnected()) + if(!client_->pd_func()->connection_->isConnected()) return; qDebug("Open channel #%d", number); QAMQP::Frame::Method frame(QAMQP::Frame::fcChannel, miOpen); @@ -256,12 +249,12 @@ void ChannelPrivate::close(int code, const QString & text, int classId, int meth stream << qint16(methodId); frame.setArguments(arguments_); - client_->d_func()->network_->sendFrame(frame); + client_->pd_func()->network_->sendFrame(frame); } void ChannelPrivate::close( const QAMQP::Frame::Method & frame ) { - q_func()->stateChanged(csClosed); + pq_func()->stateChanged(csClosed); qDebug(">> CLOSE"); QByteArray data = frame.arguments(); @@ -288,7 +281,7 @@ void ChannelPrivate::closeOk() void ChannelPrivate::closeOk( const QAMQP::Frame::Method & frame ) { Q_UNUSED(frame); - Q_Q(Channel); + P_Q(Channel); q->stateChanged(csClosed); q->onClose(); opened = false; @@ -297,7 +290,7 @@ void ChannelPrivate::closeOk( const QAMQP::Frame::Method & frame ) void ChannelPrivate::openOk( const QAMQP::Frame::Method & frame ) { Q_UNUSED(frame); - Q_Q(Channel); + P_Q(Channel); qDebug(">> OpenOK"); opened = true; q->stateChanged(csOpened); @@ -307,5 +300,5 @@ void ChannelPrivate::openOk( const QAMQP::Frame::Method & frame ) void ChannelPrivate::setQOS( qint32 prefetchSize, quint16 prefetchCount ) { - client_->d_func()->connection_->d_func()->setQOS(prefetchSize, prefetchCount, number, false); + client_->pd_func()->connection_->pd_func()->setQOS(prefetchSize, prefetchCount, number, false); } \ No newline at end of file diff --git a/src/qamqp/amqp_channel.h b/src/qamqp/amqp_channel.h index 99f1e45..3d378f7 100644 --- a/src/qamqp/amqp_channel.h +++ b/src/qamqp/amqp_channel.h @@ -2,7 +2,7 @@ #define amqp_channel_h__ #include -#include "qamqp_global.h" +#include "amqp_global.h" #include "amqp_frame.h" namespace QAMQP @@ -16,7 +16,7 @@ namespace QAMQP Q_PROPERTY(int number READ channelNumber); Q_PROPERTY(QString name READ name WRITE setName); - Q_DECLARE_PRIVATE(QAMQP::Channel) + P_DECLARE_PRIVATE(QAMQP::Channel) Q_DISABLE_COPY(Channel) public: ~Channel(); @@ -38,15 +38,17 @@ namespace QAMQP protected: Channel(int channelNumber = -1, Client * parent = 0); - Channel(ChannelPrivate &dd, int channelNumber = -1, Client* parent = 0); - virtual void onOpen();; - virtual void onClose();; + Channel(ChannelPrivate * d); + virtual void onOpen(); + virtual void onClose(); + + ChannelPrivate * const pd_ptr; private: void stateChanged(int state); friend class ClientPrivate; - Q_PRIVATE_SLOT(d_func(), void _q_open()) - Q_PRIVATE_SLOT(d_func(), void _q_method(const QAMQP::Frame::Method & frame)) + Q_PRIVATE_SLOT(pd_func(), void _q_open()) + Q_PRIVATE_SLOT(pd_func(), void _q_method(const QAMQP::Frame::Method & frame)) }; } diff --git a/src/qamqp/amqp_channel_p.h b/src/qamqp/amqp_channel_p.h index c42dab3..473f851 100644 --- a/src/qamqp/amqp_channel_p.h +++ b/src/qamqp/amqp_channel_p.h @@ -1,7 +1,8 @@ #ifndef amqp_channel_p_h__ #define amqp_channel_p_h__ -#include +#include "amqp_global.h" +#include #define METHOD_ID_ENUM(name, id) name = id, name ## Ok @@ -9,9 +10,9 @@ namespace QAMQP { class Client; class ClientPrivate; - class ChannelPrivate : public QObjectPrivate + class ChannelPrivate { - Q_DECLARE_PUBLIC(QAMQP::Channel) + P_DECLARE_PUBLIC(QAMQP::Channel) public: enum MethodId { @@ -43,7 +44,7 @@ namespace QAMQP METHOD_ID_ENUM(bmRecover, 110) }; - ChannelPrivate(int version = QObjectPrivateVersion); + ChannelPrivate(Channel * q); virtual ~ChannelPrivate(); void init(int channelNumber, Client * parent); @@ -76,6 +77,8 @@ namespace QAMQP static int nextChannelNumber_; bool opened; bool needOpen; + + Channel * const pq_ptr; }; } #endif // amqp_channel_p_h__ \ No newline at end of file diff --git a/src/qamqp/amqp_connection.cpp b/src/qamqp/amqp_connection.cpp index 5d5a5e9..d6bbe9a 100644 --- a/src/qamqp/amqp_connection.cpp +++ b/src/qamqp/amqp_connection.cpp @@ -33,8 +33,10 @@ namespace QAMQP ////////////////////////////////////////////////////////////////////////// -ConnectionPrivate::ConnectionPrivate( int version /*= QObjectPrivateVersion*/ ) - :QObjectPrivate(version), closed_(false), connected(false) +ConnectionPrivate::ConnectionPrivate( Connection * q) + :pq_ptr(q) + , closed_(false) + , connected(false) { } @@ -46,7 +48,7 @@ ConnectionPrivate::~ConnectionPrivate() void ConnectionPrivate::init(Client * parent) { - q_func()->setParent(parent); + pq_func()->setParent(parent); client_ = parent; } @@ -62,13 +64,13 @@ void ConnectionPrivate::startOk() clientProperties["product"] = "QAMQP"; QAMQP::Frame::serialize(stream, clientProperties); - client_->d_func()->auth_->write(stream); + client_->pd_func()->auth_->write(stream); QAMQP::Frame::writeField('s', stream, "en_US"); frame.setArguments(arguments_); - client_->d_func()->network_->sendFrame(frame); + client_->pd_func()->network_->sendFrame(frame); } void ConnectionPrivate::secureOk() @@ -88,7 +90,7 @@ void ConnectionPrivate::tuneOk() stream << qint16(0); //heartbeat frame.setArguments(arguments_); - client_->d_func()->network_->sendFrame(frame); + client_->pd_func()->network_->sendFrame(frame); } void ConnectionPrivate::open() @@ -103,7 +105,7 @@ void ConnectionPrivate::open() stream << qint8(0); frame.setArguments(arguments_); - client_->d_func()->network_->sendFrame(frame); + client_->pd_func()->network_->sendFrame(frame); } void ConnectionPrivate::start( const QAMQP::Frame::Method & frame ) @@ -164,7 +166,7 @@ void ConnectionPrivate::openOk( const QAMQP::Frame::Method & frame ) Q_UNUSED(frame); qDebug(">> OpenOK"); connected = true; - q_func()->openOk(); + pq_func()->openOk(); } void ConnectionPrivate::close( const QAMQP::Frame::Method & frame ) @@ -199,20 +201,20 @@ void ConnectionPrivate::close(int code, const QString & text, int classId, int m stream << qint16(methodId); frame.setArguments(arguments_); - client_->d_func()->network_->sendFrame(frame); + client_->pd_func()->network_->sendFrame(frame); } void ConnectionPrivate::closeOk() { QAMQP::Frame::Method frame(QAMQP::Frame::fcConnection, miCloseOk); connected = false; - client_->d_func()->network_->sendFrame(frame); + client_->pd_func()->network_->sendFrame(frame); } void ConnectionPrivate::closeOk( const QAMQP::Frame::Method & ) { connected = false; - QMetaObject::invokeMethod(q_func(), "disconnected"); + QMetaObject::invokeMethod(pq_func(), "disconnected"); } @@ -228,7 +230,7 @@ void ConnectionPrivate::setQOS( qint32 prefetchSize, quint16 prefetchCount, int out << qint8(global ? 1 : 0); frame.setArguments(arguments_); - client_->d_func()->network_->sendFrame(frame); + client_->pd_func()->network_->sendFrame(frame); } @@ -276,32 +278,18 @@ bool ConnectionPrivate::_q_method( const QAMQP::Frame::Method & frame ) ////////////////////////////////////////////////////////////////////////// Connection::Connection( Client * parent /*= 0*/ ) - : QObject(*new ConnectionPrivate, 0) + : pd_ptr(new ConnectionPrivate(this)) { QT_TRY { - d_func()->init(parent); + pd_func()->init(parent); } QT_CATCH(...) { - ConnectionExceptionCleaner::cleanup(this, d_func()); - QT_RETHROW; - } -} - -Connection::Connection(ConnectionPrivate &dd, Client* parent) -: QObject(dd, 0) -{ - Q_D(QAMQP::Connection); - QT_TRY { - d->init(parent); - } QT_CATCH(...) { - ConnectionExceptionCleaner::cleanup(this, d_func()); + ConnectionExceptionCleaner::cleanup(this, pd_func()); QT_RETHROW; } } Connection::~Connection() { - QObjectPrivate::clearGuards(this); - QT_TRY { QEvent e(QEvent::Destroy); QCoreApplication::sendEvent(this, &e); @@ -312,32 +300,32 @@ Connection::~Connection() void Connection::startOk() { - d_func()->startOk(); + pd_func()->startOk(); } void Connection::secureOk() { - d_func()->secureOk(); + pd_func()->secureOk(); } void Connection::tuneOk() { - d_func()->tuneOk(); + pd_func()->tuneOk(); } void Connection::open() { - d_func()->open(); + pd_func()->open(); } void Connection::close(int code, const QString & text, int classId , int methodId) { - d_func()->close(code, text, classId, methodId); + pd_func()->close(code, text, classId, methodId); } void Connection::closeOk() { - d_func()->closeOk(); + pd_func()->closeOk(); emit disconnect(); } @@ -348,11 +336,11 @@ void Connection::openOk() bool Connection::isConnected() const { - return d_func()->connected; + return pd_func()->connected; } void Connection::setQOS( qint32 prefetchSize, quint16 prefetchCount ) { - d_func()->setQOS(prefetchSize, prefetchCount, 0, true); + pd_func()->setQOS(prefetchSize, prefetchCount, 0, true); } diff --git a/src/qamqp/amqp_connection.h b/src/qamqp/amqp_connection.h index 34bca6d..f7b6bf4 100644 --- a/src/qamqp/amqp_connection.h +++ b/src/qamqp/amqp_connection.h @@ -3,7 +3,7 @@ #include #include "amqp_frame.h" -#include "qamqp_global.h" +#include "amqp_global.h" namespace QAMQP { @@ -14,7 +14,7 @@ namespace QAMQP class Connection : public QObject { Q_OBJECT - Q_DECLARE_PRIVATE(QAMQP::Connection) + P_DECLARE_PRIVATE(QAMQP::Connection) Q_DISABLE_COPY(Connection) Connection(Client * parent = 0); public: @@ -35,12 +35,13 @@ namespace QAMQP void disconnected(); void connected(); protected: - Connection(ConnectionPrivate &dd, Client* parent); + ConnectionPrivate * const pd_ptr; + private: void openOk(); friend class ClientPrivate; friend class ChannelPrivate; - Q_PRIVATE_SLOT(d_func(), void _q_method(const QAMQP::Frame::Method & frame)) + Q_PRIVATE_SLOT(pd_func(), void _q_method(const QAMQP::Frame::Method & frame)) }; } diff --git a/src/qamqp/amqp_connection_p.h b/src/qamqp/amqp_connection_p.h index 3ceecb1..4e0ae8f 100644 --- a/src/qamqp/amqp_connection_p.h +++ b/src/qamqp/amqp_connection_p.h @@ -1,17 +1,17 @@ #ifndef amqp_connection_p_h__ #define amqp_connection_p_h__ -#include - #define METHOD_ID_ENUM(name, id) name = id, name ## Ok +#include + namespace QAMQP { class Client; class ClientPrivate; - class ConnectionPrivate : public QObjectPrivate + class ConnectionPrivate { - Q_DECLARE_PUBLIC(QAMQP::Connection) + P_DECLARE_PUBLIC(QAMQP::Connection) public: enum MethodId { @@ -22,7 +22,7 @@ namespace QAMQP METHOD_ID_ENUM(miClose, 50) }; - ConnectionPrivate(int version = QObjectPrivateVersion); + ConnectionPrivate(Connection * q); ~ConnectionPrivate(); void init(Client * parent); void startOk(); @@ -45,6 +45,8 @@ namespace QAMQP QPointer client_; bool closed_; bool connected; + + Connection * const pq_ptr; }; } #endif // amqp_connection_p_h__ \ No newline at end of file diff --git a/src/qamqp/amqp_exchange.cpp b/src/qamqp/amqp_exchange.cpp index b0f7a77..fee987f 100644 --- a/src/qamqp/amqp_exchange.cpp +++ b/src/qamqp/amqp_exchange.cpp @@ -29,12 +29,12 @@ namespace QAMQP } Exchange::Exchange(int channelNumber, Client * parent /*= 0*/ ) -: Channel(*new ExchangePrivate, 0) +: Channel(new ExchangePrivate(this)) { QT_TRY { - d_func()->init(channelNumber, parent); + pd_func()->init(channelNumber, parent); } QT_CATCH(...) { - ExchangeExceptionCleaner::cleanup(this, d_func()); + ExchangeExceptionCleaner::cleanup(this, pd_func()); QT_RETHROW; } } @@ -46,7 +46,7 @@ Exchange::~Exchange() void Exchange::onOpen() { - Q_D(Exchange); + P_D(Exchange); if(d->deleyedDeclare) { d->declare(); @@ -55,23 +55,23 @@ void Exchange::onOpen() void Exchange::onClose() { - d_func()->remove(true, true); + pd_func()->remove(true, true); } Exchange::ExchangeOptions Exchange::option() const { - return d_func()->options; + return pd_func()->options; } QString Exchange::type() const { - return d_func()->type; + return pd_func()->type; } void Exchange::declare(const QString &type, ExchangeOptions option , const TableField & arg) { - Q_D(Exchange); + P_D(Exchange); d->options = option; d->type = type; d->arguments = arg; @@ -80,13 +80,13 @@ void Exchange::declare(const QString &type, ExchangeOptions option , const Tabl void Exchange::remove( bool ifUnused /*= true*/, bool noWait /*= true*/ ) { - d_func()->remove(ifUnused, noWait); + pd_func()->remove(ifUnused, noWait); } void Exchange::bind( QAMQP::Queue * queue ) { - queue->bind(this, d_func()->name); + queue->bind(this, pd_func()->name); } void Exchange::bind( const QString & queueName ) @@ -104,21 +104,21 @@ void Exchange::bind( const QString & queueName, const QString &key ) void Exchange::publish( const QString & message, const QString & key ) { - d_func()->publish(message.toUtf8(), key); + pd_func()->publish(message.toUtf8(), key); } void Exchange::publish( const QByteArray & message, const QString & key, const QString &mimeType ) { - d_func()->publish(message, key, mimeType); + pd_func()->publish(message, key, mimeType); } ////////////////////////////////////////////////////////////////////////// -ExchangePrivate::ExchangePrivate() - :ChannelPrivate() +ExchangePrivate::ExchangePrivate(Exchange * q) + :ChannelPrivate(q) , deleyedDeclare(false) , declared(false) { @@ -157,14 +157,14 @@ void ExchangePrivate::declareOk( const QAMQP::Frame::Method & ) { qDebug() << "Declared exchange: " << name; declared = true; - QMetaObject::invokeMethod(q_func(), "declared"); + QMetaObject::invokeMethod(pq_func(), "declared"); } void ExchangePrivate::deleteOk( const QAMQP::Frame::Method & ) { qDebug() << "Deleted exchange: " << name; declared = false; - QMetaObject::invokeMethod(q_func(), "removed"); + QMetaObject::invokeMethod(pq_func(), "removed"); } void ExchangePrivate::declare( ) diff --git a/src/qamqp/amqp_exchange.h b/src/qamqp/amqp_exchange.h index 1478a0a..a86b92b 100644 --- a/src/qamqp/amqp_exchange.h +++ b/src/qamqp/amqp_exchange.h @@ -18,7 +18,7 @@ namespace QAMQP Q_PROPERTY(QString type READ type); Q_PROPERTY(ExchangeOptions option READ option ); - Q_DECLARE_PRIVATE(QAMQP::Exchange) + P_DECLARE_PRIVATE(QAMQP::Exchange) Q_DISABLE_COPY(Exchange); friend class ClientPrivate; protected: diff --git a/src/qamqp/amqp_exchange_p.h b/src/qamqp/amqp_exchange_p.h index 7a28a43..41e78b9 100644 --- a/src/qamqp/amqp_exchange_p.h +++ b/src/qamqp/amqp_exchange_p.h @@ -6,7 +6,7 @@ namespace QAMQP using namespace QAMQP::Frame; class ExchangePrivate: public ChannelPrivate { - Q_DECLARE_PUBLIC(QAMQP::Exchange) + P_DECLARE_PUBLIC(QAMQP::Exchange) public: enum MethodId @@ -15,7 +15,7 @@ namespace QAMQP METHOD_ID_ENUM(miDelete, 20) }; - ExchangePrivate(); + ExchangePrivate(Exchange * q); ~ExchangePrivate(); void declare(); diff --git a/src/qamqp/amqp_p.h b/src/qamqp/amqp_p.h index 5edd73b..c9d7663 100644 --- a/src/qamqp/amqp_p.h +++ b/src/qamqp/amqp_p.h @@ -1,20 +1,21 @@ #ifndef qamqp_amqp_p_h__ #define qamqp_amqp_p_h__ -#include #include +#include "amqp_global.h" #include "amqp_network.h" #include "amqp_connection.h" #include "amqp_authenticator.h" namespace QAMQP { - class ClientPrivate : public QObjectPrivate + class ClientPrivate { - Q_DECLARE_PUBLIC(QAMQP::Client) + P_DECLARE_PUBLIC(QAMQP::Client) + public: - ClientPrivate(int version = QObjectPrivateVersion); + ClientPrivate(Client * q ) ; ~ClientPrivate(); void init(QObject * parent); @@ -32,13 +33,14 @@ namespace QAMQP quint32 port; QString host; QString virtualHost; -/* - QString user; - QString password;*/ QPointer network_; QPointer connection_; QSharedPointer auth_; + + + Client * const pq_ptr; + }; } #endif // amqp_p_h__ diff --git a/src/qamqp/amqp_queue.cpp b/src/qamqp/amqp_queue.cpp index b3a3abe..162fa46 100644 --- a/src/qamqp/amqp_queue.cpp +++ b/src/qamqp/amqp_queue.cpp @@ -30,12 +30,12 @@ namespace QAMQP } Queue::Queue( int channelNumber, Client * parent /*= 0*/ ) -: Channel(*new QueuePrivate, 0) +: Channel(new QueuePrivate(this)) { QT_TRY { - d_func()->init(channelNumber, parent); + pd_func()->init(channelNumber, parent); } QT_CATCH(...) { - QueueExceptionCleaner::cleanup(this, d_func()); + QueueExceptionCleaner::cleanup(this, pd_func()); QT_RETHROW; } } @@ -47,7 +47,7 @@ Queue::~Queue() void Queue::onOpen() { - Q_D(Queue); + P_D(Queue); if(d->deleyedDeclare) { d->declare(); @@ -65,33 +65,33 @@ void Queue::onOpen() void Queue::onClose() { - d_func()->remove(true, true); + pd_func()->remove(true, true); } Queue::QueueOptions Queue::option() const { - return d_func()->options; + return pd_func()->options; } void Queue::setNoAck( bool noAck ) { - d_func()->noAck = noAck; + pd_func()->noAck = noAck; } bool Queue::noAck() const { - return d_func()->noAck; + return pd_func()->noAck; } void Queue::declare() { - Q_D(Queue); + P_D(Queue); declare(d->name, QueueOptions(Durable | AutoDelete)); } void Queue::declare( const QString &name, QueueOptions options ) { - Q_D(Queue); + P_D(Queue); setName(name); d->options = options; d->declare(); @@ -99,85 +99,85 @@ void Queue::declare( const QString &name, QueueOptions options ) void Queue::remove( bool ifUnused /*= true*/, bool ifEmpty /*= true*/, bool noWait /*= true*/ ) { - d_func()->remove(ifUnused, ifEmpty, noWait); + pd_func()->remove(ifUnused, ifEmpty, noWait); } void Queue::purge() { - d_func()->purge(); + pd_func()->purge(); } void Queue::bind( const QString & exchangeName, const QString & key ) { - d_func()->bind(exchangeName, key); + pd_func()->bind(exchangeName, key); } void Queue::bind( Exchange * exchange, const QString & key ) { if(exchange) - d_func()->bind(exchange->name(), key); + pd_func()->bind(exchange->name(), key); } void Queue::unbind( const QString & exchangeName, const QString & key ) { - d_func()->unbind(exchangeName, key); + pd_func()->unbind(exchangeName, key); } void Queue::unbind( Exchange * exchange, const QString & key ) { if(exchange) - d_func()->unbind(exchange->name(), key); + pd_func()->unbind(exchange->name(), key); } QAMQP::MessagePtr Queue::getMessage() { - return d_func()->messages_.dequeue(); + return pd_func()->messages_.dequeue(); } bool Queue::hasMessage() const { - if(d_func()->messages_.isEmpty()) + if(pd_func()->messages_.isEmpty()) { return false; } - const MessagePtr &q = d_func()->messages_.head(); + const MessagePtr &q = pd_func()->messages_.head(); return q->leftSize == 0; } void Queue::consume(ConsumeOptions options) { - d_func()->consume(options); + pd_func()->consume(options); } void Queue::setConsumerTag( const QString &consumerTag ) { - d_func()->consumerTag = consumerTag; + pd_func()->consumerTag = consumerTag; } QString Queue::consumerTag() const { - return d_func()->consumerTag; + return pd_func()->consumerTag; } void Queue::get() { - d_func()->get(); + pd_func()->get(); } void Queue::ack( const MessagePtr & message ) { - d_func()->ack(message); + pd_func()->ack(message); } ////////////////////////////////////////////////////////////////////////// -QueuePrivate::QueuePrivate() - :ChannelPrivate() +QueuePrivate::QueuePrivate(Queue * q) + :ChannelPrivate(q) , deleyedDeclare(false) , declared(false) , recievingMessage(false) @@ -236,7 +236,7 @@ bool QueuePrivate::_q_method( const QAMQP::Frame::Method & frame ) getOk(frame); break; case bmGetEmpty: - QMetaObject::invokeMethod(q_func(), "empty"); + QMetaObject::invokeMethod(pq_func(), "empty"); break; default: break; @@ -263,7 +263,7 @@ void QueuePrivate::declareOk( const QAMQP::Frame::Method & frame ) stream >> messageCount >> consumerCount; qDebug("Message count %d\nConsumer count: %d", messageCount, consumerCount); - QMetaObject::invokeMethod(q_func(), "declared"); + QMetaObject::invokeMethod(pq_func(), "declared"); } void QueuePrivate::deleteOk( const QAMQP::Frame::Method & frame ) @@ -276,20 +276,20 @@ void QueuePrivate::deleteOk( const QAMQP::Frame::Method & frame ) qint32 messageCount = 0; stream >> messageCount; qDebug("Message count %d", messageCount); - QMetaObject::invokeMethod(q_func(), "removed"); + QMetaObject::invokeMethod(pq_func(), "removed"); } void QueuePrivate::bindOk( const QAMQP::Frame::Method & ) { qDebug() << "Binded to queue: " << name; - QMetaObject::invokeMethod(q_func(), "binded", Q_ARG(bool, true)); + QMetaObject::invokeMethod(pq_func(), "binded", Q_ARG(bool, true)); } void QueuePrivate::unbindOk( const QAMQP::Frame::Method & ) { qDebug() << "Unbinded queue: " << name; - QMetaObject::invokeMethod(q_func(), "binded", Q_ARG(bool, false)); + QMetaObject::invokeMethod(pq_func(), "binded", Q_ARG(bool, false)); } void QueuePrivate::declare() @@ -562,6 +562,6 @@ void QueuePrivate::_q_body( int channeNumber, const QByteArray & body ) if(message->leftSize == 0 && messages_.size() == 1) { - QMetaObject::invokeMethod(q_func(), "messageRecieved"); + QMetaObject::invokeMethod(pq_func(), "messageRecieved"); } } \ No newline at end of file diff --git a/src/qamqp/amqp_queue.h b/src/qamqp/amqp_queue.h index cacff6b..82b1988 100644 --- a/src/qamqp/amqp_queue.h +++ b/src/qamqp/amqp_queue.h @@ -19,7 +19,7 @@ namespace QAMQP Q_PROPERTY(QString consumerTag READ consumerTag WRITE setConsumerTag) Q_PROPERTY(bool noAck READ noAck WRITE setNoAck) - Q_DECLARE_PRIVATE(QAMQP::Queue) + P_DECLARE_PRIVATE(QAMQP::Queue) Q_DISABLE_COPY(Queue); friend class ClientPrivate; @@ -81,8 +81,8 @@ namespace QAMQP void empty(); private: - Q_PRIVATE_SLOT(d_func(), void _q_content(const QAMQP::Frame::Content & frame)) - Q_PRIVATE_SLOT(d_func(), void _q_body(int channeNumber, const QByteArray & body)) + Q_PRIVATE_SLOT(pd_func(), void _q_content(const QAMQP::Frame::Content & frame)) + Q_PRIVATE_SLOT(pd_func(), void _q_body(int channeNumber, const QByteArray & body)) }; } #ifdef QAMQP_P_INCLUDE diff --git a/src/qamqp/amqp_queue_p.h b/src/qamqp/amqp_queue_p.h index cb944c5..17472e2 100644 --- a/src/qamqp/amqp_queue_p.h +++ b/src/qamqp/amqp_queue_p.h @@ -10,7 +10,7 @@ namespace QAMQP using namespace QAMQP::Frame; class QueuePrivate: public ChannelPrivate { - Q_DECLARE_PUBLIC(QAMQP::Queue) + P_DECLARE_PUBLIC(QAMQP::Queue) public: enum MethodId @@ -22,7 +22,7 @@ namespace QAMQP METHOD_ID_ENUM(miDelete, 40) }; - QueuePrivate(); + QueuePrivate(Queue * q); ~QueuePrivate(); void declare(); diff --git a/src/qamqp/qamqp_global.h b/src/qamqp/qamqp_global.h deleted file mode 100644 index 704be3e..0000000 --- a/src/qamqp/qamqp_global.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef qamqp_global_h__ -#define qamqp_global_h__ - -#include - -#define QAMQP_P_INCLUDE -#define AMQPSCHEME "amqp" -#define AMQPPORT 5672 -#define AMQPHOST "localhost" -#define AMQPVHOST "/" -#define AMQPLOGIN "guest" -#define AMQPPSWD "guest" -#define FRAME_MAX 131072 - -#define AMQP_CONNECTION_FORCED 320 - - -#endif // qamqp_global_h__