Commit 92adb4c1 authored by Don Gagne's avatar Don Gagne

Merge pull request #1258 from dogmaphobic/linkDelete

Cleaning dangling links
parents 644ac77f 5fe34d0b
...@@ -57,7 +57,8 @@ public: ...@@ -57,7 +57,8 @@ public:
LinkInterface() : LinkInterface() :
QThread(0), QThread(0),
_ownedByLinkManager(false), _ownedByLinkManager(false),
_deletedByLinkManager(false) _deletedByLinkManager(false),
_flaggedForDeletion(false)
{ {
// Initialize everything for the data rate calculation buffers. // Initialize everything for the data rate calculation buffers.
inDataIndex = 0; inDataIndex = 0;
...@@ -340,6 +341,7 @@ private: ...@@ -340,6 +341,7 @@ private:
bool _ownedByLinkManager; ///< true: This link has been added to LinkManager, false: Link not added to LinkManager bool _ownedByLinkManager; ///< true: This link has been added to LinkManager, false: Link not added to LinkManager
bool _deletedByLinkManager; ///< true: Link being deleted from LinkManager, false: error, Links should only be deleted from LinkManager bool _deletedByLinkManager; ///< true: Link being deleted from LinkManager, false: error, Links should only be deleted from LinkManager
bool _flaggedForDeletion; ///< true: Garbage colletion ready
}; };
#endif // _LINKINTERFACE_H_ #endif // _LINKINTERFACE_H_
...@@ -193,20 +193,37 @@ bool LinkManager::disconnectLink(LinkInterface* link) ...@@ -193,20 +193,37 @@ bool LinkManager::disconnectLink(LinkInterface* link)
{ {
Q_ASSERT(link); Q_ASSERT(link);
if (link->_disconnect()) { if (link->_disconnect()) {
// TODO There is no point in disconnecting it if will stay around.
// This should be turned into a delete link instead. Deleting a link
// is not yet possible as LinkManager is broken.
// Disconnect this link from its configuration
LinkConfiguration* config = link->getLinkConfiguration(); LinkConfiguration* config = link->getLinkConfiguration();
if(config) { if(config) {
config->setLink(NULL); config->setLink(NULL);
} }
// Link is now done and over with. We can't yet delete it because it
// takes a while for the MAVLink protocol to take notice of it. We
// flag it for delayed deletion for final clean up.
link->_flaggedForDeletion = true;
QTimer::singleShot(1000, this, &LinkManager::_delayedDeleteLink);
return true; return true;
} else { } else {
return false; return false;
} }
} }
void LinkManager::_delayedDeleteLink()
{
_linkListMutex.lock();
foreach (LinkInterface* link, _links)
{
Q_ASSERT(link);
if (link->_flaggedForDeletion) {
qDebug() << "Link deleted: " << link->getName();
_linkListMutex.unlock();
deleteLink(link);
return;
}
}
_linkListMutex.unlock();
}
void LinkManager::deleteLink(LinkInterface* link) void LinkManager::deleteLink(LinkInterface* link)
{ {
Q_ASSERT(link); Q_ASSERT(link);
......
...@@ -141,6 +141,7 @@ signals: ...@@ -141,6 +141,7 @@ signals:
private slots: private slots:
void _linkConnected(void); void _linkConnected(void);
void _linkDisconnected(void); void _linkDisconnected(void);
void _delayedDeleteLink();
private: private:
/// All access to LinkManager is through LinkManager::instance /// All access to LinkManager is through LinkManager::instance
......
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