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:
parent
8e8cbd0b75
commit
6840b8934b
@ -270,47 +270,39 @@ void ConnectionManager::resumePolling()
|
|||||||
*/
|
*/
|
||||||
void ConnectionManager::updateConnectionList(IConnection *connection)
|
void ConnectionManager::updateConnectionList(IConnection *connection)
|
||||||
{
|
{
|
||||||
|
// Get the updated list of devices
|
||||||
QList <IConnection::device> availableDev = connection->availableDevices();
|
QList <IConnection::device> availableDev = connection->availableDevices();
|
||||||
|
|
||||||
// Go through the list of connections of that type. If they are not in the
|
// 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
|
// available device list then remove them. If they are connected, then
|
||||||
// disconnect them.
|
// disconnect them.
|
||||||
|
|
||||||
for (QLinkedList<DevListItem>::iterator iter = m_devList.begin(); iter != m_devList.end(); )
|
for (QLinkedList<DevListItem>::iterator iter = m_devList.begin(); iter != m_devList.end(); )
|
||||||
{
|
{
|
||||||
if (iter->connection == connection)
|
if (iter->connection != connection) {
|
||||||
{
|
++iter;
|
||||||
// See if device exists in the updated availability list
|
continue;
|
||||||
bool found = availableDev.contains(iter->device);
|
|
||||||
if (!found) {
|
|
||||||
// we are currently using the one we are about to erase
|
|
||||||
if (m_connectionDevice.connection && m_connectionDevice.connection == connection && m_connectionDevice.device == iter->device)
|
|
||||||
disconnectDevice();
|
|
||||||
|
|
||||||
iter = m_devList.erase(iter);
|
|
||||||
} else
|
|
||||||
++iter;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
// See if device exists in the updated availability list
|
||||||
|
bool found = availableDev.contains(iter->device);
|
||||||
|
if (!found) {
|
||||||
|
// we are currently using the one we are about to erase
|
||||||
|
if (m_connectionDevice.connection && m_connectionDevice.connection == connection && m_connectionDevice.device == iter->device)
|
||||||
|
disconnectDevice();
|
||||||
|
|
||||||
|
iter = m_devList.erase(iter);
|
||||||
|
} else
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go through the list of available devices. If they are not present in the device list
|
// Add any back to list that don't exist
|
||||||
// add them.
|
|
||||||
|
|
||||||
//and add them back in the list
|
|
||||||
foreach (IConnection::device dev, availableDev)
|
foreach (IConnection::device dev, availableDev)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = m_devList.contains(DevListItem(connection, dev));
|
||||||
foreach (DevListItem devList, m_devList)
|
|
||||||
if (devList.device == dev)
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
registerDevice(connection,dev);
|
registerDevice(connection,dev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -321,9 +313,7 @@ void ConnectionManager::updateConnectionList(IConnection *connection)
|
|||||||
*/
|
*/
|
||||||
void ConnectionManager::registerDevice(IConnection *conn, IConnection::device device)
|
void ConnectionManager::registerDevice(IConnection *conn, IConnection::device device)
|
||||||
{
|
{
|
||||||
DevListItem d;
|
DevListItem d(conn,device);
|
||||||
d.connection = conn;
|
|
||||||
d.device = device;
|
|
||||||
m_devList.append(d);
|
m_devList.append(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,8 +59,10 @@ namespace Internal {
|
|||||||
class DevListItem
|
class DevListItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IConnection *connection;
|
DevListItem(IConnection *c, IConnection::device d) :
|
||||||
IConnection::device device;
|
connection(c), device(d) { }
|
||||||
|
|
||||||
|
DevListItem() : connection(NULL) { }
|
||||||
|
|
||||||
QString getConName() {
|
QString getConName() {
|
||||||
if (connection == NULL)
|
if (connection == NULL)
|
||||||
@ -71,6 +73,9 @@ public:
|
|||||||
bool operator==(const DevListItem &rhs) {
|
bool operator==(const DevListItem &rhs) {
|
||||||
return connection == rhs.connection && device == rhs.device;
|
return connection == rhs.connection && device == rhs.device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IConnection *connection;
|
||||||
|
IConnection::device device;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user