Commit 3efdb876 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

S60/Trk: Make the port a property of TrkDevice.

Associate the port with the device instead of passing it to open
for better handling.
parent a6037c38
......@@ -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);
}
......
......@@ -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);
......
......@@ -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) {
......
......@@ -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();
......
......@@ -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) {
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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:
......
......@@ -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);
......
......@@ -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()));
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment