From 0fad0303828535f81ee8a96d506c3934fb8ecf9f Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 26 Feb 2022 13:44:46 +0100 Subject: [PATCH] Message queues rework: VOR localizer updates --- plugins/channelrx/demodvorsc/vordemodsc.cpp | 43 +++++++++++-------- plugins/channelrx/demodvorsc/vordemodsc.h | 3 +- plugins/feature/vorlocalizer/vorlocalizer.cpp | 31 ++++++------- plugins/feature/vorlocalizer/vorlocalizer.h | 2 +- sdrbase/pipes/objectpipesregistrations.cpp | 4 +- 5 files changed, 45 insertions(+), 38 deletions(-) diff --git a/plugins/channelrx/demodvorsc/vordemodsc.cpp b/plugins/channelrx/demodvorsc/vordemodsc.cpp index 514dec2dc..12aca1fba 100644 --- a/plugins/channelrx/demodvorsc/vordemodsc.cpp +++ b/plugins/channelrx/demodvorsc/vordemodsc.cpp @@ -157,11 +157,12 @@ bool VORDemodSC::handleMessage(const Message& cmd) m_guiMessageQueue->push(msg); } - MessagePipes& messagePipes = MainCore::instance()->getMessagePipes(); - QList *reportMessageQueues = messagePipes.getMessageQueues(this, "report"); + MessagePipes2& messagePipes = MainCore::instance()->getMessagePipes2(); + QList pipes; + messagePipes.getMessagePipes(this, "report", pipes); - if (reportMessageQueues) { - sendChannelReport(reportMessageQueues); + if (pipes.size() > 0) { + sendChannelReport(pipes); } return true; @@ -177,11 +178,12 @@ bool VORDemodSC::handleMessage(const Message& cmd) m_guiMessageQueue->push(msg); } - MessagePipes& messagePipes = MainCore::instance()->getMessagePipes(); - QList *reportMessageQueues = messagePipes.getMessageQueues(this, "report"); + MessagePipes2& messagePipes = MainCore::instance()->getMessagePipes2(); + QList pipes; + messagePipes.getMessagePipes(this, "report", pipes); - if (reportMessageQueues) { - sendChannelReport(reportMessageQueues); + if (pipes.size() > 0) { + sendChannelReport(pipes); } return true; @@ -550,19 +552,22 @@ void VORDemodSC::sendChannelSettings( } } -void VORDemodSC::sendChannelReport(QList *messageQueues) +void VORDemodSC::sendChannelReport(QList& messagePipes) { - QList::iterator it = messageQueues->begin(); - - for (; it != messageQueues->end(); ++it) + for (const auto& pipe : messagePipes) { - SWGSDRangel::SWGChannelReport *swgChannelReport = new SWGSDRangel::SWGChannelReport(); - swgChannelReport->setDirection(0); - swgChannelReport->setChannelType(new QString(m_channelId)); - swgChannelReport->setVorDemodScReport(new SWGSDRangel::SWGVORDemodSCReport()); - webapiFormatChannelReport(*swgChannelReport); - MainCore::MsgChannelReport *msg = MainCore::MsgChannelReport::create(this, swgChannelReport); - (*it)->push(msg); + MessageQueue *messageQueue = qobject_cast(pipe->m_element); + + if (messageQueue) + { + SWGSDRangel::SWGChannelReport *swgChannelReport = new SWGSDRangel::SWGChannelReport(); + swgChannelReport->setDirection(0); + swgChannelReport->setChannelType(new QString(m_channelId)); + swgChannelReport->setVorDemodScReport(new SWGSDRangel::SWGVORDemodSCReport()); + webapiFormatChannelReport(*swgChannelReport); + MainCore::MsgChannelReport *msg = MainCore::MsgChannelReport::create(this, swgChannelReport); + messageQueue->push(msg); + } } } diff --git a/plugins/channelrx/demodvorsc/vordemodsc.h b/plugins/channelrx/demodvorsc/vordemodsc.h index 22f3bd936..042c5592c 100644 --- a/plugins/channelrx/demodvorsc/vordemodsc.h +++ b/plugins/channelrx/demodvorsc/vordemodsc.h @@ -35,6 +35,7 @@ class QNetworkAccessManager; class QNetworkReply; class QThread; class DeviceAPI; +class ObjectPipe; class VORDemodSC : public BasebandSampleSink, public ChannelAPI { public: @@ -153,7 +154,7 @@ private: const VORDemodSCSettings& settings, bool force ); - void sendChannelReport(QList *messageQueues); + void sendChannelReport(QList& messagePipes); void webapiFormatChannelSettings( QList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings *swgChannelSettings, diff --git a/plugins/feature/vorlocalizer/vorlocalizer.cpp b/plugins/feature/vorlocalizer/vorlocalizer.cpp index c35ab5ef1..91fe360a0 100644 --- a/plugins/feature/vorlocalizer/vorlocalizer.cpp +++ b/plugins/feature/vorlocalizer/vorlocalizer.cpp @@ -244,25 +244,24 @@ bool VORLocalizer::handleMessage(const Message& cmd) return true; } - else if (MessagePipesCommon::MsgReportChannelDeleted::match(cmd)) - { - qDebug() << "VORLocalizer::handleMessage: MsgReportChannelDeleted"; - MessagePipesCommon::MsgReportChannelDeleted& report = (MessagePipesCommon::MsgReportChannelDeleted&) cmd; - const MessagePipesCommon::ChannelRegistrationKey& channelKey = report.getChannelRegistrationKey(); - const PipeEndPoint *channel = channelKey.m_key; - m_availableChannels.remove(const_cast(reinterpret_cast(channel))); - updateChannels(); - MessageQueue *messageQueue = MainCore::instance()->getMessagePipes().unregisterChannelToFeature(channel, this, "report"); - disconnect(messageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleChannelMessageQueue(MessageQueue*))); - - return true; - } else { return false; } } +void VORLocalizer::handleMessagePipeToBeDeleted(int reason, QObject* object) +{ + if (reason == 0) // producer (channel) + { + if (m_availableChannels.contains((ChannelAPI*) object)) + { + m_availableChannels.remove((ChannelAPI*) object); + updateChannels(); + } + } +} + QByteArray VORLocalizer::serialize() const { return m_settings.serialize(); @@ -337,7 +336,7 @@ void VORLocalizer::applySettings(const VORLocalizerSettings& settings, bool forc void VORLocalizer::updateChannels() { MainCore *mainCore = MainCore::instance(); - MessagePipes& messagePipes = mainCore->getMessagePipes(); + MessagePipes2& messagePipes = mainCore->getMessagePipes2(); std::vector& deviceSets = mainCore->getDeviceSets(); std::vector::const_iterator it = deviceSets.begin(); m_availableChannels.clear(); @@ -362,7 +361,8 @@ void VORLocalizer::updateChannels() { if (!m_availableChannels.contains(channel)) { - MessageQueue *messageQueue = messagePipes.registerChannelToFeature(channel, this, "report"); + ObjectPipe *pipe = messagePipes.registerProducerToConsumer(channel, this, "report"); + MessageQueue *messageQueue = qobject_cast(pipe->m_element); QObject::connect( messageQueue, &MessageQueue::messageEnqueued, @@ -370,6 +370,7 @@ void VORLocalizer::updateChannels() [=](){ this->handleChannelMessageQueue(messageQueue); }, Qt::QueuedConnection ); + connect(pipe, SIGNAL(toBeDeleted(int, QObject*)), this, SLOT(handleMessagePipeToBeDeleted(int, QObject*))); } VORLocalizerSettings::AvailableChannel availableChannel = diff --git a/plugins/feature/vorlocalizer/vorlocalizer.h b/plugins/feature/vorlocalizer/vorlocalizer.h index a34d7052c..647a3f413 100644 --- a/plugins/feature/vorlocalizer/vorlocalizer.h +++ b/plugins/feature/vorlocalizer/vorlocalizer.h @@ -218,7 +218,7 @@ private: private slots: void networkManagerFinished(QNetworkReply *reply); void handleChannelMessageQueue(MessageQueue* messageQueue); - + void handleMessagePipeToBeDeleted(int reason, QObject* object); }; #endif // INCLUDE_FEATURE_VORLOCALIZER_H_ diff --git a/sdrbase/pipes/objectpipesregistrations.cpp b/sdrbase/pipes/objectpipesregistrations.cpp index c885f26a9..c92c2b0eb 100644 --- a/sdrbase/pipes/objectpipesregistrations.cpp +++ b/sdrbase/pipes/objectpipesregistrations.cpp @@ -164,7 +164,7 @@ void ObjectPipesRegistrations::processGC() void ObjectPipesRegistrations::removeProducer(QObject *producer) { - qDebug("ObjectPipesRegistrations::removeProducer: %p", producer); + qDebug("ObjectPipesRegistrations::removeProducer: %p %s", producer, qPrintable(producer->objectName())); QMutexLocker mlock(&m_mutex); if (m_producerPipes.contains(producer) && (m_producerPipes[producer].size() != 0)) @@ -212,7 +212,7 @@ void ObjectPipesRegistrations::removeProducer(QObject *producer) void ObjectPipesRegistrations::removeConsumer(QObject *consumer) { - qDebug("ObjectPipesRegistrations::removeConsumer: %p", consumer); + qDebug("ObjectPipesRegistrations::removeConsumer: %p %s", consumer, qPrintable(consumer->objectName())); QMutexLocker mlock(&m_mutex); if (m_consumerPipes.contains(consumer) && (m_consumerPipes[consumer].size() != 0))