From 58eef4b27d1075120994daf381d121ab7564332d Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Tue, 9 Dec 2014 18:15:57 -0800 Subject: [PATCH] Fix create/destroy ordering problems between LinkManager and MAVLinkProtocol --- src/comm/LinkManager.cc | 8 +++++--- src/comm/MAVLinkProtocol.cc | 10 +++++----- src/comm/MAVLinkProtocol.h | 6 +++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/comm/LinkManager.cc b/src/comm/LinkManager.cc index dd0cefcb2..6c5385199 100644 --- a/src/comm/LinkManager.cc +++ b/src/comm/LinkManager.cc @@ -68,10 +68,12 @@ LinkManager::LinkManager(QObject* parent, bool registerSingleton) : _connectionsSuspended(false), _mavlink(NULL) { - Q_ASSERT(_instance == NULL); - _instance = this; + if (registerSingleton) { + Q_ASSERT(_instance == NULL); + _instance = this; + } - _mavlink = new MAVLinkProtocol; + _mavlink = new MAVLinkProtocol(this); Q_CHECK_PTR(_mavlink); } diff --git a/src/comm/MAVLinkProtocol.cc b/src/comm/MAVLinkProtocol.cc index f30424415..8fb72a3d4 100644 --- a/src/comm/MAVLinkProtocol.cc +++ b/src/comm/MAVLinkProtocol.cc @@ -39,7 +39,7 @@ const char* MAVLinkProtocol::_logFileExtension = "mavlink"; ///< Ext * The default constructor will create a new MAVLink object sending heartbeats at * the MAVLINK_HEARTBEAT_DEFAULT_RATE to all connected links. */ -MAVLinkProtocol::MAVLinkProtocol() : +MAVLinkProtocol::MAVLinkProtocol(LinkManager* linkMgr) : heartbeatTimer(NULL), heartbeatRate(MAVLINK_HEARTBEAT_DEFAULT_RATE), m_heartbeatsEnabled(true), @@ -58,8 +58,8 @@ MAVLinkProtocol::MAVLinkProtocol() : _logSuspendReplay(false), _tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension)), _protocolStatusMessageConnected(false), - _saveTempFlightDataLogConnected(false) - + _saveTempFlightDataLogConnected(false), + _linkMgr(linkMgr) { qRegisterMetaType("mavlink_message_t"); @@ -452,7 +452,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b) if (m_multiplexingEnabled) { // Get all links connected to this unit - QList links = LinkManager::instance()->getLinks(); + QList links = _linkMgr->getLinks(); // Emit message on all links that are currently connected foreach (LinkInterface* currLink, links) @@ -497,7 +497,7 @@ int MAVLinkProtocol::getComponentId() void MAVLinkProtocol::sendMessage(mavlink_message_t message) { // Get all links connected to this unit - QList links = LinkManager::instance()->getLinks(); + QList links = _linkMgr->getLinks(); // Emit message on all links that are currently connected QList::iterator i; diff --git a/src/comm/MAVLinkProtocol.h b/src/comm/MAVLinkProtocol.h index f379296d4..1c87ed0a1 100644 --- a/src/comm/MAVLinkProtocol.h +++ b/src/comm/MAVLinkProtocol.h @@ -43,6 +43,8 @@ This file is part of the QGROUNDCONTROL project #include "QGC.h" #include "QGCTemporaryFile.h" +class LinkManager; + /** * @brief MAVLink micro air vehicle protocol reference implementation. * @@ -55,7 +57,7 @@ class MAVLinkProtocol : public QThread Q_OBJECT public: - MAVLinkProtocol(); + MAVLinkProtocol(LinkManager *linkMgr); ~MAVLinkProtocol(); /** @brief Get the human-friendly name of this protocol */ @@ -297,6 +299,8 @@ private: bool _protocolStatusMessageConnected; ///< true: protocolStatusMessage signal has been connected bool _saveTempFlightDataLogConnected; ///< true: saveTempFlightDataLog signal has been connected + + LinkManager* _linkMgr; }; #endif // MAVLINKPROTOCOL_H_ -- 2.22.0