Commit 5fe34d0b authored by dogmaphobic's avatar dogmaphobic

Cleaning dangling links

parent b1a9d302
......@@ -57,7 +57,8 @@ public:
LinkInterface() :
QThread(0),
_ownedByLinkManager(false),
_deletedByLinkManager(false)
_deletedByLinkManager(false),
_flaggedForDeletion(false)
{
// Initialize everything for the data rate calculation buffers.
inDataIndex = 0;
......@@ -340,6 +341,7 @@ private:
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 _flaggedForDeletion; ///< true: Garbage colletion ready
};
#endif // _LINKINTERFACE_H_
......@@ -193,20 +193,37 @@ bool LinkManager::disconnectLink(LinkInterface* link)
{
Q_ASSERT(link);
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();
if(config) {
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;
} else {
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)
{
Q_ASSERT(link);
......
......@@ -141,6 +141,7 @@ signals:
private slots:
void _linkConnected(void);
void _linkDisconnected(void);
void _delayedDeleteLink();
private:
/// 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