diff --git a/plugins/feature/demodanalyzer/demodanalyzer.cpp b/plugins/feature/demodanalyzer/demodanalyzer.cpp index 02146a4cb..0cf03e52b 100644 --- a/plugins/feature/demodanalyzer/demodanalyzer.cpp +++ b/plugins/feature/demodanalyzer/demodanalyzer.cpp @@ -348,6 +348,7 @@ void DemodAnalyzer::setChannel(ChannelAPI *selectedChannel) } m_dataPipe = mainCore->getDataPipes().registerProducerToConsumer(selectedChannel, this, "demod"); + connect(m_dataPipe, SIGNAL(toBeDeleted(int, QObject*)), this, SLOT(handleDataPipeToBeDeleted(int, QObject*))); DataFifo *fifo = qobject_cast(m_dataPipe->m_element); if (fifo) @@ -601,3 +602,22 @@ void DemodAnalyzer::handleChannelMessageQueue(MessageQueue* messageQueue) } } } + +void DemodAnalyzer::handleDataPipeToBeDeleted(int reason, QObject *object) +{ + qDebug("DemodAnalyzer::handleDataPipeToBeDeleted: %d %p", reason, object); + + if ((reason == 0) && (m_selectedChannel == object)) + { + DataFifo *fifo = qobject_cast(m_dataPipe->m_element); + + if (fifo && m_worker->isRunning()) + { + DemodAnalyzerWorker::MsgConnectFifo *msg = DemodAnalyzerWorker::MsgConnectFifo::create(fifo, false); + m_worker->getInputMessageQueue()->push(msg); + } + + updateChannels(); + m_selectedChannel = nullptr; + } +} diff --git a/plugins/feature/demodanalyzer/demodanalyzer.h b/plugins/feature/demodanalyzer/demodanalyzer.h index 1d88478ac..1413c25d3 100644 --- a/plugins/feature/demodanalyzer/demodanalyzer.h +++ b/plugins/feature/demodanalyzer/demodanalyzer.h @@ -217,6 +217,7 @@ private: private slots: void networkManagerFinished(QNetworkReply *reply); void handleChannelMessageQueue(MessageQueue *messageQueues); + void handleDataPipeToBeDeleted(int reason, QObject *object); }; #endif // INCLUDE_FEATURE_DEMODANALYZER_H_ diff --git a/plugins/feature/demodanalyzer/demodanalyzerworker.cpp b/plugins/feature/demodanalyzer/demodanalyzerworker.cpp index cc63d8154..2b28a1cee 100644 --- a/plugins/feature/demodanalyzer/demodanalyzerworker.cpp +++ b/plugins/feature/demodanalyzer/demodanalyzerworker.cpp @@ -156,11 +156,11 @@ bool DemodAnalyzerWorker::handleMessage(const Message& cmd) } else if (MsgConnectFifo::match(cmd)) { - qDebug("DemodAnalyzerWorker::handleMessage: MsgConnectFifo"); QMutexLocker mutexLocker(&m_mutex); MsgConnectFifo& msg = (MsgConnectFifo&) cmd; m_dataFifo = msg.getFifo(); bool doConnect = msg.getConnect(); + qDebug("DemodAnalyzerWorker::handleMessage: MsgConnectFifo: %s", (doConnect ? "connect" : "disconnect")); if (doConnect) { QObject::connect( @@ -170,7 +170,9 @@ bool DemodAnalyzerWorker::handleMessage(const Message& cmd) &DemodAnalyzerWorker::handleData, Qt::QueuedConnection ); - } else { + } + else + { QObject::disconnect( m_dataFifo, &DataFifo::dataReady, diff --git a/sdrbase/pipes/objectpipe.cpp b/sdrbase/pipes/objectpipe.cpp index 2d7cf220a..10962f775 100644 --- a/sdrbase/pipes/objectpipe.cpp +++ b/sdrbase/pipes/objectpipe.cpp @@ -26,10 +26,10 @@ ObjectPipe::ObjectPipe() : m_gcCount(0) {} -void ObjectPipe::setToBeDeleted(int reason) +void ObjectPipe::setToBeDeleted(int reason, QObject *object) { m_gcCount = 2; // will defer actual deletion by one GC pass - emit toBeDeleted(reason); + emit toBeDeleted(reason, object); } int ObjectPipe::getGCCount() const { diff --git a/sdrbase/pipes/objectpipe.h b/sdrbase/pipes/objectpipe.h index 94a9f15cb..5882730c7 100644 --- a/sdrbase/pipes/objectpipe.h +++ b/sdrbase/pipes/objectpipe.h @@ -30,7 +30,7 @@ public: ObjectPipe(const ObjectPipe&) = default; ObjectPipe& operator=(const ObjectPipe&) = default; - void setToBeDeleted(int reason); + void setToBeDeleted(int reason, QObject *object); int getGCCount() const; int decreaseGCCount(); @@ -41,7 +41,7 @@ public: QObject *m_element; signals: - void toBeDeleted(int reason); + void toBeDeleted(int reason, QObject *object); private: int m_gcCount; diff --git a/sdrbase/pipes/objectpipesregistrations.cpp b/sdrbase/pipes/objectpipesregistrations.cpp index 685e32185..58c758923 100644 --- a/sdrbase/pipes/objectpipesregistrations.cpp +++ b/sdrbase/pipes/objectpipesregistrations.cpp @@ -29,6 +29,7 @@ ObjectPipesRegistrations::~ObjectPipesRegistrations() ObjectPipe *ObjectPipesRegistrations::registerProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type) { + qDebug("ObjectPipesRegistrations::registerProducerToConsumer: %p %p %s", producer, consumer, qPrintable("type")); int typeId; QMutexLocker mlock(&m_mutex); @@ -72,6 +73,7 @@ ObjectPipe *ObjectPipesRegistrations::registerProducerToConsumer(const QObject * ObjectPipe *ObjectPipesRegistrations::unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type) { + qDebug("ObjectPipesRegistrations::unregisterProducerToConsumer: %p %p %s", producer, consumer, qPrintable("type")); ObjectPipe *pipe = nullptr; if (m_typeIds.contains(type)) @@ -102,7 +104,7 @@ ObjectPipe *ObjectPipesRegistrations::unregisterProducerToConsumer(const QObject m_producerAndTypeIdPipes.remove(std::make_tuple(producer, typeId)); } - pipe->setToBeDeleted(PipeDeletionReason::PipeDeleted); + pipe->setToBeDeleted(PipeDeletionReason::PipeDeleted, pipe); } } @@ -123,7 +125,6 @@ void ObjectPipesRegistrations::getPipes(const QObject *producer, const QString& void ObjectPipesRegistrations::processGC() { - qDebug("ObjectPipesRegistrations::processGC"); QMutexLocker mlock(&m_mutex); typename QList::iterator itPipe = m_pipes.begin(); @@ -143,12 +144,16 @@ void ObjectPipesRegistrations::processGC() ++itPipe; } } + else + { + ++itPipe; + } } } void ObjectPipesRegistrations::removeProducer(QObject *producer) { - qDebug("ObjectPipesRegistrations::removeProducer"); + qDebug("ObjectPipesRegistrations::removeProducer: %p", producer); QMutexLocker mlock(&m_mutex); if (m_producerPipes.contains(producer) && (m_producerPipes[producer].size() != 0)) @@ -165,7 +170,7 @@ void ObjectPipesRegistrations::removeProducer(QObject *producer) m_typeIdPipes[typeId].removeAll(pipe); } - pipe->setToBeDeleted(PipeDeletionReason::PipeProducerDeleted); + pipe->setToBeDeleted(PipeDeletionReason::PipeProducerDeleted, producer); } m_producerPipes.remove(producer); @@ -196,7 +201,7 @@ void ObjectPipesRegistrations::removeProducer(QObject *producer) void ObjectPipesRegistrations::removeConsumer(QObject *consumer) { - qDebug("ObjectPipesRegistrations::removeConsumer"); + qDebug("ObjectPipesRegistrations::removeConsumer: %p", consumer); QMutexLocker mlock(&m_mutex); if (m_consumerPipes.contains(consumer) && (m_consumerPipes[consumer].size() != 0)) @@ -217,7 +222,7 @@ void ObjectPipesRegistrations::removeConsumer(QObject *consumer) m_producerAndTypeIdPipes[producerAndTypeId].removeAll(pipe); } - pipe->setToBeDeleted(PipeDeletionReason::PipeConsumerDeleted); + pipe->setToBeDeleted(PipeDeletionReason::PipeConsumerDeleted, consumer); } m_consumerPipes.remove(consumer);