1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

Added exception catches in known problem areas if GCS is closed while it's still connected to a USB device.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2958 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2011-03-03 22:03:03 +00:00 committed by pip
parent e4535ed575
commit f8f25bf2d2

View File

@ -129,8 +129,8 @@ void ConnectionManager::aboutToRemoveObject(QObject *obj)
IConnection *connection = Aggregation::query<IConnection>(obj); IConnection *connection = Aggregation::query<IConnection>(obj);
if (!connection) return; if (!connection) return;
if (m_connectionsList.contains(connection)) if (m_connectionsList.contains(connection))
m_connectionsList.removeAt(m_connectionsList.indexOf(connection)); m_connectionsList.removeAt(m_connectionsList.indexOf(connection));
} }
/** /**
@ -146,12 +146,20 @@ bool ConnectionManager::disconnectDevice()
//signal interested plugins that we are disconnecting the device //signal interested plugins that we are disconnecting the device
emit deviceDisconnected(); emit deviceDisconnected();
if (m_connectionDevice.connection) try
{ {
m_connectionDevice.connection->closeDevice(m_connectionDevice.devName); if (m_connectionDevice.connection)
m_ioDev = NULL; {
m_connectionDevice.connection = NULL; m_connectionDevice.connection->closeDevice(m_connectionDevice.devName);
} m_connectionDevice.connection = NULL;
m_ioDev = NULL;
}
}
catch (...)
{ // handle exception
m_connectionDevice.connection = NULL;
m_ioDev = NULL;
}
m_connectBtn->setText("Connect"); m_connectBtn->setText("Connect");
m_availableDevList->setEnabled(true); m_availableDevList->setEnabled(true);
@ -164,9 +172,20 @@ void ConnectionManager::onConnectionClosed(QObject *obj) // Pip
if (!m_connectionDevice.connection || m_connectionDevice.connection != obj) if (!m_connectionDevice.connection || m_connectionDevice.connection != obj)
return; return;
m_connectionDevice.connection->closeDevice(m_connectionDevice.devName); try
m_connectionDevice.connection = NULL; {
m_ioDev = NULL; if (m_connectionDevice.connection)
{
m_connectionDevice.connection->closeDevice(m_connectionDevice.devName);
m_connectionDevice.connection = NULL;
m_ioDev = NULL;
}
}
catch (...)
{ // handle exception
m_connectionDevice.connection = NULL;
m_ioDev = NULL;
}
m_connectBtn->setText("Connect"); m_connectBtn->setText("Connect");
m_availableDevList->setEnabled(true); m_availableDevList->setEnabled(true);
@ -200,8 +219,7 @@ void ConnectionManager::onConnectPressed()
if (m_connectionDevice.connection) if (m_connectionDevice.connection)
{ {
m_ioDev = m_connectionDevice.connection->openDevice(m_connectionDevice.devName); m_ioDev = m_connectionDevice.connection->openDevice(m_connectionDevice.devName);
if (m_ioDev)
if(m_ioDev)
{ {
m_ioDev->open(QIODevice::ReadWrite); m_ioDev->open(QIODevice::ReadWrite);
@ -212,7 +230,7 @@ void ConnectionManager::onConnectPressed()
// TODO: inform the user that something went wrong // TODO: inform the user that something went wrong
m_connectionDevice.connection = NULL; // Pip m_connectionDevice.connection = NULL;
m_ioDev = NULL; m_ioDev = NULL;
return; return;
} }
@ -239,12 +257,20 @@ void ConnectionManager::onConnectPressed()
//signal interested plugins that user is disconnecting his device //signal interested plugins that user is disconnecting his device
emit deviceDisconnected(); emit deviceDisconnected();
if (m_connectionDevice.connection) try
{ {
m_connectionDevice.connection->closeDevice(m_connectionDevice.devName); if (m_connectionDevice.connection)
m_ioDev = NULL; {
m_connectionDevice.connection = NULL; m_connectionDevice.connection->closeDevice(m_connectionDevice.devName);
} m_connectionDevice.connection = NULL;
m_ioDev = NULL;
}
}
catch (...)
{ // handle exception
m_connectionDevice.connection = NULL;
m_ioDev = NULL;
}
m_connectBtn->setText("Connect"); m_connectBtn->setText("Connect");
m_availableDevList->setEnabled(true); m_availableDevList->setEnabled(true);