1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-21 23:55:13 -05:00

Data pipes redesign: renaming. Part of #1154

This commit is contained in:
f4exb 2022-02-21 03:06:16 +01:00
parent adfaac1545
commit 113aff6e57
12 changed files with 45 additions and 411 deletions

View File

@ -167,12 +167,9 @@ set(sdrbase_SOURCES
limerfe/limerfeusbcalib.cpp
pipes/datapipes.cpp
pipes/datapipescommon.cpp
pipes/datapipesgcworker.cpp
pipes/datafifostore.cpp
pipes/datapipes2.cpp
pipes/datapipes2gcworker.cpp
pipes/datapipes.cpp
pipes/datapipesgcworker.cpp
pipes/messagepipes.cpp
pipes/messagepipescommon.cpp
pipes/messagepipesgcworker.cpp
@ -376,12 +373,9 @@ set(sdrbase_HEADERS
limerfe/limerfeusbcalib.h
pipes/datapipes.h
pipes/datapipescommon.h
pipes/datapipesgcworker.h
pipes/datafifostore.h
pipes/datapipes2.h
pipes/datapipes2gcworker.h
pipes/datapipes.h
pipes/datapipesgcworker.h
pipes/elementpipescommon.h
pipes/elementpipesgc.h
pipes/messagepipes.h

View File

@ -28,7 +28,7 @@
#include "settings/mainsettings.h"
#include "util/message.h"
#include "pipes/messagepipes.h"
#include "pipes/datapipes2.h"
#include "pipes/datapipes.h"
#include "channel/channelapi.h"
class DeviceSet;
@ -731,7 +731,7 @@ public:
void clearFeatures(FeatureSet *featureSet);
// pipes
MessagePipes& getMessagePipes() { return m_messagePipes; }
DataPipes2& getDataPipes() { return m_dataPipes; }
DataPipes& getDataPipes() { return m_dataPipes; }
friend class MainServer;
friend class MainWindow;
@ -751,7 +751,7 @@ private:
QMap<Feature*, FeatureSet*> m_featuresMap; //!< Feature to feature set map
PluginManager* m_pluginManager;
MessagePipes m_messagePipes;
DataPipes2 m_dataPipes;
DataPipes m_dataPipes;
void debugMaps();
};

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
// Copyright (C) 2022 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 //
@ -16,18 +16,13 @@
///////////////////////////////////////////////////////////////////////////////////
#include "dsp/datafifo.h"
#include "datapipesgcworker.h"
#include "datapipes.h"
#include "datapipesgcworker.h"
DataPipes::DataPipes()
DataPipes::DataPipes() :
m_registrations(&m_dataFifoStore)
{
m_gcWorker = new DataPipesGCWorker();
m_gcWorker->setC2FRegistrations(
m_registrations.getMutex(),
m_registrations.getElements(),
m_registrations.getConsumers()
);
m_gcWorker = new DataPipesGCWorker(m_registrations);
m_gcWorker->moveToThread(&m_gcThread);
startGC();
}
@ -37,23 +32,23 @@ DataPipes::~DataPipes()
if (m_gcWorker->isRunning()) {
stopGC();
}
m_gcWorker->deleteLater();
}
DataFifo *DataPipes::registerChannelToFeature(const ChannelAPI *source, Feature *feature, const QString& type)
ObjectPipe *DataPipes::registerProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type)
{
return m_registrations.registerProducerToConsumer(source, feature, type);
return m_registrations.registerProducerToConsumer(producer, consumer, type);
}
DataFifo *DataPipes::unregisterChannelToFeature(const ChannelAPI *source, Feature *feature, const QString& type)
ObjectPipe *DataPipes::unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type)
{
DataFifo *dataFifo = m_registrations.unregisterProducerToConsumer(source, feature, type);
m_gcWorker->addDataFifoToDelete(dataFifo);
return dataFifo;
return m_registrations.unregisterProducerToConsumer(producer, consumer, type);
}
QList<DataFifo*>* DataPipes::getFifos(const ChannelAPI *source, const QString& type)
void DataPipes::getDataPipes(const QObject *producer, const QString& type, QList<ObjectPipe*>& pipes)
{
return m_registrations.getElements(source, type);
return m_registrations.getPipes(producer, type, pipes);
}
void DataPipes::startGC()

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
// Copyright (C) 2022 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 //
@ -15,24 +15,18 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRBASE_PIPES_DATAPIPES_H_
#define SDRBASE_PIPES_DATAPIPES_H_
#ifndef SDRBASE_PIPES_DATAPIPES2_H_
#define SDRBASE_PIPES_DATAPIPES2_H_
#include <QObject>
#include <QHash>
#include <QMap>
#include <QMutex>
#include <QThread>
#include "export.h"
#include "objectpipesregistrations.h"
#include "datafifostore.h"
#include "datapipescommon.h"
#include "elementpipesregistrations.h"
class ChannelAPI;
class Feature;
class DataPipesGCWorker;
class DataFifo;
class DataPipesGCWorker;
class SDRBASE_API DataPipes : public QObject
{
@ -43,12 +37,13 @@ public:
DataPipes& operator=(const DataPipes&) = delete;
~DataPipes();
DataFifo *registerChannelToFeature(const ChannelAPI *source, Feature *feature, const QString& type);
DataFifo *unregisterChannelToFeature(const ChannelAPI *source, Feature *feature, const QString& type);
QList<DataFifo*>* getFifos(const ChannelAPI *source, const QString& type);
ObjectPipe *registerProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type);
ObjectPipe *unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type);
void getDataPipes(const QObject *producer, const QString& type, QList<ObjectPipe*>& pipes);
private:
ElementPipesRegistrations<ChannelAPI, Feature, DataFifo> m_registrations;
DataFifoStore m_dataFifoStore;
ObjectPipesRegistrations m_registrations;
QThread m_gcThread; //!< Garbage collector thread
DataPipesGCWorker *m_gcWorker; //!< Garbage collector
@ -56,4 +51,5 @@ private:
void stopGC(); //!< Stop garbage collector
};
#endif // SDRBASE_PIPES_DATAPIPES_H_
#endif // SDRBASE_PIPES_DATAPIPES2_H_

View File

@ -1,68 +0,0 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2022 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "dsp/datafifo.h"
#include "datapipes2.h"
#include "datapipes2gcworker.h"
DataPipes2::DataPipes2() :
m_registrations(&m_dataFifoStore)
{
m_gcWorker = new DataPipes2GCWorker(m_registrations);
m_gcWorker->moveToThread(&m_gcThread);
startGC();
}
DataPipes2::~DataPipes2()
{
if (m_gcWorker->isRunning()) {
stopGC();
}
m_gcWorker->deleteLater();
}
ObjectPipe *DataPipes2::registerProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type)
{
return m_registrations.registerProducerToConsumer(producer, consumer, type);
}
ObjectPipe *DataPipes2::unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type)
{
return m_registrations.unregisterProducerToConsumer(producer, consumer, type);
}
void DataPipes2::getDataPipes(const QObject *producer, const QString& type, QList<ObjectPipe*>& pipes)
{
return m_registrations.getPipes(producer, type, pipes);
}
void DataPipes2::startGC()
{
qDebug("DataPipes2::startGC");
m_gcWorker->startWork();
m_gcThread.start();
}
void DataPipes2::stopGC()
{
qDebug("DataPipes2::stopGC");
m_gcWorker->stopWork();
m_gcThread.quit();
m_gcThread.wait();
}

View File

@ -1,55 +0,0 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2022 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRBASE_PIPES_DATAPIPES2_H_
#define SDRBASE_PIPES_DATAPIPES2_H_
#include <QObject>
#include <QThread>
#include "export.h"
#include "objectpipesregistrations.h"
#include "datafifostore.h"
class DataFifo;
class DataPipes2GCWorker;
class SDRBASE_API DataPipes2 : public QObject
{
Q_OBJECT
public:
DataPipes2();
DataPipes2(const DataPipes2&) = delete;
DataPipes2& operator=(const DataPipes2&) = delete;
~DataPipes2();
ObjectPipe *registerProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type);
ObjectPipe *unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type);
void getDataPipes(const QObject *producer, const QString& type, QList<ObjectPipe*>& pipes);
private:
DataFifoStore m_dataFifoStore;
ObjectPipesRegistrations m_registrations;
QThread m_gcThread; //!< Garbage collector thread
DataPipes2GCWorker *m_gcWorker; //!< Garbage collector
void startGC(); //!< Start garbage collector
void stopGC(); //!< Stop garbage collector
};
#endif // SDRBASE_PIPES_DATAPIPES2_H_

View File

@ -1,46 +0,0 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2022 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "dsp/datafifo.h"
#include "datapipes2gcworker.h"
DataPipes2GCWorker::DataPipes2GCWorker(ObjectPipesRegistrations& objectPipesRegistrations) :
m_running(false),
m_objectPipesRegistrations(objectPipesRegistrations)
{}
DataPipes2GCWorker::~DataPipes2GCWorker()
{}
void DataPipes2GCWorker::startWork()
{
connect(&m_gcTimer, SIGNAL(timeout()), this, SLOT(processGC()));
m_gcTimer.start(10000); // collect garbage every 10s
m_running = true;
}
void DataPipes2GCWorker::stopWork()
{
m_running = false;
m_gcTimer.stop();
disconnect(&m_gcTimer, SIGNAL(timeout()), this, SLOT(processGC()));
}
void DataPipes2GCWorker::processGC()
{
m_objectPipesRegistrations.processGC();
}

View File

@ -1,49 +0,0 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2022 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRBASE_PIPES_DATAPIPES2GCWORKER_H_
#define SDRBASE_PIPES_DATAPIPES2GCWORKER_H_
#include <QObject>
#include <QTimer>
#include "export.h"
#include "objectpipesregistrations.h"
class DataFifo;
class SDRBASE_API DataPipes2GCWorker : public QObject
{
Q_OBJECT
public:
DataPipes2GCWorker(ObjectPipesRegistrations& objectPipesRegistrations);
~DataPipes2GCWorker();
void startWork();
void stopWork();
bool isRunning() const { return m_running; }
private:
bool m_running;
QTimer m_gcTimer;
ObjectPipesRegistrations& m_objectPipesRegistrations;
private slots:
void processGC(); //!< Collect garbage
};
#endif // SDRBASE_PIPES_DATAPIPES2GCWORKER_H_

View File

@ -1,20 +0,0 @@
///////////////////////////////////////////////////////////////////////////////////
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "datapipescommon.h"
MESSAGE_CLASS_DEFINITION(DataPipesCommon::MsgReportChannelDeleted, Message)

View File

@ -1,63 +0,0 @@
///////////////////////////////////////////////////////////////////////////////////
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRBASE_PIPES_DATAPIPESCOMON_H_
#define SDRBASE_PIPES_DATAPIPESCOMON_H_
#include <QHash>
#include <QMap>
#include <QMutex>
#include "export.h"
#include "util/message.h"
#include "elementpipescommon.h"
class ChannelAPI;
class Feature;
class DataFifo;
class SDRBASE_API DataPipesCommon
{
public:
typedef ElementPipesCommon::RegistrationKey<ChannelAPI> ChannelRegistrationKey;
/** Send this message to stakeholders when the garbage collector finds that a channel was deleted */
class SDRBASE_API MsgReportChannelDeleted : public Message {
MESSAGE_CLASS_DECLARATION
public:
const DataFifo *getFifo() const { return m_fifo; }
const ChannelRegistrationKey& getChannelRegistrationKey() const { return m_channelRegistrationKey; }
static MsgReportChannelDeleted* create(const DataFifo *fifo, const ChannelRegistrationKey& channelRegistrationKey) {
return new MsgReportChannelDeleted(fifo, channelRegistrationKey);
}
private:
const DataFifo *m_fifo;
ChannelRegistrationKey m_channelRegistrationKey;
MsgReportChannelDeleted(const DataFifo *fifo, const ChannelRegistrationKey& channelRegistrationKey) :
Message(),
m_fifo(fifo),
m_channelRegistrationKey(channelRegistrationKey)
{ }
};
};
#endif // SDRBASE_PIPES_DATAPIPESCOMON_H_

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
// Copyright (C) 2022 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 //
@ -15,31 +15,12 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "feature/feature.h"
#include "dsp/datafifo.h"
#include "maincore.h"
#include "datapipescommon.h"
#include "datapipesgcworker.h"
bool DataPipesGCWorker::DataPipesGC::existsProducer(const ChannelAPI *channel)
{
return MainCore::instance()->existsChannel(channel);
}
bool DataPipesGCWorker::DataPipesGC::existsConsumer(const Feature *feature)
{
return MainCore::instance()->existsFeature(feature);
}
void DataPipesGCWorker::DataPipesGC::sendMessageToConsumer(const DataFifo *fifo, DataPipesCommon::ChannelRegistrationKey channelKey, Feature *feature)
{
DataPipesCommon::MsgReportChannelDeleted *msg = DataPipesCommon::MsgReportChannelDeleted::create(
fifo, channelKey);
feature->getInputMessageQueue()->push(msg);
}
DataPipesGCWorker::DataPipesGCWorker() :
m_running(false)
DataPipesGCWorker::DataPipesGCWorker(ObjectPipesRegistrations& objectPipesRegistrations) :
m_running(false),
m_objectPipesRegistrations(objectPipesRegistrations)
{}
DataPipesGCWorker::~DataPipesGCWorker()
@ -59,17 +40,7 @@ void DataPipesGCWorker::stopWork()
disconnect(&m_gcTimer, SIGNAL(timeout()), this, SLOT(processGC()));
}
void DataPipesGCWorker::addDataFifoToDelete(DataFifo *dataFifo)
{
if (dataFifo)
{
m_gcTimer.start(10000); // restart GC to make sure deletion is postponed
m_dataPipesGC.addElementToDelete(dataFifo);
}
}
void DataPipesGCWorker::processGC()
{
// qDebug("MessagePipesGCWorker::processGC");
m_dataPipesGC.processGC();
m_objectPipesRegistrations.processGC();
}

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
// Copyright (C) 2022 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 //
@ -15,56 +15,35 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRBASE_PIPES_DATAPIPESGCWORKER_H_
#define SDRBASE_PIPES_DATAPIPESGCWORKER_H_
#ifndef SDRBASE_PIPES_DATAPIPES2GCWORKER_H_
#define SDRBASE_PIPES_DATAPIPES2GCWORKER_H_
#include <QObject>
#include <QTimer>
#include "export.h"
#include "objectpipesregistrations.h"
#include "elementpipesgc.h"
#include "datapipescommon.h"
class QMutex;
class DataFifo;
class SDRBASE_API DataPipesGCWorker : public QObject
{
Q_OBJECT
public:
DataPipesGCWorker();
DataPipesGCWorker(ObjectPipesRegistrations& objectPipesRegistrations);
~DataPipesGCWorker();
void setC2FRegistrations(
QMutex *c2fMutex,
QMap<DataPipesCommon::ChannelRegistrationKey, QList<DataFifo*>> *c2fFifos,
QMap<DataPipesCommon::ChannelRegistrationKey, QList<Feature*>> *c2fFeatures
)
{
m_dataPipesGC.setRegistrations(c2fMutex, c2fFifos, c2fFeatures);
}
void startWork();
void stopWork();
void addDataFifoToDelete(DataFifo *dataFifo);
bool isRunning() const { return m_running; }
private:
class DataPipesGC : public ElementPipesGC<ChannelAPI, Feature, DataFifo>
{
private:
virtual bool existsProducer(const ChannelAPI *channelAPI);
virtual bool existsConsumer(const Feature *feature);
virtual void sendMessageToConsumer(const DataFifo *fifo, DataPipesCommon::ChannelRegistrationKey key, Feature *feature);
};
DataPipesGC m_dataPipesGC;
bool m_running;
QTimer m_gcTimer;
ObjectPipesRegistrations& m_objectPipesRegistrations;
private slots:
void processGC(); //!< Collect garbage
};
#endif // SDRBASE_PIPES_DATAPIPESGCWORKER_H_
#endif // SDRBASE_PIPES_DATAPIPES2GCWORKER_H_