QAmqpClient: Add garbage collection slot.
On 'destroyed', do a clean up of our exchanges and queues.
This commit is contained in:
parent
bca3f5f8bd
commit
6599fdbc63
|
|
@ -551,6 +551,26 @@ void QAmqpClientPrivate::close(int code, const QString &text, int classId, int m
|
||||||
sendFrame(frame);
|
sendFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Iterate through our list of objects and clean up the NULL pointers.
|
||||||
|
*/
|
||||||
|
void QAmqpClientPrivate::_q_objectDestroyed()
|
||||||
|
{
|
||||||
|
/* Clean up Exchanges */
|
||||||
|
QHash<QString, QPointer<QAmqpExchange> > exchanges(this->exchanges);
|
||||||
|
QHash<QString, QPointer<QAmqpExchange> >::iterator ex_it;
|
||||||
|
for (ex_it = exchanges.begin() ; ex_it != exchanges.end(); ex_it++)
|
||||||
|
if (ex_it.value.isNull())
|
||||||
|
this->exchanges.remove(ex_it.key());
|
||||||
|
|
||||||
|
/* Clean up Queues */
|
||||||
|
QHash<QString, QPointer<QAmqpQueue> > queues(this->queues);
|
||||||
|
QHash<QString, QPointer<QAmqpQueue> >::iterator q_it;
|
||||||
|
for (q_it = queues.begin() ; q_it != queues.end(); q_it++)
|
||||||
|
if (q_it.value.isNull())
|
||||||
|
this->queues.remove(q_it.key());
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
QAmqpClient::QAmqpClient(QObject *parent)
|
QAmqpClient::QAmqpClient(QObject *parent)
|
||||||
|
|
@ -668,6 +688,7 @@ QAmqpExchange *QAmqpClient::createExchange(const QString &name, int channelNumbe
|
||||||
d->methodHandlersByChannel[exchange->channelNumber()].append(exchange->d_func());
|
d->methodHandlersByChannel[exchange->channelNumber()].append(exchange->d_func());
|
||||||
connect(this, SIGNAL(connected()), exchange, SLOT(_q_open()));
|
connect(this, SIGNAL(connected()), exchange, SLOT(_q_open()));
|
||||||
connect(this, SIGNAL(disconnected()), exchange, SLOT(_q_disconnected()));
|
connect(this, SIGNAL(disconnected()), exchange, SLOT(_q_disconnected()));
|
||||||
|
connect(exchange, SIGNAL(destroyed()), this, SLOT(_q_objectDestroyed()));
|
||||||
exchange->d_func()->open();
|
exchange->d_func()->open();
|
||||||
|
|
||||||
if (!name.isEmpty())
|
if (!name.isEmpty())
|
||||||
|
|
@ -703,6 +724,7 @@ QAmqpQueue *QAmqpClient::createQueue(const QString &name, int channelNumber)
|
||||||
d->bodyHandlersByChannel[queue->channelNumber()].append(queue->d_func());
|
d->bodyHandlersByChannel[queue->channelNumber()].append(queue->d_func());
|
||||||
connect(this, SIGNAL(connected()), queue, SLOT(_q_open()));
|
connect(this, SIGNAL(connected()), queue, SLOT(_q_open()));
|
||||||
connect(this, SIGNAL(disconnected()), queue, SLOT(_q_disconnected()));
|
connect(this, SIGNAL(disconnected()), queue, SLOT(_q_disconnected()));
|
||||||
|
connect(queue, SIGNAL(destroyed()), this, SLOT(_q_objectDestroyed()));
|
||||||
queue->d_func()->open();
|
queue->d_func()->open();
|
||||||
|
|
||||||
if (!name.isEmpty()) {
|
if (!name.isEmpty()) {
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,7 @@ private:
|
||||||
Q_PRIVATE_SLOT(d_func(), void _q_heartbeat())
|
Q_PRIVATE_SLOT(d_func(), void _q_heartbeat())
|
||||||
Q_PRIVATE_SLOT(d_func(), void _q_connect())
|
Q_PRIVATE_SLOT(d_func(), void _q_connect())
|
||||||
Q_PRIVATE_SLOT(d_func(), void _q_disconnect())
|
Q_PRIVATE_SLOT(d_func(), void _q_disconnect())
|
||||||
|
Q_PRIVATE_SLOT(d_func(), void _q_objectDestroyed())
|
||||||
|
|
||||||
friend class QAmqpChannelPrivate;
|
friend class QAmqpChannelPrivate;
|
||||||
friend class QAmqpQueuePrivate;
|
friend class QAmqpQueuePrivate;
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,11 @@ public:
|
||||||
virtual void _q_connect();
|
virtual void _q_connect();
|
||||||
void _q_disconnect();
|
void _q_disconnect();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Iterate through our list of objects and clean up the NULL pointers.
|
||||||
|
*/
|
||||||
|
void _q_objectDestroyed();
|
||||||
|
|
||||||
virtual bool _q_method(const QAmqpMethodFrame &frame);
|
virtual bool _q_method(const QAmqpMethodFrame &frame);
|
||||||
|
|
||||||
// method handlers, FROM server
|
// method handlers, FROM server
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue