Fix for crash when stopping running an app over CODA TCP

This commit is contained in:
Tom Sutcliffe
2011-03-04 13:43:25 +01:00
committed by Pawel Polanski
parent b9614cdf7d
commit 2cc342a882
4 changed files with 189 additions and 188 deletions

View File

@@ -134,7 +134,7 @@ bool CodaRunControl::setupLauncher()
m_codaDevice->sendSerialPing(false); m_codaDevice->sendSerialPing(false);
} else { } else {
// For TCP we don't use device manager, we just set it up directly // For TCP we don't use device manager, we just set it up directly
m_codaDevice = QSharedPointer<Coda::CodaDevice>(new Coda::CodaDevice); m_codaDevice = QSharedPointer<Coda::CodaDevice>(new Coda::CodaDevice, &QObject::deleteLater); // finishRunControl, which deletes m_codaDevice, can get called from within a coda callback, so need to use deleteLater
connect(m_codaDevice.data(), SIGNAL(error(QString)), this, SLOT(slotError(QString))); connect(m_codaDevice.data(), SIGNAL(error(QString)), this, SLOT(slotError(QString)));
connect(m_codaDevice.data(), SIGNAL(logMessage(QString)), this, SLOT(slotTrkLogMessage(QString))); connect(m_codaDevice.data(), SIGNAL(logMessage(QString)), this, SLOT(slotTrkLogMessage(QString)));
connect(m_codaDevice.data(), SIGNAL(tcfEvent(Coda::CodaEvent)), this, SLOT(slotCodaEvent(Coda::CodaEvent))); connect(m_codaDevice.data(), SIGNAL(tcfEvent(Coda::CodaEvent)), this, SLOT(slotCodaEvent(Coda::CodaEvent)));

View File

@@ -554,6 +554,7 @@ void S60DeployConfigurationWidget::updateDeviceInfo()
{ {
if (result.type == Coda::CodaCommandResult::FailReply) { if (result.type == Coda::CodaCommandResult::FailReply) {
setDeviceInfoLabel(tr("No device information available"), true); setDeviceInfoLabel(tr("No device information available"), true);
SymbianUtils::SymbianDeviceManager::instance()->releaseCodaDevice(m_codaInfoDevice);
m_deviceInfoButton->setEnabled(true); m_deviceInfoButton->setEnabled(true);
return; return;
} else if (result.type == Coda::CodaCommandResult::CommandErrorReply){ } else if (result.type == Coda::CodaCommandResult::CommandErrorReply){

View File

@@ -274,7 +274,7 @@ struct SymbianDeviceManagerPrivate {
//QSignalMapper *m_destroyReleaseMapper; //QSignalMapper *m_destroyReleaseMapper;
// The following 2 variables are needed to manage requests for a TCF port not coming from the main thread // The following 2 variables are needed to manage requests for a TCF port not coming from the main thread
int m_constructTcfPortEventType; int m_constructTcfPortEventType;
QMutex m_tcfPortWaitMutex; QMutex m_codaPortWaitMutex;
}; };
class QConstructTcfPortEvent : public QEvent class QConstructTcfPortEvent : public QEvent
@@ -375,16 +375,16 @@ CodaDevicePtr SymbianDeviceManager::getCodaDevice(const QString &port)
// Check we instanciate in the correct thread - we can't afford to create the CodaDevice (and more specifically, open the VirtualSerialDevice) in a thread that isn't guaranteed to be long-lived. // Check we instanciate in the correct thread - we can't afford to create the CodaDevice (and more specifically, open the VirtualSerialDevice) in a thread that isn't guaranteed to be long-lived.
// Therefore, if we're not in SymbianDeviceManager's thread, rejig things so it's opened in the main thread // Therefore, if we're not in SymbianDeviceManager's thread, rejig things so it's opened in the main thread
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
// SymbianDeviceManager is owned by the current thread // SymbianDeviceManager is owned by the main thread
d->m_tcfPortWaitMutex.lock(); d->m_codaPortWaitMutex.lock();
QWaitCondition waiter; QWaitCondition waiter;
QCoreApplication::postEvent(this, new QConstructTcfPortEvent((QEvent::Type)d->m_constructTcfPortEventType, port, &devicePtr, &waiter)); QCoreApplication::postEvent(this, new QConstructTcfPortEvent((QEvent::Type)d->m_constructTcfPortEventType, port, &devicePtr, &waiter));
waiter.wait(&d->m_tcfPortWaitMutex); waiter.wait(&d->m_codaPortWaitMutex);
// When the wait returns (due to the wakeAll in SymbianDeviceManager::customEvent), the CodaDevice will be fully set up // When the wait returns (due to the wakeAll in SymbianDeviceManager::customEvent), the CodaDevice will be fully set up
d->m_tcfPortWaitMutex.unlock(); d->m_codaPortWaitMutex.unlock();
} else { } else {
// We're in the main thread, just set it up directly // We're in the main thread, just set it up directly
constructTcfPort(devicePtr, port); constructCodaPort(devicePtr, port);
} }
// We still carry on in the case we failed to open so the client can access the IODevice's errorString() // We still carry on in the case we failed to open so the client can access the IODevice's errorString()
} }
@@ -393,9 +393,9 @@ CodaDevicePtr SymbianDeviceManager::getCodaDevice(const QString &port)
return devicePtr; return devicePtr;
} }
void SymbianDeviceManager::constructTcfPort(CodaDevicePtr& device, const QString& portName) void SymbianDeviceManager::constructCodaPort(CodaDevicePtr& device, const QString& portName)
{ {
QMutexLocker locker(&d->m_tcfPortWaitMutex); QMutexLocker locker(&d->m_codaPortWaitMutex);
if (device.isNull()) { if (device.isNull()) {
device = QSharedPointer<Coda::CodaDevice>(new Coda::CodaDevice); device = QSharedPointer<Coda::CodaDevice>(new Coda::CodaDevice);
const QSharedPointer<SymbianUtils::VirtualSerialDevice> serialDevice(new SymbianUtils::VirtualSerialDevice(portName)); const QSharedPointer<SymbianUtils::VirtualSerialDevice> serialDevice(new SymbianUtils::VirtualSerialDevice(portName));
@@ -414,7 +414,7 @@ void SymbianDeviceManager::customEvent(QEvent *event)
{ {
if (event->type() == d->m_constructTcfPortEventType) { if (event->type() == d->m_constructTcfPortEventType) {
QConstructTcfPortEvent* constructEvent = static_cast<QConstructTcfPortEvent*>(event); QConstructTcfPortEvent* constructEvent = static_cast<QConstructTcfPortEvent*>(event);
constructTcfPort(*constructEvent->m_device, constructEvent->m_portName); constructCodaPort(*constructEvent->m_device, constructEvent->m_portName);
constructEvent->m_waiter->wakeAll(); // Should only ever be one thing waiting on this constructEvent->m_waiter->wakeAll(); // Should only ever be one thing waiting on this
} }
} }
@@ -680,7 +680,7 @@ qint64 OstChannel::readData(char *data, qint64 maxSize)
qint64 OstChannel::writeData(const char *data, qint64 maxSize) qint64 OstChannel::writeData(const char *data, qint64 maxSize)
{ {
static const qint64 KMaxOstPayload = 1022; static const qint64 KMaxOstPayload = 1024;
// If necessary, split the packet up // If necessary, split the packet up
while (maxSize) { while (maxSize) {
QByteArray dataBuf = QByteArray::fromRawData(data, qMin(KMaxOstPayload, maxSize)); QByteArray dataBuf = QByteArray::fromRawData(data, qMin(KMaxOstPayload, maxSize));

View File

@@ -186,7 +186,7 @@ private:
SymbianDeviceList serialPorts() const; SymbianDeviceList serialPorts() const;
SymbianDeviceList blueToothDevices() const; SymbianDeviceList blueToothDevices() const;
void customEvent(QEvent *event); void customEvent(QEvent *event);
void constructTcfPort(CodaDevicePtr& device, const QString& portName); void constructCodaPort(CodaDevicePtr& device, const QString& portName);
SymbianDeviceManagerPrivate *d; SymbianDeviceManagerPrivate *d;
}; };