2020-12-12 15:31:38 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-01-13 17:07:38 +00:00
|
|
|
#include "channel/channelapi.h"
|
2020-12-12 15:31:38 +00:00
|
|
|
#include "feature/feature.h"
|
2020-12-15 22:40:52 +00:00
|
|
|
#include "util/messagequeue.h"
|
2020-12-12 15:31:38 +00:00
|
|
|
#include "maincore.h"
|
|
|
|
#include "messagepipescommon.h"
|
|
|
|
#include "messagepipesgcworker.h"
|
|
|
|
|
2021-01-13 17:07:38 +00:00
|
|
|
bool MessagePipesGCWorker::MessagePipesGC::existsProducer(const PipeEndPoint *pipeEndPoint)
|
2020-12-15 22:40:52 +00:00
|
|
|
{
|
2021-01-13 17:07:38 +00:00
|
|
|
return MainCore::instance()->existsChannel((const ChannelAPI *)pipeEndPoint)
|
|
|
|
|| MainCore::instance()->existsFeature((const Feature *)pipeEndPoint);
|
2020-12-15 22:40:52 +00:00
|
|
|
}
|
|
|
|
|
2021-10-12 10:18:29 +00:00
|
|
|
bool MessagePipesGCWorker::MessagePipesGC::existsConsumer(const PipeEndPoint *pipeEndPoint)
|
2020-12-15 22:40:52 +00:00
|
|
|
{
|
2021-10-12 10:18:29 +00:00
|
|
|
return MainCore::instance()->existsChannel((const ChannelAPI *)pipeEndPoint)
|
|
|
|
|| MainCore::instance()->existsFeature((const Feature *)pipeEndPoint);
|
2020-12-15 22:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessagePipesGCWorker::MessagePipesGC::sendMessageToConsumer(
|
|
|
|
const MessageQueue *messageQueue,
|
|
|
|
MessagePipesCommon::ChannelRegistrationKey channelKey,
|
2021-10-12 10:18:29 +00:00
|
|
|
PipeEndPoint *pipeEndPoint)
|
2020-12-15 22:40:52 +00:00
|
|
|
{
|
|
|
|
MessagePipesCommon::MsgReportChannelDeleted *msg = MessagePipesCommon::MsgReportChannelDeleted::create(
|
|
|
|
messageQueue, channelKey);
|
2021-10-12 10:18:29 +00:00
|
|
|
if (MainCore::instance()->existsFeature((const Feature *)pipeEndPoint)) // Use RTTI instead?
|
|
|
|
{
|
|
|
|
Feature *feature = (Feature *)pipeEndPoint;
|
|
|
|
feature->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ChannelAPI *channel = (ChannelAPI *)pipeEndPoint;
|
|
|
|
channel->getChannelMessageQueue()->push(msg);
|
|
|
|
}
|
2020-12-15 22:40:52 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 15:31:38 +00:00
|
|
|
MessagePipesGCWorker::MessagePipesGCWorker() :
|
2020-12-15 22:40:52 +00:00
|
|
|
m_running(false)
|
2020-12-12 15:31:38 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
MessagePipesGCWorker::~MessagePipesGCWorker()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void MessagePipesGCWorker::startWork()
|
|
|
|
{
|
|
|
|
connect(&m_gcTimer, SIGNAL(timeout()), this, SLOT(processGC()));
|
|
|
|
m_gcTimer.start(10000); // collect garbage every 10s
|
|
|
|
m_running = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagePipesGCWorker::stopWork()
|
|
|
|
{
|
|
|
|
m_running = false;
|
|
|
|
m_gcTimer.stop();
|
|
|
|
disconnect(&m_gcTimer, SIGNAL(timeout()), this, SLOT(processGC()));
|
|
|
|
}
|
|
|
|
|
2020-12-20 00:53:03 +00:00
|
|
|
void MessagePipesGCWorker::addMessageQueueToDelete(MessageQueue *messageQueue)
|
|
|
|
{
|
|
|
|
if (messageQueue)
|
|
|
|
{
|
|
|
|
m_gcTimer.start(10000); // restart GC to make sure deletion is postponed
|
|
|
|
m_messagePipesGC.addElementToDelete(messageQueue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-12 15:31:38 +00:00
|
|
|
void MessagePipesGCWorker::processGC()
|
|
|
|
{
|
|
|
|
// qDebug("MessagePipesGCWorker::processGC");
|
2020-12-15 22:40:52 +00:00
|
|
|
m_messagePipesGC.processGC();
|
2020-12-12 15:31:38 +00:00
|
|
|
}
|