From 9f043e9e2ee7e2f46a80a906aba15c1c9fc1b5f2 Mon Sep 17 00:00:00 2001 From: Holden Date: Sat, 9 Nov 2024 06:59:20 -0500 Subject: [PATCH] Convert FirmwarePluginManager to Singleton --- src/FirmwarePlugin/FirmwarePluginManager.cc | 52 ++++++++++++------- src/FirmwarePlugin/FirmwarePluginManager.h | 29 +++++++---- src/MissionManager/MissionCommandTree.cc | 6 +-- src/MissionManager/PlanMasterController.cc | 4 +- src/QGCApplication.cc | 1 - src/QGCToolbox.cc | 3 -- src/QGCToolbox.h | 3 -- src/QmlControls/QGroundControlQmlGlobal.cc | 9 ++-- src/QmlControls/QGroundControlQmlGlobal.h | 1 - src/Vehicle/Components/CompInfoParam.cc | 5 +- src/Vehicle/MultiVehicleManager.cc | 6 +-- src/Vehicle/MultiVehicleManager.h | 2 - src/Vehicle/Vehicle.cc | 8 +-- src/Vehicle/Vehicle.h | 4 -- .../MissionCommandTreeEditorTest.cc | 4 +- test/MissionManager/MissionCommandTreeTest.cc | 7 +-- 16 files changed, 71 insertions(+), 73 deletions(-) diff --git a/src/FirmwarePlugin/FirmwarePluginManager.cc b/src/FirmwarePlugin/FirmwarePluginManager.cc index 8a82ac48c55..f337430e2ee 100644 --- a/src/FirmwarePlugin/FirmwarePluginManager.cc +++ b/src/FirmwarePlugin/FirmwarePluginManager.cc @@ -14,54 +14,67 @@ #include "FirmwarePluginManager.h" #include "FirmwarePlugin.h" #include "FirmwarePluginFactory.h" +#include "QGCLoggingCategory.h" -FirmwarePluginManager::FirmwarePluginManager(QGCApplication* app, QGCToolbox* toolbox) - : QGCTool(app, toolbox) - , _genericFirmwarePlugin(nullptr) -{ +#include + +QGC_LOGGING_CATEGORY(FirmwarePluginManagerLog, "qgc.firmwareplugin.firmwarepluginmanager"); + +Q_APPLICATION_STATIC(FirmwarePluginManager, _firmwarePluginManagerInstance); +FirmwarePluginManager::FirmwarePluginManager(QObject *parent) + : QObject(parent) +{ + // qCDebug(FirmwarePluginManagerLog) << Q_FUNC_INFO << this; } FirmwarePluginManager::~FirmwarePluginManager() { + // qCDebug(FirmwarePluginManagerLog) << Q_FUNC_INFO << this; + delete _genericFirmwarePlugin; } -QList FirmwarePluginManager::supportedFirmwareClasses(void) +FirmwarePluginManager *FirmwarePluginManager::instance() +{ + return _firmwarePluginManagerInstance(); +} + +QList FirmwarePluginManager::supportedFirmwareClasses() { if (_supportedFirmwareClasses.isEmpty()) { - QList factoryList = FirmwarePluginFactoryRegister::instance()->pluginFactories(); - for (int i = 0; i < factoryList.count(); i++) { - _supportedFirmwareClasses.append(factoryList[i]->supportedFirmwareClasses()); + const QList factoryList = FirmwarePluginFactoryRegister::instance()->pluginFactories(); + for (const FirmwarePluginFactory *factory: factoryList) { + _supportedFirmwareClasses.append(factory->supportedFirmwareClasses()); } _supportedFirmwareClasses.append(QGCMAVLink::FirmwareClassGeneric); } + return _supportedFirmwareClasses; } QList FirmwarePluginManager::supportedVehicleClasses(QGCMAVLink::FirmwareClass_t firmwareClass) { QList vehicleClasses; - - FirmwarePluginFactory* factory = _findPluginFactory(firmwareClass); + const FirmwarePluginFactory *const factory = _findPluginFactory(firmwareClass); if (factory) { vehicleClasses = factory->supportedVehicleClasses(); } else if (firmwareClass == QGCMAVLink::FirmwareClassGeneric) { // Generic supports all specific vehicle class vehicleClasses = QGCMAVLink::allVehicleClasses(); - vehicleClasses.removeOne(QGCMAVLink::VehicleClassGeneric); + (void) vehicleClasses.removeOne(QGCMAVLink::VehicleClassGeneric); } else { - qWarning() << "Request for unknown firmware plugin factory" << firmwareClass; + qCWarning(FirmwarePluginManagerLog) << "Request for unknown firmware plugin factory" << firmwareClass; } return vehicleClasses; } -FirmwarePlugin* FirmwarePluginManager::firmwarePluginForAutopilot(MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType) +FirmwarePlugin *FirmwarePluginManager::firmwarePluginForAutopilot(MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType) { - FirmwarePluginFactory* factory = _findPluginFactory(firmwareType); - FirmwarePlugin* plugin = nullptr; + FirmwarePluginFactory *const factory = _findPluginFactory(firmwareType); + FirmwarePlugin *plugin = nullptr; if (factory) { plugin = factory->firmwarePluginForAutopilot(firmwareType, vehicleType); @@ -70,7 +83,7 @@ FirmwarePlugin* FirmwarePluginManager::firmwarePluginForAutopilot(MAV_AUTOPILOT if (!plugin) { // Default plugin fallback if (!_genericFirmwarePlugin) { - _genericFirmwarePlugin = new FirmwarePlugin; + _genericFirmwarePlugin = new FirmwarePlugin(); } plugin = _genericFirmwarePlugin; } @@ -78,13 +91,12 @@ FirmwarePlugin* FirmwarePluginManager::firmwarePluginForAutopilot(MAV_AUTOPILOT return plugin; } -FirmwarePluginFactory* FirmwarePluginManager::_findPluginFactory(QGCMAVLink::FirmwareClass_t firmwareClass) +FirmwarePluginFactory *FirmwarePluginManager::_findPluginFactory(QGCMAVLink::FirmwareClass_t firmwareClass) { - QList factoryList = FirmwarePluginFactoryRegister::instance()->pluginFactories(); + const QList factoryList = FirmwarePluginFactoryRegister::instance()->pluginFactories(); // Find the plugin which supports this vehicle - for (int i=0; isupportedFirmwareClasses().contains(firmwareClass)) { return factory; } diff --git a/src/FirmwarePlugin/FirmwarePluginManager.h b/src/FirmwarePlugin/FirmwarePluginManager.h index a9f09282fb0..b742c62bf0f 100644 --- a/src/FirmwarePlugin/FirmwarePluginManager.h +++ b/src/FirmwarePlugin/FirmwarePluginManager.h @@ -9,28 +9,35 @@ #pragma once +#include #include #include "QGCMAVLink.h" -#include "QGCToolbox.h" - -class QGCApplication; class FirmwarePlugin; class FirmwarePluginFactory; -/// FirmwarePluginManager is a singleton which is used to return the correct FirmwarePlugin for a MAV_AUTOPILOT type. +Q_DECLARE_LOGGING_CATEGORY(FirmwarePluginManagerLog) -class FirmwarePluginManager : public QGCTool +/// FirmwarePluginManager is a singleton which is used to return the correct FirmwarePlugin for a MAV_AUTOPILOT type. +class FirmwarePluginManager : public QObject { Q_OBJECT public: - FirmwarePluginManager(QGCApplication* app, QGCToolbox* toolbox); + /// Constructs an FirmwarePluginManager object. + /// @param parent The parent QObject. + explicit FirmwarePluginManager(QObject *parent = nullptr); + + /// Destructor for the FirmwarePluginManager class. ~FirmwarePluginManager(); + /// Gets the singleton instance of FirmwarePluginManager. + /// @return The singleton instance. + static FirmwarePluginManager *instance(); + /// Returns list of firmwares which are supported by the system - QList supportedFirmwareClasses(void); + QList supportedFirmwareClasses(); /// Returns the list of supported vehicle types for the specified firmware QList supportedVehicleClasses(QGCMAVLink::FirmwareClass_t firmwareClass); @@ -39,11 +46,11 @@ class FirmwarePluginManager : public QGCTool /// @param firmwareType Type of firmwware to return plugin for. /// @param vehicleType Vehicle type to return plugin for. /// @return Singleton FirmwarePlugin instance for the specified MAV_AUTOPILOT. - FirmwarePlugin* firmwarePluginForAutopilot(MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType); + FirmwarePlugin *firmwarePluginForAutopilot(MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType); private: - FirmwarePluginFactory* _findPluginFactory(QGCMAVLink::FirmwareClass_t firmwareClass); + FirmwarePluginFactory *_findPluginFactory(QGCMAVLink::FirmwareClass_t firmwareClass); - FirmwarePlugin* _genericFirmwarePlugin; - QList _supportedFirmwareClasses; + FirmwarePlugin *_genericFirmwarePlugin = nullptr; + QList _supportedFirmwareClasses; }; diff --git a/src/MissionManager/MissionCommandTree.cc b/src/MissionManager/MissionCommandTree.cc index bd940772576..7b2881f163c 100644 --- a/src/MissionManager/MissionCommandTree.cc +++ b/src/MissionManager/MissionCommandTree.cc @@ -43,8 +43,8 @@ void MissionCommandTree::setToolbox(QGCToolbox* toolbox) } else { #endif // Load all levels of hierarchy - for (const QGCMAVLink::FirmwareClass_t firmwareClass: _toolbox->firmwarePluginManager()->supportedFirmwareClasses()) { - FirmwarePlugin* plugin = _toolbox->firmwarePluginManager()->firmwarePluginForAutopilot(QGCMAVLink::firmwareClassToAutopilot(firmwareClass), MAV_TYPE_QUADROTOR); + for (const QGCMAVLink::FirmwareClass_t firmwareClass: FirmwarePluginManager::instance()->supportedFirmwareClasses()) { + FirmwarePlugin* plugin = FirmwarePluginManager::instance()->firmwarePluginForAutopilot(QGCMAVLink::firmwareClassToAutopilot(firmwareClass), MAV_TYPE_QUADROTOR); for (const QGCMAVLink::VehicleClass_t vehicleClass: QGCMAVLink::allVehicleClasses()) { QString overrideFile = plugin->missionCommandOverrides(vehicleClass); @@ -209,7 +209,7 @@ QVariantList MissionCommandTree::getCommandsForCategory(Vehicle* vehicle, const // vehicle can be null in which case _firmwareAndVehicleClassInfo will tell of the firmware/vehicle type for the offline editing vehicle. // We then use that to get a firmware plugin so we can get the list of supported commands. - FirmwarePlugin* firmwarePlugin = qgcApp()->toolbox()->firmwarePluginManager()->firmwarePluginForAutopilot(QGCMAVLink::firmwareClassToAutopilot(firmwareClass), QGCMAVLink::vehicleClassToMavType(vehicleClass)); + FirmwarePlugin* firmwarePlugin = FirmwarePluginManager::instance()->firmwarePluginForAutopilot(QGCMAVLink::firmwareClassToAutopilot(firmwareClass), QGCMAVLink::vehicleClassToMavType(vehicleClass)); QList supportedCommands = firmwarePlugin->supportedMissionCommands(vehicleClass); QVariantList list; diff --git a/src/MissionManager/PlanMasterController.cc b/src/MissionManager/PlanMasterController.cc index ff9a083b91d..91133889fd2 100644 --- a/src/MissionManager/PlanMasterController.cc +++ b/src/MissionManager/PlanMasterController.cc @@ -34,7 +34,7 @@ QGC_LOGGING_CATEGORY(PlanMasterControllerLog, "PlanMasterControllerLog") PlanMasterController::PlanMasterController(QObject* parent) : QObject (parent) , _multiVehicleMgr (qgcApp()->toolbox()->multiVehicleManager()) - , _controllerVehicle (new Vehicle(Vehicle::MAV_AUTOPILOT_TRACK, Vehicle::MAV_TYPE_TRACK, qgcApp()->toolbox()->firmwarePluginManager(), this)) + , _controllerVehicle (new Vehicle(Vehicle::MAV_AUTOPILOT_TRACK, Vehicle::MAV_TYPE_TRACK, this)) , _managerVehicle (_controllerVehicle) , _missionController (this) , _geoFenceController (this) @@ -47,7 +47,7 @@ PlanMasterController::PlanMasterController(QObject* parent) PlanMasterController::PlanMasterController(MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType, QObject* parent) : QObject (parent) , _multiVehicleMgr (qgcApp()->toolbox()->multiVehicleManager()) - , _controllerVehicle (new Vehicle(firmwareType, vehicleType, qgcApp()->toolbox()->firmwarePluginManager())) + , _controllerVehicle (new Vehicle(firmwareType, vehicleType)) , _managerVehicle (_controllerVehicle) , _missionController (this) , _geoFenceController (this) diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 35477c2d7fb..3f1a248019e 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -46,7 +46,6 @@ #include "SyslinkComponentController.h" #include "AutoPilotPlugin.h" #include "VehicleComponent.h" -#include "FirmwarePluginManager.h" #include "MultiVehicleManager.h" #include "Vehicle.h" #include "JoystickConfigController.h" diff --git a/src/QGCToolbox.cc b/src/QGCToolbox.cc index 4d27635eb18..719401bb437 100644 --- a/src/QGCToolbox.cc +++ b/src/QGCToolbox.cc @@ -8,7 +8,6 @@ ****************************************************************************/ -#include "FirmwarePluginManager.h" #include "LinkManager.h" #include "MAVLinkProtocol.h" #include "MissionCommandTree.h" @@ -38,7 +37,6 @@ QGCToolbox::QGCToolbox(QGCApplication* app) //-- Scan and load plugins _scanAndLoadPlugins(app); - _firmwarePluginManager = new FirmwarePluginManager (app, this); _linkManager = new LinkManager (app, this); _mavlinkProtocol = new MAVLinkProtocol (app, this); _missionCommandTree = new MissionCommandTree (app, this); @@ -60,7 +58,6 @@ void QGCToolbox::setChildToolboxes(void) _settingsManager->setToolbox(this); _corePlugin->setToolbox(this); - _firmwarePluginManager->setToolbox(this); _linkManager->setToolbox(this); _mavlinkProtocol->setToolbox(this); _missionCommandTree->setToolbox(this); diff --git a/src/QGCToolbox.h b/src/QGCToolbox.h index e243c11660c..e7e8d50a22b 100644 --- a/src/QGCToolbox.h +++ b/src/QGCToolbox.h @@ -13,7 +13,6 @@ #include -class FirmwarePluginManager; class LinkManager; class MAVLinkProtocol; class MissionCommandTree; @@ -37,7 +36,6 @@ class QGCToolbox : public QObject { public: QGCToolbox(QGCApplication* app); - FirmwarePluginManager* firmwarePluginManager () { return _firmwarePluginManager; } LinkManager* linkManager () { return _linkManager; } MAVLinkProtocol* mavlinkProtocol () { return _mavlinkProtocol; } MissionCommandTree* missionCommandTree () { return _missionCommandTree; } @@ -57,7 +55,6 @@ class QGCToolbox : public QObject { void setChildToolboxes(void); void _scanAndLoadPlugins(QGCApplication *app); - FirmwarePluginManager* _firmwarePluginManager = nullptr; LinkManager* _linkManager = nullptr; MAVLinkProtocol* _mavlinkProtocol = nullptr; MissionCommandTree* _missionCommandTree = nullptr; diff --git a/src/QmlControls/QGroundControlQmlGlobal.cc b/src/QmlControls/QGroundControlQmlGlobal.cc index 53ed7a85167..8e42c29bec6 100644 --- a/src/QmlControls/QGroundControlQmlGlobal.cc +++ b/src/QmlControls/QGroundControlQmlGlobal.cc @@ -83,7 +83,6 @@ void QGroundControlQmlGlobal::setToolbox(QGCToolbox* toolbox) _videoManager = toolbox->videoManager(); _mavlinkLogManager = toolbox->mavlinkLogManager(); _corePlugin = toolbox->corePlugin(); - _firmwarePluginManager = toolbox->firmwarePluginManager(); _settingsManager = toolbox->settingsManager(); #ifndef NO_SERIAL_LINK _gpsRtkFactGroup = GPSManager::instance()->gpsRtk()->gpsRtkFactGroup(); @@ -209,13 +208,13 @@ void QGroundControlQmlGlobal::setMavlinkSystemID(int id) bool QGroundControlQmlGlobal::singleFirmwareSupport(void) { - return _firmwarePluginManager->supportedFirmwareClasses().count() == 1; + return FirmwarePluginManager::instance()->supportedFirmwareClasses().count() == 1; } bool QGroundControlQmlGlobal::singleVehicleSupport(void) { if (singleFirmwareSupport()) { - return _firmwarePluginManager->supportedVehicleClasses(_firmwarePluginManager->supportedFirmwareClasses()[0]).count() == 1; + return FirmwarePluginManager::instance()->supportedVehicleClasses(FirmwarePluginManager::instance()->supportedFirmwareClasses()[0]).count() == 1; } return false; @@ -223,12 +222,12 @@ bool QGroundControlQmlGlobal::singleVehicleSupport(void) bool QGroundControlQmlGlobal::px4ProFirmwareSupported() { - return _firmwarePluginManager->supportedFirmwareClasses().contains(QGCMAVLink::FirmwareClassPX4); + return FirmwarePluginManager::instance()->supportedFirmwareClasses().contains(QGCMAVLink::FirmwareClassPX4); } bool QGroundControlQmlGlobal::apmFirmwareSupported() { - return _firmwarePluginManager->supportedFirmwareClasses().contains(QGCMAVLink::FirmwareClassArduPilot); + return FirmwarePluginManager::instance()->supportedFirmwareClasses().contains(QGCMAVLink::FirmwareClassArduPilot); } bool QGroundControlQmlGlobal::linesIntersect(QPointF line1A, QPointF line1B, QPointF line2A, QPointF line2B) diff --git a/src/QmlControls/QGroundControlQmlGlobal.h b/src/QmlControls/QGroundControlQmlGlobal.h index a2456b96757..33ba64129fb 100644 --- a/src/QmlControls/QGroundControlQmlGlobal.h +++ b/src/QmlControls/QGroundControlQmlGlobal.h @@ -268,7 +268,6 @@ class QGroundControlQmlGlobal : public QGCTool VideoManager* _videoManager = nullptr; MAVLinkLogManager* _mavlinkLogManager = nullptr; QGCCorePlugin* _corePlugin = nullptr; - FirmwarePluginManager* _firmwarePluginManager = nullptr; SettingsManager* _settingsManager = nullptr; #ifndef NO_SERIAL_LINK FactGroup* _gpsRtkFactGroup = nullptr; diff --git a/src/Vehicle/Components/CompInfoParam.cc b/src/Vehicle/Components/CompInfoParam.cc index d2194c4f536..f0d501161e2 100644 --- a/src/Vehicle/Components/CompInfoParam.cc +++ b/src/Vehicle/Components/CompInfoParam.cc @@ -144,16 +144,15 @@ FactMetaData* CompInfoParam::factMetaDataForName(const QString& name, FactMetaDa FirmwarePlugin* CompInfoParam::_anyVehicleTypeFirmwarePlugin(MAV_AUTOPILOT firmwareType) { - FirmwarePluginManager* const pluginMgr = qgcApp()->toolbox()->firmwarePluginManager(); const QGCMAVLink::FirmwareClass_t firmwareClass = QGCMAVLink::firmwareClass(firmwareType); - const QList supportedClasses = pluginMgr->supportedVehicleClasses(firmwareClass); + const QList supportedClasses = FirmwarePluginManager::instance()->supportedVehicleClasses(firmwareClass); MAV_TYPE anySupportedVehicleType; if (!supportedClasses.isEmpty()) { anySupportedVehicleType = QGCMAVLink::vehicleClassToMavType(supportedClasses[0]); } else { anySupportedVehicleType = MAV_TYPE_GENERIC; } - return pluginMgr->firmwarePluginForAutopilot(firmwareType, anySupportedVehicleType); + return FirmwarePluginManager::instance()->firmwarePluginForAutopilot(firmwareType, anySupportedVehicleType); } QString CompInfoParam::_parameterMetaDataFile(Vehicle* vehicle, MAV_AUTOPILOT firmwareType, int& majorVersion, int& minorVersion) diff --git a/src/Vehicle/MultiVehicleManager.cc b/src/Vehicle/MultiVehicleManager.cc index 48231e1ba75..a7fe3f6c909 100644 --- a/src/Vehicle/MultiVehicleManager.cc +++ b/src/Vehicle/MultiVehicleManager.cc @@ -31,7 +31,6 @@ MultiVehicleManager::MultiVehicleManager(QGCApplication* app, QGCToolbox* toolbo , _parameterReadyVehicleAvailable(false) , _activeVehicle(nullptr) , _offlineEditingVehicle(nullptr) - , _firmwarePluginManager(nullptr) , _mavlinkProtocol(nullptr) , _gcsHeartbeatEnabled(true) { @@ -45,7 +44,6 @@ void MultiVehicleManager::setToolbox(QGCToolbox *toolbox) { QGCTool::setToolbox(toolbox); - _firmwarePluginManager = _toolbox->firmwarePluginManager(); _mavlinkProtocol = _toolbox->mavlinkProtocol(); QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); @@ -62,7 +60,7 @@ void MultiVehicleManager::setToolbox(QGCToolbox *toolbox) _gcsHeartbeatTimer.start(); } - _offlineEditingVehicle = new Vehicle(Vehicle::MAV_AUTOPILOT_TRACK, Vehicle::MAV_TYPE_TRACK, _firmwarePluginManager, this); + _offlineEditingVehicle = new Vehicle(Vehicle::MAV_AUTOPILOT_TRACK, Vehicle::MAV_TYPE_TRACK, this); } void MultiVehicleManager::_vehicleHeartbeatInfo(LinkInterface* link, int vehicleId, int componentId, int vehicleFirmwareType, int vehicleType) @@ -117,7 +115,7 @@ void MultiVehicleManager::_vehicleHeartbeatInfo(LinkInterface* link, int vehicle _app->showAppMessage(tr("Warning: A vehicle is using the same system id as %1: %2").arg(QCoreApplication::applicationName()).arg(vehicleId)); } - Vehicle* vehicle = new Vehicle(link, vehicleId, componentId, (MAV_AUTOPILOT)vehicleFirmwareType, (MAV_TYPE)vehicleType, _firmwarePluginManager, this); + Vehicle* vehicle = new Vehicle(link, vehicleId, componentId, (MAV_AUTOPILOT)vehicleFirmwareType, (MAV_TYPE)vehicleType, this); connect(vehicle, &Vehicle::requestProtocolVersion, this, &MultiVehicleManager::_requestProtocolVersion); connect(vehicle->vehicleLinkManager(), &VehicleLinkManager::allLinksRemoved, this, &MultiVehicleManager::_deleteVehiclePhase1); connect(vehicle->parameterManager(), &ParameterManager::parametersReadyChanged, this, &MultiVehicleManager::_vehicleParametersReadyChanged); diff --git a/src/Vehicle/MultiVehicleManager.h b/src/Vehicle/MultiVehicleManager.h index be09b4b6298..f95a7a7a1ef 100644 --- a/src/Vehicle/MultiVehicleManager.h +++ b/src/Vehicle/MultiVehicleManager.h @@ -20,7 +20,6 @@ #include "QGCToolbox.h" #include "QmlObjectListModel.h" -class FirmwarePluginManager; class QGCApplication; class MAVLinkProtocol; class LinkInterface; @@ -109,7 +108,6 @@ private slots: QmlObjectListModel _vehicles; - FirmwarePluginManager* _firmwarePluginManager; MAVLinkProtocol* _mavlinkProtocol; QGeoCoordinate _lastKnownLocation; diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index a9982a81783..019c5ea3f51 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -79,7 +79,6 @@ Vehicle::Vehicle(LinkInterface* link, int defaultComponentId, MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType, - FirmwarePluginManager* firmwarePluginManager, QObject* parent) : VehicleFactGroup (parent) , _id (vehicleId) @@ -90,7 +89,6 @@ Vehicle::Vehicle(LinkInterface* link, , _settingsManager (_toolbox->settingsManager()) , _defaultCruiseSpeed (_settingsManager->appSettings()->offlineEditingCruiseSpeed()->rawValue().toDouble()) , _defaultHoverSpeed (_settingsManager->appSettings()->offlineEditingHoverSpeed()->rawValue().toDouble()) - , _firmwarePluginManager (firmwarePluginManager) , _trajectoryPoints (new TrajectoryPoints(this, this)) , _mavlinkStreamConfig (std::bind(&Vehicle::_setMessageInterval, this, std::placeholders::_1, std::placeholders::_2)) , _vehicleFactGroup (this) @@ -198,7 +196,6 @@ Vehicle::Vehicle(LinkInterface* link, // Disconnected Vehicle for offline editing Vehicle::Vehicle(MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType, - FirmwarePluginManager* firmwarePluginManager, QObject* parent) : VehicleFactGroup (parent) , _id (0) @@ -214,7 +211,6 @@ Vehicle::Vehicle(MAV_AUTOPILOT firmwareType, , _maxProtoVersion (200) , _capabilityBitsKnown (true) , _capabilityBits (MAV_PROTOCOL_CAPABILITY_MISSION_FENCE | MAV_PROTOCOL_CAPABILITY_MISSION_RALLY) - , _firmwarePluginManager (firmwarePluginManager) , _trajectoryPoints (new TrajectoryPoints(this, this)) , _mavlinkStreamConfig (std::bind(&Vehicle::_setMessageInterval, this, std::placeholders::_1, std::placeholders::_2)) , _vehicleFactGroup (this) @@ -260,7 +256,7 @@ void Vehicle::stopTrackingFirmwareVehicleTypeChanges(void) void Vehicle::_commonInit() { - _firmwarePlugin = _firmwarePluginManager->firmwarePluginForAutopilot(_firmwareType, _vehicleType); + _firmwarePlugin = FirmwarePluginManager::instance()->firmwarePluginForAutopilot(_firmwareType, _vehicleType); connect(_firmwarePlugin, &FirmwarePlugin::toolIndicatorsChanged, this, &Vehicle::toolIndicatorsChanged); connect(_firmwarePlugin, &FirmwarePlugin::modeIndicatorsChanged, this, &Vehicle::modeIndicatorsChanged); @@ -423,7 +419,7 @@ void Vehicle::deleteGimbalController() void Vehicle::_offlineFirmwareTypeSettingChanged(QVariant varFirmwareType) { _firmwareType = static_cast(varFirmwareType.toInt()); - _firmwarePlugin = _firmwarePluginManager->firmwarePluginForAutopilot(_firmwareType, _vehicleType); + _firmwarePlugin = FirmwarePluginManager::instance()->firmwarePluginForAutopilot(_firmwareType, _vehicleType); if (_firmwareType == MAV_AUTOPILOT_ARDUPILOTMEGA) { _capabilityBits |= MAV_PROTOCOL_CAPABILITY_TERRAIN; } else { diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index 03495d9fb94..c3f070e55d5 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -51,7 +51,6 @@ class Autotune; class ComponentInformationManager; class EventHandler; class FirmwarePlugin; -class FirmwarePluginManager; class FTPManager; class GeoFenceManager; class ImageProtocolManager; @@ -116,7 +115,6 @@ class Vehicle : public VehicleFactGroup int defaultComponentId, MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType, - FirmwarePluginManager* firmwarePluginManager, QObject* parent = nullptr); // Pass these into the offline constructor to create an offline vehicle which tracks the offline vehicle settings @@ -126,7 +124,6 @@ class Vehicle : public VehicleFactGroup // The following is used to create a disconnected Vehicle for use while offline editing. Vehicle(MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType, - FirmwarePluginManager* firmwarePluginManager, QObject* parent = nullptr); ~Vehicle(); @@ -1057,7 +1054,6 @@ private slots: LinkManager* _linkManager = nullptr; ParameterManager* _parameterManager = nullptr; - FirmwarePluginManager* _firmwarePluginManager = nullptr; ComponentInformationManager* _componentInformationManager = nullptr; VehicleObjectAvoidance* _objectAvoidance = nullptr; Autotune* _autotune = nullptr; diff --git a/test/MissionManager/MissionCommandTreeEditorTest.cc b/test/MissionManager/MissionCommandTreeEditorTest.cc index f3318476007..709de2e053d 100644 --- a/test/MissionManager/MissionCommandTreeEditorTest.cc +++ b/test/MissionManager/MissionCommandTreeEditorTest.cc @@ -35,9 +35,9 @@ void MissionCommandTreeEditorTest::_testEditorsWorker(QGCMAVLink::FirmwareClass_ appSettings->offlineEditingVehicleClass()->setRawValue(vehicleClass); PlanMasterController masterController; - FirmwarePlugin* firmwarePlugin = qgcApp()->toolbox()->firmwarePluginManager()->firmwarePluginForAutopilot(QGCMAVLink::firmwareClassToAutopilot(firmwareClass), QGCMAVLink::vehicleClassToMavType(vehicleClass)); + FirmwarePlugin* firmwarePlugin = FirmwarePluginManager::instance()->firmwarePluginForAutopilot(QGCMAVLink::firmwareClassToAutopilot(firmwareClass), QGCMAVLink::vehicleClassToMavType(vehicleClass)); if (firmwarePlugin->supportedMissionCommands(vehicleClass).count() == 0) { - firmwarePlugin = qgcApp()->toolbox()->firmwarePluginManager()->firmwarePluginForAutopilot(QGCMAVLink::firmwareClassToAutopilot(QGCMAVLink::FirmwareClassPX4), QGCMAVLink::vehicleClassToMavType(vehicleClass)); + firmwarePlugin = FirmwarePluginManager::instance()->firmwarePluginForAutopilot(QGCMAVLink::firmwareClassToAutopilot(QGCMAVLink::FirmwareClassPX4), QGCMAVLink::vehicleClassToMavType(vehicleClass)); } int cColumns = firmwarePlugin->supportedMissionCommands(vehicleClass).count(); diff --git a/test/MissionManager/MissionCommandTreeTest.cc b/test/MissionManager/MissionCommandTreeTest.cc index 2a6e01cba0e..7ad8d1463ed 100644 --- a/test/MissionManager/MissionCommandTreeTest.cc +++ b/test/MissionManager/MissionCommandTreeTest.cc @@ -13,6 +13,7 @@ #include "MissionCommandList.h" #include "MissionCommandTree.h" #include "Vehicle.h" +#include "FirmwarePluginManager.h" #include @@ -190,12 +191,12 @@ void MissionCommandTreeTest::testJsonLoad(void) void MissionCommandTreeTest::testOverride(void) { // Generic/Generic should not have any overrides - Vehicle* vehicle = new Vehicle(MAV_AUTOPILOT_GENERIC, MAV_TYPE_GENERIC, qgcApp()->toolbox()->firmwarePluginManager()); + Vehicle* vehicle = new Vehicle(MAV_AUTOPILOT_GENERIC, MAV_TYPE_GENERIC, FirmwarePluginManager::instance()); _checkBaseValues(_commandTree->getUIInfo(vehicle, QGCMAVLink::VehicleClassGeneric, (MAV_CMD)4), 4); delete vehicle; // Generic/FixedWing should have overrides - vehicle = new Vehicle(MAV_AUTOPILOT_GENERIC, MAV_TYPE_FIXED_WING, qgcApp()->toolbox()->firmwarePluginManager()); + vehicle = new Vehicle(MAV_AUTOPILOT_GENERIC, MAV_TYPE_FIXED_WING, FirmwarePluginManager::instance()); _checkOverrideValues(_commandTree->getUIInfo(vehicle, QGCMAVLink::VehicleClassGeneric, (MAV_CMD)4), 4); delete vehicle; } @@ -216,7 +217,7 @@ void MissionCommandTreeTest::testAllTrees(void) continue; } qDebug() << firmwareType << vehicleType; - Vehicle* vehicle = new Vehicle(firmwareType, vehicleType, qgcApp()->toolbox()->firmwarePluginManager()); + Vehicle* vehicle = new Vehicle(firmwareType, vehicleType, FirmwarePluginManager::instance()); QVERIFY(qgcApp()->toolbox()->missionCommandTree()->getUIInfo(vehicle, QGCMAVLink::VehicleClassMultiRotor, MAV_CMD_NAV_WAYPOINT) != nullptr); delete vehicle; }