diff --git a/src/plugins/debugger/gdb/s60debuggerbluetoothstarter.cpp b/src/plugins/debugger/gdb/s60debuggerbluetoothstarter.cpp index ad2869aac5812ea9a87bcefb197299f47a26e948..41856d8014fc8a8eb74a6a5838f1f44be2d233a5 100644 --- a/src/plugins/debugger/gdb/s60debuggerbluetoothstarter.cpp +++ b/src/plugins/debugger/gdb/s60debuggerbluetoothstarter.cpp @@ -51,7 +51,6 @@ trk::BluetoothListener *S60DebuggerBluetoothStarter::createListener() trk::PromptStartCommunicationResult S60DebuggerBluetoothStarter::startCommunication(const TrkDevicePtr &trkDevice, - const QString &device, int communicationType, QWidget *msgBoxParent, QString *errorMessage) @@ -59,12 +58,10 @@ S60DebuggerBluetoothStarter::startCommunication(const TrkDevicePtr &trkDevice, // Bluetooth? if (communicationType == TrkOptions::BlueTooth) { S60DebuggerBluetoothStarter bluetoothStarter(trkDevice); - bluetoothStarter.setDevice(device); return trk::promptStartBluetooth(bluetoothStarter, msgBoxParent, errorMessage); } // Serial BaseCommunicationStarter serialStarter(trkDevice); - serialStarter.setDevice(device); return trk::promptStartSerial(serialStarter, msgBoxParent, errorMessage); } diff --git a/src/plugins/debugger/gdb/s60debuggerbluetoothstarter.h b/src/plugins/debugger/gdb/s60debuggerbluetoothstarter.h index 1fbf16a9c826908cded92bf9e770fe271fdbba70..c97088c2452107fa6dc1ebc9e4aed100a8e38595 100644 --- a/src/plugins/debugger/gdb/s60debuggerbluetoothstarter.h +++ b/src/plugins/debugger/gdb/s60debuggerbluetoothstarter.h @@ -47,7 +47,6 @@ class S60DebuggerBluetoothStarter : public trk::AbstractBluetoothStarter public: static trk::PromptStartCommunicationResult startCommunication(const TrkDevicePtr &trkDevice, - const QString &device, int communicationType, QWidget *msgBoxParent, QString *errorMessage); diff --git a/src/plugins/debugger/gdb/trkgdbadapter.cpp b/src/plugins/debugger/gdb/trkgdbadapter.cpp index ca905af19383a5c0d0c238079c6726d352424c3d..a3f4513cd328c8535e087153aaa452dc8717d7f7 100644 --- a/src/plugins/debugger/gdb/trkgdbadapter.cpp +++ b/src/plugins/debugger/gdb/trkgdbadapter.cpp @@ -1730,12 +1730,13 @@ void TrkGdbAdapter::startAdapter() setState(AdapterStarting); debugMessage(_("TRYING TO START ADAPTER")); logMessage(QLatin1String("### Starting TrkGdbAdapter")); + m_trkDevice->setPort(effectiveTrkDevice()); m_trkDevice->setSerialFrame(effectiveTrkDeviceType() != TrkOptions::BlueTooth); // Prompt the user to start communication QString message; + const trk::PromptStartCommunicationResult src = S60DebuggerBluetoothStarter::startCommunication(m_trkDevice, - effectiveTrkDevice(), effectiveTrkDeviceType(), 0, &message); switch (src) { diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp index e33867b5285b955599b8d963448fd7fe2853c929..5d0aef4a40d51c79db4a572ccfb94054e30d7945 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp @@ -764,7 +764,6 @@ void S60DeviceRunControlBase::startDeployment() // Prompt the user to start up the Blue tooth connection const trk::PromptStartCommunicationResult src = S60RunConfigBluetoothStarter::startCommunication(m_launcher->trkDevice(), - m_serialPortName, m_communicationType, 0, &errorMessage); switch (src) { @@ -779,7 +778,6 @@ void S60DeviceRunControlBase::startDeployment() }; if (!m_launcher->startServer(&errorMessage)) { - error(this, tr("Could not connect to phone on port '%1': %2\n" "Check if the phone is connected and App TRK is running.").arg(m_serialPortName, errorMessage)); stop(); diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfigurationwidget.cpp b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfigurationwidget.cpp index 9c82b77d90bbf664638893ef6e0bdf79687d21ff..e496b174eb3e6f35172100673f49c16d37342b87 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfigurationwidget.cpp +++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfigurationwidget.cpp @@ -330,7 +330,6 @@ void S60DeviceRunConfigurationWidget::updateDeviceInfo() QString message; const trk::PromptStartCommunicationResult src = S60RunConfigBluetoothStarter::startCommunication(m_infoLauncher->trkDevice(), - commDev.portName(), commDev.type(), this, &message); switch (src) { diff --git a/src/plugins/qt4projectmanager/qt-s60/s60runconfigbluetoothstarter.cpp b/src/plugins/qt4projectmanager/qt-s60/s60runconfigbluetoothstarter.cpp index 593c85c0d2e7c34e756530ba387c70026da52b9b..9bd6e2a60f2efa8b357821d424d5cb749197c3f4 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60runconfigbluetoothstarter.cpp +++ b/src/plugins/qt4projectmanager/qt-s60/s60runconfigbluetoothstarter.cpp @@ -53,7 +53,6 @@ trk::BluetoothListener *S60RunConfigBluetoothStarter::createListener() trk::PromptStartCommunicationResult S60RunConfigBluetoothStarter::startCommunication(const TrkDevicePtr &trkDevice, - const QString &device, int communicationType, QWidget *msgBoxParent, QString *errorMessage) @@ -61,12 +60,10 @@ S60RunConfigBluetoothStarter::startCommunication(const TrkDevicePtr &trkDevice, // Bluetooth? if (communicationType == SymbianUtils::BlueToothCommunication) { S60RunConfigBluetoothStarter bluetoothStarter(trkDevice); - bluetoothStarter.setDevice(device); return trk::promptStartBluetooth(bluetoothStarter, msgBoxParent, errorMessage); } // Serial BaseCommunicationStarter serialStarter(trkDevice); - serialStarter.setDevice(device); return trk::promptStartSerial(serialStarter, msgBoxParent, errorMessage); } diff --git a/src/plugins/qt4projectmanager/qt-s60/s60runconfigbluetoothstarter.h b/src/plugins/qt4projectmanager/qt-s60/s60runconfigbluetoothstarter.h index 70ea0123f5d44ca5772a9e1d42dd03a31663c6c9..67822af3485144e2f127e262341814bdc7735034 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60runconfigbluetoothstarter.h +++ b/src/plugins/qt4projectmanager/qt-s60/s60runconfigbluetoothstarter.h @@ -49,7 +49,6 @@ public: // passing on the right messages. static trk::PromptStartCommunicationResult startCommunication(const TrkDevicePtr &trkDevice, - const QString &device, int communicationType, QWidget *msgBoxParent, QString *errorMessage); diff --git a/src/shared/symbianutils/communicationstarter.cpp b/src/shared/symbianutils/communicationstarter.cpp index b425db2506280b3a22293d2a7e7b04171103d42d..83121cbe14dc8bc1934ad628b9957b7f3de905d5 100644 --- a/src/shared/symbianutils/communicationstarter.cpp +++ b/src/shared/symbianutils/communicationstarter.cpp @@ -46,7 +46,6 @@ struct BaseCommunicationStarterPrivate { int intervalMS; int attempts; int n; - QString device; QString errorString; BaseCommunicationStarter::State state; }; @@ -58,7 +57,6 @@ BaseCommunicationStarterPrivate::BaseCommunicationStarterPrivate(const BaseCommu intervalMS(1000), attempts(-1), n(0), - device(QLatin1String("/dev/rfcomm0")), state(BaseCommunicationStarter::TimedOut) { } @@ -96,7 +94,7 @@ BaseCommunicationStarter::StartResult BaseCommunicationStarter::start() // Before we instantiate timers, and such, try to open the device, // which should succeed if another listener is already running in // 'Watch' mode - if (d->trkDevice->open(d->device , &(d->errorString))) + if (d->trkDevice->open(&(d->errorString))) return ConnectionSucceeded; // Pull up resources for next attempt d->n = 0; @@ -143,12 +141,7 @@ void BaseCommunicationStarter::setAttempts(int a) QString BaseCommunicationStarter::device() const { - return d->device; -} - -void BaseCommunicationStarter::setDevice(const QString &dv) -{ - d->device = dv; + return d->trkDevice->port(); } QString BaseCommunicationStarter::errorString() const @@ -163,20 +156,20 @@ void BaseCommunicationStarter::slotTimer() if (d->attempts >= 0 && d->n >= d->attempts) { stopTimer(); d->errorString = tr("%1: timed out after %n attempts using an interval of %2ms.", 0, d->n) - .arg(d->device).arg(d->intervalMS); + .arg(d->trkDevice->port()).arg(d->intervalMS); d->state = TimedOut; emit timeout(); } else { // Attempt n to connect? - if (d->trkDevice->open(d->device , &(d->errorString))) { + if (d->trkDevice->open(&(d->errorString))) { stopTimer(); - const QString msg = tr("%1: Connection attempt %2 succeeded.").arg(d->device).arg(d->n); + const QString msg = tr("%1: Connection attempt %2 succeeded.").arg(d->trkDevice->port()).arg(d->n); emit message(msg); d->state = Connected; emit connected(); } else { const QString msg = tr("%1: Connection attempt %2 failed: %3 (retrying)...") - .arg(d->device).arg(d->n).arg(d->errorString); + .arg(d->trkDevice->port()).arg(d->n).arg(d->errorString); emit message(msg); } } @@ -216,13 +209,11 @@ BluetoothListener *ConsoleBluetoothStarter::createListener() bool ConsoleBluetoothStarter::startBluetooth(const TrkDevicePtr &trkDevice, QObject *listenerParent, - const QString &device, int attempts, QString *errorMessage) { // Set up a console starter to print to stdout. ConsoleBluetoothStarter starter(trkDevice, listenerParent); - starter.setDevice(device); starter.setAttempts(attempts); switch (starter.start()) { case Started: diff --git a/src/shared/symbianutils/communicationstarter.h b/src/shared/symbianutils/communicationstarter.h index 304ec06f73cd6cea38783cf55bbd56c582e24650..e61d2e4fc55d8618f268b90f0c331e8d94acad07 100644 --- a/src/shared/symbianutils/communicationstarter.h +++ b/src/shared/symbianutils/communicationstarter.h @@ -67,8 +67,7 @@ public: int attempts() const; void setAttempts(int a); - QString device() const; - void setDevice(const QString &); + QString device() const; // via TrkDevice State state() const; QString errorString() const; @@ -130,7 +129,6 @@ class SYMBIANUTILS_EXPORT ConsoleBluetoothStarter : public AbstractBluetoothStar public: static bool startBluetooth(const TrkDevicePtr& trkDevice, QObject *listenerParent, - const QString &device, int attempts, QString *errorMessage); diff --git a/src/shared/symbianutils/launcher.cpp b/src/shared/symbianutils/launcher.cpp index e927c4122635a0bb3c938ed090bf66485960e614..6f521571f528c87d9cfc46240cc15b8c9c22177d 100644 --- a/src/shared/symbianutils/launcher.cpp +++ b/src/shared/symbianutils/launcher.cpp @@ -55,7 +55,6 @@ struct LauncherPrivate { explicit LauncherPrivate(const TrkDevicePtr &d); TrkDevicePtr m_device; - QString m_trkServerName; QByteArray m_trkReadBuffer; Launcher::State m_state; @@ -119,12 +118,12 @@ void Launcher::addStartupActions(trk::Launcher::Actions startupActions) void Launcher::setTrkServerName(const QString &name) { - d->m_trkServerName = name; + d->m_device->setPort(name); } QString Launcher::trkServerName() const { - return d->m_trkServerName; + return d->m_device->port(); } TrkDevicePtr Launcher::trkDevice() const @@ -179,7 +178,7 @@ bool Launcher::startServer(QString *errorMessage) errorMessage->clear(); if (d->m_verbose) { const QString msg = QString::fromLatin1("Port=%1 Executable=%2 Arguments=%3 Package=%4 Remote Package=%5 Install file=%6") - .arg(d->m_trkServerName, d->m_fileName, + .arg(trkServerName(), d->m_fileName, d->m_commandLineArgs.join(QString(QLatin1Char(' '))), d->m_copyState.sourceFileName, d->m_copyState.destinationFileName, d->m_installFileName); logMessage(msg); @@ -201,7 +200,7 @@ bool Launcher::startServer(QString *errorMessage) qWarning("No remote executable given for running."); return false; } - if (!d->m_device->isOpen() && !d->m_device->open(d->m_trkServerName, errorMessage)) + if (!d->m_device->isOpen() && !d->m_device->open(errorMessage)) return false; if (d->m_closeDevice) { connect(this, SIGNAL(finished()), d->m_device.data(), SLOT(close())); diff --git a/src/shared/symbianutils/trkdevice.cpp b/src/shared/symbianutils/trkdevice.cpp index e7fb8c4f78822e0afee05513d2f5688a4948c078..6c5b8b2648f0d4337567622db9932d6a6324ff07 100644 --- a/src/shared/symbianutils/trkdevice.cpp +++ b/src/shared/symbianutils/trkdevice.cpp @@ -871,6 +871,7 @@ struct TrkDevicePrivate QByteArray trkReadBuffer; int verbose; QString errorString; + QString port; }; /////////////////////////////////////////////////////////////////////// @@ -902,13 +903,19 @@ TrkDevice::~TrkDevice() delete d; } -bool TrkDevice::open(const QString &port, QString *errorMessage) +bool TrkDevice::open(QString *errorMessage) { if (d->verbose) - qDebug() << "Opening" << port << "is open: " << isOpen() << " serialFrame=" << serialFrame(); + qDebug() << "Opening" << port() << "is open: " << isOpen() << " serialFrame=" << serialFrame(); + if (d->port.isEmpty()) { + *errorMessage = QLatin1String("Internal error: No port set on TrkDevice"); + return false; + } + close(); #ifdef Q_OS_WIN - d->deviceContext->device = CreateFile(QString("\\\\.\\").append(port).toStdWString().c_str(), + const QString fullPort = QLatin1String("\\\\.\\") + d->port; + d->deviceContext->device = CreateFile(reinterpret_cast<const WCHAR*>(fullPort.utf16()), GENERIC_READ | GENERIC_WRITE, 0, NULL, @@ -917,7 +924,7 @@ bool TrkDevice::open(const QString &port, QString *errorMessage) NULL); if (INVALID_HANDLE_VALUE == d->deviceContext->device) { - *errorMessage = QString::fromLatin1("Could not open device '%1': %2").arg(port, winErrorMessage(GetLastError())); + *errorMessage = QString::fromLatin1("Could not open device '%1': %2").arg(port(), winErrorMessage(GetLastError())); return false; } memset(&d->deviceContext->readOverlapped, 0, sizeof(OVERLAPPED)); @@ -929,9 +936,9 @@ bool TrkDevice::open(const QString &port, QString *errorMessage) return false; } #else - d->deviceContext->file.setFileName(port); + d->deviceContext->file.setFileName(d->port); if (!d->deviceContext->file.open(QIODevice::ReadWrite|QIODevice::Unbuffered)) { - *errorMessage = QString::fromLatin1("Cannot open %1: %2").arg(port, d->deviceContext->file.errorString()); + *errorMessage = QString::fromLatin1("Cannot open %1: %2").arg(d->port, d->deviceContext->file.errorString()); return false; } @@ -970,7 +977,7 @@ bool TrkDevice::open(const QString &port, QString *errorMessage) d->writerThread->start(); if (d->verbose) - qDebug() << "Opened" << port; + qDebug() << "Opened" << d->port; return true; } @@ -1004,6 +1011,16 @@ bool TrkDevice::isOpen() const #endif } +QString TrkDevice::port() const +{ + return d->port; +} + +void TrkDevice::setPort(const QString &p) +{ + d->port = p; +} + QString TrkDevice::errorString() const { return d->errorString; diff --git a/src/shared/symbianutils/trkdevice.h b/src/shared/symbianutils/trkdevice.h index 7a906e5cec5b2c41e6a7e5f9b0c630a5cb8bf750..763b60ff2517b89b93dd52907c796c7b9c21e95b 100644 --- a/src/shared/symbianutils/trkdevice.h +++ b/src/shared/symbianutils/trkdevice.h @@ -68,13 +68,17 @@ class SYMBIANUTILS_EXPORT TrkDevice : public QObject Q_OBJECT Q_PROPERTY(bool serialFrame READ serialFrame WRITE setSerialFrame) Q_PROPERTY(bool verbose READ verbose WRITE setVerbose) + Q_PROPERTY(QString port READ port WRITE setPort) public: explicit TrkDevice(QObject *parent = 0); virtual ~TrkDevice(); - bool open(const QString &port, QString *errorMessage); + bool open(QString *errorMessage); bool isOpen() const; + QString port() const; + void setPort(const QString &p); + QString errorString() const; bool serialFrame() const; diff --git a/tests/manual/trklauncher/main.cpp b/tests/manual/trklauncher/main.cpp index 0f8570646dda26aafdb611c2ce074b744523278a..ec53d0bcad9cc13f21eaa4db7da2cd2dbe224b66 100644 --- a/tests/manual/trklauncher/main.cpp +++ b/tests/manual/trklauncher/main.cpp @@ -153,7 +153,6 @@ int main(int argc, char *argv[]) QString errorMessage; if (bluetooth && !trk::ConsoleBluetoothStarter::startBluetooth(launcher->trkDevice(), launcher.data(), - launcher->trkServerName(), 30, &errorMessage)) { qWarning("%s\n", qPrintable(errorMessage)); return -1;