Commit e0d94b4d authored by dogmaphobic's avatar dogmaphobic

Fixing asynchronous issue with link disconnect.

I noticed that some times, the disconnect signal would get to the updateConnect button (tool bar) before the link was physically disconnected. That would cause it to count it as a still connected link and get the connect button logic out of sync.
While at it, added an interface to the UDP link to return its configuration instance. That allows the LinkManager to unlink it when disconnecting it.
parent 3fd9497c
...@@ -164,6 +164,8 @@ public: ...@@ -164,6 +164,8 @@ public:
bool connect(void); bool connect(void);
bool disconnect(void); bool disconnect(void);
LinkConfiguration* getLinkConfiguration() { return _config; }
public slots: public slots:
/*! @brief Add a new host to broadcast messages to */ /*! @brief Add a new host to broadcast messages to */
......
...@@ -585,18 +585,17 @@ void QGCToolBar::_linkConnected(LinkInterface* link) ...@@ -585,18 +585,17 @@ void QGCToolBar::_linkConnected(LinkInterface* link)
void QGCToolBar::_linkDisconnected(LinkInterface* link) void QGCToolBar::_linkDisconnected(LinkInterface* link)
{ {
Q_UNUSED(link); _updateConnectButton(link);
_updateConnectButton();
} }
void QGCToolBar::_updateConnectButton(void) void QGCToolBar::_updateConnectButton(LinkInterface *disconnectedLink)
{ {
QMenu* menu = new QMenu(this); QMenu* menu = new QMenu(this);
// If there are multiple connected links add/update the connect button menu // If there are multiple connected links add/update the connect button menu
int connectedCount = 0; int connectedCount = 0;
QList<LinkInterface*> links = _linkMgr->getLinks(); QList<LinkInterface*> links = _linkMgr->getLinks();
foreach(LinkInterface* link, links) { foreach(LinkInterface* link, links) {
if (link->isConnected()) { if (disconnectedLink != link && link->isConnected()) {
connectedCount++; connectedCount++;
QAction* action = menu->addAction(link->getName()); QAction* action = menu->addAction(link->getName());
action->setData(QVariant::fromValue((void*)link)); action->setData(QVariant::fromValue((void*)link));
......
...@@ -123,7 +123,7 @@ private slots: ...@@ -123,7 +123,7 @@ private slots:
void _updateConfigurations(); void _updateConfigurations();
private: private:
void _updateConnectButton(void); void _updateConnectButton(LinkInterface* disconnectedLink = NULL);
LinkManager* _linkMgr; LinkManager* _linkMgr;
......
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