2017-04-23 08:33:18 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2016 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 //
|
2019-04-11 12:32:15 +00:00
|
|
|
// (at your option) any later version. //
|
2017-04-23 08:33:18 +00:00
|
|
|
// //
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-11-01 21:56:32 +00:00
|
|
|
#include <QCoreApplication>
|
2017-04-23 08:33:18 +00:00
|
|
|
#include <QPluginLoader>
|
2017-11-01 21:56:32 +00:00
|
|
|
//#include <QComboBox>
|
2017-10-24 12:15:08 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2017-04-23 08:33:18 +00:00
|
|
|
#include <cstdio>
|
|
|
|
|
2017-10-24 12:15:08 +00:00
|
|
|
#include <plugin/plugininstancegui.h>
|
2017-11-02 02:30:54 +00:00
|
|
|
#include "device/deviceenumerator.h"
|
2017-04-23 08:33:18 +00:00
|
|
|
#include "settings/preset.h"
|
|
|
|
#include "util/message.h"
|
|
|
|
#include "dsp/dspdevicesourceengine.h"
|
|
|
|
#include "dsp/dspdevicesinkengine.h"
|
|
|
|
|
2017-10-24 12:15:08 +00:00
|
|
|
#include "plugin/pluginmanager.h"
|
|
|
|
|
2019-05-02 02:02:40 +00:00
|
|
|
const QString PluginManager::m_localInputHardwareID = "LocalInput";
|
|
|
|
const QString PluginManager::m_localInputDeviceTypeID = "sdrangel.samplesource.localinput";
|
2019-02-03 00:52:11 +00:00
|
|
|
const QString PluginManager::m_remoteInputHardwareID = "RemoteInput";
|
|
|
|
const QString PluginManager::m_remoteInputDeviceTypeID = "sdrangel.samplesource.remoteinput";
|
2017-04-23 08:33:18 +00:00
|
|
|
const QString PluginManager::m_fileSourceHardwareID = "FileSource";
|
|
|
|
const QString PluginManager::m_fileSourceDeviceTypeID = "sdrangel.samplesource.filesource";
|
2017-11-01 12:03:12 +00:00
|
|
|
|
2019-05-10 21:38:52 +00:00
|
|
|
const QString PluginManager::m_localOutputHardwareID = "LocalOutput";
|
|
|
|
const QString PluginManager::m_localOutputDeviceTypeID = "sdrangel.samplesource.localoutput";
|
2019-02-03 00:52:11 +00:00
|
|
|
const QString PluginManager::m_remoteOutputHardwareID = "RemoteOutput";
|
|
|
|
const QString PluginManager::m_remoteOutputDeviceTypeID = "sdrangel.samplesink.remoteoutput";
|
2017-11-01 12:03:12 +00:00
|
|
|
const QString PluginManager::m_fileSinkHardwareID = "FileSink";
|
2017-04-23 08:33:18 +00:00
|
|
|
const QString PluginManager::m_fileSinkDeviceTypeID = "sdrangel.samplesink.filesink";
|
|
|
|
|
2017-10-24 12:15:08 +00:00
|
|
|
PluginManager::PluginManager(QObject* parent) :
|
2017-04-23 08:33:18 +00:00
|
|
|
QObject(parent),
|
2017-10-24 12:01:31 +00:00
|
|
|
m_pluginAPI(this)
|
2017-04-23 08:33:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginManager::~PluginManager()
|
|
|
|
{
|
2019-05-01 13:17:27 +00:00
|
|
|
// freeAll();
|
2017-04-23 08:33:18 +00:00
|
|
|
}
|
|
|
|
|
2017-12-17 09:36:22 +00:00
|
|
|
void PluginManager::loadPlugins(const QString& pluginsSubDir)
|
2017-04-23 08:33:18 +00:00
|
|
|
{
|
2018-08-18 19:30:51 +00:00
|
|
|
loadPluginsPart(pluginsSubDir);
|
|
|
|
loadPluginsFinal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginManager::loadPluginsPart(const QString& pluginsSubDir)
|
|
|
|
{
|
|
|
|
QString applicationDirPath = QCoreApplication::instance()->applicationDirPath();
|
2019-05-01 13:17:27 +00:00
|
|
|
QStringList PluginsPath;
|
|
|
|
|
|
|
|
// NOTE: not the best solution but for now this is
|
|
|
|
// on make install [PREFIX]/bin and [PREFIX]/lib/sdrangel
|
|
|
|
PluginsPath << applicationDirPath + "/../lib/sdrangel/" + pluginsSubDir;
|
|
|
|
// on build
|
|
|
|
PluginsPath << applicationDirPath + "/lib/" + pluginsSubDir;
|
2018-12-27 08:48:30 +00:00
|
|
|
#ifdef __APPLE__
|
2019-05-01 13:17:27 +00:00
|
|
|
// on SDRAngel.app
|
|
|
|
PluginsPath << applicationDirPath + "/../Frameworks/" + pluginsSubDir;
|
2018-12-27 08:48:30 +00:00
|
|
|
#endif
|
2017-12-16 12:39:13 +00:00
|
|
|
|
2019-05-01 13:17:27 +00:00
|
|
|
// NOTE: exit on the first folder found
|
|
|
|
bool found = false;
|
|
|
|
foreach (QString dir, PluginsPath)
|
|
|
|
{
|
|
|
|
QDir d(dir);
|
|
|
|
if (d.isEmpty()) {
|
|
|
|
qDebug("PluginManager::loadPluginsPart folder %s is empty", qPrintable(dir));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
found = true;
|
|
|
|
loadPluginsDir(d);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
qCritical("No plugins found. Exit immediately.");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2018-08-18 19:30:51 +00:00
|
|
|
}
|
2017-12-16 12:39:13 +00:00
|
|
|
|
2018-08-18 19:30:51 +00:00
|
|
|
void PluginManager::loadPluginsFinal()
|
|
|
|
{
|
|
|
|
qSort(m_plugins);
|
2017-04-23 08:33:18 +00:00
|
|
|
|
2018-08-18 19:30:51 +00:00
|
|
|
for (Plugins::const_iterator it = m_plugins.begin(); it != m_plugins.end(); ++it)
|
|
|
|
{
|
|
|
|
it->pluginInterface->initPlugin(&m_pluginAPI);
|
|
|
|
}
|
2017-04-23 08:33:18 +00:00
|
|
|
|
2018-08-18 19:30:51 +00:00
|
|
|
DeviceEnumerator::instance()->enumerateRxDevices(this);
|
|
|
|
DeviceEnumerator::instance()->enumerateTxDevices(this);
|
2017-04-23 08:33:18 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 00:19:32 +00:00
|
|
|
void PluginManager::registerRxChannel(const QString& channelIdURI, const QString& channelId, PluginInterface* plugin)
|
2017-04-23 08:33:18 +00:00
|
|
|
{
|
|
|
|
qDebug() << "PluginManager::registerRxChannel "
|
|
|
|
<< plugin->getPluginDescriptor().displayedName.toStdString().c_str()
|
2017-11-23 00:19:32 +00:00
|
|
|
<< " with channel name " << channelIdURI;
|
2017-04-23 08:33:18 +00:00
|
|
|
|
2017-11-23 00:19:32 +00:00
|
|
|
m_rxChannelRegistrations.append(PluginAPI::ChannelRegistration(channelIdURI, channelId, plugin));
|
2017-04-23 08:33:18 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 00:19:32 +00:00
|
|
|
void PluginManager::registerTxChannel(const QString& channelIdURI, const QString& channelId, PluginInterface* plugin)
|
2017-04-23 08:33:18 +00:00
|
|
|
{
|
|
|
|
qDebug() << "PluginManager::registerTxChannel "
|
|
|
|
<< plugin->getPluginDescriptor().displayedName.toStdString().c_str()
|
2017-11-23 00:19:32 +00:00
|
|
|
<< " with channel name " << channelIdURI;
|
2017-04-23 08:33:18 +00:00
|
|
|
|
2017-11-23 00:19:32 +00:00
|
|
|
m_txChannelRegistrations.append(PluginAPI::ChannelRegistration(channelIdURI, channelId, plugin));
|
2017-04-23 08:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PluginManager::registerSampleSource(const QString& sourceName, PluginInterface* plugin)
|
|
|
|
{
|
|
|
|
qDebug() << "PluginManager::registerSampleSource "
|
|
|
|
<< plugin->getPluginDescriptor().displayedName.toStdString().c_str()
|
|
|
|
<< " with source name " << sourceName.toStdString().c_str();
|
|
|
|
|
2017-11-02 02:30:54 +00:00
|
|
|
m_sampleSourceRegistrations.append(PluginAPI::SamplingDeviceRegistration(sourceName, plugin));
|
2017-04-23 08:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PluginManager::registerSampleSink(const QString& sinkName, PluginInterface* plugin)
|
|
|
|
{
|
|
|
|
qDebug() << "PluginManager::registerSampleSink "
|
|
|
|
<< plugin->getPluginDescriptor().displayedName.toStdString().c_str()
|
|
|
|
<< " with sink name " << sinkName.toStdString().c_str();
|
|
|
|
|
2017-11-02 02:30:54 +00:00
|
|
|
m_sampleSinkRegistrations.append(PluginAPI::SamplingDeviceRegistration(sinkName, plugin));
|
2017-04-23 08:33:18 +00:00
|
|
|
}
|
|
|
|
|
2017-12-17 09:36:22 +00:00
|
|
|
void PluginManager::loadPluginsDir(const QDir& dir)
|
2017-04-23 08:33:18 +00:00
|
|
|
{
|
|
|
|
QDir pluginsDir(dir);
|
|
|
|
|
2019-05-01 13:17:27 +00:00
|
|
|
foreach (QString fileName, pluginsDir.entryList(QDir::Files))
|
|
|
|
{
|
|
|
|
if (QLibrary::isLibrary(fileName))
|
|
|
|
{
|
|
|
|
qDebug("PluginManager::loadPluginsDir: fileName: %s", qPrintable(fileName));
|
|
|
|
|
|
|
|
QPluginLoader* plugin = new QPluginLoader(pluginsDir.absoluteFilePath(fileName));
|
|
|
|
if (!plugin->load())
|
|
|
|
{
|
|
|
|
qWarning("PluginManager::loadPluginsDir: %s", qPrintable(plugin->errorString()));
|
|
|
|
delete plugin;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginInterface* instance = qobject_cast<PluginInterface*>(plugin->instance());
|
|
|
|
if (instance == nullptr)
|
|
|
|
{
|
|
|
|
qWarning("PluginManager::loadPluginsDir: Unable to get main instance of plugin: %s", qPrintable(fileName) );
|
|
|
|
delete plugin;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
qInfo("PluginManager::loadPluginsDir: loaded plugin %s", qPrintable(fileName));
|
|
|
|
m_plugins.append(Plugin(fileName, plugin, instance));
|
|
|
|
}
|
|
|
|
}
|
2017-04-23 08:33:18 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 07:32:44 +00:00
|
|
|
void PluginManager::listTxChannels(QList<QString>& list)
|
2017-04-23 08:33:18 +00:00
|
|
|
{
|
2019-05-01 13:17:27 +00:00
|
|
|
list.clear();
|
2017-11-01 07:32:44 +00:00
|
|
|
|
2019-05-01 13:17:27 +00:00
|
|
|
for(PluginAPI::ChannelRegistrations::iterator it = m_txChannelRegistrations.begin(); it != m_txChannelRegistrations.end(); ++it)
|
2017-04-23 08:33:18 +00:00
|
|
|
{
|
2019-05-01 13:17:27 +00:00
|
|
|
const PluginDescriptor& pluginDescipror = it->m_plugin->getPluginDescriptor();
|
|
|
|
list.append(pluginDescipror.displayedName);
|
2017-04-23 08:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-01 07:32:44 +00:00
|
|
|
void PluginManager::listRxChannels(QList<QString>& list)
|
2017-04-23 08:33:18 +00:00
|
|
|
{
|
2019-05-01 13:17:27 +00:00
|
|
|
list.clear();
|
2017-11-01 07:32:44 +00:00
|
|
|
|
2019-05-01 13:17:27 +00:00
|
|
|
for(PluginAPI::ChannelRegistrations::iterator it = m_rxChannelRegistrations.begin(); it != m_rxChannelRegistrations.end(); ++it)
|
2017-04-23 08:33:18 +00:00
|
|
|
{
|
2019-05-01 13:17:27 +00:00
|
|
|
const PluginDescriptor& pluginDesciptor = it->m_plugin->getPluginDescriptor();
|
|
|
|
list.append(pluginDesciptor.displayedName);
|
2017-04-23 08:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-08 20:11:53 +00:00
|
|
|
void PluginManager::createRxChannelInstance(int channelPluginIndex, DeviceUISet *deviceUISet, DeviceAPI *deviceAPI)
|
2017-10-30 23:07:55 +00:00
|
|
|
{
|
2019-05-01 13:17:27 +00:00
|
|
|
if (channelPluginIndex < m_rxChannelRegistrations.size())
|
2017-10-30 23:07:55 +00:00
|
|
|
{
|
2019-05-01 13:17:27 +00:00
|
|
|
PluginInterface *pluginInterface = m_rxChannelRegistrations[channelPluginIndex].m_plugin;
|
|
|
|
BasebandSampleSink *rxChannel = pluginInterface->createRxChannelBS(deviceAPI);
|
|
|
|
pluginInterface->createRxChannelGUI(deviceUISet, rxChannel);
|
2017-10-30 23:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-08 20:11:53 +00:00
|
|
|
void PluginManager::createTxChannelInstance(int channelPluginIndex, DeviceUISet *deviceUISet, DeviceAPI *deviceAPI)
|
2017-04-23 08:33:18 +00:00
|
|
|
{
|
2019-05-01 13:17:27 +00:00
|
|
|
if (channelPluginIndex < m_txChannelRegistrations.size())
|
2017-04-23 08:33:18 +00:00
|
|
|
{
|
2019-05-01 13:17:27 +00:00
|
|
|
PluginInterface *pluginInterface = m_txChannelRegistrations[channelPluginIndex].m_plugin;
|
|
|
|
BasebandSampleSource *txChannel = pluginInterface->createTxChannelBS(deviceAPI);
|
|
|
|
pluginInterface->createTxChannelGUI(deviceUISet, txChannel);
|
2017-04-23 08:33:18 +00:00
|
|
|
}
|
|
|
|
}
|