diff --git a/src/AutoPilotPlugins/PX4/AirframeComponentController.cc b/src/AutoPilotPlugins/PX4/AirframeComponentController.cc index 4641ce21d62..ea0344557c5 100644 --- a/src/AutoPilotPlugins/PX4/AirframeComponentController.cc +++ b/src/AutoPilotPlugins/PX4/AirframeComponentController.cc @@ -127,7 +127,7 @@ void AirframeComponentController::_rebootAfterStackUnwind(void) QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); } QGuiApplication::restoreOverrideCursor(); - qgcApp()->toolbox()->linkManager()->disconnectAll(); + LinkManager::instance()->disconnectAll(); } AirframeType::AirframeType(const QString& name, const QString& imageResource, QObject* parent) : diff --git a/src/Comms/CMakeLists.txt b/src/Comms/CMakeLists.txt index 55ff89d3b25..4a651f99d82 100644 --- a/src/Comms/CMakeLists.txt +++ b/src/Comms/CMakeLists.txt @@ -26,6 +26,7 @@ target_link_libraries(Comms Qt6::Test MockLink PositionManager + QGC Settings Vehicle PUBLIC @@ -33,7 +34,6 @@ target_link_libraries(Comms Qt6::Network AirLink MAVLink - QGC QmlControls Utilities ) diff --git a/src/Comms/LinkInterface.cc b/src/Comms/LinkInterface.cc index fb1391c3ab3..ba5122e6b60 100644 --- a/src/Comms/LinkInterface.cc +++ b/src/Comms/LinkInterface.cc @@ -83,7 +83,7 @@ bool LinkInterface::_allocateMavlinkChannel() return true; } - _mavlinkChannel = qgcApp()->toolbox()->linkManager()->allocateMavlinkChannel(); + _mavlinkChannel = LinkManager::instance()->allocateMavlinkChannel(); if (!mavlinkChannelIsSet()) { qCWarning(LinkInterfaceLog) << Q_FUNC_INFO << "failed"; @@ -105,7 +105,7 @@ void LinkInterface::_freeMavlinkChannel() return; } - qgcApp()->toolbox()->linkManager()->freeMavlinkChannel(_mavlinkChannel); + LinkManager::instance()->freeMavlinkChannel(_mavlinkChannel); _mavlinkChannel = LinkManager::invalidMavlinkChannel(); } diff --git a/src/Comms/LinkManager.cc b/src/Comms/LinkManager.cc index bbcfe8f593a..fa38bff10b4 100644 --- a/src/Comms/LinkManager.cc +++ b/src/Comms/LinkManager.cc @@ -47,14 +47,17 @@ #include #endif +#include #include #include QGC_LOGGING_CATEGORY(LinkManagerLog, "qgc.comms.linkmanager") QGC_LOGGING_CATEGORY(LinkManagerVerboseLog, "qgc.comms.linkmanager:verbose") -LinkManager::LinkManager(QGCApplication *app, QGCToolbox *toolbox) - : QGCTool(app, toolbox) +Q_APPLICATION_STATIC(LinkManager, _linkManagerInstance); + +LinkManager::LinkManager(QObject *parent) + : QObject(parent) , _portListTimer(new QTimer(this)) , _qmlConfigurations(new QmlObjectListModel(this)) #ifndef NO_SERIAL_LINK @@ -62,7 +65,20 @@ LinkManager::LinkManager(QGCApplication *app, QGCToolbox *toolbox) #endif { // qCDebug(LinkManagerLog) << Q_FUNC_INFO << this; +} +LinkManager::~LinkManager() +{ + // qCDebug(LinkManagerLog) << Q_FUNC_INFO << this; +} + +LinkManager *LinkManager::instance() +{ + return _linkManagerInstance(); +} + +void LinkManager::registerQmlTypes() +{ (void) qmlRegisterUncreatableType("QGroundControl", 1, 0, "LinkManager", "Reference only"); (void) qmlRegisterUncreatableType("QGroundControl", 1, 0, "LinkConfiguration", "Reference only"); (void) qmlRegisterUncreatableType("QGroundControl", 1, 0, "LinkInterface", "Reference only"); @@ -78,16 +94,9 @@ LinkManager::LinkManager(QGCApplication *app, QGCToolbox *toolbox) #endif } -LinkManager::~LinkManager() -{ - // qCDebug(LinkManagerLog) << Q_FUNC_INFO << this; -} - -void LinkManager::setToolbox(QGCToolbox *toolbox) +void LinkManager::init() { - QGCTool::setToolbox(toolbox); - - _autoConnectSettings = toolbox->settingsManager()->autoConnectSettings(); + _autoConnectSettings = qgcApp()->toolbox()->settingsManager()->autoConnectSettings(); if (!qgcApp()->runningUnitTests()) { (void) connect(_portListTimer, &QTimer::timeout, this, &LinkManager::_updateAutoConnectLinks); @@ -160,7 +169,7 @@ bool LinkManager::createConnectedLink(SharedLinkConfigurationPtr &config) (void) _rgLinks.append(link); config->setLink(link); - (void) connect(link.get(), &LinkInterface::communicationError, _app, &QGCApplication::criticalMessageBoxOnMainThread); + (void) connect(link.get(), &LinkInterface::communicationError, qgcApp(), &QGCApplication::showAppMessage); (void) connect(link.get(), &LinkInterface::bytesReceived, MAVLinkProtocol::instance(), &MAVLinkProtocol::receiveBytes); (void) connect(link.get(), &LinkInterface::bytesSent, MAVLinkProtocol::instance(), &MAVLinkProtocol::logSentBytes); (void) connect(link.get(), &LinkInterface::disconnected, this, &LinkManager::_linkDisconnected); @@ -218,7 +227,7 @@ void LinkManager::_linkDisconnected() return; } - (void) disconnect(link, &LinkInterface::communicationError, _app, &QGCApplication::criticalMessageBoxOnMainThread); + (void) disconnect(link, &LinkInterface::communicationError, qgcApp(), &QGCApplication::showAppMessage); (void) disconnect(link, &LinkInterface::bytesReceived, MAVLinkProtocol::instance(), &MAVLinkProtocol::receiveBytes); (void) disconnect(link, &LinkInterface::bytesSent, MAVLinkProtocol::instance(), &MAVLinkProtocol::logSentBytes); (void) disconnect(link, &LinkInterface::disconnected, this, &LinkManager::_linkDisconnected); @@ -227,7 +236,7 @@ void LinkManager::_linkDisconnected() for (auto it = _rgLinks.begin(); it != _rgLinks.end(); ++it) { if (it->get() == link) { - qCDebug(LinkManagerLog) << "LinkManager::_linkDisconnected" << it->get()->linkConfiguration()->name() << it->use_count(); + qCDebug(LinkManagerLog) << Q_FUNC_INFO << it->get()->linkConfiguration()->name() << it->use_count(); SharedLinkConfigurationPtr config = it->get()->linkConfiguration(); config->setLink(nullptr); (void) _rgLinks.erase(it); @@ -391,7 +400,7 @@ void LinkManager::_addUDPAutoConnectLink() void LinkManager::_addMAVLinkForwardingLink() { - if (!_toolbox->settingsManager()->appSettings()->forwardMavlink()->rawValue().toBool()) { + if (!qgcApp()->toolbox()->settingsManager()->appSettings()->forwardMavlink()->rawValue().toBool()) { return; } @@ -403,7 +412,7 @@ void LinkManager::_addMAVLinkForwardingLink() } } - const QString hostName = _toolbox->settingsManager()->appSettings()->forwardMavlinkHostName()->rawValue().toString(); + const QString hostName = qgcApp()->toolbox()->settingsManager()->appSettings()->forwardMavlinkHostName()->rawValue().toString(); _createDynamicForwardLink(_mavlinkForwardingLinkName, hostName); } @@ -502,7 +511,7 @@ void LinkManager::shutdown() disconnectAll(); // Wait for all the vehicles to go away to ensure an orderly shutdown and deletion of all objects - while (_toolbox->multiVehicleManager()->vehicles()->count()) { + while (qgcApp()->toolbox()->multiVehicleManager()->vehicles()->count()) { QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); } } @@ -608,7 +617,7 @@ void LinkManager::removeConfiguration(LinkConfiguration *config) void LinkManager::createMavlinkForwardingSupportLink() { - const QString hostName = _toolbox->settingsManager()->appSettings()->forwardMavlinkAPMSupportHostName()->rawValue().toString(); + const QString hostName = qgcApp()->toolbox()->settingsManager()->appSettings()->forwardMavlinkAPMSupportHostName()->rawValue().toString(); _createDynamicForwardLink(_mavlinkForwardingSupportLinkName, hostName); _mavlinkSupportForwardingEnabled = true; emit mavlinkSupportForwardingEnabledChanged(); diff --git a/src/Comms/LinkManager.h b/src/Comms/LinkManager.h index 6a94b63cf7a..7889d9339fb 100644 --- a/src/Comms/LinkManager.h +++ b/src/Comms/LinkManager.h @@ -15,7 +15,6 @@ #include -#include "QGCToolbox.h" #include "LinkConfiguration.h" #include "LinkInterface.h" #ifndef NO_SERIAL_LINK @@ -28,7 +27,6 @@ Q_DECLARE_LOGGING_CATEGORY(LinkManagerVerboseLog) class AutoConnectSettings; class LogReplayLink; class MAVLinkProtocol; -class QGCApplication; class QmlObjectListModel; class QTimer; class SerialLink; @@ -39,7 +37,7 @@ class UdpIODevice; /// The Link Manager organizes the physical Links. It can manage arbitrary /// links and takes care of connecting them as well assigning the correct /// protocol instance to transport the link data into the application. -class LinkManager : public QGCTool +class LinkManager : public QObject { Q_OBJECT Q_MOC_INCLUDE("QmlObjectListModel.h") @@ -49,11 +47,13 @@ class LinkManager : public QGCTool Q_PROPERTY(bool mavlinkSupportForwardingEnabled READ mavlinkSupportForwardingEnabled NOTIFY mavlinkSupportForwardingEnabledChanged) public: - LinkManager(QGCApplication *app, QGCToolbox *toolbox); + LinkManager(QObject *parent = nullptr); ~LinkManager(); - // Override from QGCTool - void setToolbox(QGCToolbox *toolbox) final; + static LinkManager *instance(); + static void registerQmlTypes(); + + void init(); /// Create/Edit Link Configuration Q_INVOKABLE LinkConfiguration *createConfiguration(int type, const QString &name); @@ -141,6 +141,10 @@ private slots: void _addZeroConfAutoConnectLink(); #endif + QTimer *_portListTimer = nullptr; + QmlObjectListModel *_qmlConfigurations = nullptr; + AutoConnectSettings *_autoConnectSettings = nullptr; + bool _configUpdateSuspended = false; ///< true: stop updating configuration list bool _configurationsLoaded = false; ///< true: Link configurations have been loaded bool _connectionsSuspended = false; ///< true: all new connections should not be allowed @@ -148,16 +152,12 @@ private slots: uint32_t _mavlinkChannelsUsedBitMask = 1; QString _connectionsSuspendedReason; ///< User visible reason for suspension - AutoConnectSettings *_autoConnectSettings = nullptr; - QTimer *_portListTimer = nullptr; - QmlObjectListModel *_qmlConfigurations = nullptr; - QList _rgLinks; QList _rgLinkConfigs; - static constexpr const char* _defaultUDPLinkName = "UDP Link (AutoConnect)"; - static constexpr const char* _mavlinkForwardingLinkName = "MAVLink Forwarding Link"; - static constexpr const char* _mavlinkForwardingSupportLinkName = "MAVLink Support Forwarding Link"; + static constexpr const char *_defaultUDPLinkName = "UDP Link (AutoConnect)"; + static constexpr const char *_mavlinkForwardingLinkName = "MAVLink Forwarding Link"; + static constexpr const char *_mavlinkForwardingSupportLinkName = "MAVLink Support Forwarding Link"; static constexpr int _autoconnectUpdateTimerMSecs = 1000; #ifdef Q_OS_WIN @@ -168,11 +168,12 @@ private slots: #endif #ifndef NO_SERIAL_LINK -public: +private: Q_PROPERTY(QStringList serialBaudRates READ serialBaudRates CONSTANT) Q_PROPERTY(QStringList serialPortStrings READ serialPortStrings NOTIFY commPortStringsChanged) Q_PROPERTY(QStringList serialPorts READ serialPorts NOTIFY commPortsChanged) +public: static QStringList serialBaudRates(); QStringList serialPortStrings(); QStringList serialPorts(); @@ -188,6 +189,7 @@ private slots: void _addSerialAutoConnectLink(); bool _portAlreadyConnected(const QString &portName) const; + UdpIODevice *_nmeaSocket = nullptr; QMap _autoconnectPortWaitList; ///< key: QGCSerialPortInfo::systemLocation, value: wait count QList _activeLinkCheckList; ///< List of links we are waiting for a vehicle to show up on QStringList _commPortList; @@ -196,6 +198,5 @@ private slots: QString _nmeaDeviceName; uint32_t _nmeaBaud = 0; QSerialPort *_nmeaPort = nullptr; - UdpIODevice *_nmeaSocket = nullptr; #endif // NO_SERIAL_LINK }; diff --git a/src/Comms/LogReplayLink.cc b/src/Comms/LogReplayLink.cc index ffb8155d9ee..c3bd3f6aaef 100644 --- a/src/Comms/LogReplayLink.cc +++ b/src/Comms/LogReplayLink.cc @@ -358,7 +358,7 @@ void LogReplayLink::_readNextLogEntry(void) void LogReplayLink::_play(void) { - qgcApp()->toolbox()->linkManager()->setConnectionsSuspended(tr("Connect not allowed during Flight Data replay.")); + LinkManager::instance()->setConnectionsSuspended(tr("Connect not allowed during Flight Data replay.")); #ifndef __mobile__ MAVLinkProtocol::instance()->suspendLogForReplay(true); #endif @@ -377,7 +377,7 @@ void LogReplayLink::_play(void) void LogReplayLink::_pause(void) { - qgcApp()->toolbox()->linkManager()->setConnectionsAllowed(); + LinkManager::instance()->setConnectionsAllowed(); #ifndef __mobile__ MAVLinkProtocol::instance()->suspendLogForReplay(false); #endif diff --git a/src/Comms/MAVLinkProtocol.cc b/src/Comms/MAVLinkProtocol.cc index 614c3892b0e..01035056f69 100644 --- a/src/Comms/MAVLinkProtocol.cc +++ b/src/Comms/MAVLinkProtocol.cc @@ -16,6 +16,7 @@ #include "QGCToolbox.h" #include "SettingsManager.h" +#include #include #include #include @@ -54,7 +55,7 @@ MAVLinkProtocol *MAVLinkProtocol::instance() void MAVLinkProtocol::setVersion(unsigned version) { - const QList sharedLinks = qgcApp()->toolbox()->linkManager()->links(); + const QList sharedLinks = LinkManager::instance()->links(); for (const SharedLinkInterfacePtr &interface : sharedLinks) { mavlink_set_proto_version(interface.get()->mavlinkChannel(), version / 100); } @@ -127,7 +128,7 @@ void MAVLinkProtocol::logSentBytes(const LinkInterface *link, const QByteArray & void MAVLinkProtocol::receiveBytes(LinkInterface *link, const QByteArray &data) { - const SharedLinkInterfacePtr linkPtr = qgcApp()->toolbox()->linkManager()->sharedLinkInterfacePointerForLink(link); + const SharedLinkInterfacePtr linkPtr = LinkManager::instance()->sharedLinkInterfacePointerForLink(link); if (!linkPtr) { qCDebug(MAVLinkProtocolLog) << "receiveBytes: link gone!" << data.size() << "bytes arrived too late"; return; @@ -213,7 +214,7 @@ void MAVLinkProtocol::_forward(const mavlink_message_t &message) return; } - SharedLinkInterfacePtr forwardingLink = qgcApp()->toolbox()->linkManager()->mavlinkForwardingLink(); + SharedLinkInterfacePtr forwardingLink = LinkManager::instance()->mavlinkForwardingLink(); if (!forwardingLink) { return; } @@ -229,11 +230,11 @@ void MAVLinkProtocol::_forwardSupport(const mavlink_message_t &message) return; } - if (!qgcApp()->toolbox()->linkManager()->mavlinkSupportForwardingEnabled()) { + if (!LinkManager::instance()->mavlinkSupportForwardingEnabled()) { return; } - SharedLinkInterfacePtr forwardingSupportLink = qgcApp()->toolbox()->linkManager()->mavlinkForwardingSupportLink(); + SharedLinkInterfacePtr forwardingSupportLink = LinkManager::instance()->mavlinkForwardingSupportLink(); if (!forwardingSupportLink) { return; } diff --git a/src/Comms/MockLink/MockLink.cc b/src/Comms/MockLink/MockLink.cc index b485ba5b2c4..5a40c0d44bd 100644 --- a/src/Comms/MockLink/MockLink.cc +++ b/src/Comms/MockLink/MockLink.cc @@ -148,8 +148,7 @@ bool MockLink::_allocateMavlinkChannel() return false; } - auto mgr = qgcApp()->toolbox()->linkManager(); - _mavlinkAuxChannel = mgr->allocateMavlinkChannel(); + _mavlinkAuxChannel = LinkManager::instance()->allocateMavlinkChannel(); if (!mavlinkAuxChannelIsSet()) { qCWarning(MockLinkLog) << "_allocateMavlinkChannel failed"; LinkInterface::_freeMavlinkChannel(); @@ -167,8 +166,7 @@ void MockLink::_freeMavlinkChannel() return; } - auto mgr = qgcApp()->toolbox()->linkManager(); - mgr->freeMavlinkChannel(_mavlinkAuxChannel); + LinkManager::instance()->freeMavlinkChannel(_mavlinkAuxChannel); LinkInterface::_freeMavlinkChannel(); } @@ -1501,12 +1499,10 @@ void MockConfiguration::loadSettings(QSettings& settings, const QString& root) MockLink* MockLink::_startMockLink(MockConfiguration* mockConfig) { - LinkManager* linkMgr = qgcApp()->toolbox()->linkManager(); - mockConfig->setDynamic(true); - SharedLinkConfigurationPtr config = linkMgr->addConfiguration(mockConfig); + SharedLinkConfigurationPtr config = LinkManager::instance()->addConfiguration(mockConfig); - if (linkMgr->createConnectedLink(config)) { + if (LinkManager::instance()->createConnectedLink(config)) { return qobject_cast(config->link()); } else { return nullptr; diff --git a/src/Comms/SerialLink.cc b/src/Comms/SerialLink.cc index 62ff2978e6d..18de72d747e 100644 --- a/src/Comms/SerialLink.cc +++ b/src/Comms/SerialLink.cc @@ -82,7 +82,7 @@ void SerialLink::disconnect(void) } #ifdef Q_OS_ANDROID - qgcApp()->toolbox()->linkManager()->suspendConfigurationUpdates(false); + LinkManager::instance()->suspendConfigurationUpdates(false); #endif } @@ -96,7 +96,7 @@ bool SerialLink::_connect(void) } #ifdef Q_OS_ANDROID - qgcApp()->toolbox()->linkManager()->suspendConfigurationUpdates(true); + LinkManager::instance()->suspendConfigurationUpdates(true); #endif QSerialPort::SerialPortError error; diff --git a/src/FirmwarePlugin/APM/APMFirmwarePlugin.cc b/src/FirmwarePlugin/APM/APMFirmwarePlugin.cc index a47677f2000..b4126e0753c 100644 --- a/src/FirmwarePlugin/APM/APMFirmwarePlugin.cc +++ b/src/FirmwarePlugin/APM/APMFirmwarePlugin.cc @@ -1174,7 +1174,7 @@ uint8_t APMFirmwarePlugin::_reencodeMavlinkChannel() _channelMutex.lock(); static uint8_t channel{LinkManager::invalidMavlinkChannel()}; if (LinkManager::invalidMavlinkChannel() == channel) { - channel = qgcApp()->toolbox()->linkManager()->allocateMavlinkChannel(); + channel = LinkManager::instance()->allocateMavlinkChannel(); } _channelMutex.unlock(); return channel; diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 71dab30c4b6..511e0f8a133 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -265,6 +265,7 @@ void QGCApplication::init() { // Register our Qml objects + LinkManager::registerQmlTypes(); ParameterManager::registerQmlTypes(); QGroundControlQmlGlobal::registerQmlTypes(); MissionManager::registerQmlTypes(); @@ -333,6 +334,7 @@ void QGCApplication::_initForNormalAppBoot() AudioOutput::instance()->init(_toolbox->settingsManager()->appSettings()->audioMuted()); FollowMe::instance()->init(); QGCPositionManager::instance()->init(); + LinkManager::instance()->init(); // Image provider for Optical Flow _qmlAppEngine->addImageProvider(qgcImageProviderId, new QGCImageProvider()); @@ -373,7 +375,7 @@ void QGCApplication::_initForNormalAppBoot() MAVLinkProtocol::instance()->checkForLostLogFiles(); // Load known link configurations - _toolbox->linkManager()->loadLinkConfigurationList(); + LinkManager::instance()->loadLinkConfigurationList(); // Probe for joysticks JoystickManager::instance()->init(); @@ -384,7 +386,7 @@ void QGCApplication::_initForNormalAppBoot() } // Connect links with flag AutoconnectLink - _toolbox->linkManager()->startAutoConnectedLinks(); + LinkManager::instance()->startAutoConnectedLinks(); } void QGCApplication::deleteAllSettingsNextBoot(void) diff --git a/src/QGCToolbox.cc b/src/QGCToolbox.cc index 7a228d85fb1..5030722c271 100644 --- a/src/QGCToolbox.cc +++ b/src/QGCToolbox.cc @@ -7,8 +7,7 @@ * ****************************************************************************/ - -#include "LinkManager.h" +#include "QGCToolbox.h" #include "MultiVehicleManager.h" #include "QGCCorePlugin.h" #include "SettingsManager.h" @@ -26,7 +25,6 @@ QGCToolbox::QGCToolbox(QGCApplication* app) //-- Scan and load plugins _scanAndLoadPlugins(app); - _linkManager = new LinkManager (app, this); _multiVehicleManager = new MultiVehicleManager (app, this); } @@ -36,7 +34,6 @@ void QGCToolbox::setChildToolboxes(void) _settingsManager->setToolbox(this); _corePlugin->setToolbox(this); - _linkManager->setToolbox(this); _multiVehicleManager->setToolbox(this); } diff --git a/src/QGCToolbox.h b/src/QGCToolbox.h index 2ca2aa23436..fa37268cb20 100644 --- a/src/QGCToolbox.h +++ b/src/QGCToolbox.h @@ -13,7 +13,6 @@ #include -class LinkManager; class MultiVehicleManager; class QGCApplication; class QGCCorePlugin; @@ -26,7 +25,6 @@ class QGCToolbox : public QObject { public: QGCToolbox(QGCApplication* app); - LinkManager* linkManager () { return _linkManager; } MultiVehicleManager* multiVehicleManager () { return _multiVehicleManager; } QGCCorePlugin* corePlugin () { return _corePlugin; } SettingsManager* settingsManager () { return _settingsManager; } @@ -35,7 +33,6 @@ class QGCToolbox : public QObject { void setChildToolboxes(void); void _scanAndLoadPlugins(QGCApplication *app); - LinkManager* _linkManager = nullptr; MultiVehicleManager* _multiVehicleManager = nullptr; QGCCorePlugin* _corePlugin = nullptr; SettingsManager* _settingsManager = nullptr; diff --git a/src/QmlControls/QGroundControlQmlGlobal.cc b/src/QmlControls/QGroundControlQmlGlobal.cc index f9ee2722e10..ce65ccd9f4d 100644 --- a/src/QmlControls/QGroundControlQmlGlobal.cc +++ b/src/QmlControls/QGroundControlQmlGlobal.cc @@ -112,6 +112,7 @@ QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app, QGCToolbox , _qgcPositionManager(QGCPositionManager::instance()) , _missionCommandTree(MissionCommandTree::instance()) , _videoManager(VideoManager::instance()) + , _linkManager(LinkManager::instance()) #ifndef QGC_AIRLINK_DISABLED , _airlinkManager(AirLinkManager::instance()) #endif @@ -158,7 +159,6 @@ void QGroundControlQmlGlobal::setToolbox(QGCToolbox* toolbox) { QGCTool::setToolbox(toolbox); - _linkManager = toolbox->linkManager(); _multiVehicleManager = toolbox->multiVehicleManager(); _corePlugin = toolbox->corePlugin(); _settingsManager = toolbox->settingsManager(); @@ -253,7 +253,7 @@ void QGroundControlQmlGlobal::startAPMArduRoverMockLink(bool sendStatusText) void QGroundControlQmlGlobal::stopOneMockLink(void) { #ifdef QT_DEBUG - QList sharedLinks = _toolbox->linkManager()->links(); + QList sharedLinks = LinkManager::instance()->links(); for (int i=0; itoolbox()->linkManager()->resetMavlinkSigning(); + LinkManager::instance()->resetMavlinkSigning(); } QString AppSettings::missionSavePath(void) diff --git a/src/Vehicle/MultiVehicleManager.cc b/src/Vehicle/MultiVehicleManager.cc index 0dc00571528..f76b5111cf8 100644 --- a/src/Vehicle/MultiVehicleManager.cc +++ b/src/Vehicle/MultiVehicleManager.cc @@ -362,8 +362,7 @@ void MultiVehicleManager::setGcsHeartbeatEnabled(bool gcsHeartBeatEnabled) void MultiVehicleManager::_sendGCSHeartbeat(void) { - LinkManager* linkManager = qgcApp()->toolbox()->linkManager(); - QList sharedLinks = linkManager->links(); + QList sharedLinks = LinkManager::instance()->links(); // Send a heartbeat out on each link for (int i=0; ilinkManager(); - connect(JoystickManager::instance(), &JoystickManager::activeJoystickChanged, this, &Vehicle::_loadJoystickSettings); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &Vehicle::_activeVehicleChanged); @@ -220,8 +218,6 @@ Vehicle::Vehicle(MAV_AUTOPILOT firmwareType, , _localPositionFactGroup (this) , _localPositionSetpointFactGroup (this) { - _linkManager = _toolbox->linkManager(); - // This will also set the settings based firmware/vehicle types. So it needs to happen first. if (_firmwareType == MAV_AUTOPILOT_TRACK) { trackFirmwareVehicleTypeChanges(); diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index b0370620b36..d69a212f9d8 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -58,7 +58,6 @@ class StatusTextHandler; class InitialConnectStateMachine; class Joystick; class LinkInterface; -class LinkManager; class MAVLinkLogManager; class MissionManager; class ParameterManager; @@ -1051,7 +1050,6 @@ private slots: bool _initialPlanRequestComplete = false; - LinkManager* _linkManager = nullptr; ParameterManager* _parameterManager = nullptr; ComponentInformationManager* _componentInformationManager = nullptr; VehicleObjectAvoidance* _objectAvoidance = nullptr; diff --git a/src/Vehicle/VehicleLinkManager.cc b/src/Vehicle/VehicleLinkManager.cc index 1f18e5a4154..805fb7a22b2 100644 --- a/src/Vehicle/VehicleLinkManager.cc +++ b/src/Vehicle/VehicleLinkManager.cc @@ -21,7 +21,6 @@ QGC_LOGGING_CATEGORY(VehicleLinkManagerLog, "VehicleLinkManagerLog") VehicleLinkManager::VehicleLinkManager(Vehicle* vehicle) : QObject (vehicle) , _vehicle (vehicle) - , _linkMgr (qgcApp()->toolbox()->linkManager()) { connect(this, &VehicleLinkManager::linkNamesChanged, this, &VehicleLinkManager::linkStatusesChanged); connect(&_commLostCheckTimer, &QTimer::timeout, this, &VehicleLinkManager::_commLostCheck); @@ -170,7 +169,7 @@ void VehicleLinkManager::_addLink(LinkInterface* link) qCWarning(VehicleLinkManagerLog) << "_addLink call with link which is already in the list"; return; } else { - SharedLinkInterfacePtr sharedLink = _linkMgr->sharedLinkInterfacePointerForLink(link); + SharedLinkInterfacePtr sharedLink = LinkManager::instance()->sharedLinkInterfacePointerForLink(link); if (!sharedLink) { qCDebug(VehicleLinkManagerLog) << "_addLink stale link" << (void*)link; return; diff --git a/src/Vehicle/VehicleLinkManager.h b/src/Vehicle/VehicleLinkManager.h index 10ff37df23e..f9751a23491 100644 --- a/src/Vehicle/VehicleLinkManager.h +++ b/src/Vehicle/VehicleLinkManager.h @@ -20,7 +20,6 @@ Q_DECLARE_LOGGING_CATEGORY(VehicleLinkManagerLog) class Vehicle; -class LinkManager; class VehicleLinkManagerTest; class VehicleLinkManager : public QObject @@ -80,7 +79,6 @@ private slots: } LinkInfo_t; Vehicle* _vehicle = nullptr; - LinkManager* _linkMgr = nullptr; QTimer _commLostCheckTimer; QList _rgLinkInfo; WeakLinkInterfacePtr _primaryLink; diff --git a/src/VehicleSetup/FirmwareUpgradeController.cc b/src/VehicleSetup/FirmwareUpgradeController.cc index b519762c3af..766148a1e03 100644 --- a/src/VehicleSetup/FirmwareUpgradeController.cc +++ b/src/VehicleSetup/FirmwareUpgradeController.cc @@ -154,19 +154,17 @@ FirmwareUpgradeController::FirmwareUpgradeController(void) FirmwareUpgradeController::~FirmwareUpgradeController() { - qgcApp()->toolbox()->linkManager()->setConnectionsAllowed(); + LinkManager::instance()->setConnectionsAllowed(); } void FirmwareUpgradeController::startBoardSearch(void) { - LinkManager* linkMgr = qgcApp()->toolbox()->linkManager(); - - linkMgr->setConnectionsSuspended(tr("Connect not allowed during Firmware Upgrade.")); + LinkManager::instance()->setConnectionsSuspended(tr("Connect not allowed during Firmware Upgrade.")); // FIXME: Why did we get here with active vehicle? if (!qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()) { // We have to disconnect any inactive links - linkMgr->disconnectAll(); + LinkManager::instance()->disconnectAll(); } _bootloaderFound = false; @@ -435,7 +433,7 @@ void FirmwareUpgradeController::_flashComplete(void) _appendStatusLog(tr("Upgrade complete"), true); _appendStatusLog("------------------------------------------", false); emit flashComplete(); - qgcApp()->toolbox()->linkManager()->setConnectionsAllowed(); + LinkManager::instance()->setConnectionsAllowed(); } void FirmwareUpgradeController::_error(const QString& errorString) @@ -492,7 +490,7 @@ void FirmwareUpgradeController::_errorCancel(const QString& msg) _appendStatusLog("------------------------------------------", false); emit error(); cancel(); - qgcApp()->toolbox()->linkManager()->setConnectionsAllowed(); + LinkManager::instance()->setConnectionsAllowed(); } void FirmwareUpgradeController::_eraseStarted(void) diff --git a/test/Vehicle/InitialConnectTest.cc b/test/Vehicle/InitialConnectTest.cc index bb67ec3d857..c148b76475e 100644 --- a/test/Vehicle/InitialConnectTest.cc +++ b/test/Vehicle/InitialConnectTest.cc @@ -48,7 +48,7 @@ void InitialConnectTest::_boardVendorProductId(void) mockConfig->setBoardVendorProduct(mockVendor, mockProduct); SharedLinkConfigurationPtr linkConfig = mockConfig; - _linkManager->createConnectedLink(linkConfig); + LinkManager::instance()->createConnectedLink(linkConfig); QVERIFY(activeVehicleSpy.wait()); auto *vehicle = mvm->activeVehicle(); @@ -61,5 +61,5 @@ void InitialConnectTest::_boardVendorProductId(void) QCOMPARE(vehicle->firmwareBoardVendorId(), mockVendor); QCOMPARE(vehicle->firmwareBoardProductId(), mockProduct); - _linkManager->disconnectAll(); + LinkManager::instance()->disconnectAll(); } diff --git a/test/Vehicle/VehicleLinkManagerTest.cc b/test/Vehicle/VehicleLinkManagerTest.cc index 88ad18cd578..b68963677c8 100644 --- a/test/Vehicle/VehicleLinkManagerTest.cc +++ b/test/Vehicle/VehicleLinkManagerTest.cc @@ -37,19 +37,19 @@ void VehicleLinkManagerTest::init(void) _multiVehicleMgr = qgcApp()->toolbox()->multiVehicleManager(); - QCOMPARE(_linkManager->links().count(), 0); + QCOMPARE(LinkManager::instance()->links().count(), 0); QCOMPARE(_multiVehicleMgr->vehicles()->count(), 0); } void VehicleLinkManagerTest::cleanup(void) { // Disconnect all links - if (_linkManager->links().count()) { + if (LinkManager::instance()->links().count()) { QSignalSpy spyActiveVehicleChanged(_multiVehicleMgr, &MultiVehicleManager::activeVehicleChanged); - _linkManager->disconnectAll(); + LinkManager::instance()->disconnectAll(); QCOMPARE(spyActiveVehicleChanged.wait(1000), true); QCOMPARE(_multiVehicleMgr->vehicles()->count(), 0); - QCOMPARE(_linkManager->links().count(), 0); + QCOMPARE(LinkManager::instance()->links().count(), 0); } _multiVehicleMgr = nullptr; @@ -331,9 +331,9 @@ void VehicleLinkManagerTest::_startMockLink(int mockIndex, bool highLatency, boo SharedLinkConfigurationPtr sharedConfigmockConfig; - QVERIFY(_linkManager->createConnectedLink(mockConfig)); + QVERIFY(LinkManager::instance()->createConnectedLink(mockConfig)); QVERIFY(mockConfig->link()); - mockLink = _linkManager->sharedLinkInterfacePointerForLink(mockConfig->link()); + mockLink = LinkManager::instance()->sharedLinkInterfacePointerForLink(mockConfig->link()); QVERIFY(mockLink); } diff --git a/test/qgcunittest/UnitTest.cc b/test/qgcunittest/UnitTest.cc index 9b230a9444f..dfaa407bd9c 100644 --- a/test/qgcunittest/UnitTest.cc +++ b/test/qgcunittest/UnitTest.cc @@ -92,11 +92,7 @@ void UnitTest::init(void) { _initCalled = true; - if (!_linkManager) { - _linkManager = qgcApp()->toolbox()->linkManager(); - } - - _linkManager->setConnectionsAllowed(); + LinkManager::instance()->setConnectionsAllowed(); // Force offline vehicle back to defaults AppSettings* appSettings = qgcApp()->toolbox()->settingsManager()->appSettings(); diff --git a/test/qgcunittest/UnitTest.h b/test/qgcunittest/UnitTest.h index 9aea26624d8..ca6eadbaa3f 100644 --- a/test/qgcunittest/UnitTest.h +++ b/test/qgcunittest/UnitTest.h @@ -22,7 +22,6 @@ class QGCMessageBox; class QGCQFileDialog; -class LinkManager; class Vehicle; class Fact; class LinkInterface; @@ -114,7 +113,6 @@ protected slots: void _disconnectMockLink(void); void _missionItemsEqual(MissionItem& actual, MissionItem& expected); - LinkManager* _linkManager = nullptr; MockLink* _mockLink = nullptr; Vehicle* _vehicle = nullptr;