Sharing TcfTrkDevice connections between multiple clients

This commit is contained in:
Tom Sutcliffe
2011-02-07 14:14:57 +01:00
committed by Pawel Polanski
parent 31b352d219
commit a034989350
9 changed files with 171 additions and 153 deletions

View File

@@ -37,7 +37,7 @@
#include "codadevice.h" #include "codadevice.h"
#include "trkutils.h" #include "trkutils.h"
#include "gdbmi.h" #include "gdbmi.h"
#include "virtualserialdevice.h" #include "symbiandevicemanager.h"
#include "registerhandler.h" #include "registerhandler.h"
#include "threadshandler.h" #include "threadshandler.h"
@@ -123,7 +123,6 @@ CodaGdbAdapter::CodaGdbAdapter(GdbEngine *engine) :
AbstractGdbAdapter(engine), AbstractGdbAdapter(engine),
m_running(false), m_running(false),
m_stopReason(0), m_stopReason(0),
m_trkDevice(new CodaDevice(this)),
m_gdbAckMode(true), m_gdbAckMode(true),
m_uid(0), m_uid(0),
m_verbose(0), m_verbose(0),
@@ -148,11 +147,15 @@ CodaGdbAdapter::CodaGdbAdapter(GdbEngine *engine) :
connect(debuggerCore()->action(VerboseLog), SIGNAL(valueChanged(QVariant)), connect(debuggerCore()->action(VerboseLog), SIGNAL(valueChanged(QVariant)),
this, SLOT(setVerbose(QVariant))); this, SLOT(setVerbose(QVariant)));
connect(m_trkDevice, SIGNAL(error(QString)), }
void CodaGdbAdapter::setupTrkDeviceSignals()
{
connect(m_codaDevice.data(), SIGNAL(error(QString)),
this, SLOT(codaDeviceError(QString))); this, SLOT(codaDeviceError(QString)));
connect(m_trkDevice, SIGNAL(logMessage(QString)), connect(m_codaDevice.data(), SIGNAL(logMessage(QString)),
this, SLOT(trkLogMessage(QString))); this, SLOT(trkLogMessage(QString)));
connect(m_trkDevice, SIGNAL(tcfEvent(Coda::CodaEvent)), connect(m_codaDevice.data(), SIGNAL(tcfEvent(Coda::CodaEvent)),
this, SLOT(codaEvent(Coda::CodaEvent))); this, SLOT(codaEvent(Coda::CodaEvent)));
} }
@@ -172,7 +175,8 @@ void CodaGdbAdapter::setVerbose(int verbose)
if (debug) if (debug)
qDebug("CodaGdbAdapter::setVerbose %d", verbose); qDebug("CodaGdbAdapter::setVerbose %d", verbose);
m_verbose = verbose; m_verbose = verbose;
m_trkDevice->setVerbose(m_verbose); if (m_codaDevice)
m_codaDevice->setVerbose(m_verbose);
} }
void CodaGdbAdapter::trkLogMessage(const QString &msg) void CodaGdbAdapter::trkLogMessage(const QString &msg)
@@ -278,7 +282,7 @@ void CodaGdbAdapter::handleCodaRunControlModuleLoadContextSuspendedEvent(const C
qDebug() << "Initial module load suspended: " << m_session.toString(); qDebug() << "Initial module load suspended: " << m_session.toString();
} else { } else {
// Consecutive module load suspended: (not observed yet): Just continue // Consecutive module load suspended: (not observed yet): Just continue
m_trkDevice->sendRunControlResumeCommand(CodaCallback(), se.id()); m_codaDevice->sendRunControlResumeCommand(CodaCallback(), se.id());
} }
} }
} }
@@ -305,7 +309,7 @@ void CodaGdbAdapter::codaEvent(const CodaEvent &e)
switch (e.type()) { switch (e.type()) {
case CodaEvent::LocatorHello: case CodaEvent::LocatorHello:
m_trkDevice->sendLoggingAddListenerCommand(CodaCallback()); m_codaDevice->sendLoggingAddListenerCommand(CodaCallback());
startGdb(); // Commands are only accepted after hello startGdb(); // Commands are only accepted after hello
break; break;
case CodaEvent::RunControlModuleLoadSuspended: // A module was loaded case CodaEvent::RunControlModuleLoadSuspended: // A module was loaded
@@ -349,7 +353,7 @@ void CodaGdbAdapter::codaEvent(const CodaEvent &e)
m_stopReason = reason.contains(QLatin1String("exception"), Qt::CaseInsensitive) m_stopReason = reason.contains(QLatin1String("exception"), Qt::CaseInsensitive)
|| reason.contains(QLatin1String("panic"), Qt::CaseInsensitive) ? || reason.contains(QLatin1String("panic"), Qt::CaseInsensitive) ?
gdbServerSignalSegfault : gdbServerSignalTrap; gdbServerSignalSegfault : gdbServerSignalTrap;
m_trkDevice->sendRegistersGetMRangeCommand( m_codaDevice->sendRegistersGetMRangeCommand(
CodaCallback(this, &CodaGdbAdapter::handleAndReportReadRegistersAfterStop), CodaCallback(this, &CodaGdbAdapter::handleAndReportReadRegistersAfterStop),
currentThreadContextId(), 0, currentThreadContextId(), 0,
Symbian::RegisterCount); Symbian::RegisterCount);
@@ -604,7 +608,7 @@ void CodaGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
reportRegisters(); reportRegisters();
} else { } else {
sendGdbServerAck(); sendGdbServerAck();
if (m_trkDevice->registerNames().isEmpty()) { if (m_codaDevice->registerNames().isEmpty()) {
m_registerRequestPending = true; m_registerRequestPending = true;
} else { } else {
sendRegistersGetMCommand(); sendRegistersGetMCommand();
@@ -688,7 +692,7 @@ void CodaGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
logMessage(_("Writing %1 bytes from 0x%2: %3"). logMessage(_("Writing %1 bytes from 0x%2: %3").
arg(addrLength.second).arg(addrLength.first, 0, 16). arg(addrLength.second).arg(addrLength.first, 0, 16).
arg(QString::fromAscii(data.toHex()))); arg(QString::fromAscii(data.toHex())));
m_trkDevice->sendMemorySetCommand( m_codaDevice->sendMemorySetCommand(
CodaCallback(this, &CodaGdbAdapter::handleWriteMemory), CodaCallback(this, &CodaGdbAdapter::handleWriteMemory),
m_tcfProcessId, addrLength.first, data); m_tcfProcessId, addrLength.first, data);
} }
@@ -707,7 +711,7 @@ void CodaGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
sendGdbServerMessage(thread.gdbReportSingleRegister(registerNumber), thread.gdbSingleRegisterLogMessage(registerNumber)); sendGdbServerMessage(thread.gdbReportSingleRegister(registerNumber), thread.gdbSingleRegisterLogMessage(registerNumber));
} else { } else {
//qDebug() << "Fetching single register"; //qDebug() << "Fetching single register";
m_trkDevice->sendRegistersGetMRangeCommand( m_codaDevice->sendRegistersGetMRangeCommand(
CodaCallback(this, &CodaGdbAdapter::handleAndReportReadRegister), CodaCallback(this, &CodaGdbAdapter::handleAndReportReadRegister),
currentThreadContextId(), registerNumber, 1); currentThreadContextId(), registerNumber, 1);
} }
@@ -723,7 +727,7 @@ void CodaGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
logMessage(_("Setting register #%1 to 0x%2").arg(regnumValue.first).arg(regnumValue.second, 0, 16)); logMessage(_("Setting register #%1 to 0x%2").arg(regnumValue.first).arg(regnumValue.second, 0, 16));
QByteArray registerValue; QByteArray registerValue;
trk::appendInt(&registerValue, trk::BigEndian); // Registers are big endian trk::appendInt(&registerValue, trk::BigEndian); // Registers are big endian
m_trkDevice->sendRegistersSetCommand( m_codaDevice->sendRegistersSetCommand(
CodaCallback(this, &CodaGdbAdapter::handleWriteRegister), CodaCallback(this, &CodaGdbAdapter::handleWriteRegister),
currentThreadContextId(), regnumValue.first, registerValue, currentThreadContextId(), regnumValue.first, registerValue,
QVariant(regnumValue.first)); QVariant(regnumValue.first));
@@ -899,7 +903,7 @@ void CodaGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
bp.setContextId(m_session.pid); bp.setContextId(m_session.pid);
// We use the automatic ids calculated from the location // We use the automatic ids calculated from the location
// address instead of the map in snapshot. // address instead of the map in snapshot.
m_trkDevice->sendBreakpointsAddCommand( m_codaDevice->sendBreakpointsAddCommand(
CodaCallback(this, &CodaGdbAdapter::handleAndReportSetBreakpoint), CodaCallback(this, &CodaGdbAdapter::handleAndReportSetBreakpoint),
bp); bp);
} else { } else {
@@ -914,7 +918,7 @@ void CodaGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
// $z0,786a4ccc,4#99 // $z0,786a4ccc,4#99
const int pos = cmd.lastIndexOf(','); const int pos = cmd.lastIndexOf(',');
const uint addr = cmd.mid(3, pos - 3).toUInt(0, 16); const uint addr = cmd.mid(3, pos - 3).toUInt(0, 16);
m_trkDevice->sendBreakpointsRemoveCommand( m_codaDevice->sendBreakpointsRemoveCommand(
CodaCallback(this, &CodaGdbAdapter::handleClearBreakpoint), CodaCallback(this, &CodaGdbAdapter::handleClearBreakpoint),
Coda::Breakpoint::idFromLocation(addr)); Coda::Breakpoint::idFromLocation(addr));
} }
@@ -960,7 +964,7 @@ void CodaGdbAdapter::sendRunControlTerminateCommand()
// Requires id of main thread to terminate. // Requires id of main thread to terminate.
// Note that calling 'Settings|set|removeExecutable' crashes TCF TRK, // Note that calling 'Settings|set|removeExecutable' crashes TCF TRK,
// so, it is apparently not required. // so, it is apparently not required.
m_trkDevice->sendRunControlTerminateCommand(CodaCallback(this, &CodaGdbAdapter::handleRunControlTerminate), m_codaDevice->sendRunControlTerminateCommand(CodaCallback(this, &CodaGdbAdapter::handleRunControlTerminate),
mainThreadContextId()); mainThreadContextId());
} }
@@ -993,7 +997,7 @@ void CodaGdbAdapter::gdbSetCurrentThread(const QByteArray &cmd, const char *why)
void CodaGdbAdapter::interruptInferior() void CodaGdbAdapter::interruptInferior()
{ {
m_trkDevice->sendRunControlSuspendCommand(CodaCallback(), m_tcfProcessId); m_codaDevice->sendRunControlSuspendCommand(CodaCallback(), m_tcfProcessId);
} }
void CodaGdbAdapter::startAdapter() void CodaGdbAdapter::startAdapter()
@@ -1015,22 +1019,25 @@ void CodaGdbAdapter::startAdapter()
QSharedPointer<QTcpSocket> codaSocket; QSharedPointer<QTcpSocket> codaSocket;
if (parameters.communicationChannel == DebuggerStartParameters::CommunicationChannelTcpIp) { if (parameters.communicationChannel == DebuggerStartParameters::CommunicationChannelTcpIp) {
m_codaDevice = QSharedPointer<Coda::CodaDevice>(new Coda::CodaDevice);
setupTrkDeviceSignals();
codaSocket = QSharedPointer<QTcpSocket>(new QTcpSocket); codaSocket = QSharedPointer<QTcpSocket>(new QTcpSocket);
m_trkDevice->setDevice(codaSocket); m_codaDevice->setDevice(codaSocket);
m_trkIODevice = codaSocket; m_trkIODevice = codaSocket;
} else { } else {
QSharedPointer<SymbianUtils::VirtualSerialDevice> serialDevice(new SymbianUtils::VirtualSerialDevice(parameters.remoteChannel)); m_codaDevice = SymbianUtils::SymbianDeviceManager::instance()->getTcfPort(parameters.remoteChannel);
m_trkDevice->setSerialFrame(true); bool ok = m_codaDevice && m_codaDevice->device()->isOpen();
m_trkDevice->setDevice(serialDevice);
bool ok = serialDevice->open(QIODevice::ReadWrite);
if (!ok) { if (!ok) {
QString msg = QString("Couldn't open serial device: %1.") QString msg = QString("Couldn't open serial device %1").arg(parameters.remoteChannel);
.arg(serialDevice->errorString()); if (m_codaDevice)
msg.append(QString(": %1").arg(m_codaDevice->device()->errorString()));
logMessage(msg, LogError); logMessage(msg, LogError);
m_engine->handleAdapterStartFailed(msg, QString()); m_engine->handleAdapterStartFailed(msg, QString());
return; return;
} }
m_trkIODevice = serialDevice; setupTrkDeviceSignals();
m_codaDevice->setVerbose(m_verbose);
} }
if (debug) if (debug)
@@ -1071,7 +1078,7 @@ void CodaGdbAdapter::startAdapter()
.arg(codaAddress.first).arg(codaAddress.second)); .arg(codaAddress.first).arg(codaAddress.second));
codaSocket->connectToHost(codaAddress.first, codaAddress.second); codaSocket->connectToHost(codaAddress.first, codaAddress.second);
} else { } else {
m_trkDevice->sendSerialPing(false); m_codaDevice->sendSerialPing(false);
} }
} }
@@ -1085,7 +1092,7 @@ void CodaGdbAdapter::setupInferior()
for (unsigned i = 0; i < libraryCount; i++) for (unsigned i = 0; i < libraryCount; i++)
libraries.push_back(QString::fromAscii(librariesC[i])); libraries.push_back(QString::fromAscii(librariesC[i]));
m_trkDevice->sendProcessStartCommand( m_codaDevice->sendProcessStartCommand(
CodaCallback(this, &CodaGdbAdapter::handleCreateProcess), CodaCallback(this, &CodaGdbAdapter::handleCreateProcess),
m_remoteExecutable, m_uid, m_remoteArguments, m_remoteExecutable, m_uid, m_remoteArguments,
QString(), true, libraries); QString(), true, libraries);
@@ -1105,7 +1112,7 @@ void CodaGdbAdapter::addThread(unsigned id)
// We cannot retrieve register values unless the registers of that // We cannot retrieve register values unless the registers of that
// thread have been retrieved (TCF TRK oddity). // thread have been retrieved (TCF TRK oddity).
const QByteArray contextId = Coda::RunControlContext::tcfId(m_session.pid, id); const QByteArray contextId = Coda::RunControlContext::tcfId(m_session.pid, id);
m_trkDevice->sendRegistersGetChildrenCommand(CodaCallback(this, &CodaGdbAdapter::handleRegisterChildren), m_codaDevice->sendRegistersGetChildrenCommand(CodaCallback(this, &CodaGdbAdapter::handleRegisterChildren),
contextId, QVariant(contextId)); contextId, QVariant(contextId));
} }
} }
@@ -1197,6 +1204,10 @@ void CodaGdbAdapter::cleanup()
} }
} }
} //!m_trkIODevice.isNull() } //!m_trkIODevice.isNull()
if (m_codaDevice) {
disconnect(m_codaDevice.data(), 0, this, 0);
SymbianUtils::SymbianDeviceManager::instance()->releaseTcfPort(m_codaDevice);
}
} }
void CodaGdbAdapter::shutdownInferior() void CodaGdbAdapter::shutdownInferior()
@@ -1211,7 +1222,7 @@ void CodaGdbAdapter::shutdownAdapter()
m_engine->notifyAdapterShutdownOk(); m_engine->notifyAdapterShutdownOk();
} else { } else {
// Something is wrong, gdb crashed. Kill debuggee (see handleDeleteProcess2) // Something is wrong, gdb crashed. Kill debuggee (see handleDeleteProcess2)
if (m_trkDevice->device()->isOpen()) { if (m_codaDevice->device()->isOpen()) {
logMessage("Emergency shutdown of CODA", LogError); logMessage("Emergency shutdown of CODA", LogError);
sendRunControlTerminateCommand(); sendRunControlTerminateCommand();
} }
@@ -1244,9 +1255,9 @@ void CodaGdbAdapter::handleWriteRegister(const CodaCommandResult &result)
void CodaGdbAdapter::sendRegistersGetMCommand() void CodaGdbAdapter::sendRegistersGetMCommand()
{ {
// Send off a register command, which requires the names to be present. // Send off a register command, which requires the names to be present.
QTC_ASSERT(!m_trkDevice->registerNames().isEmpty(), return ) QTC_ASSERT(!m_codaDevice->registerNames().isEmpty(), return )
m_trkDevice->sendRegistersGetMRangeCommand( m_codaDevice->sendRegistersGetMRangeCommand(
CodaCallback(this, &CodaGdbAdapter::handleAndReportReadRegisters), CodaCallback(this, &CodaGdbAdapter::handleAndReportReadRegisters),
currentThreadContextId(), 0, currentThreadContextId(), 0,
Symbian::RegisterCount); Symbian::RegisterCount);
@@ -1273,12 +1284,12 @@ void CodaGdbAdapter::handleRegisterChildren(const Coda::CodaCommandResult &resul
// able to access the register contents. // able to access the register contents.
QVector<QByteArray> registerNames = Coda::CodaDevice::parseRegisterGetChildren(result); QVector<QByteArray> registerNames = Coda::CodaDevice::parseRegisterGetChildren(result);
if (registerNames.size() == 1) { if (registerNames.size() == 1) {
m_trkDevice->sendRegistersGetChildrenCommand(CodaCallback(this, &CodaGdbAdapter::handleRegisterChildren), m_codaDevice->sendRegistersGetChildrenCommand(CodaCallback(this, &CodaGdbAdapter::handleRegisterChildren),
registerNames.front(), result.cookie); registerNames.front(), result.cookie);
return; return;
} }
// First thread: Set base names in device. // First thread: Set base names in device.
if (!m_trkDevice->registerNames().isEmpty()) if (!m_codaDevice->registerNames().isEmpty())
return; return;
// Make sure we get all registers // Make sure we get all registers
const int registerCount = registerNames.size(); const int registerCount = registerNames.size();
@@ -1297,7 +1308,7 @@ void CodaGdbAdapter::handleRegisterChildren(const Coda::CodaCommandResult &resul
msg += QString::fromAscii(registerNames[i]); msg += QString::fromAscii(registerNames[i]);
} }
logMessage(msg); logMessage(msg);
m_trkDevice->setRegisterNames(registerNames); m_codaDevice->setRegisterNames(registerNames);
if (m_registerRequestPending) { // Request already pending? if (m_registerRequestPending) { // Request already pending?
logMessage(_("Resuming registers request after receiving register names...")); logMessage(_("Resuming registers request after receiving register names..."));
sendRegistersGetMCommand(); sendRegistersGetMCommand();
@@ -1425,7 +1436,7 @@ void CodaGdbAdapter::sendMemoryGetCommand(const MemoryRange &range, bool buffere
const CodaCallback cb = buffered ? const CodaCallback cb = buffered ?
CodaCallback(this, &CodaGdbAdapter::handleReadMemoryBuffered) : CodaCallback(this, &CodaGdbAdapter::handleReadMemoryBuffered) :
CodaCallback(this, &CodaGdbAdapter::handleReadMemoryUnbuffered); CodaCallback(this, &CodaGdbAdapter::handleReadMemoryUnbuffered);
m_trkDevice->sendMemoryGetCommand(cb, currentThreadContextId(), range.from, range.size(), cookie); m_codaDevice->sendMemoryGetCommand(cb, currentThreadContextId(), range.from, range.size(), cookie);
} }
void CodaGdbAdapter::handleReadMemoryBuffered(const CodaCommandResult &result) void CodaGdbAdapter::handleReadMemoryBuffered(const CodaCommandResult &result)
@@ -1563,7 +1574,7 @@ void CodaGdbAdapter::sendTrkContinue()
// at the next stop. // at the next stop.
if (m_snapshot.threadInfo.size() > 1) if (m_snapshot.threadInfo.size() > 1)
m_snapshot.threadInfo.remove(1, m_snapshot.threadInfo.size() - 1); m_snapshot.threadInfo.remove(1, m_snapshot.threadInfo.size() - 1);
m_trkDevice->sendRunControlResumeCommand(CodaCallback(), m_tcfProcessId); m_codaDevice->sendRunControlResumeCommand(CodaCallback(), m_tcfProcessId);
} }
void CodaGdbAdapter::sendTrkStepRange() void CodaGdbAdapter::sendTrkStepRange()
@@ -1586,7 +1597,7 @@ void CodaGdbAdapter::sendTrkStepRange()
logMessage(_("Stepping from 0x%1 to 0x%2 (current PC=0x%3), mode %4"). logMessage(_("Stepping from 0x%1 to 0x%2 (current PC=0x%3), mode %4").
arg(from, 0, 16).arg(to, 0, 16).arg(pc).arg(int(mode))); arg(from, 0, 16).arg(to, 0, 16).arg(pc).arg(int(mode)));
m_trkDevice->sendRunControlResumeCommand( m_codaDevice->sendRunControlResumeCommand(
CodaCallback(this, &CodaGdbAdapter::handleStep), CodaCallback(this, &CodaGdbAdapter::handleStep),
currentThreadContextId(), currentThreadContextId(),
mode, 1, from, to); mode, 1, from, to);

View File

@@ -106,6 +106,7 @@ public:
virtual DumperHandling dumperHandling() const { return DumperNotAvailable; } virtual DumperHandling dumperHandling() const { return DumperNotAvailable; }
private: private:
void setupTrkDeviceSignals();
void startAdapter(); void startAdapter();
void setupInferior(); void setupInferior();
void runEngine(); void runEngine();
@@ -144,7 +145,8 @@ private:
QString m_gdbServerName; // 127.0.0.1:(2222+uid) QString m_gdbServerName; // 127.0.0.1:(2222+uid)
bool m_running; bool m_running;
int m_stopReason; int m_stopReason;
Coda::CodaDevice *m_trkDevice;
QSharedPointer<Coda::CodaDevice> m_codaDevice;
QSharedPointer<QIODevice> m_trkIODevice; QSharedPointer<QIODevice> m_trkIODevice;
// //

View File

@@ -65,7 +65,7 @@ using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal; using namespace Qt4ProjectManager::Internal;
using namespace Coda; using namespace Coda;
enum { debug = 1 }; enum { debug = 0 };
CodaRunControl::CodaRunControl(RunConfiguration *runConfiguration, const QString &mode) : CodaRunControl::CodaRunControl(RunConfiguration *runConfiguration, const QString &mode) :
S60RunControlBase(runConfiguration, mode), S60RunControlBase(runConfiguration, mode),
@@ -115,35 +115,37 @@ bool CodaRunControl::setupLauncher()
appendMessage(tr("Connecting to '%2'...").arg(m_serialPort), NormalMessageFormat); appendMessage(tr("Connecting to '%2'...").arg(m_serialPort), NormalMessageFormat);
m_codaDevice = SymbianUtils::SymbianDeviceManager::instance()->getTcfPort(m_serialPort); m_codaDevice = SymbianUtils::SymbianDeviceManager::instance()->getTcfPort(m_serialPort);
bool ok = m_codaDevice && m_tcfTrkDevice->device()->isOpen(); bool ok = m_codaDevice && m_codaDevice->device()->isOpen();
if (!ok) { if (!ok) {
appendMessage(tr("Couldn't open serial device: %1").arg(m_tcfTrkDevice->device()->errorString()), ErrorMessageFormat); appendMessage(tr("Couldn't open serial device: %1").arg(m_codaDevice->device()->errorString()), ErrorMessageFormat);
return false; return false;
} }
connect(SymbianUtils::SymbianDeviceManager::instance(), SIGNAL(deviceRemoved(const SymbianUtils::SymbianDevice)), connect(SymbianUtils::SymbianDeviceManager::instance(), SIGNAL(deviceRemoved(const SymbianUtils::SymbianDevice)),
this, SLOT(deviceRemoved(SymbianUtils::SymbianDevice))); this, SLOT(deviceRemoved(SymbianUtils::SymbianDevice)));
connect(m_tcfTrkDevice.data(), SIGNAL(error(QString)), this, SLOT(slotError(QString))); connect(m_codaDevice.data(), SIGNAL(error(QString)), this, SLOT(slotError(QString)));
connect(m_tcfTrkDevice.data(), SIGNAL(logMessage(QString)), this, SLOT(slotTrkLogMessage(QString))); connect(m_codaDevice.data(), SIGNAL(logMessage(QString)), this, SLOT(slotTrkLogMessage(QString)));
connect(m_tcfTrkDevice.data(), SIGNAL(tcfEvent(tcftrk::TcfTrkEvent)), this, SLOT(slotTcftrkEvent(tcftrk::TcfTrkEvent))); connect(m_codaDevice.data(), SIGNAL(tcfEvent(Coda::CodaEvent)), this, SLOT(slotCodaEvent(Coda::CodaEvent)));
connect(m_tcfTrkDevice.data(), SIGNAL(serialPong(QString)), this, SLOT(slotSerialPong(QString))); connect(m_codaDevice.data(), SIGNAL(serialPong(QString)), this, SLOT(slotSerialPong(QString)));
m_state = StateConnecting; m_state = StateConnecting;
m_codaDevice->sendSerialPing(false); m_codaDevice->sendSerialPing(false);
QTimer::singleShot(4000, this, SLOT(checkForTimeout()));
} 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);
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(tcftrk::TcfTrkEvent)), this, SLOT(slotTcftrkEvent(tcftrk::TcfTrkEvent))); connect(m_codaDevice.data(), SIGNAL(tcfEvent(Coda::CodaEvent)), this, SLOT(slotCodaEvent(Coda::CodaEvent)));
const QSharedPointer<QTcpSocket> codaSocket(new QTcpSocket); const QSharedPointer<QTcpSocket> codaSocket(new QTcpSocket);
m_codaDevice->setDevice(codaSocket); m_codaDevice->setDevice(codaSocket);
codaSocket->connectToHost(m_address, m_port); codaSocket->connectToHost(m_address, m_port);
m_state = StateConnecting; m_state = StateConnecting;
appendMessage(tr("Connecting to %1:%2...").arg(m_address).arg(m_port), NormalMessageFormat); appendMessage(tr("Connecting to %1:%2...").arg(m_address).arg(m_port), NormalMessageFormat);
QTimer::singleShot(4000, this, SLOT(checkForTimeout()));
} }
if (debug) m_tcfTrkDevice->setVerbose(1); QTimer::singleShot(4000, this, SLOT(checkForTimeout()));
if (debug)
m_codaDevice->setVerbose(debug);
return true; return true;
} }

View File

@@ -314,9 +314,9 @@ void S60DeployStep::stop()
if (m_launcher) if (m_launcher)
m_launcher->terminate(); m_launcher->terminate();
} else { } else {
if (m_trkDevice) { if (m_codaDevice) {
disconnect(m_trkDevice.data(), 0, this, 0); disconnect(m_codaDevice.data(), 0, this, 0);
SymbianUtils::SymbianDeviceManager::instance()->releaseTcfPort(m_trkDevice); SymbianUtils::SymbianDeviceManager::instance()->releaseTcfPort(m_codaDevice);
} }
} }
emit finished(false); emit finished(false);
@@ -342,7 +342,7 @@ void S60DeployStep::setupConnections()
} else { } else {
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(tcftrk::TcfTrkEvent)), this, SLOT(slotTcftrkEvent(tcftrk::TcfTrkEvent)), Qt::DirectConnection); connect(m_codaDevice.data(), SIGNAL(tcfEvent(Coda::CodaEvent)), this, SLOT(slotCodaEvent(Coda::CodaEvent)), Qt::DirectConnection);
connect(m_codaDevice.data(), SIGNAL(serialPong(QString)), this, SLOT(slotSerialPong(QString))); connect(m_codaDevice.data(), SIGNAL(serialPong(QString)), this, SLOT(slotSerialPong(QString)));
connect(this, SIGNAL(manualInstallation()), this, SLOT(showManualInstallationInfo())); connect(this, SIGNAL(manualInstallation()), this, SLOT(showManualInstallationInfo()));
} }
@@ -353,7 +353,7 @@ void S60DeployStep::startDeployment()
if (m_channel == S60DeployConfiguration::CommunicationTrkSerialConnection) { if (m_channel == S60DeployConfiguration::CommunicationTrkSerialConnection) {
QTC_ASSERT(m_launcher, return); QTC_ASSERT(m_launcher, return);
} }
QTC_ASSERT(!m_trkDevice.data(), return); QTC_ASSERT(!m_codaDevice.data(), return);
// We need to defer setupConnections() in the case of CommunicationCodaSerialConnection // We need to defer setupConnections() in the case of CommunicationCodaSerialConnection
//setupConnections(); //setupConnections();
@@ -383,18 +383,19 @@ void S60DeployStep::startDeployment()
} }
} else if (m_channel == S60DeployConfiguration::CommunicationCodaSerialConnection) { } else if (m_channel == S60DeployConfiguration::CommunicationCodaSerialConnection) {
appendMessage(tr("Deploying application to '%1'...").arg(m_serialPortFriendlyName), false); appendMessage(tr("Deploying application to '%1'...").arg(m_serialPortFriendlyName), false);
m_trkDevice = SymbianUtils::SymbianDeviceManager::instance()->getTcfPort(m_serialPortName); m_codaDevice = SymbianUtils::SymbianDeviceManager::instance()->getTcfPort(m_serialPortName);
bool ok = m_trkDevice && m_trkDevice->device()->isOpen(); bool ok = m_codaDevice && m_codaDevice->device()->isOpen();
if (!ok) { if (!ok) {
QString deviceError = tr("No such port"); QString deviceError = tr("No such port");
if (m_trkDevice) deviceError = m_trkDevice->device()->errorString(); if (m_codaDevice)
deviceError = m_codaDevice->device()->errorString();
reportError(tr("Couldn't open serial device: %1").arg(deviceError)); reportError(tr("Couldn't open serial device: %1").arg(deviceError));
stop(); stop();
return; return;
} }
setupConnections(); setupConnections();
m_state = StateConnecting; m_state = StateConnecting;
m_trkDevice->sendSerialPing(false); m_codaDevice->sendSerialPing(false);
QTimer::singleShot(4000, this, SLOT(checkForTimeout())); QTimer::singleShot(4000, this, SLOT(checkForTimeout()));
} else { } else {
m_codaDevice = QSharedPointer<Coda::CodaDevice>(new Coda::CodaDevice); m_codaDevice = QSharedPointer<Coda::CodaDevice>(new Coda::CodaDevice);
@@ -439,9 +440,9 @@ void S60DeployStep::run(QFutureInterface<bool> &fi)
delete m_timer; delete m_timer;
m_timer = 0; m_timer = 0;
if (m_trkDevice) { if (m_codaDevice) {
disconnect(m_trkDevice.data(), 0, this, 0); disconnect(m_codaDevice.data(), 0, this, 0);
SymbianUtils::SymbianDeviceManager::instance()->releaseTcfPort(m_trkDevice); SymbianUtils::SymbianDeviceManager::instance()->releaseTcfPort(m_codaDevice);
} }
delete m_eventLoop; delete m_eventLoop;
@@ -499,7 +500,7 @@ void S60DeployStep::initFileSending()
QString packageName(QFileInfo(m_signedPackages.at(m_currentFileIndex)).fileName()); QString packageName(QFileInfo(m_signedPackages.at(m_currentFileIndex)).fileName());
QString remoteFileLocation = QString::fromLatin1("%1:\\Data\\%2").arg(m_installationDrive).arg(packageName); QString remoteFileLocation = QString::fromLatin1("%1:\\Data\\%2").arg(m_installationDrive).arg(packageName);
m_trkDevice->sendFileSystemOpenCommand(Coda::CodaCallback(this, &S60DeployStep::handleFileSystemOpen), m_codaDevice->sendFileSystemOpenCommand(Coda::CodaCallback(this, &S60DeployStep::handleFileSystemOpen),
remoteFileLocation.toAscii(), flags); remoteFileLocation.toAscii(), flags);
appendMessage(tr("Copying \"%1\"...").arg(packageName), false); appendMessage(tr("Copying \"%1\"...").arg(packageName), false);
} }
@@ -512,11 +513,11 @@ void S60DeployStep::initFileInstallation()
QString packageName(QFileInfo(m_signedPackages.at(m_currentFileIndex)).fileName()); QString packageName(QFileInfo(m_signedPackages.at(m_currentFileIndex)).fileName());
QString remoteFileLocation = QString::fromLatin1("%1:\\Data\\%2").arg(m_installationDrive).arg(packageName); QString remoteFileLocation = QString::fromLatin1("%1:\\Data\\%2").arg(m_installationDrive).arg(packageName);
if (m_silentInstall) { if (m_silentInstall) {
m_trkDevice->sendSymbianInstallSilentInstallCommand(Coda::CodaCallback(this, &S60DeployStep::handleSymbianInstall), m_codaDevice->sendSymbianInstallSilentInstallCommand(Coda::CodaCallback(this, &S60DeployStep::handleSymbianInstall),
remoteFileLocation.toAscii(), QString::fromLatin1("%1:").arg(m_installationDrive).toAscii()); remoteFileLocation.toAscii(), QString::fromLatin1("%1:").arg(m_installationDrive).toAscii());
appendMessage(tr("Installing package \"%1\" on drive %2:...").arg(packageName).arg(m_installationDrive), false); appendMessage(tr("Installing package \"%1\" on drive %2:...").arg(packageName).arg(m_installationDrive), false);
} else { } else {
m_trkDevice->sendSymbianInstallUIInstallCommand(Coda::CodaCallback(this, &S60DeployStep::handleSymbianInstall), m_codaDevice->sendSymbianInstallUIInstallCommand(Coda::CodaCallback(this, &S60DeployStep::handleSymbianInstall),
remoteFileLocation.toAscii()); remoteFileLocation.toAscii());
appendMessage(tr("Please continue the installation on your device."), false); appendMessage(tr("Please continue the installation on your device."), false);
emit manualInstallation(); emit manualInstallation();
@@ -588,7 +589,7 @@ void S60DeployStep::putSendNextChunk()
qDebug("Writing %llu bytes to remote file '%s' at %llu\n", qDebug("Writing %llu bytes to remote file '%s' at %llu\n",
m_putLastChunkSize, m_putLastChunkSize,
m_remoteFileHandle.constData(), pos); m_remoteFileHandle.constData(), pos);
m_trkDevice->sendFileSystemWriteCommand(Coda::CodaCallback(this, &S60DeployStep::handleFileSystemWrite), m_codaDevice->sendFileSystemWriteCommand(Coda::CodaCallback(this, &S60DeployStep::handleFileSystemWrite),
m_remoteFileHandle, data, unsigned(pos)); m_remoteFileHandle, data, unsigned(pos));
setCopyProgress((100*(m_putLastChunkSize+pos))/size); setCopyProgress((100*(m_putLastChunkSize+pos))/size);
} }
@@ -596,7 +597,7 @@ void S60DeployStep::putSendNextChunk()
void S60DeployStep::closeRemoteFile() void S60DeployStep::closeRemoteFile()
{ {
m_trkDevice->sendFileSystemCloseCommand(Coda::CodaCallback(this, &S60DeployStep::handleFileSystemClose), m_codaDevice->sendFileSystemCloseCommand(Coda::CodaCallback(this, &S60DeployStep::handleFileSystemClose),
m_remoteFileHandle); m_remoteFileHandle);
} }

View File

@@ -43,7 +43,7 @@
#include <QtCore/QDateTime> #include <QtCore/QDateTime>
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
enum { debug = 1 }; enum { debug = 0 };
static const char tcpMessageTerminatorC[] = "\003\001"; static const char tcpMessageTerminatorC[] = "\003\001";
@@ -60,15 +60,18 @@ static const char locatorAnswerC[] = "E\0Locator\0Hello\0[\"Locator\"]";
static const unsigned serialChunkLength = 0x400; // 1K max USB router static const unsigned serialChunkLength = 0x400; // 1K max USB router
static const int maxSerialMessageLength = 0x10000; // given chunking scheme static const int maxSerialMessageLength = 0x10000; // given chunking scheme
static const char validProtocolIdStart = (char)0x90;
static const char validProtocolIdEnd = (char)0x95;
static const char codaProtocolId = (char)0x92;
static const unsigned char serialChunkingStart = 0xfe; static const unsigned char serialChunkingStart = 0xfe;
static const unsigned char serialChunkingContinuation = 0x0; static const unsigned char serialChunkingContinuation = 0x0;
enum { SerialChunkHeaderSize = 2 }; enum { SerialChunkHeaderSize = 2 };
// Create USB router frame // Create USB router frame
static inline void encodeSerialFrame(const QByteArray &data, QByteArray *target) static inline void encodeSerialFrame(const QByteArray &data, QByteArray *target, char protocolId)
{ {
target->append(char(0x01)); target->append(char(0x01));
target->append(char(0x92)); // CODA serial message ID target->append(protocolId);
appendShort(target, ushort(data.size()), trk::BigEndian); appendShort(target, ushort(data.size()), trk::BigEndian);
target->append(data); target->append(data);
} }
@@ -83,7 +86,7 @@ static inline QByteArray encodeUsbSerialMessage(const QByteArray &dataIn)
// Do we need to split? // Do we need to split?
if (size < chunkSize) { // Nope, all happy. if (size < chunkSize) { // Nope, all happy.
frame.reserve(size + 4); frame.reserve(size + 4);
encodeSerialFrame(dataIn, &frame); encodeSerialFrame(dataIn, &frame, codaProtocolId);
return frame; return frame;
} }
// Split. // Split.
@@ -102,7 +105,7 @@ static inline QByteArray encodeUsbSerialMessage(const QByteArray &dataIn)
chunk.append(char(static_cast<unsigned char>(c))); // Avoid any signedness issues. chunk.append(char(static_cast<unsigned char>(c))); // Avoid any signedness issues.
const int chunkEnd = qMin(pos + chunkSize, size); const int chunkEnd = qMin(pos + chunkSize, size);
chunk.append(dataIn.mid(pos, chunkEnd - pos)); chunk.append(dataIn.mid(pos, chunkEnd - pos));
encodeSerialFrame(chunk, &frame); encodeSerialFrame(chunk, &frame, codaProtocolId);
pos = chunkEnd; pos = chunkEnd;
} }
if (debug > 1) if (debug > 1)
@@ -471,26 +474,24 @@ void CodaDevice::slotDeviceReadyRead()
// Find a serial header in input stream '0x1', '0x92', 'lenH', 'lenL' // Find a serial header in input stream '0x1', '0x92', 'lenH', 'lenL'
// and return message position and size. // and return message position and size.
QPair<int, int> TcfTrkDevice::findSerialHeader(QByteArray &in) QPair<int, int> CodaDevice::findSerialHeader(QByteArray &in)
{ {
const char header1 = 0x1; static const char header1 = 0x1;
const char header2 = char(0x92);
const char header2tracecore = char(0x91);
// Header should in theory always be at beginning of // Header should in theory always be at beginning of
// buffer. Warn if there are bogus data in-between. // buffer. Warn if there are bogus data in-between.
while (in.size() >= 4) { while (in.size() >= 4) {
if (in.at(0) == header1 && in.at(1) == header2) { if (in.at(0) == header1 && in.at(1) == codaProtocolId) {
// Good packet // Good packet
const int length = trk::extractShort(in.constData() + 2); const int length = trk::extractShort(in.constData() + 2);
return QPair<int, int>(4, length); return QPair<int, int>(4, length);
} else if (in.at(0) == header1 && in.at(1) == header2tracecore) { } else if (in.at(0) == header1 && in.at(1) >= validProtocolIdStart && in.at(1) <= validProtocolIdEnd) {
// We recognise it but it's not a TCF message - emit it for any interested party to handle // We recognise it but it's not a TCF message - emit it for any interested party to handle
const int length = trk::extractShort(in.constData() + 2); const int length = trk::extractShort(in.constData() + 2);
if (4 + length <= in.size()) { if (4 + length <= in.size()) {
// We have all the data // We have all the data
QByteArray data(in.mid(4, length)); QByteArray data(in.mid(4, length));
emit traceCoreEvent(data); emit unknownEvent(in.at(1), data);
in.remove(0, 4+length); in.remove(0, 4+length);
// and continue // and continue
} else { } else {
@@ -504,7 +505,6 @@ QPair<int, int> TcfTrkDevice::findSerialHeader(QByteArray &in)
QByteArray bad = in.mid(0, nextHeader); QByteArray bad = in.mid(0, nextHeader);
qWarning("Bogus data received on serial line: %s\n" qWarning("Bogus data received on serial line: %s\n"
"Frame Header at: %d", qPrintable(trk::stringFromArray(bad)), nextHeader); "Frame Header at: %d", qPrintable(trk::stringFromArray(bad)), nextHeader);
d->m_device->write(bad); // Backatcha - TOMSCI TESTING
in.remove(0, bad.length()); in.remove(0, bad.length());
// and continue // and continue
} }
@@ -787,9 +787,6 @@ void CodaDevice::sendSerialPing(bool pingOnly)
if (!checkOpen()) if (!checkOpen())
return; return;
dumpObjectInfo();
d->m_device->dumpObjectInfo();
d->m_serialPingOnly = pingOnly; d->m_serialPingOnly = pingOnly;
setSerialFrame(true); setSerialFrame(true);
writeMessage(QByteArray(serialPingC, qstrlen(serialPingC)), false); writeMessage(QByteArray(serialPingC, qstrlen(serialPingC)), false);
@@ -869,6 +866,24 @@ void CodaDevice::writeMessage(QByteArray data, bool ensureTerminating0)
as->flush(); as->flush();
} }
void CodaDevice::writeCustomData(char protocolId, const QByteArray &data)
{
if (!checkOpen())
return;
if (!d->m_serialFrame) {
qWarning("Ignoring request to send data to non-serial CodaDevice");
return;
}
if (data.length() > 0xFFFF) {
qWarning("Ignoring request to send too large packet, of size %d", data.length());
return;
}
QByteArray framedData;
encodeSerialFrame(data, &framedData, protocolId);
device()->write(framedData);
}
void CodaDevice::checkSendQueue() void CodaDevice::checkSendQueue()
{ {
// Fire off messages or invoke noops until a message with reply is found // Fire off messages or invoke noops until a message with reply is found

View File

@@ -360,6 +360,8 @@ public:
// Settings // Settings
void sendSettingsEnableLogCommand(); void sendSettingsEnableLogCommand();
void writeCustomData(char protocolId, const QByteArray &aData);
static QByteArray parseMemoryGet(const CodaCommandResult &r); static QByteArray parseMemoryGet(const CodaCommandResult &r);
static QVector<QByteArray> parseRegisterGetChildren(const CodaCommandResult &r); static QVector<QByteArray> parseRegisterGetChildren(const CodaCommandResult &r);
static CodaStatResponse parseStat(const CodaCommandResult &r); static CodaStatResponse parseStat(const CodaCommandResult &r);
@@ -367,7 +369,7 @@ public:
signals: signals:
void genericTcfEvent(int service, const QByteArray &name, const QVector<JsonValue> &value); void genericTcfEvent(int service, const QByteArray &name, const QVector<JsonValue> &value);
void tcfEvent(const Coda::CodaEvent &knownEvent); void tcfEvent(const Coda::CodaEvent &knownEvent);
void traceCoreEvent(const QByteArray& data); void unknownEvent(uchar protocolId, const QByteArray& data);
void serialPong(const QString &codaVersion); void serialPong(const QString &codaVersion);
void logMessage(const QString &); void logMessage(const QString &);

View File

@@ -33,7 +33,7 @@
#include "symbiandevicemanager.h" #include "symbiandevicemanager.h"
#include "trkdevice.h" #include "trkdevice.h"
#include "tcftrkdevice.h" #include "codadevice.h"
#include "virtualserialdevice.h" #include "virtualserialdevice.h"
#include <QtCore/QSettings> #include <QtCore/QSettings>
@@ -73,7 +73,7 @@ public:
DeviceCommunicationType type; DeviceCommunicationType type;
QSharedPointer<trk::TrkDevice> device; QSharedPointer<trk::TrkDevice> device;
QSharedPointer<tcftrk::TcfTrkDevice> tcfdevice; QSharedPointer<Coda::CodaDevice> codaDevice;
bool deviceAcquired; bool deviceAcquired;
}; };
@@ -85,14 +85,11 @@ SymbianDeviceData::SymbianDeviceData() :
bool SymbianDeviceData::isOpen() const bool SymbianDeviceData::isOpen() const
{ {
if (device) { if (device)
// TRK device
return device->isOpen(); return device->isOpen();
} else if (tcfdevice) { if (codaDevice)
return tcfdevice->device()->isOpen(); return codaDevice->device()->isOpen();
} else {
return false; return false;
}
} }
SymbianDeviceData::~SymbianDeviceData() SymbianDeviceData::~SymbianDeviceData()
@@ -110,8 +107,10 @@ void SymbianDeviceData::forcedClose()
if (deviceAcquired) if (deviceAcquired)
qWarning("Device on '%s' unplugged while an operation is in progress.", qWarning("Device on '%s' unplugged while an operation is in progress.",
qPrintable(portName)); qPrintable(portName));
if (device) device->close(); if (device)
else tcfdevice->device()->close(); device->close();
else
codaDevice->device()->close();
} }
} }
@@ -278,12 +277,12 @@ struct SymbianDeviceManagerPrivate {
class QConstructTcfPortEvent : public QEvent class QConstructTcfPortEvent : public QEvent
{ {
public: public:
QConstructTcfPortEvent(QEvent::Type eventId, const QString &portName, TcfTrkDevicePtr *device, QWaitCondition *waiter) : QConstructTcfPortEvent(QEvent::Type eventId, const QString &portName, CodaDevicePtr *device, QWaitCondition *waiter) :
QEvent(eventId), m_portName(portName), m_device(device), m_waiter(waiter) QEvent(eventId), m_portName(portName), m_device(device), m_waiter(waiter)
{} {}
QString m_portName; QString m_portName;
TcfTrkDevicePtr* m_device; CodaDevicePtr* m_device;
QWaitCondition *m_waiter; QWaitCondition *m_waiter;
}; };
@@ -353,7 +352,7 @@ SymbianDeviceManager::TrkDevicePtr
return rc; return rc;
} }
TcfTrkDevicePtr SymbianDeviceManager::getTcfPort(const QString &port) CodaDevicePtr SymbianDeviceManager::getTcfPort(const QString &port)
{ {
ensureInitialized(); ensureInitialized();
const int idx = findByPortName(port); const int idx = findByPortName(port);
@@ -361,16 +360,16 @@ TcfTrkDevicePtr SymbianDeviceManager::getTcfPort(const QString &port)
qWarning("Attempt to acquire device '%s' that does not exist.", qPrintable(port)); qWarning("Attempt to acquire device '%s' that does not exist.", qPrintable(port));
if (debug) if (debug)
qDebug() << *this; qDebug() << *this;
return TcfTrkDevicePtr(); return CodaDevicePtr();
} }
SymbianDevice& device = d->m_devices[idx]; SymbianDevice& device = d->m_devices[idx];
if (device.m_data->device) { if (device.m_data->device) {
qWarning("Attempting to open a port '%s' that is configured for TRK!", qPrintable(port)); qWarning("Attempting to open a port '%s' that is configured for TRK!", qPrintable(port));
return TcfTrkDevicePtr(); return CodaDevicePtr();
} }
TcfTrkDevicePtr& devicePtr = device.m_data->tcfdevice; CodaDevicePtr& devicePtr = device.m_data->codaDevice;
if (devicePtr.isNull()) { if (devicePtr.isNull() || !devicePtr->device()->isOpen()) {
// Check we instanciate in the correct thread - we can't afford to create the TcfTrkDevice (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 current thread
@@ -378,57 +377,47 @@ TcfTrkDevicePtr SymbianDeviceManager::getTcfPort(const QString &port)
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_tcfPortWaitMutex);
// When the wait returns (due to the wakeAll in SymbianDeviceManager::customEvent), the TcfTrkDevice 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_tcfPortWaitMutex.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); constructTcfPort(devicePtr, port);
} }
}
if (!devicePtr->device()->isOpen()) {
bool ok = devicePtr->device().staticCast<SymbianUtils::VirtualSerialDevice>()->open(QIODevice::ReadWrite);
if (!ok && debug) {
qDebug("SymbianDeviceManager: Failed to open port %s", qPrintable(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()
} }
//Q_ASSERT(QThread::currentThread() == devicePtr->thread());
return devicePtr; return devicePtr;
} }
void SymbianDeviceManager::constructTcfPort(TcfTrkDevicePtr& device, const QString& portName) void SymbianDeviceManager::constructTcfPort(CodaDevicePtr& device, const QString& portName)
{ {
QMutexLocker locker(&d->m_tcfPortWaitMutex); QMutexLocker locker(&d->m_tcfPortWaitMutex);
device = QSharedPointer<tcftrk::TcfTrkDevice>(new tcftrk::TcfTrkDevice); if (device.isNull()) {
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));
device->setSerialFrame(true); device->setSerialFrame(true);
device->setDevice(serialDevice); device->setDevice(serialDevice);
}
if (!device->device()->isOpen()) {
bool ok = device->device().staticCast<SymbianUtils::VirtualSerialDevice>()->open(QIODevice::ReadWrite);
if (!ok && debug) {
qDebug("SymbianDeviceManager: Failed to open port %s", qPrintable(portName));
}
}
} }
void SymbianDeviceManager::customEvent(QEvent *event) 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); constructTcfPort(*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
} }
} }
/* void SymbianDeviceManager::releaseTcfPort(CodaDevicePtr &aPort)
TcfTrkDevicePtr SymbianDeviceManager::getTcfPort(const QString &host, quint16 port)
{ {
// No attempt to check the device list. The main purpose in doing that is to cooperatively share the port with other services, and there's no need to do that with TCP/IP as you can just use separate port numbers. if (aPort)
// Ok it might make it slightly quicker but I'm not going to worry about it just now
}
*/
void SymbianDeviceManager::releaseTcfPort(TcfTrkDevicePtr &aPort)
{
if (aPort) {
aPort.clear(); aPort.clear();
}
//TODO close the port after a timeer if last reference? //TODO close the port after a timeer if last reference?
} }
@@ -442,11 +431,10 @@ void SymbianDeviceManager::releaseDevice(const QString &port)
const int idx = findByPortName(port); const int idx = findByPortName(port);
if (debug) if (debug)
qDebug() << "SymbianDeviceManager::releaseDevice" << port << idx << sender(); qDebug() << "SymbianDeviceManager::releaseDevice" << port << idx << sender();
if (idx != -1) { if (idx != -1)
d->m_devices[idx].releaseDevice(); d->m_devices[idx].releaseDevice();
} else { else
qWarning("Attempt to release non-existing device %s.", qPrintable(port)); qWarning("Attempt to release non-existing device %s.", qPrintable(port));
}
} }
void SymbianDeviceManager::setAdditionalInformation(const QString &port, const QString &ai) void SymbianDeviceManager::setAdditionalInformation(const QString &port, const QString &ai)

View File

@@ -48,8 +48,8 @@ QT_END_NAMESPACE
namespace trk { namespace trk {
class TrkDevice; class TrkDevice;
} }
namespace tcftrk { namespace Coda {
class TcfTrkDevice; class CodaDevice;
} }
namespace SymbianUtils { namespace SymbianUtils {
@@ -62,7 +62,7 @@ enum DeviceCommunicationType {
BlueToothCommunication = 1 BlueToothCommunication = 1
}; };
typedef QSharedPointer<tcftrk::TcfTrkDevice> TcfTrkDevicePtr; typedef QSharedPointer<Coda::CodaDevice> CodaDevicePtr;
// SymbianDevice: Explicitly shared device data and a TrkDevice // SymbianDevice: Explicitly shared device data and a TrkDevice
// instance that can be acquired (exclusively) for use. // instance that can be acquired (exclusively) for use.
@@ -146,17 +146,17 @@ public:
// Acquire a TRK device for use. Assuming the port is found, equivalent to devices()[findByPortName(port)].acquireDevice(). See also releaseDevice(). // Acquire a TRK device for use. Assuming the port is found, equivalent to devices()[findByPortName(port)].acquireDevice(). See also releaseDevice().
TrkDevicePtr acquireDevice(const QString &port); TrkDevicePtr acquireDevice(const QString &port);
//// The TCF code prefers to set up the TcfTrkDevice object itself, so we let it and just handle opening the underlying QIODevice and keeping track of the TcfTrkDevice //// The TCF code prefers to set up the CodaDevice object itself, so we let it and just handle opening the underlying QIODevice and keeping track of the CodaDevice
//// Returns true if port was opened successfully. //// Returns true if port was opened successfully.
// Gets the TcfTrkDevice, which may or may not be open depending on what other clients have already acquired it. // Gets the CodaDevice, which may or may not be open depending on what other clients have already acquired it.
// Therefore once clients have set up any signals and slots they required, they should check TcfTrkDevice::device()->isOpen() // Therefore once clients have set up any signals and slots they required, they should check CodaDevice::device()->isOpen()
// and if false, the open failed and they should check device()->errorString() if required. // and if false, the open failed and they should check device()->errorString() if required.
// Caller should call releaseTcfPort if they want the port to auto-close itself // Caller should call releaseTcfPort if they want the port to auto-close itself
TcfTrkDevicePtr getTcfPort(const QString &port); CodaDevicePtr getTcfPort(const QString &port);
// Caller is responsible for disconnecting any signals from aPort - do not assume the TcfTrkDevice will be deleted as a result of this call. On return aPort will be clear()ed. // Caller is responsible for disconnecting any signals from aPort - do not assume the CodaDevice will be deleted as a result of this call. On return aPort will be clear()ed.
void releaseTcfPort(TcfTrkDevicePtr &aPort); void releaseTcfPort(CodaDevicePtr &aPort);
int findByPortName(const QString &p) const; int findByPortName(const QString &p) const;
QString friendlyNameForPort(const QString &port) const; QString friendlyNameForPort(const QString &port) const;
@@ -178,7 +178,7 @@ private:
SymbianDeviceList serialPorts() const; SymbianDeviceList serialPorts() const;
SymbianDeviceList blueToothDevices() const; SymbianDeviceList blueToothDevices() const;
void customEvent(QEvent *event); void customEvent(QEvent *event);
void constructTcfPort(TcfTrkDevicePtr& device, const QString& portName); void constructTcfPort(CodaDevicePtr& device, const QString& portName);
SymbianDeviceManagerPrivate *d; SymbianDeviceManagerPrivate *d;
}; };

View File

@@ -127,14 +127,11 @@ bool VirtualSerialDevice::tryWrite(const char *data, qint64 maxSize, qint64& byt
while (maxSize > 0) { while (maxSize > 0) {
int result = ::write(d->portHandle, data, maxSize); int result = ::write(d->portHandle, data, maxSize);
if (result == -1) { if (result == -1) {
if (errno == EAGAIN) { if (errno == EAGAIN)
// Need to wait return true; // Need to wait
return true;
} else {
setErrorString(QString("Posix error %1 from write to %2").arg(errno).arg(portName)); setErrorString(QString("Posix error %1 from write to %2").arg(errno).arg(portName));
bytesWritten = -1; bytesWritten = -1;
return false; return false;
}
} else { } else {
if (result == 0) if (result == 0)
qWarning("Zero bytes written to port!"); qWarning("Zero bytes written to port!");