1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 17:58:43 -05:00
sdrangel/sdrbase/plugin/pluginmanager.h

167 lines
7.5 KiB
C
Raw Normal View History

///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016-2019 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 INCLUDE_PLUGINMANAGER_H
#define INCLUDE_PLUGINMANAGER_H
#include <stdint.h>
#include <QObject>
#include <QDir>
#include <QList>
#include <QString>
#include "plugin/plugininterface.h"
#include "plugin/pluginapi.h"
#include "export.h"
class QComboBox;
class QPluginLoader;
class Message;
class MessageQueue;
2019-05-08 16:11:53 -04:00
class DeviceAPI;
2020-11-20 13:47:04 -05:00
struct DeviceUserArgs;
class WebAPIAdapterInterface;
2018-03-03 14:23:38 -05:00
class SDRBASE_API PluginManager : public QObject {
Q_OBJECT
public:
struct Plugin
{
QString filename;
2015-09-30 02:55:58 -04:00
PluginInterface* pluginInterface;
Plugin(const QString& _filename, PluginInterface* _plugin) :
filename(_filename),
2015-09-30 02:55:58 -04:00
pluginInterface(_plugin)
{ }
};
typedef QList<Plugin> Plugins;
explicit PluginManager(QObject* parent = 0);
~PluginManager();
PluginAPI *getPluginAPI() { return &m_pluginAPI; }
void loadPlugins(const QString& pluginsSubDir);
2018-08-18 15:30:51 -04:00
void loadPluginsPart(const QString& pluginsSubDir);
void loadPluginsFinal();
void loadPluginsNonDiscoverable(const DeviceUserArgs& deviceUserArgs);
const Plugins& getPlugins() const { return m_plugins; }
// Callbacks from the plugins
void registerRxChannel(const QString& channelIdURI, const QString& channelId, PluginInterface* plugin);
void registerTxChannel(const QString& channelIdURI, const QString& channelId, PluginInterface* plugin);
void registerMIMOChannel(const QString& channelIdURI, const QString& channelId, PluginInterface* plugin);
void registerSampleSource(const QString& sourceName, PluginInterface* plugin);
void registerSampleSink(const QString& sinkName, PluginInterface* plugin);
void registerSampleMIMO(const QString& mimoName, PluginInterface* plugin);
void registerFeature(const QString& featureIdURI, const QString& featureId, PluginInterface* plugin);
2017-11-01 22:30:54 -04:00
PluginAPI::SamplingDeviceRegistrations& getSourceDeviceRegistrations() { return m_sampleSourceRegistrations; }
PluginAPI::SamplingDeviceRegistrations& getSinkDeviceRegistrations() { return m_sampleSinkRegistrations; }
PluginAPI::SamplingDeviceRegistrations& getMIMODeviceRegistrations() { return m_sampleMIMORegistrations; }
2016-10-13 16:23:43 -04:00
PluginAPI::ChannelRegistrations *getRxChannelRegistrations() { return &m_rxChannelRegistrations; }
PluginAPI::ChannelRegistrations *getTxChannelRegistrations() { return &m_txChannelRegistrations; }
PluginAPI::ChannelRegistrations *getMIMOChannelRegistrations() { return &m_mimoChannelRegistrations; }
PluginAPI::FeatureRegistrations *getFeatureRegistrations() { return &m_featureRegistrations; }
void listRxChannels(QList<QString>& list);
void listTxChannels(QList<QString>& list);
void listMIMOChannels(QList<QString>& list);
void listFeatures(QList<QString>& list);
const PluginInterface *getChannelPluginInterface(const QString& channelIdURI) const;
const PluginInterface *getDevicePluginInterface(const QString& deviceId) const;
2020-09-23 23:38:05 -04:00
const PluginInterface *getFeaturePluginInterface(const QString& featureIdURI) const;
2021-02-26 15:25:48 -05:00
// Map channel/feature URI to short form Id
QString uriToId(const QString& uri) const;
static const QString& getFileInputDeviceId() { return m_fileInputDeviceTypeID; }
2020-11-10 06:08:58 -05:00
static const QString& getTestMIMODeviceId() { return m_testMIMODeviceTypeID; }
static const QString& getFileOutputDeviceId() { return m_fileOutputDeviceTypeID; }
2017-11-01 22:30:54 -04:00
private:
struct SamplingDevice { //!< This is the device registration
PluginInterface* m_plugin;
QString m_displayName;
2016-12-29 06:41:10 -05:00
QString m_hadrwareId;
2016-10-13 16:23:43 -04:00
QString m_deviceId;
QString m_deviceSerial;
2017-05-25 14:13:34 -04:00
uint32_t m_deviceSequence;
2016-10-13 16:23:43 -04:00
SamplingDevice(PluginInterface* plugin,
const QString& displayName,
2016-12-29 06:41:10 -05:00
const QString& hadrwareId,
2016-10-13 16:23:43 -04:00
const QString& deviceId,
const QString& deviceSerial,
int deviceSequence) :
m_plugin(plugin),
m_displayName(displayName),
2016-12-29 06:41:10 -05:00
m_hadrwareId(hadrwareId),
2016-10-13 16:23:43 -04:00
m_deviceId(deviceId),
m_deviceSerial(deviceSerial),
m_deviceSequence(deviceSequence)
{ }
};
2016-10-13 16:23:43 -04:00
typedef QList<SamplingDevice> SamplingDevices;
PluginAPI m_pluginAPI;
Plugins m_plugins;
2017-11-01 22:30:54 -04:00
PluginAPI::ChannelRegistrations m_rxChannelRegistrations; //!< Channel plugins register here
PluginAPI::ChannelRegistrations m_txChannelRegistrations; //!< Channel plugins register here
PluginAPI::ChannelRegistrations m_mimoChannelRegistrations; //!< Channel plugins register here
PluginAPI::SamplingDeviceRegistrations m_sampleSourceRegistrations; //!< Input source plugins (one per device kind) register here
PluginAPI::SamplingDeviceRegistrations m_sampleSinkRegistrations; //!< Output sink plugins (one per device kind) register here
PluginAPI::SamplingDeviceRegistrations m_sampleMIMORegistrations; //!< MIMO sink plugins (one per device kind) register here
PluginAPI::FeatureRegistrations m_featureRegistrations; //!< Feature plugins register here
// "Local" sample source device IDs
static const QString m_localInputHardwareID; //!< Local input hardware ID
static const QString m_localInputDeviceTypeID; //!< Local input plugin ID
static const QString m_remoteInputHardwareID; //!< Remote input hardware ID
static const QString m_remoteInputDeviceTypeID; //!< Remote input plugin ID
static const QString m_fileInputHardwareID; //!< File input hardware ID
static const QString m_fileInputDeviceTypeID; //!< File input plugin ID
// "Local" sample sink device IDs
2019-05-10 17:38:52 -04:00
static const QString m_localOutputHardwareID; //!< Local output hardware ID
static const QString m_localOutputDeviceTypeID; //!< Local output plugin ID
static const QString m_remoteOutputHardwareID; //!< Remote output hardware ID
static const QString m_remoteOutputDeviceTypeID; //!< Remote output plugin ID
2020-08-03 18:29:15 -04:00
static const QString m_fileOutputHardwareID; //!< FileOutput sink hardware ID
static const QString m_fileOutputDeviceTypeID; //!< FileOutput sink plugin ID
2020-11-10 06:08:58 -05:00
// "Local" sample MIMO device IDs
static const QString m_testMIMOHardwareID; //!< Test MIMO hardware ID
static const QString m_testMIMODeviceTypeID; //!< Test MIMO plugin ID
void loadPluginsDir(const QDir& dir);
};
static inline bool operator<(const PluginManager::Plugin& a, const PluginManager::Plugin& b)
{
2015-09-30 02:55:58 -04:00
return a.pluginInterface->getPluginDescriptor().displayedName < b.pluginInterface->getPluginDescriptor().displayedName;
}
#endif // INCLUDE_PLUGINMANAGER_H