Commit 1856e1cb authored by Don Gagne's avatar Don Gagne

Return AutoPilotPlugin as QSharedPointer

If Facts are referenced from FactPanelController, we need to reference
count the AutoPilotPlugin such that it doesn’t get destroyed until
after the FactPanelController is destroyed.
parent d01987c1
...@@ -43,6 +43,11 @@ AutoPilotPlugin::AutoPilotPlugin(UASInterface* uas, QObject* parent) : ...@@ -43,6 +43,11 @@ AutoPilotPlugin::AutoPilotPlugin(UASInterface* uas, QObject* parent) :
connect(this, &AutoPilotPlugin::pluginReadyChanged, this, &AutoPilotPlugin::_pluginReadyChanged); connect(this, &AutoPilotPlugin::pluginReadyChanged, this, &AutoPilotPlugin::_pluginReadyChanged);
} }
AutoPilotPlugin::~AutoPilotPlugin()
{
}
void AutoPilotPlugin::_uasDisconnected(void) void AutoPilotPlugin::_uasDisconnected(void)
{ {
_pluginReady = false; _pluginReady = false;
......
...@@ -51,6 +51,7 @@ class AutoPilotPlugin : public QObject ...@@ -51,6 +51,7 @@ class AutoPilotPlugin : public QObject
public: public:
AutoPilotPlugin(UASInterface* uas, QObject* parent); AutoPilotPlugin(UASInterface* uas, QObject* parent);
~AutoPilotPlugin();
/// true: plugin is ready for use, plugin should no longer be used /// true: plugin is ready for use, plugin should no longer be used
Q_PROPERTY(bool pluginReady READ pluginReady NOTIFY pluginReadyChanged) Q_PROPERTY(bool pluginReady READ pluginReady NOTIFY pluginReadyChanged)
......
...@@ -74,13 +74,13 @@ void AutoPilotPluginManager::_uasCreated(UASInterface* uas) ...@@ -74,13 +74,13 @@ void AutoPilotPluginManager::_uasCreated(UASInterface* uas)
case MAV_AUTOPILOT_PX4: case MAV_AUTOPILOT_PX4:
plugin = new PX4AutoPilotPlugin(uas, this); plugin = new PX4AutoPilotPlugin(uas, this);
Q_CHECK_PTR(plugin); Q_CHECK_PTR(plugin);
_pluginMap[MAV_AUTOPILOT_PX4][uasId] = plugin; _pluginMap[MAV_AUTOPILOT_PX4][uasId] = QSharedPointer<AutoPilotPlugin>(plugin);
break; break;
case MAV_AUTOPILOT_GENERIC: case MAV_AUTOPILOT_GENERIC:
default: default:
plugin = new GenericAutoPilotPlugin(uas, this); plugin = new GenericAutoPilotPlugin(uas, this);
Q_CHECK_PTR(plugin); Q_CHECK_PTR(plugin);
_pluginMap[MAV_AUTOPILOT_GENERIC][uasId] = plugin; _pluginMap[MAV_AUTOPILOT_GENERIC][uasId] = QSharedPointer<AutoPilotPlugin>(plugin);
} }
} }
...@@ -94,12 +94,12 @@ void AutoPilotPluginManager::_uasDeleted(UASInterface* uas) ...@@ -94,12 +94,12 @@ void AutoPilotPluginManager::_uasDeleted(UASInterface* uas)
Q_ASSERT(uasId != 0); Q_ASSERT(uasId != 0);
if (_pluginMap.contains(autopilotType) && _pluginMap[autopilotType].contains(uasId)) { if (_pluginMap.contains(autopilotType) && _pluginMap[autopilotType].contains(uasId)) {
delete _pluginMap[autopilotType][uasId]; _pluginMap[autopilotType][uasId].clear();
_pluginMap[autopilotType].remove(uasId); _pluginMap[autopilotType].remove(uasId);
} }
} }
AutoPilotPlugin* AutoPilotPluginManager::getInstanceForAutoPilotPlugin(UASInterface* uas) QSharedPointer<AutoPilotPlugin> AutoPilotPluginManager::getInstanceForAutoPilotPlugin(UASInterface* uas)
{ {
Q_ASSERT(uas); Q_ASSERT(uas);
......
...@@ -47,9 +47,10 @@ class AutoPilotPluginManager : public QGCSingleton ...@@ -47,9 +47,10 @@ class AutoPilotPluginManager : public QGCSingleton
DECLARE_QGC_SINGLETON(AutoPilotPluginManager, AutoPilotPluginManager) DECLARE_QGC_SINGLETON(AutoPilotPluginManager, AutoPilotPluginManager)
public: public:
/// Returns the singleton AutoPilotPlugin instance for the specified uas. /// Returns the singleton AutoPilotPlugin instance for the specified uas. Returned as QSharedPointer
/// to prevent shutdown ordering problems with Qml destruction happening after Facts are destroyed.
/// @param uas Uas to get plugin for /// @param uas Uas to get plugin for
AutoPilotPlugin* getInstanceForAutoPilotPlugin(UASInterface* uas); QSharedPointer<AutoPilotPlugin> getInstanceForAutoPilotPlugin(UASInterface* uas);
typedef struct { typedef struct {
uint8_t baseMode; uint8_t baseMode;
...@@ -73,7 +74,7 @@ private: ...@@ -73,7 +74,7 @@ private:
MAV_AUTOPILOT _installedAutopilotType(MAV_AUTOPILOT autopilot); MAV_AUTOPILOT _installedAutopilotType(MAV_AUTOPILOT autopilot);
QMap<MAV_AUTOPILOT, QMap<int, AutoPilotPlugin*> > _pluginMap; ///< Map of AutoPilot plugins _pluginMap[MAV_TYPE][UASid] QMap<MAV_AUTOPILOT, QMap<int, QSharedPointer<AutoPilotPlugin> > > _pluginMap; ///< Map of AutoPilot plugins _pluginMap[MAV_TYPE][UASid]
}; };
#endif #endif
...@@ -62,8 +62,8 @@ protected: ...@@ -62,8 +62,8 @@ protected:
/// Report a missing parameter to the FactPanel Qml element /// Report a missing parameter to the FactPanel Qml element
void _reportMissingParameter(int componentId, const QString& name); void _reportMissingParameter(int componentId, const QString& name);
UASInterface* _uas; UASInterface* _uas;
AutoPilotPlugin* _autopilot; QSharedPointer<AutoPilotPlugin> _autopilot;
private slots: private slots:
void _checkForMissingFactPanel(void); void _checkForMissingFactPanel(void);
......
...@@ -64,7 +64,7 @@ void FactSystemTestBase::_init(MAV_AUTOPILOT autopilot) ...@@ -64,7 +64,7 @@ void FactSystemTestBase::_init(MAV_AUTOPILOT autopilot)
AutoPilotPluginManager* pluginMgr = AutoPilotPluginManager::instance(); AutoPilotPluginManager* pluginMgr = AutoPilotPluginManager::instance();
Q_ASSERT(pluginMgr); Q_ASSERT(pluginMgr);
_plugin = pluginMgr->getInstanceForAutoPilotPlugin(_uas); _plugin = pluginMgr->getInstanceForAutoPilotPlugin(_uas).data();
Q_ASSERT(_plugin); Q_ASSERT(_plugin);
// Wait for the plugin to be ready // Wait for the plugin to be ready
......
...@@ -83,7 +83,7 @@ QGCView { ...@@ -83,7 +83,7 @@ QGCView {
} }
Repeater { Repeater {
model: autopilot ? controller.getFactsForGroup(componentId, group) : 0 model: controller.getFactsForGroup(componentId, group)
Column { Column {
property Fact modelFact: controller.getParameterFact(componentId, modelData) property Fact modelFact: controller.getParameterFact(componentId, modelData)
......
...@@ -42,6 +42,11 @@ ParameterEditorController::ParameterEditorController(void) ...@@ -42,6 +42,11 @@ ParameterEditorController::ParameterEditorController(void)
} }
} }
ParameterEditorController::~ParameterEditorController()
{
}
QStringList ParameterEditorController::getGroupsForComponent(int componentId) QStringList ParameterEditorController::getGroupsForComponent(int componentId)
{ {
const QMap<int, QMap<QString, QStringList> >& groupMap = _autopilot->getGroupMap(); const QMap<int, QMap<QString, QStringList> >& groupMap = _autopilot->getGroupMap();
......
...@@ -40,6 +40,7 @@ class ParameterEditorController : public FactPanelController ...@@ -40,6 +40,7 @@ class ParameterEditorController : public FactPanelController
public: public:
ParameterEditorController(void); ParameterEditorController(void);
~ParameterEditorController();
Q_PROPERTY(QStringList componentIds MEMBER _componentIds CONSTANT) Q_PROPERTY(QStringList componentIds MEMBER _componentIds CONSTANT)
......
...@@ -84,7 +84,7 @@ void SetupView::_setActiveUAS(UASInterface* uas) ...@@ -84,7 +84,7 @@ void SetupView::_setActiveUAS(UASInterface* uas)
_uasCurrent = uas; _uasCurrent = uas;
if (_uasCurrent) { if (_uasCurrent) {
_autoPilotPlugin = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_uasCurrent); _autoPilotPlugin = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_uasCurrent).data();
_pluginReadyChanged(_autoPilotPlugin->pluginReady()); _pluginReadyChanged(_autoPilotPlugin->pluginReady());
connect(_autoPilotPlugin, &AutoPilotPlugin::pluginReadyChanged, this, &SetupView::_pluginReadyChanged); connect(_autoPilotPlugin, &AutoPilotPlugin::pluginReadyChanged, this, &SetupView::_pluginReadyChanged);
} }
......
...@@ -71,7 +71,7 @@ void SetupViewTest::_clickThrough_test(void) ...@@ -71,7 +71,7 @@ void SetupViewTest::_clickThrough_test(void)
linkMgr->connectLink(link); linkMgr->connectLink(link);
QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through
AutoPilotPlugin* autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(UASManager::instance()->getActiveUAS()); AutoPilotPlugin* autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(UASManager::instance()->getActiveUAS()).data();
Q_ASSERT(autopilot); Q_ASSERT(autopilot);
QSignalSpy spyPlugin(autopilot, SIGNAL(pluginReadyChanged(bool))); QSignalSpy spyPlugin(autopilot, SIGNAL(pluginReadyChanged(bool)));
......
...@@ -41,13 +41,13 @@ void ViewWidgetController::_activeUasChanged(UASInterface* currentUas) ...@@ -41,13 +41,13 @@ void ViewWidgetController::_activeUasChanged(UASInterface* currentUas)
if (_uas) { if (_uas) {
disconnect(_autopilot, &AutoPilotPlugin::pluginReadyChanged, this, &ViewWidgetController::_pluginReadyChanged); disconnect(_autopilot, &AutoPilotPlugin::pluginReadyChanged, this, &ViewWidgetController::_pluginReadyChanged);
_uas = NULL; _uas = NULL;
_autopilot = NULL; _autopilot = NULL;
emit pluginDisconnected(); emit pluginDisconnected();
} }
if (currentUas) { if (currentUas) {
_uas = currentUas; _uas = currentUas;
_autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(currentUas); _autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(currentUas).data();
Q_ASSERT(_autopilot); Q_ASSERT(_autopilot);
connect(_autopilot, &AutoPilotPlugin::pluginReadyChanged, this, &ViewWidgetController::_pluginReadyChanged); connect(_autopilot, &AutoPilotPlugin::pluginReadyChanged, this, &ViewWidgetController::_pluginReadyChanged);
......
...@@ -48,9 +48,9 @@ private slots: ...@@ -48,9 +48,9 @@ private slots:
void _pluginReadyChanged(bool pluginReady); void _pluginReadyChanged(bool pluginReady);
private: private:
AutoPilotPlugin* _autopilot; AutoPilotPlugin* _autopilot;
UASManagerInterface* _uasManager; UASManagerInterface* _uasManager;
UASInterface* _uas; UASInterface* _uas;
}; };
#endif #endif
\ No newline at end of file
...@@ -151,7 +151,7 @@ void PX4RCCalibrationTest::init(void) ...@@ -151,7 +151,7 @@ void PX4RCCalibrationTest::init(void)
LinkManager::instance()->connectLink(_mockLink); LinkManager::instance()->connectLink(_mockLink);
QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through
_autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(UASManager::instance()->getActiveUAS()); _autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(UASManager::instance()->getActiveUAS()).data();
Q_ASSERT(_autopilot); Q_ASSERT(_autopilot);
QSignalSpy spyPlugin(_autopilot, SIGNAL(pluginReadyChanged(bool))); QSignalSpy spyPlugin(_autopilot, SIGNAL(pluginReadyChanged(bool)));
......
...@@ -101,7 +101,7 @@ ParamLoader::ParamLoader(QString paramName, UASInterface* uas, QObject* parent) ...@@ -101,7 +101,7 @@ ParamLoader::ParamLoader(QString paramName, UASInterface* uas, QObject* parent)
_paramName(paramName), _paramName(paramName),
_paramReceived(false) _paramReceived(false)
{ {
_autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_uas); _autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_uas).data();
Q_ASSERT(_autopilot); Q_ASSERT(_autopilot);
} }
......
...@@ -256,8 +256,8 @@ private: ...@@ -256,8 +256,8 @@ private:
RCValueWidget* _rgRCValueMonitorWidget[_chanMax]; ///< Array of radio channel value widgets RCValueWidget* _rgRCValueMonitorWidget[_chanMax]; ///< Array of radio channel value widgets
QLabel* _rgRCValueMonitorLabel[_chanMax]; ///< Array of radio channel value labels QLabel* _rgRCValueMonitorLabel[_chanMax]; ///< Array of radio channel value labels
UASInterface* _uas; UASInterface* _uas;
AutoPilotPlugin* _autopilot; QSharedPointer<AutoPilotPlugin> _autopilot;
Ui::PX4RCCalibration* _ui; Ui::PX4RCCalibration* _ui;
......
...@@ -282,7 +282,7 @@ void MainToolBar::_forgetUAS(UASInterface* uas) ...@@ -282,7 +282,7 @@ void MainToolBar::_forgetUAS(UASInterface* uas)
if (_mav != NULL && _mav == uas) { if (_mav != NULL && _mav == uas) {
disconnect(UASMessageHandler::instance(), &UASMessageHandler::textMessageCountChanged, this, &MainToolBar::_handleTextMessage); disconnect(UASMessageHandler::instance(), &UASMessageHandler::textMessageCountChanged, this, &MainToolBar::_handleTextMessage);
disconnect(_mav, &UASInterface::remoteControlRSSIChanged, this, &MainToolBar::_remoteControlRSSIChanged); disconnect(_mav, &UASInterface::remoteControlRSSIChanged, this, &MainToolBar::_remoteControlRSSIChanged);
disconnect(AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_mav), &AutoPilotPlugin::parameterListProgress, this, &MainToolBar::_setProgressBarValue); disconnect(AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_mav).data(), &AutoPilotPlugin::parameterListProgress, this, &MainToolBar::_setProgressBarValue);
_mav = NULL; _mav = NULL;
} }
} }
...@@ -302,7 +302,7 @@ void MainToolBar::_setActiveUAS(UASInterface* active) ...@@ -302,7 +302,7 @@ void MainToolBar::_setActiveUAS(UASInterface* active)
{ {
connect(UASMessageHandler::instance(), &UASMessageHandler::textMessageCountChanged, this, &MainToolBar::_handleTextMessage); connect(UASMessageHandler::instance(), &UASMessageHandler::textMessageCountChanged, this, &MainToolBar::_handleTextMessage);
connect(_mav, &UASInterface::remoteControlRSSIChanged, this, &MainToolBar::_remoteControlRSSIChanged); connect(_mav, &UASInterface::remoteControlRSSIChanged, this, &MainToolBar::_remoteControlRSSIChanged);
connect(AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_mav), &AutoPilotPlugin::parameterListProgress, this, &MainToolBar::_setProgressBarValue); connect(AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_mav).data(), &AutoPilotPlugin::parameterListProgress, this, &MainToolBar::_setProgressBarValue);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment