1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

GCS ConnectionManager: Get rid of all the copies of various forms of the names and

store a handle to the IConnection::device and generate the appropriate names from
consistent functions.
This commit is contained in:
James Cotton 2012-09-08 15:14:06 -05:00
parent 1ca8abb3c8
commit 65ef8a59b4
3 changed files with 65 additions and 67 deletions

View File

@ -95,7 +95,7 @@ bool ConnectionManager::connectDevice()
if (!connection_device.connection) if (!connection_device.connection)
return false; return false;
QIODevice *io_dev = connection_device.connection->openDevice(connection_device.Name); QIODevice *io_dev = connection_device.connection->openDevice(connection_device.device.name);
if (!io_dev) if (!io_dev)
return false; return false;
@ -105,15 +105,6 @@ bool ConnectionManager::connectDevice()
if (!io_dev->isOpen()) { if (!io_dev->isOpen()) {
qDebug() << "Error: io_dev->isOpen() returned FALSE .. could not open connection to " << connection_device.devName qDebug() << "Error: io_dev->isOpen() returned FALSE .. could not open connection to " << connection_device.devName
<< ": " << io_dev->errorString(); << ": " << io_dev->errorString();
// close the device
// EDOUARD: why do we close if we could not open ???
try {
connection_device.connection->closeDevice(connection_device.devName);
}
catch (...) { // handle exception
qDebug() << "Exception: connection_device.connection->closeDevice(" << connection_device.devName << ")";
}
return false; return false;
} }
@ -150,8 +141,9 @@ bool ConnectionManager::disconnectDevice()
emit deviceAboutToDisconnect(); emit deviceAboutToDisconnect();
try { try {
if (m_connectionDevice.connection) if (m_connectionDevice.connection) {
m_connectionDevice.connection->closeDevice(m_connectionDevice.devName); m_connectionDevice.connection->closeDevice(m_connectionDevice.getConName());
}
} catch (...) { // handle exception } catch (...) { // handle exception
qDebug() << "Exception: m_connectionDevice.connection->closeDevice(" << m_connectionDevice.devName << ")"; qDebug() << "Exception: m_connectionDevice.connection->closeDevice(" << m_connectionDevice.devName << ")";
} }
@ -235,7 +227,7 @@ devListItem ConnectionManager::findDevice(const QString &devName)
{ {
foreach (devListItem d, m_devList) foreach (devListItem d, m_devList)
{ {
if (d.devName == devName) if (d.getConName() == devName)
return d; return d;
} }
@ -303,7 +295,6 @@ void ConnectionManager::updateConnectionList(IConnection *connection)
if (!found) { if (!found) {
if (m_connectionDevice.connection && m_connectionDevice.connection == connection && m_connectionDevice.device == iter->device) if (m_connectionDevice.connection && m_connectionDevice.connection == connection && m_connectionDevice.device == iter->device)
{ // we are currently using the one we are about to erase { // we are currently using the one we are about to erase
//onConnectionClosed(m_connectionDevice.connection);
disconnectDevice(); disconnectDevice();
} }
@ -344,9 +335,6 @@ void ConnectionManager::registerDevice(IConnection *conn, IConnection::device de
devListItem d; devListItem d;
d.connection = conn; d.connection = conn;
d.device = device; d.device = device;
d.devName = conn->shortName() + ": " + device.name;
d.Name = device.name;
d.displayName = conn->shortName() + " : " + device.displayName;
m_devList.append(d); m_devList.append(d);
} }
@ -369,12 +357,24 @@ void ConnectionManager::devChanged(IConnection *connection)
//remove registered devices of this IConnection from the list //remove registered devices of this IConnection from the list
updateConnectionList(connection); updateConnectionList(connection);
updateConnectionDropdown();
//disable connection button if the liNameif (m_availableDevList->count() > 0)
if (m_availableDevList->count() > 0)
m_connectBtn->setEnabled(true);
else
m_connectBtn->setEnabled(false);
}
void ConnectionManager::updateConnectionDropdown()
{
//add all the list again to the combobox //add all the list again to the combobox
foreach (devListItem d, m_devList) foreach (devListItem d, m_devList)
{ {
m_availableDevList->addItem(d.displayName); m_availableDevList->addItem(d.getConName());
m_availableDevList->setItemData(m_availableDevList->count()-1,(const QString)d.devName,Qt::ToolTipRole); m_availableDevList->setItemData(m_availableDevList->count()-1, d.getConName(), Qt::ToolTipRole);
if(!m_ioDev && d.displayName.startsWith("USB")) if(!m_ioDev && d.getConName().startsWith("USB"))
{ {
if(m_mainWindow->generalSettings()->autoConnect() || m_mainWindow->generalSettings()->autoSelect()) if(m_mainWindow->generalSettings()->autoConnect() || m_mainWindow->generalSettings()->autoSelect())
m_availableDevList->setCurrentIndex(m_availableDevList->count()-1); m_availableDevList->setCurrentIndex(m_availableDevList->count()-1);
@ -389,19 +389,10 @@ void ConnectionManager::devChanged(IConnection *connection)
{ {
for(int x=0;x<m_availableDevList->count();++x) for(int x=0;x<m_availableDevList->count();++x)
{ {
if(m_connectionDevice.devName==m_availableDevList->itemData(x,Qt::ToolTipRole).toString()) if(m_connectionDevice.getConName()==m_availableDevList->itemData(x,Qt::ToolTipRole).toString())
m_availableDevList->setCurrentIndex(x); m_availableDevList->setCurrentIndex(x);
} }
} }
//disable connection button if the liNameif (m_availableDevList->count() > 0)
if (m_availableDevList->count() > 0)
m_connectBtn->setEnabled(true);
else
m_connectBtn->setEnabled(false);
}
} }
void Core::ConnectionManager::connectionsCallBack() void Core::ConnectionManager::connectionsCallBack()
@ -412,4 +403,6 @@ void Core::ConnectionManager::connectionsCallBack()
} }
connectionBackup.clear(); connectionBackup.clear();
disconnect(ExtensionSystem::PluginManager::instance(),SIGNAL(pluginsLoadEnded()),this,SLOT(connectionsCallBack())); disconnect(ExtensionSystem::PluginManager::instance(),SIGNAL(pluginsLoadEnded()),this,SLOT(connectionsCallBack()));
}
} //namespace Core } //namespace Core

View File

@ -56,13 +56,17 @@ namespace Internal {
} // namespace Internal } // namespace Internal
struct devListItem class devListItem
{ {
public:
IConnection *connection; IConnection *connection;
IConnection::device device; IConnection::device device;
QString devName;
QString Name; QString getConName() {
QString displayName; if (connection == NULL)
return "";
return connection->shortName() + ": " + device.displayName;
}
}; };
@ -85,6 +89,7 @@ public:
protected: protected:
void updateConnectionList(IConnection *connection); void updateConnectionList(IConnection *connection);
void registerDevice(IConnection *conn, IConnection::device device); void registerDevice(IConnection *conn, IConnection::device device);
void updateConnectionDropdown();
devListItem findDevice(const QString &devName); devListItem findDevice(const QString &devName);
signals: signals:

View File

@ -249,8 +249,8 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
// The board is now reset: we have to disconnect telemetry // The board is now reset: we have to disconnect telemetry
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager(); Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
QString dli = cm->getCurrentDevice().Name; QString dli = cm->getCurrentDevice().getConName();
QString dlj = cm->getCurrentDevice().devName; QString dlj = cm->getCurrentDevice().getConName();
cm->disconnectDevice(); cm->disconnectDevice();
QTimer::singleShot(200, &m_eventloop, SLOT(quit())); QTimer::singleShot(200, &m_eventloop, SLOT(quit()));
m_eventloop.exec(); m_eventloop.exec();