From dda5d55ffaa0ced859c49b1070c74553278d9da0 Mon Sep 17 00:00:00 2001 From: edouard Date: Wed, 12 Jan 2011 07:43:02 +0000 Subject: [PATCH] Improvements in suspendPolling/resumePolling in the connection manager even if a connection plugin does not have devices connected when called. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2388 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../plugins/coreplugin/connectionmanager.cpp | 32 ++++++++----------- .../plugins/coreplugin/connectionmanager.h | 1 + 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/ground/src/plugins/coreplugin/connectionmanager.cpp b/ground/src/plugins/coreplugin/connectionmanager.cpp index 7332e6d64..0e6f013d3 100644 --- a/ground/src/plugins/coreplugin/connectionmanager.cpp +++ b/ground/src/plugins/coreplugin/connectionmanager.cpp @@ -117,13 +117,22 @@ void ConnectionManager::objectAdded(QObject *obj) //register devices and populate CB devChanged(connection); + // Keep track of the registration to be able to tell plugins + // to do things + m_connectionsList.append(connection); + QObject::connect(connection, SIGNAL(availableDevChanged(IConnection *)), this, SLOT(devChanged(IConnection*))); } void ConnectionManager::aboutToRemoveObject(QObject *obj) { - Q_UNUSED(obj); + //Check if a plugin added a connection object to the pool + IConnection *connection = Aggregation::query(obj); + if (!connection) + return; + if (m_connectionsList.contains(connection)) + m_connectionsList.removeAt(m_connectionsList.indexOf(connection)); } /** @@ -250,18 +259,11 @@ void ConnectionManager::unregisterAll(IConnection *connection) /** * Tells every connection plugin to stop polling for devices if they * are doing that. +* */ void ConnectionManager::suspendPolling() { - QList connections; - connections.clear(); - - for(QLinkedList::iterator iter = m_devList.begin(); - iter != m_devList.end(); iter++ ){ - if (!connections.contains(iter->connection)) - connections.append(iter->connection); - } - foreach (IConnection* cnx, connections) { + foreach (IConnection* cnx, m_connectionsList) { cnx->suspendPolling(); } } @@ -272,15 +274,7 @@ void ConnectionManager::suspendPolling() */ void ConnectionManager::resumePolling() { - QList connections; - connections.clear(); - - for(QLinkedList::iterator iter = m_devList.begin(); - iter != m_devList.end(); iter++ ){ - if (!connections.contains(iter->connection)) - connections.append(iter->connection); - } - foreach (IConnection* cnx, connections) { + foreach (IConnection* cnx, m_connectionsList) { cnx->resumePolling(); } } diff --git a/ground/src/plugins/coreplugin/connectionmanager.h b/ground/src/plugins/coreplugin/connectionmanager.h index 29d5e390d..5105c1223 100644 --- a/ground/src/plugins/coreplugin/connectionmanager.h +++ b/ground/src/plugins/coreplugin/connectionmanager.h @@ -94,6 +94,7 @@ protected: QComboBox *m_availableDevList; QPushButton *m_connectBtn; QLinkedList m_devList; + QList m_connectionsList; //currently connected connection plugin devListItem m_connectionDevice;