1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

GCS ConnectionManager: More cleaner code structure.

This commit is contained in:
James Cotton 2012-09-08 15:59:54 -05:00
parent 8e8cbd0b75
commit 6840b8934b
2 changed files with 24 additions and 29 deletions

View File

@ -270,16 +270,19 @@ void ConnectionManager::resumePolling()
*/
void ConnectionManager::updateConnectionList(IConnection *connection)
{
// Get the updated list of devices
QList <IConnection::device> availableDev = connection->availableDevices();
// Go through the list of connections of that type. If they are not in the
// available device list then remove them. If they are connected, then
// disconnect them.
for (QLinkedList<DevListItem>::iterator iter = m_devList.begin(); iter != m_devList.end(); )
{
if (iter->connection == connection)
{
if (iter->connection != connection) {
++iter;
continue;
}
// See if device exists in the updated availability list
bool found = availableDev.contains(iter->device);
if (!found) {
@ -291,26 +294,15 @@ void ConnectionManager::updateConnectionList(IConnection *connection)
} else
++iter;
}
else
++iter;
}
// Go through the list of available devices. If they are not present in the device list
// add them.
//and add them back in the list
// Add any back to list that don't exist
foreach (IConnection::device dev, availableDev)
{
bool found = false;
foreach (DevListItem devList, m_devList)
if (devList.device == dev)
found = true;
bool found = m_devList.contains(DevListItem(connection, dev));
if (!found) {
registerDevice(connection,dev);
}
}
}
/**
@ -321,9 +313,7 @@ void ConnectionManager::updateConnectionList(IConnection *connection)
*/
void ConnectionManager::registerDevice(IConnection *conn, IConnection::device device)
{
DevListItem d;
d.connection = conn;
d.device = device;
DevListItem d(conn,device);
m_devList.append(d);
}

View File

@ -59,8 +59,10 @@ namespace Internal {
class DevListItem
{
public:
IConnection *connection;
IConnection::device device;
DevListItem(IConnection *c, IConnection::device d) :
connection(c), device(d) { }
DevListItem() : connection(NULL) { }
QString getConName() {
if (connection == NULL)
@ -71,6 +73,9 @@ public:
bool operator==(const DevListItem &rhs) {
return connection == rhs.connection && device == rhs.device;
}
IConnection *connection;
IConnection::device device;
};