Commit 58eef4b2 authored by Don Gagne's avatar Don Gagne

Fix create/destroy ordering problems between LinkManager and MAVLinkProtocol

parent 09286429
...@@ -68,10 +68,12 @@ LinkManager::LinkManager(QObject* parent, bool registerSingleton) : ...@@ -68,10 +68,12 @@ LinkManager::LinkManager(QObject* parent, bool registerSingleton) :
_connectionsSuspended(false), _connectionsSuspended(false),
_mavlink(NULL) _mavlink(NULL)
{ {
Q_ASSERT(_instance == NULL); if (registerSingleton) {
_instance = this; Q_ASSERT(_instance == NULL);
_instance = this;
}
_mavlink = new MAVLinkProtocol; _mavlink = new MAVLinkProtocol(this);
Q_CHECK_PTR(_mavlink); Q_CHECK_PTR(_mavlink);
} }
......
...@@ -39,7 +39,7 @@ const char* MAVLinkProtocol::_logFileExtension = "mavlink"; ///< Ext ...@@ -39,7 +39,7 @@ const char* MAVLinkProtocol::_logFileExtension = "mavlink"; ///< Ext
* The default constructor will create a new MAVLink object sending heartbeats at * The default constructor will create a new MAVLink object sending heartbeats at
* the MAVLINK_HEARTBEAT_DEFAULT_RATE to all connected links. * the MAVLINK_HEARTBEAT_DEFAULT_RATE to all connected links.
*/ */
MAVLinkProtocol::MAVLinkProtocol() : MAVLinkProtocol::MAVLinkProtocol(LinkManager* linkMgr) :
heartbeatTimer(NULL), heartbeatTimer(NULL),
heartbeatRate(MAVLINK_HEARTBEAT_DEFAULT_RATE), heartbeatRate(MAVLINK_HEARTBEAT_DEFAULT_RATE),
m_heartbeatsEnabled(true), m_heartbeatsEnabled(true),
...@@ -58,8 +58,8 @@ MAVLinkProtocol::MAVLinkProtocol() : ...@@ -58,8 +58,8 @@ MAVLinkProtocol::MAVLinkProtocol() :
_logSuspendReplay(false), _logSuspendReplay(false),
_tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension)), _tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension)),
_protocolStatusMessageConnected(false), _protocolStatusMessageConnected(false),
_saveTempFlightDataLogConnected(false) _saveTempFlightDataLogConnected(false),
_linkMgr(linkMgr)
{ {
qRegisterMetaType<mavlink_message_t>("mavlink_message_t"); qRegisterMetaType<mavlink_message_t>("mavlink_message_t");
...@@ -452,7 +452,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b) ...@@ -452,7 +452,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b)
if (m_multiplexingEnabled) if (m_multiplexingEnabled)
{ {
// Get all links connected to this unit // Get all links connected to this unit
QList<LinkInterface*> links = LinkManager::instance()->getLinks(); QList<LinkInterface*> links = _linkMgr->getLinks();
// Emit message on all links that are currently connected // Emit message on all links that are currently connected
foreach (LinkInterface* currLink, links) foreach (LinkInterface* currLink, links)
...@@ -497,7 +497,7 @@ int MAVLinkProtocol::getComponentId() ...@@ -497,7 +497,7 @@ int MAVLinkProtocol::getComponentId()
void MAVLinkProtocol::sendMessage(mavlink_message_t message) void MAVLinkProtocol::sendMessage(mavlink_message_t message)
{ {
// Get all links connected to this unit // Get all links connected to this unit
QList<LinkInterface*> links = LinkManager::instance()->getLinks(); QList<LinkInterface*> links = _linkMgr->getLinks();
// Emit message on all links that are currently connected // Emit message on all links that are currently connected
QList<LinkInterface*>::iterator i; QList<LinkInterface*>::iterator i;
......
...@@ -43,6 +43,8 @@ This file is part of the QGROUNDCONTROL project ...@@ -43,6 +43,8 @@ This file is part of the QGROUNDCONTROL project
#include "QGC.h" #include "QGC.h"
#include "QGCTemporaryFile.h" #include "QGCTemporaryFile.h"
class LinkManager;
/** /**
* @brief MAVLink micro air vehicle protocol reference implementation. * @brief MAVLink micro air vehicle protocol reference implementation.
* *
...@@ -55,7 +57,7 @@ class MAVLinkProtocol : public QThread ...@@ -55,7 +57,7 @@ class MAVLinkProtocol : public QThread
Q_OBJECT Q_OBJECT
public: public:
MAVLinkProtocol(); MAVLinkProtocol(LinkManager *linkMgr);
~MAVLinkProtocol(); ~MAVLinkProtocol();
/** @brief Get the human-friendly name of this protocol */ /** @brief Get the human-friendly name of this protocol */
...@@ -297,6 +299,8 @@ private: ...@@ -297,6 +299,8 @@ private:
bool _protocolStatusMessageConnected; ///< true: protocolStatusMessage signal has been connected bool _protocolStatusMessageConnected; ///< true: protocolStatusMessage signal has been connected
bool _saveTempFlightDataLogConnected; ///< true: saveTempFlightDataLog signal has been connected bool _saveTempFlightDataLogConnected; ///< true: saveTempFlightDataLog signal has been connected
LinkManager* _linkMgr;
}; };
#endif // MAVLINKPROTOCOL_H_ #endif // MAVLINKPROTOCOL_H_
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