1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-18 07:35:47 -05:00

Multi device support: fixed segfaults when changing device

This commit is contained in:
f4exb 2016-05-17 11:06:56 +02:00
parent 5a8d05bfaf
commit cae0012399
3 changed files with 75 additions and 57 deletions

View File

@ -155,6 +155,12 @@ void DeviceAPI::setSampleSourceSequence(int sequence)
void DeviceAPI::setSampleSourcePluginGUI(PluginGUI *gui) void DeviceAPI::setSampleSourcePluginGUI(PluginGUI *gui)
{ {
if (m_sampleSourcePluginGUI != 0)
{
m_sampleSourcePluginGUI->destroy();
m_sampleSourceId.clear();
}
m_sampleSourcePluginGUI = gui; m_sampleSourcePluginGUI = gui;
} }

View File

@ -17,11 +17,11 @@
PluginManager::PluginManager(MainWindow* mainWindow, QObject* parent) : PluginManager::PluginManager(MainWindow* mainWindow, QObject* parent) :
QObject(parent), QObject(parent),
m_pluginAPI(this, mainWindow), m_pluginAPI(this, mainWindow),
m_mainWindow(mainWindow), m_mainWindow(mainWindow)//,
m_sampleSourceId(), // m_sampleSourceId(),
m_sampleSourceSerial(), // m_sampleSourceSerial(),
m_sampleSourceSequence(0), // m_sampleSourceSequence(0),
m_sampleSourcePluginGUI(NULL) // m_sampleSourcePluginGUI(NULL)
{ {
} }
@ -99,16 +99,6 @@ int PluginManager::selectSampleSourceByIndex(int index, DeviceAPI *deviceAPI)
{ {
qDebug("PluginManager::selectSampleSourceByIndex: index: %d", index); qDebug("PluginManager::selectSampleSourceByIndex: index: %d", index);
deviceAPI->stopAcquisition();
if(m_sampleSourcePluginGUI != NULL) {
deviceAPI->stopAcquisition();
deviceAPI->setSource(0);
m_sampleSourcePluginGUI->destroy();
m_sampleSourcePluginGUI = NULL;
m_sampleSourceId.clear();
}
if (m_sampleSourceDevices.count() == 0) if (m_sampleSourceDevices.count() == 0)
{ {
return -1; return -1;
@ -124,18 +114,32 @@ int PluginManager::selectSampleSourceByIndex(int index, DeviceAPI *deviceAPI)
index = 0; index = 0;
} }
m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId; // deviceAPI->stopAcquisition();
m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial; //
m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence; // if(m_sampleSourcePluginGUI != NULL) {
// deviceAPI->stopAcquisition();
// deviceAPI->setSource(0);
// m_sampleSourcePluginGUI->destroy();
// m_sampleSourcePluginGUI = NULL;
// m_sampleSourceId.clear();
// }
//
// m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId;
// m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial;
// m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence;
qDebug() << "PluginManager::selectSampleSourceByIndex: m_sampleSource at index " << index qDebug() << "PluginManager::selectSampleSourceByIndex: m_sampleSource at index " << index
<< " id: " << m_sampleSourceId.toStdString().c_str() << " id: " << m_sampleSourceDevices[index].m_sourceId.toStdString().c_str()
<< " ser: " << m_sampleSourceSerial.toStdString().c_str() << " ser: " << m_sampleSourceDevices[index].m_sourceSerial.toStdString().c_str()
<< " seq: " << m_sampleSourceSequence; << " seq: " << m_sampleSourceDevices[index].m_sourceSequence;
deviceAPI->stopAcquisition();
deviceAPI->setSampleSourcePluginGUI(0); // this effectively destroys the previous GUI if it exists
QWidget *gui; QWidget *gui;
PluginGUI *pluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceId, &gui, deviceAPI); PluginGUI *pluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceDevices[index].m_sourceId, &gui, deviceAPI);
m_sampleSourcePluginGUI = pluginGUI;
// m_sampleSourcePluginGUI = pluginGUI;
deviceAPI->setSampleSourceSequence(m_sampleSourceDevices[index].m_sourceSequence); deviceAPI->setSampleSourceSequence(m_sampleSourceDevices[index].m_sourceSequence);
deviceAPI->setSampleSourceId(m_sampleSourceDevices[index].m_sourceId); deviceAPI->setSampleSourceId(m_sampleSourceDevices[index].m_sourceId);
deviceAPI->setSampleSourceSerial(m_sampleSourceDevices[index].m_sourceSerial); deviceAPI->setSampleSourceSerial(m_sampleSourceDevices[index].m_sourceSerial);
@ -151,15 +155,15 @@ int PluginManager::selectFirstSampleSource(const QString& sourceId, DeviceAPI *d
int index = -1; int index = -1;
deviceAPI->stopAcquisition(); // deviceAPI->stopAcquisition();
//
if(m_sampleSourcePluginGUI != NULL) { // if(m_sampleSourcePluginGUI != NULL) {
deviceAPI->stopAcquisition(); // deviceAPI->stopAcquisition();
deviceAPI->setSource(0); // deviceAPI->setSource(0);
m_sampleSourcePluginGUI->destroy(); // m_sampleSourcePluginGUI->destroy();
m_sampleSourcePluginGUI = NULL; // m_sampleSourcePluginGUI = NULL;
m_sampleSourceId.clear(); // m_sampleSourceId.clear();
} // }
for (int i = 0; i < m_sampleSourceDevices.count(); i++) for (int i = 0; i < m_sampleSourceDevices.count(); i++)
{ {
@ -184,18 +188,22 @@ int PluginManager::selectFirstSampleSource(const QString& sourceId, DeviceAPI *d
} }
} }
m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId; // m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId;
m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial; // m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial;
m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence; // m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence;
qDebug() << "m_sampleSource at index " << index qDebug() << "PluginManager::selectFirstSampleSource: m_sampleSource at index " << index
<< " id: " << m_sampleSourceId.toStdString().c_str() << " id: " << m_sampleSourceDevices[index].m_sourceId.toStdString().c_str()
<< " ser: " << m_sampleSourceSerial.toStdString().c_str() << " ser: " << m_sampleSourceDevices[index].m_sourceSerial.toStdString().c_str()
<< " seq: " << m_sampleSourceSequence; << " seq: " << m_sampleSourceDevices[index].m_sourceSequence;
deviceAPI->stopAcquisition();
deviceAPI->setSampleSourcePluginGUI(0); // this effectively destroys the previous GUI if it exists
QWidget *gui; QWidget *gui;
PluginGUI *pluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceId, &gui, deviceAPI); PluginGUI *pluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceDevices[index].m_sourceId, &gui, deviceAPI);
m_sampleSourcePluginGUI = pluginGUI;
// m_sampleSourcePluginGUI = pluginGUI;
deviceAPI->setSampleSourceSequence(m_sampleSourceDevices[index].m_sourceSequence); deviceAPI->setSampleSourceSequence(m_sampleSourceDevices[index].m_sourceSequence);
deviceAPI->setSampleSourceId(m_sampleSourceDevices[index].m_sourceId); deviceAPI->setSampleSourceId(m_sampleSourceDevices[index].m_sourceId);
deviceAPI->setSampleSourceSerial(m_sampleSourceDevices[index].m_sourceSerial); deviceAPI->setSampleSourceSerial(m_sampleSourceDevices[index].m_sourceSerial);
@ -258,18 +266,22 @@ int PluginManager::selectSampleSourceBySerialOrSequence(const QString& sourceId,
} }
} }
m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId; // m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId;
m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial; // m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial;
m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence; // m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence;
qDebug() << "PluginManager::selectSampleSourceBySequence by sequence: m_sampleSource at index " << index qDebug() << "PluginManager::selectSampleSourceBySequence: m_sampleSource at index " << index
<< " id: " << qPrintable(m_sampleSourceId) << " id: " << m_sampleSourceDevices[index].m_sourceId.toStdString().c_str()
<< " ser: " << qPrintable(m_sampleSourceSerial) << " ser: " << m_sampleSourceDevices[index].m_sourceSerial.toStdString().c_str()
<< " seq: " << m_sampleSourceSequence; << " seq: " << m_sampleSourceDevices[index].m_sourceSequence;
deviceAPI->stopAcquisition();
deviceAPI->setSampleSourcePluginGUI(0); // this effectively destroys the previous GUI if it exists
QWidget *gui; QWidget *gui;
PluginGUI *pluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceId, &gui, deviceAPI); PluginGUI *pluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceDevices[index].m_sourceId, &gui, deviceAPI);
m_sampleSourcePluginGUI = pluginGUI;
// m_sampleSourcePluginGUI = pluginGUI;
deviceAPI->setSampleSourceSequence(m_sampleSourceDevices[index].m_sourceSequence); deviceAPI->setSampleSourceSequence(m_sampleSourceDevices[index].m_sourceSequence);
deviceAPI->setSampleSourceId(m_sampleSourceDevices[index].m_sourceId); deviceAPI->setSampleSourceId(m_sampleSourceDevices[index].m_sourceId);
deviceAPI->setSampleSourceSerial(m_sampleSourceDevices[index].m_sourceSerial); deviceAPI->setSampleSourceSerial(m_sampleSourceDevices[index].m_sourceSerial);

View File

@ -99,10 +99,10 @@ private:
SampleSourceRegistrations m_sampleSourceRegistrations; //!< Input source plugins (one per device kind) register here SampleSourceRegistrations m_sampleSourceRegistrations; //!< Input source plugins (one per device kind) register here
SampleSourceDevices m_sampleSourceDevices; //!< Instances of input sources present in the system SampleSourceDevices m_sampleSourceDevices; //!< Instances of input sources present in the system
QString m_sampleSourceId; // QString m_sampleSourceId;
QString m_sampleSourceSerial; // QString m_sampleSourceSerial;
int m_sampleSourceSequence; // int m_sampleSourceSequence;
PluginGUI* m_sampleSourcePluginGUI; // PluginGUI* m_sampleSourcePluginGUI;
void loadPlugins(const QDir& dir); void loadPlugins(const QDir& dir);