1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

OP-87 modified connection manager to not delete the m_ioDev and moved this functionality into the iConnection plugins

This change was made to the following plugins:
serialconnection
ipconnection
RawHID

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1053 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
andrew 2010-07-10 01:24:32 +00:00 committed by andrew
parent e367d341a9
commit d23ac909db
7 changed files with 81 additions and 28 deletions

View File

@ -151,18 +151,28 @@ void ConnectionManager::onConnectPressed()
else
{
m_connectionDevice.connection = NULL;
m_ioDev = NULL;
}
}
}
else {
//only do this if we are disconnecting
//signal interested plugins that user is disconnecting his device
emit deviceDisconnected();
if(m_connectionDevice.connection){
m_connectionDevice.connection->closeDevice(m_connectionDevice.devName);
m_ioDev = NULL;
m_connectionDevice.connection = NULL;
}
}
//both in case of error and disconnection, we fall back here
m_connectBtn->setText("Connect");
m_availableDevList->setEnabled(true);
//signal interested plugins that user is disconnecting his device
emit deviceDisconnected();
//close the device
/*//close the device
if(m_ioDev)
{
m_ioDev->close();
@ -171,11 +181,9 @@ void ConnectionManager::onConnectPressed()
delete m_ioDev;
m_ioDev = NULL;
}
*/
if(m_connectionDevice.connection)
m_connectionDevice.connection->closeDevice(m_connectionDevice.devName);
m_connectionDevice.connection = NULL;
}
/**

View File

@ -44,6 +44,7 @@
IPconnectionConnection::IPconnectionConnection()
{
ipSocket = NULL;
//create all our objects
m_config = new IPconnectionConfiguration("IP Network Telemetry", NULL, this);
m_config->restoresettings();
@ -59,9 +60,11 @@ IPconnectionConnection::IPconnectionConnection()
}
IPconnectionConnection::~IPconnectionConnection()
{
//tcpSocket->close ();
//delete(tcpSocket);
{//clean up out resources...
if (ipSocket){
ipSocket->close ();
delete(ipSocket);
}
}
void IPconnectionConnection::onEnumerationChanged()
@ -89,10 +92,17 @@ QIODevice *IPconnectionConnection::openDevice(const QString &deviceName)
int Port;
QMessageBox msgBox;
if (ipSocket){
//Andrew: close any existing socket... this should never occur
ipSocket->close ();
delete(ipSocket);
ipSocket = NULL;
}
if (m_config->UseTCP()) {
tcpSocket = new QTcpSocket(this);
ipSocket = new QTcpSocket(this);
} else {
tcpSocket = new QUdpSocket(this);
ipSocket = new QUdpSocket(this);
}
//get the configuration info
@ -107,30 +117,29 @@ QIODevice *IPconnectionConnection::openDevice(const QString &deviceName)
}
else {
//try to connect...
tcpSocket->connectToHost((const QString )HostName, Port);
ipSocket->connectToHost((const QString )HostName, Port);
//in blocking mode so we wait for the connection to succeed
if (tcpSocket->waitForConnected(Timeout)) {
return tcpSocket;
if (ipSocket->waitForConnected(Timeout)) {
return ipSocket;
}
//tell user something went wrong
msgBox.setText((const QString )tcpSocket->errorString ());
msgBox.setText((const QString )ipSocket->errorString ());
msgBox.exec();
}
/* BUGBUG TODO - returning null here leads to segfault because some caller still calls disconnect without checking our return value properly
* someone needs to debug this, I got lost in the calling chain.*/
//return NULL;
return tcpSocket;
ipSocket = NULL;
return ipSocket;
}
void IPconnectionConnection::closeDevice(const QString &deviceName)
{
//still having problems with the app crashing when we reference the tcpsocket outside the openDevice function...
//tcpSocket->close ();
//delete(tcpSocket);
// Note: CorvusCorax thinks its because the socket got deleted by the caller before this close() is even called
// so we end up with a dangling reference! Is this a bug?
if (ipSocket){
ipSocket->close ();
delete(ipSocket);
ipSocket = NULL;
}
}

View File

@ -69,7 +69,7 @@ public:
protected slots:
void onEnumerationChanged();
private:
QAbstractSocket *tcpSocket;
QAbstractSocket *ipSocket;
IPconnectionConfiguration *m_config;
IPconnectionOptionsPage *m_optionspage;
//QSettings* settings;

View File

@ -75,6 +75,10 @@ void RawHIDEnumerationThread::run()
RawHIDConnection::RawHIDConnection()
: m_enumerateThread(this)
{
//added by andrew
RawHidHandle = NULL;
QObject::connect(&m_enumerateThread, SIGNAL(enumerationChanged()),
this, SLOT(onEnumerationChanged()));
m_enumerateThread.start();
@ -112,12 +116,27 @@ QStringList RawHIDConnection::availableDevices()
QIODevice *RawHIDConnection::openDevice(const QString &deviceName)
{
//added by andrew
if (RawHidHandle){
closeDevice(deviceName);
}
//end added by andrew
m_deviceOpened = true;
return new RawHID(deviceName);
//return new RawHID(deviceName);
RawHidHandle = new RawHID(deviceName);
return RawHidHandle;
}
void RawHIDConnection::closeDevice(const QString &deviceName)
{
//added by andrew...
if (RawHidHandle){
RawHidHandle->close();
delete(RawHidHandle);
RawHidHandle=NULL;
}
//end added by andrew
m_deviceOpened = false;
}

View File

@ -29,6 +29,7 @@
#define RAWHIDPLUGIN_H
#include "rawhid_global.h"
#include "rawhid.h"
#include "coreplugin/iconnection.h"
#include <extensionsystem/iplugin.h>
@ -88,6 +89,9 @@ public:
protected slots:
void onEnumerationChanged();
private:
RawHID *RawHidHandle;
protected:
QMutex m_enumMutex;
RawHIDEnumerationThread m_enumerateThread;

View File

@ -37,6 +37,7 @@
SerialConnection::SerialConnection()
{
serialHandle = NULL;
//I'm cheating a little bit here:
//Knowing if the device enumeration really changed is a bit complicated
//so I just signal it whenever we have a device event...
@ -74,6 +75,9 @@ QStringList SerialConnection::availableDevices()
QIODevice *SerialConnection::openDevice(const QString &deviceName)
{
if (serialHandle){
closeDevice(deviceName);
}
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
foreach( QextPortInfo port, ports ) {
if(port.friendName == deviceName)
@ -87,10 +91,11 @@ QIODevice *SerialConnection::openDevice(const QString &deviceName)
set.FlowControl = FLOW_OFF;
set.Timeout_Millisec = 500;
#ifdef Q_OS_WIN
return new QextSerialPort(port.portName, set);
serialHandle = new QextSerialPort(port.portName, set);
#else
return new QextSerialPort(port.physName, set);
serialHandle = new QextSerialPort(port.physName, set);
#endif
return serialHandle;
}
}
return NULL;
@ -98,7 +103,12 @@ QIODevice *SerialConnection::openDevice(const QString &deviceName)
void SerialConnection::closeDevice(const QString &deviceName)
{
//nothing to do here
//we have to delete the serial connection we created
if (serialHandle){
serialHandle->close ();
delete(serialHandle);
serialHandle = NULL;
}
}

View File

@ -57,6 +57,9 @@ public:
virtual QString connectionName();
virtual QString shortName();
private:
QextSerialPort* serialHandle;
protected slots:
void onEnumerationChanged();
};