| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include <QApplication>
 | 
					
						
							|  |  |  | #include <QPluginLoader>
 | 
					
						
							|  |  |  | #include <QComboBox>
 | 
					
						
							|  |  |  | #include "plugin/pluginmanager.h"
 | 
					
						
							|  |  |  | #include "plugin/plugingui.h"
 | 
					
						
							|  |  |  | #include "settings/preset.h"
 | 
					
						
							|  |  |  | #include "mainwindow.h"
 | 
					
						
							|  |  |  | #include "dsp/dspengine.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-25 08:31:57 +02:00
										 |  |  | #include "dsp/samplesource.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-09 10:33:04 +02:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | PluginManager::PluginManager(MainWindow* mainWindow, DSPEngine* dspEngine, QObject* parent) : | 
					
						
							|  |  |  | 	QObject(parent), | 
					
						
							|  |  |  | 	m_pluginAPI(this, mainWindow, dspEngine), | 
					
						
							|  |  |  | 	m_mainWindow(mainWindow), | 
					
						
							|  |  |  | 	m_dspEngine(dspEngine), | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 	m_sampleSourceId(), | 
					
						
							| 
									
										
										
										
											2015-09-30 08:55:58 +02:00
										 |  |  | 	m_sampleSourceSerial(), | 
					
						
							|  |  |  | 	m_sampleSourceSequence(0), | 
					
						
							| 
									
										
										
										
											2015-08-18 02:47:14 +02:00
										 |  |  | 	m_sampleSourcePluginGUI(NULL) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PluginManager::~PluginManager() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	freeAll(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PluginManager::loadPlugins() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-02-24 11:51:36 +01:00
										 |  |  | 	QString applicationDirPath = QApplication::instance()->applicationDirPath(); | 
					
						
							|  |  |  | 	QString applicationLibPath = applicationDirPath + "/../lib"; | 
					
						
							|  |  |  | 	qDebug() << "PluginManager::loadPlugins: " << qPrintable(applicationDirPath) << ", " << qPrintable(applicationLibPath); | 
					
						
							| 
									
										
										
										
											2015-08-26 02:03:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-24 11:51:36 +01:00
										 |  |  | 	QDir pluginsBinDir = QDir(applicationDirPath); | 
					
						
							|  |  |  | 	QDir pluginsLibDir = QDir(applicationLibPath); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-24 11:51:36 +01:00
										 |  |  | 	loadPlugins(pluginsBinDir); | 
					
						
							|  |  |  | 	loadPlugins(pluginsLibDir); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	qSort(m_plugins); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-26 02:03:20 +02:00
										 |  |  | 	for (Plugins::const_iterator it = m_plugins.begin(); it != m_plugins.end(); ++it) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-09-30 08:55:58 +02:00
										 |  |  | 		it->pluginInterface->initPlugin(&m_pluginAPI); | 
					
						
							| 
									
										
										
										
											2015-08-09 04:09:05 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	updateSampleSourceDevices(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PluginManager::registerChannel(const QString& channelName, PluginInterface* plugin, QAction* action) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_channelRegistrations.append(ChannelRegistration(channelName, plugin)); | 
					
						
							|  |  |  | 	m_mainWindow->addChannelCreateAction(action); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PluginManager::registerChannelInstance(const QString& channelName, PluginGUI* pluginGUI) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, pluginGUI)); | 
					
						
							|  |  |  | 	renameChannelInstances(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PluginManager::addChannelRollup(QWidget* pluginGUI) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_mainWindow->addChannelRollup(pluginGUI); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PluginManager::removeChannelInstance(PluginGUI* pluginGUI) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for(ChannelInstanceRegistrations::iterator it = m_channelInstanceRegistrations.begin(); it != m_channelInstanceRegistrations.end(); ++it) { | 
					
						
							|  |  |  | 		if(it->m_gui == pluginGUI) { | 
					
						
							|  |  |  | 			m_channelInstanceRegistrations.erase(it); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	renameChannelInstances(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PluginManager::registerSampleSource(const QString& sourceName, PluginInterface* plugin) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-09 10:33:04 +02:00
										 |  |  | 	qDebug() << "PluginManager::registerSampleSource " | 
					
						
							| 
									
										
										
										
											2015-08-09 11:11:28 +02:00
										 |  |  | 			<< plugin->getPluginDescriptor().displayedName.toStdString().c_str() | 
					
						
							|  |  |  | 			<< " with source name " << sourceName.toStdString().c_str(); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	m_sampleSourceRegistrations.append(SampleSourceRegistration(sourceName, plugin)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  | void PluginManager::loadSettings(const Preset* preset) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-09-30 03:46:46 +02:00
										 |  |  | 	fprintf(stderr, "PluginManager::loadSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// copy currently open channels and clear list
 | 
					
						
							|  |  |  | 	ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations; | 
					
						
							|  |  |  | 	m_channelInstanceRegistrations.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 09:24:56 +02:00
										 |  |  | 	for(int i = 0; i < preset->getChannelCount(); i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i); | 
					
						
							|  |  |  | 		ChannelInstanceRegistration reg; | 
					
						
							| 
									
										
										
										
											2015-08-18 09:24:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		// if we have one instance available already, use it
 | 
					
						
							| 
									
										
										
										
											2015-08-18 09:24:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		for(int i = 0; i < openChannels.count(); i++) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-09-30 03:46:46 +02:00
										 |  |  | 			qDebug("PluginManager::loadSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channel)); | 
					
						
							| 
									
										
										
										
											2015-08-18 09:24:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if(openChannels[i].m_channelName == channelConfig.m_channel) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2015-09-30 03:46:46 +02:00
										 |  |  | 				qDebug("PluginManager::loadSettings: channel [%s] found", qPrintable(openChannels[i].m_channelName)); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 				reg = openChannels.takeAt(i); | 
					
						
							|  |  |  | 				m_channelInstanceRegistrations.append(reg); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-08-18 09:24:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		// if we haven't one already, create one
 | 
					
						
							| 
									
										
										
										
											2015-08-18 09:24:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if(reg.m_gui == NULL) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			for(int i = 0; i < m_channelRegistrations.count(); i++) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				if(m_channelRegistrations[i].m_channelName == channelConfig.m_channel) | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2015-09-30 03:46:46 +02:00
										 |  |  | 					qDebug("PluginManager::loadSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel)); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 					reg = ChannelInstanceRegistration(channelConfig.m_channel, m_channelRegistrations[i].m_plugin->createChannel(channelConfig.m_channel)); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-08-18 09:24:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		if(reg.m_gui != NULL) | 
					
						
							| 
									
										
										
										
											2015-08-18 09:24:56 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-09-30 03:46:46 +02:00
										 |  |  | 			qDebug("PluginManager::loadSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channel)); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			reg.m_gui->deserialize(channelConfig.m_config); | 
					
						
							| 
									
										
										
										
											2015-08-18 09:24:56 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// everything, that is still "available" is not needed anymore
 | 
					
						
							| 
									
										
										
										
											2015-08-18 09:24:56 +02:00
										 |  |  | 	for(int i = 0; i < openChannels.count(); i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-09-30 03:46:46 +02:00
										 |  |  | 		qDebug("PluginManager::loadSettings: destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName)); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		openChannels[i].m_gui->destroy(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	renameChannelInstances(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  | 	loadSourceSettings(preset); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PluginManager::loadSourceSettings(const Preset* preset) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	fprintf(stderr, "PluginManager::loadSourceSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 02:47:14 +02:00
										 |  |  | 	if(m_sampleSourcePluginGUI != 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 		const QByteArray* sourceConfig = preset->findBestSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (sourceConfig != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			qDebug() << "PluginManager::loadSettings: deserializing source " << qPrintable(m_sampleSourceId); | 
					
						
							|  |  |  | 			m_sampleSourcePluginGUI->deserialize(*sourceConfig); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-29 03:35:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		qint64 centerFrequency = preset->getCenterFrequency(); | 
					
						
							|  |  |  | 		m_sampleSourcePluginGUI->setCenterFrequency(centerFrequency); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-19 02:07:40 +02:00
										 |  |  | // sort by increasing delta frequency and type (i.e. name)
 | 
					
						
							|  |  |  | bool PluginManager::ChannelInstanceRegistration::operator<(const ChannelInstanceRegistration& other) const { | 
					
						
							|  |  |  | 	if (m_gui && other.m_gui) { | 
					
						
							|  |  |  | 		if (m_gui->getCenterFrequency() == other.m_gui->getCenterFrequency()) { | 
					
						
							|  |  |  | 			return m_gui->getName() < other.m_gui->getName(); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			return m_gui->getCenterFrequency() < other.m_gui->getCenterFrequency(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PluginManager::saveSettings(Preset* preset) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  | 	qDebug("PluginManager::saveSettings"); | 
					
						
							|  |  |  | 	saveSourceSettings(preset); | 
					
						
							| 
									
										
										
										
											2015-09-30 03:46:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-19 02:07:40 +02:00
										 |  |  | 	qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type
 | 
					
						
							| 
									
										
										
										
											2015-09-30 03:46:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for(int i = 0; i < m_channelInstanceRegistrations.count(); i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		preset->addChannel(m_channelInstanceRegistrations[i].m_channelName, m_channelInstanceRegistrations[i].m_gui->serialize()); | 
					
						
							| 
									
										
										
										
											2015-07-19 02:07:40 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  | void PluginManager::saveSourceSettings(Preset* preset) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	qDebug("PluginManager::saveSourceSettings"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(m_sampleSourcePluginGUI != NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		preset->addOrUpdateSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize()); | 
					
						
							|  |  |  | 		//preset->setSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize());
 | 
					
						
							|  |  |  | 		preset->setCenterFrequency(m_sampleSourcePluginGUI->getCenterFrequency()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | void PluginManager::freeAll() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_dspEngine->stopAcquistion(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while(!m_channelInstanceRegistrations.isEmpty()) { | 
					
						
							|  |  |  | 		ChannelInstanceRegistration reg(m_channelInstanceRegistrations.takeLast()); | 
					
						
							|  |  |  | 		reg.m_gui->destroy(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 02:47:14 +02:00
										 |  |  | 	if(m_sampleSourcePluginGUI != NULL) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		m_dspEngine->setSource(NULL); | 
					
						
							| 
									
										
										
										
											2015-08-18 02:47:14 +02:00
										 |  |  | 		m_sampleSourcePluginGUI->destroy(); | 
					
						
							|  |  |  | 		m_sampleSourcePluginGUI = NULL; | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 		m_sampleSourceId.clear(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | bool PluginManager::handleMessage(const Message& message) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-18 02:47:14 +02:00
										 |  |  | 	if (m_sampleSourcePluginGUI != 0) | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-08-18 02:47:14 +02:00
										 |  |  | 		if ((message.getDestination() == 0) || (message.getDestination() == m_sampleSourcePluginGUI)) | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-08-18 02:47:14 +02:00
										 |  |  | 			if (m_sampleSourcePluginGUI->handleMessage(message)) | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 				return true; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	for (ChannelInstanceRegistrations::iterator it = m_channelInstanceRegistrations.begin(); it != m_channelInstanceRegistrations.end(); ++it) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if ((message.getDestination() == 0) || (message.getDestination() == it->m_gui)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if (it->m_gui->handleMessage(message)) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 				return true; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PluginManager::updateSampleSourceDevices() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_sampleSourceDevices.clear(); | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for(int i = 0; i < m_sampleSourceRegistrations.count(); ++i) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		PluginInterface::SampleSourceDevices ssd = m_sampleSourceRegistrations[i].m_plugin->enumSampleSources(); | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		for(int j = 0; j < ssd.count(); ++j) | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			m_sampleSourceDevices.append(SampleSourceDevice(m_sampleSourceRegistrations[i].m_plugin, | 
					
						
							|  |  |  | 					ssd[j].displayedName, | 
					
						
							|  |  |  | 					ssd[j].id, | 
					
						
							|  |  |  | 					ssd[j].serial, | 
					
						
							|  |  |  | 					ssd[j].sequence)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 14:21:02 +02:00
										 |  |  | void PluginManager::fillSampleSourceSelector(QComboBox* comboBox) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	comboBox->clear(); | 
					
						
							| 
									
										
										
										
											2015-10-02 14:21:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for(int i = 0; i < m_sampleSourceDevices.count(); i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		comboBox->addItem(m_sampleSourceDevices[i].m_displayName, i); | 
					
						
							| 
									
										
										
										
											2015-10-02 14:21:56 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 14:19:28 +02:00
										 |  |  | int PluginManager::selectSampleSourceByIndex(int index) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-02 14:19:28 +02:00
										 |  |  | 	qDebug("PluginManager::selectSampleSourceByIndex: index: %d", index); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	m_dspEngine->stopAcquistion(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 02:47:14 +02:00
										 |  |  | 	if(m_sampleSourcePluginGUI != NULL) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		m_dspEngine->stopAcquistion(); | 
					
						
							|  |  |  | 		m_dspEngine->setSource(NULL); | 
					
						
							| 
									
										
										
										
											2015-08-18 02:47:14 +02:00
										 |  |  | 		m_sampleSourcePluginGUI->destroy(); | 
					
						
							|  |  |  | 		m_sampleSourcePluginGUI = NULL; | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 		m_sampleSourceId.clear(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 14:19:28 +02:00
										 |  |  | 	if (m_sampleSourceDevices.count() == 0) | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-10-02 14:19:28 +02:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 14:19:28 +02:00
										 |  |  | 	if (index < 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (index >= m_sampleSourceDevices.count()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		index = 0; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId; | 
					
						
							|  |  |  | 	m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial; | 
					
						
							|  |  |  | 	m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-03 23:59:02 +02:00
										 |  |  | 	qDebug() << "PluginManager::selectSampleSourceByIndex: m_sampleSource at index " << index | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 			<< " id: " << m_sampleSourceId.toStdString().c_str() | 
					
						
							|  |  |  | 			<< " ser: " << m_sampleSourceSerial.toStdString().c_str() | 
					
						
							|  |  |  | 			<< " seq: " << m_sampleSourceSequence; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-30 08:55:58 +02:00
										 |  |  | 	m_sampleSourcePluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceId); | 
					
						
							| 
									
										
										
										
											2015-10-03 23:59:02 +02:00
										 |  |  | 	m_dspEngine->setSourceSequence(m_sampleSourceSequence); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return index; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | int PluginManager::selectFirstSampleSource(const QString& sourceId) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 	qDebug("PluginManager::selectFirstSampleSource by id: [%s]", qPrintable(sourceId)); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	int index = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_dspEngine->stopAcquistion(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 02:47:14 +02:00
										 |  |  | 	if(m_sampleSourcePluginGUI != NULL) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		m_dspEngine->stopAcquistion(); | 
					
						
							|  |  |  | 		m_dspEngine->setSource(NULL); | 
					
						
							| 
									
										
										
										
											2015-08-18 02:47:14 +02:00
										 |  |  | 		m_sampleSourcePluginGUI->destroy(); | 
					
						
							|  |  |  | 		m_sampleSourcePluginGUI = NULL; | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 		m_sampleSourceId.clear(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 	for (int i = 0; i < m_sampleSourceDevices.count(); i++) | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		qDebug("*** %s vs %s", qPrintable(m_sampleSourceDevices[i].m_sourceId), qPrintable(sourceId)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(m_sampleSourceDevices[i].m_sourceId == sourceId) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			index = i; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(index == -1) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		if(m_sampleSourceDevices.count() > 0) | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			index = 0; | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId; | 
					
						
							|  |  |  | 	m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial; | 
					
						
							|  |  |  | 	m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qDebug() << "m_sampleSource at index " << index | 
					
						
							|  |  |  | 			<< " id: " << m_sampleSourceId.toStdString().c_str() | 
					
						
							|  |  |  | 			<< " ser: " << m_sampleSourceSerial.toStdString().c_str() | 
					
						
							|  |  |  | 			<< " seq: " << m_sampleSourceSequence; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-30 08:55:58 +02:00
										 |  |  | 	m_sampleSourcePluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceId); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return index; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | int PluginManager::selectSampleSourceBySerialOrSequence(const QString& sourceId, const QString& sourceSerial, int sourceSequence) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	qDebug("PluginManager::selectSampleSourceBySequence by sequence: id: %s ser: %s seq: %d", qPrintable(sourceId), qPrintable(sourceSerial), sourceSequence); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int index = -1; | 
					
						
							|  |  |  | 	int index_matchingSequence = -1; | 
					
						
							|  |  |  | 	int index_firstOfKind = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < m_sampleSourceDevices.count(); i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (m_sampleSourceDevices[i].m_sourceId == sourceId) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			index_firstOfKind = i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (m_sampleSourceDevices[i].m_sourceSerial == sourceSerial) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				index = i; // exact match
 | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (m_sampleSourceDevices[i].m_sourceSequence == sourceSequence) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				index_matchingSequence = i; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(index == -1) // no exact match
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (index_matchingSequence == -1) // no matching sequence
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if (index_firstOfKind == -1) // no matching device type
 | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				if(m_sampleSourceDevices.count() > 0) // take first if any
 | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					index = 0; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					return -1; // return if no device attached
 | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				index = index_firstOfKind; // take first that matches device type
 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			index = index_matchingSequence; // take the one that matches the sequence in the device type
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId; | 
					
						
							|  |  |  | 	m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial; | 
					
						
							|  |  |  | 	m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qDebug() << "PluginManager::selectSampleSourceBySequence by sequence:  m_sampleSource at index " << index | 
					
						
							|  |  |  | 			<< " id: " << qPrintable(m_sampleSourceId) | 
					
						
							|  |  |  | 			<< " ser: " << qPrintable(m_sampleSourceSerial) | 
					
						
							|  |  |  | 			<< " seq: " << m_sampleSourceSequence; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_sampleSourcePluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return index; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | void PluginManager::loadPlugins(const QDir& dir) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QDir pluginsDir(dir); | 
					
						
							| 
									
										
										
										
											2015-08-09 04:09:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	foreach (QString fileName, pluginsDir.entryList(QDir::Files)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-03-08 13:58:53 +01:00
										 |  |  | 		if (fileName.endsWith(".so") || fileName.endsWith(".dll")) | 
					
						
							| 
									
										
										
										
											2015-08-26 02:03:20 +02:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			qDebug() << "PluginManager::loadPlugins: fileName: " << qPrintable(fileName); | 
					
						
							| 
									
										
										
										
											2015-08-09 04:09:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-26 02:03:20 +02:00
										 |  |  | 			QPluginLoader* loader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName)); | 
					
						
							|  |  |  | 			PluginInterface* plugin = qobject_cast<PluginInterface*>(loader->instance()); | 
					
						
							| 
									
										
										
										
											2015-08-09 04:09:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-26 02:03:20 +02:00
										 |  |  | 			if (loader->isLoaded()) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				qWarning("PluginManager::loadPlugins: loaded plugin %s", qPrintable(fileName)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				qWarning() << "PluginManager::loadPlugins: " << qPrintable(loader->errorString()); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (plugin != 0) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				m_plugins.append(Plugin(fileName, loader, plugin)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				loader->unload(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-08-29 03:09:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			delete loader; // Valgrind memcheck
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-08-09 04:09:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-26 02:03:20 +02:00
										 |  |  | 	// recursive calls on subdirectories
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	foreach (QString dirName, pluginsDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		loadPlugins(pluginsDir.absoluteFilePath(dirName)); | 
					
						
							| 
									
										
										
										
											2015-08-09 04:09:05 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PluginManager::renameChannelInstances() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for(int i = 0; i < m_channelInstanceRegistrations.count(); i++) { | 
					
						
							|  |  |  | 		m_channelInstanceRegistrations[i].m_gui->setName(QString("%1:%2").arg(m_channelInstanceRegistrations[i].m_channelName).arg(i)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |