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

View File

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

View File

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

View File

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

View File

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