Commit f053edc8 authored by Don Gagne's avatar Don Gagne

Merge pull request #1403 from DonLakeFlyer/DebugConsole

Track links using shared pointed
parents 8dd7b72d f712a7f4
......@@ -91,8 +91,7 @@ DebugConsole::DebugConsole(QWidget *parent) :
// Connect to UAS manager to get notified about new UAS
connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(uasCreated(UASInterface*)));
// Get a list of all existing links
links = QList<LinkInterface*>();
// Add all existing links
foreach (LinkInterface* link, LinkManager::instance()->getLinks()) {
addLink(link);
}
......@@ -171,12 +170,16 @@ void DebugConsole::uasCreated(UASInterface* uas)
*/
void DebugConsole::addLink(LinkInterface* link)
{
// Add link to link list
links.insert(link->getMavlinkChannel(), link);
// Add link to list
foreach (SharedLinkInterface sharedLink, _links) {
Q_ASSERT(sharedLink.data() != link);
}
_links.append(LinkManager::instance()->sharedPointerForLink(link));
m_ui->linkComboBox->insertItem(link->getMavlinkChannel(), link->getName());
// Set new item as current
m_ui->linkComboBox->setCurrentIndex(qMax(0, links.size() - 1));
m_ui->linkComboBox->setCurrentIndex(qMax(0, _links.size() - 1));
linkSelected(m_ui->linkComboBox->currentIndex());
// Register for name changes
......@@ -184,18 +187,24 @@ void DebugConsole::addLink(LinkInterface* link)
connect(LinkManager::instance(), &LinkManager::linkDisconnected, this, &DebugConsole::removeLink, Qt::UniqueConnection);
}
void DebugConsole::removeLink(LinkInterface* const linkInterface)
void DebugConsole::removeLink(LinkInterface* const link)
{
// Add link to link list
if (links.contains(linkInterface)) {
int linkIndex = links.indexOf(linkInterface);
links.removeAt(linkIndex);
m_ui->linkComboBox->removeItem(linkIndex);
bool found = false;
int linkIndex;
for (linkIndex=0; linkIndex<_links.count(); linkIndex++) {
if (_links[linkIndex].data() == link) {
found = true;
_links.removeAt(linkIndex);
break;
}
}
Q_UNUSED(found);
Q_ASSERT(found);
m_ui->linkComboBox->removeItem(linkIndex);
// Now if this was the current link, clean up some stuff.
if (linkInterface == currLink)
if (link == currLink)
{
// Like disable the update time for the UI.
snapShotTimer.stop();
......@@ -211,7 +220,7 @@ void DebugConsole::linkStatusUpdate(const QString& name,const QString& text)
m_ui->receiveText->ensureCursorVisible();
}
void DebugConsole::linkSelected(int linkId)
void DebugConsole::linkSelected(int linkIndex)
{
// Disconnect
if (currLink)
......@@ -226,8 +235,8 @@ void DebugConsole::linkSelected(int linkId)
m_ui->receiveText->clear();
// Connect new link
if (linkId != -1) {
currLink = links[linkId];
if (linkIndex != -1) {
currLink = _links[linkIndex].data();
connect(currLink, SIGNAL(bytesReceived(LinkInterface*,QByteArray)), this, SLOT(receiveBytes(LinkInterface*, QByteArray)));
disconnect(currLink, &LinkInterface::connected, this, &DebugConsole::_linkConnected);
connect(currLink,SIGNAL(communicationUpdate(QString,QString)),this,SLOT(linkStatusUpdate(QString,QString)));
......@@ -241,13 +250,21 @@ void DebugConsole::linkSelected(int linkId)
*/
void DebugConsole::updateLinkName(QString name)
{
// Set name if signal came from a link
LinkInterface* link = qobject_cast<LinkInterface*>(sender());
if((link != NULL) && (links.contains(link)))
{
const qint16 &linkIndex(links.indexOf(link));
m_ui->linkComboBox->setItemText(linkIndex,name);
}
if (link != NULL) {
bool found = false;
int linkIndex;
for (linkIndex=0; linkIndex<_links.count(); linkIndex++) {
if (_links[linkIndex].data() == link) {
found = true;
break;
}
}
if (found) {
m_ui->linkComboBox->setItemText(linkIndex, name);
}
}
}
void DebugConsole::setAutoHold(bool hold)
......
......@@ -116,7 +116,6 @@ protected:
/** @brief Cycle through the command history */
void cycleCommandHistory(bool up);
QList<LinkInterface*> links;
LinkInterface* currLink;
bool holdOn; ///< Hold current view, ignore new data
......@@ -150,6 +149,11 @@ private slots:
private:
/** @brief Set connection state of the current link */
void _setConnectionState(bool);
/// List of all links we are keeping track of. We keep SharedLinkInterface objects
/// which are QSharedPointer's in order to maintain reference counts. Otherwise signals
/// can get out of order and the link may be deleted before we clean up our side.
QList<SharedLinkInterface> _links;
Ui::DebugConsole *m_ui;
};
......
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