1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-16 05:11:49 -05:00
sdrangel/sdrbase/plugin/pluginmanager.h

124 lines
4.4 KiB
C
Raw Normal View History

#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 "util/export.h"
class QComboBox;
class QPluginLoader;
class Preset;
class Message;
class MessageQueue;
class DeviceSourceAPI;
class DeviceSinkAPI;
2015-08-29 19:26:51 -04:00
class SDRANGEL_API PluginManager : public QObject {
Q_OBJECT
public:
struct Plugin
{
QString filename;
QPluginLoader* loader;
2015-09-30 02:55:58 -04:00
PluginInterface* pluginInterface;
Plugin(const QString& _filename, QPluginLoader* pluginLoader, PluginInterface* _plugin) :
filename(_filename),
loader(pluginLoader),
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);
const Plugins& getPlugins() const { return m_plugins; }
// Callbacks from the plugins
void registerRxChannel(const QString& channelIdURI, const QString& channelId, PluginInterface* plugin);
void registerSampleSource(const QString& sourceName, PluginInterface* plugin);
void registerTxChannel(const QString& channelIdURI, const QString& channelId, PluginInterface* plugin);
void registerSampleSink(const QString& sourceName, PluginInterface* plugin);
2017-11-01 22:30:54 -04:00
PluginAPI::SamplingDeviceRegistrations& getSourceDeviceRegistrations() { return m_sampleSourceRegistrations; }
PluginAPI::SamplingDeviceRegistrations& getSinkDeviceRegistrations() { return m_sampleSinkRegistrations; }
2016-10-13 16:23:43 -04:00
PluginAPI::ChannelRegistrations *getRxChannelRegistrations() { return &m_rxChannelRegistrations; }
PluginAPI::ChannelRegistrations *getTxChannelRegistrations() { return &m_txChannelRegistrations; }
void createRxChannelInstance(int channelPluginIndex, DeviceUISet *deviceUISet, DeviceSourceAPI *deviceAPI);
void listRxChannels(QList<QString>& list);
void createTxChannelInstance(int channelPluginIndex, DeviceUISet *deviceUISet, DeviceSinkAPI *deviceAPI);
void listTxChannels(QList<QString>& list);
2017-11-01 22:30:54 -04:00
static const QString& getFileSourceDeviceId() { return m_fileSourceDeviceTypeID; }
static const QString& getFileSinkDeviceId() { return m_fileSinkDeviceTypeID; }
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::SamplingDeviceRegistrations m_sampleSourceRegistrations; //!< Input source plugins (one per device kind) register here
2017-11-01 22:30:54 -04:00
PluginAPI::ChannelRegistrations m_txChannelRegistrations; //!< Channel plugins register here
PluginAPI::SamplingDeviceRegistrations m_sampleSinkRegistrations; //!< Output sink plugins (one per device kind) register here
// "Local" sample source device IDs
static const QString m_sdrDaemonSourceHardwareID; //!< SDRdaemon source hardware ID
static const QString m_sdrDaemonSourceDeviceTypeID; //!< SDRdaemon source plugin ID
static const QString m_fileSourceHardwareID; //!< FileSource source hardware ID
static const QString m_fileSourceDeviceTypeID; //!< FileSource source plugin ID
// "Local" sample sink device IDs
static const QString m_sdrDaemonSinkHardwareID; //!< SDRdaemon source hardware ID
static const QString m_sdrDaemonSinkDeviceTypeID; //!< SDRdaemon source plugin ID
static const QString m_fileSinkHardwareID; //!< FileSource source hardware ID
static const QString m_fileSinkDeviceTypeID; //!< FileSink sink 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