forked from qt-creator/qt-creator
Trk: Ensure proper connecting and disconnecting.
This commit is contained in:
@@ -64,10 +64,12 @@ struct LauncherPrivate {
|
|||||||
QString m_installFileName;
|
QString m_installFileName;
|
||||||
int m_verbose;
|
int m_verbose;
|
||||||
Launcher::Actions m_startupActions;
|
Launcher::Actions m_startupActions;
|
||||||
|
bool m_connected;
|
||||||
};
|
};
|
||||||
|
|
||||||
LauncherPrivate::LauncherPrivate() :
|
LauncherPrivate::LauncherPrivate() :
|
||||||
m_verbose(0)
|
m_verbose(0),
|
||||||
|
m_connected(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,18 +150,27 @@ bool Launcher::startServer(QString *errorMessage)
|
|||||||
if (!d->m_device.open(d->m_trkServerName, errorMessage))
|
if (!d->m_device.open(d->m_trkServerName, errorMessage))
|
||||||
return false;
|
return false;
|
||||||
d->m_device.sendTrkInitialPing();
|
d->m_device.sendTrkInitialPing();
|
||||||
d->m_device.sendTrkMessage(TrkConnect); // Connect
|
|
||||||
d->m_device.sendTrkMessage(TrkSupported, TrkCallback(this, &Launcher::handleSupportMask));
|
d->m_device.sendTrkMessage(TrkSupported, TrkCallback(this, &Launcher::handleSupportMask));
|
||||||
d->m_device.sendTrkMessage(TrkCpuType, TrkCallback(this, &Launcher::handleCpuType));
|
d->m_device.sendTrkMessage(TrkCpuType, TrkCallback(this, &Launcher::handleCpuType));
|
||||||
d->m_device.sendTrkMessage(TrkVersions, TrkCallback(this, &Launcher::handleTrkVersion));
|
d->m_device.sendTrkMessage(TrkVersions, TrkCallback(this, &Launcher::handleTrkVersion));
|
||||||
|
if (d->m_startupActions != ActionPingOnly)
|
||||||
|
d->m_device.sendTrkMessage(TrkConnect, TrkCallback(this, &Launcher::handleConnect));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Launcher::handleConnect(const TrkResult &result)
|
||||||
|
{
|
||||||
|
if (result.errorCode()) {
|
||||||
|
emit canNotConnect(result.errorString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
d->m_connected = true;
|
||||||
if (d->m_startupActions & ActionCopy)
|
if (d->m_startupActions & ActionCopy)
|
||||||
copyFileToRemote();
|
copyFileToRemote();
|
||||||
else if (d->m_startupActions & ActionInstall)
|
else if (d->m_startupActions & ActionInstall)
|
||||||
installRemotePackageSilently();
|
installRemotePackageSilently();
|
||||||
else if (d->m_startupActions & ActionRun)
|
else if (d->m_startupActions & ActionRun)
|
||||||
startInferiorIfNeeded();
|
startInferiorIfNeeded();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::setVerbose(int v)
|
void Launcher::setVerbose(int v)
|
||||||
@@ -176,11 +187,24 @@ void Launcher::logMessage(const QString &msg)
|
|||||||
|
|
||||||
void Launcher::terminate()
|
void Launcher::terminate()
|
||||||
{
|
{
|
||||||
//TODO handle case where application has not been started
|
if (d->m_session.pid) {
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
appendShort(&ba, 0x0000, TargetByteOrder);
|
appendShort(&ba, 0x0000, TargetByteOrder);
|
||||||
appendInt(&ba, d->m_session.pid, TargetByteOrder);
|
appendInt(&ba, d->m_session.pid, TargetByteOrder);
|
||||||
d->m_device.sendTrkMessage(TrkDeleteItem, TrkCallback(this, &Launcher::handleWaitForFinished), ba);
|
d->m_device.sendTrkMessage(TrkDeleteItem, TrkCallback(this, &Launcher::handleRemoteProcessKilled), ba);
|
||||||
|
} else if (d->m_connected) {
|
||||||
|
if (d->m_copyState.copyFileHandle)
|
||||||
|
closeRemoteFile(true);
|
||||||
|
disconnectTrk();
|
||||||
|
} else {
|
||||||
|
emit finished();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Launcher::handleRemoteProcessKilled(const TrkResult &result)
|
||||||
|
{
|
||||||
|
Q_UNUSED(result)
|
||||||
|
disconnectTrk();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::handleResult(const TrkResult &result)
|
void Launcher::handleResult(const TrkResult &result)
|
||||||
@@ -267,7 +291,7 @@ void Launcher::handleResult(const TrkResult &result)
|
|||||||
if (itemType == 0 // process
|
if (itemType == 0 // process
|
||||||
&& result.data.size() >= 10
|
&& result.data.size() >= 10
|
||||||
&& d->m_session.pid == extractInt(result.data.data() + 6)) {
|
&& d->m_session.pid == extractInt(result.data.data() + 6)) {
|
||||||
d->m_device.sendTrkMessage(TrkDisconnect, TrkCallback(this, &Launcher::handleWaitForFinished));
|
disconnectTrk();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -321,7 +345,7 @@ void Launcher::handleFileCreation(const TrkResult &result)
|
|||||||
{
|
{
|
||||||
if (result.errorCode() || result.data.size() < 6) {
|
if (result.errorCode() || result.data.size() < 6) {
|
||||||
emit canNotCreateFile(d->m_copyState.destinationFileName, result.errorString());
|
emit canNotCreateFile(d->m_copyState.destinationFileName, result.errorString());
|
||||||
emit finished();
|
disconnectTrk();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const char *data = result.data.data();
|
const char *data = result.data.data();
|
||||||
@@ -339,7 +363,7 @@ void Launcher::handleCopy(const TrkResult &result)
|
|||||||
if (result.errorCode() || result.data.size() < 4) {
|
if (result.errorCode() || result.data.size() < 4) {
|
||||||
closeRemoteFile(true);
|
closeRemoteFile(true);
|
||||||
emit canNotWriteFile(d->m_copyState.destinationFileName, result.errorString());
|
emit canNotWriteFile(d->m_copyState.destinationFileName, result.errorString());
|
||||||
emit finished();
|
disconnectTrk();
|
||||||
} else {
|
} else {
|
||||||
continueCopying(extractShort(result.data.data() + 2));
|
continueCopying(extractShort(result.data.data() + 2));
|
||||||
}
|
}
|
||||||
@@ -374,6 +398,8 @@ void Launcher::closeRemoteFile(bool failed)
|
|||||||
failed ? TrkCallback() : TrkCallback(this, &Launcher::handleFileCopied),
|
failed ? TrkCallback() : TrkCallback(this, &Launcher::handleFileCopied),
|
||||||
ba);
|
ba);
|
||||||
d->m_copyState.data.reset();
|
d->m_copyState.data.reset();
|
||||||
|
d->m_copyState.copyFileHandle = 0;
|
||||||
|
d->m_copyState.position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::handleFileCopied(const TrkResult &result)
|
void Launcher::handleFileCopied(const TrkResult &result)
|
||||||
@@ -385,7 +411,7 @@ void Launcher::handleFileCopied(const TrkResult &result)
|
|||||||
else if (d->m_startupActions & ActionRun)
|
else if (d->m_startupActions & ActionRun)
|
||||||
startInferiorIfNeeded();
|
startInferiorIfNeeded();
|
||||||
else
|
else
|
||||||
emit finished();
|
disconnectTrk();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::handleCpuType(const TrkResult &result)
|
void Launcher::handleCpuType(const TrkResult &result)
|
||||||
@@ -410,7 +436,7 @@ void Launcher::handleCreateProcess(const TrkResult &result)
|
|||||||
{
|
{
|
||||||
if (result.errorCode()) {
|
if (result.errorCode()) {
|
||||||
emit canNotRun(result.errorString());
|
emit canNotRun(result.errorString());
|
||||||
emit finished();
|
disconnectTrk();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 40 00 00]
|
// 40 00 00]
|
||||||
@@ -511,6 +537,11 @@ void Launcher::cleanUp()
|
|||||||
// Error: 0x00
|
// Error: 0x00
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Launcher::disconnectTrk()
|
||||||
|
{
|
||||||
|
d->m_device.sendTrkMessage(TrkDisconnect, TrkCallback(this, &Launcher::handleWaitForFinished));
|
||||||
|
}
|
||||||
|
|
||||||
void Launcher::copyFileToRemote()
|
void Launcher::copyFileToRemote()
|
||||||
{
|
{
|
||||||
emit copyingStarted();
|
emit copyingStarted();
|
||||||
@@ -533,11 +564,11 @@ void Launcher::handleInstallPackageFinished(const TrkResult &result)
|
|||||||
{
|
{
|
||||||
if (result.errorCode()) {
|
if (result.errorCode()) {
|
||||||
emit canNotInstall(d->m_installFileName, result.errorString());
|
emit canNotInstall(d->m_installFileName, result.errorString());
|
||||||
emit finished();
|
disconnectTrk();
|
||||||
} else if (d->m_startupActions & ActionRun) {
|
} else if (d->m_startupActions & ActionRun) {
|
||||||
startInferiorIfNeeded();
|
startInferiorIfNeeded();
|
||||||
} else {
|
} else {
|
||||||
emit finished();
|
disconnectTrk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -69,6 +69,7 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void copyingStarted();
|
void copyingStarted();
|
||||||
|
void canNotConnect(const QString &errorMessage);
|
||||||
void canNotCreateFile(const QString &filename, const QString &errorMessage);
|
void canNotCreateFile(const QString &filename, const QString &errorMessage);
|
||||||
void canNotWriteFile(const QString &filename, const QString &errorMessage);
|
void canNotWriteFile(const QString &filename, const QString &errorMessage);
|
||||||
void canNotCloseFile(const QString &filename, const QString &errorMessage);
|
void canNotCloseFile(const QString &filename, const QString &errorMessage);
|
||||||
@@ -90,7 +91,10 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
// kill process and breakpoints
|
// kill process and breakpoints
|
||||||
void cleanUp();
|
void cleanUp();
|
||||||
|
void disconnectTrk();
|
||||||
|
|
||||||
|
void handleRemoteProcessKilled(const TrkResult &result);
|
||||||
|
void handleConnect(const TrkResult &result);
|
||||||
void handleFileCreation(const TrkResult &result);
|
void handleFileCreation(const TrkResult &result);
|
||||||
void handleCopy(const TrkResult &result);
|
void handleCopy(const TrkResult &result);
|
||||||
void continueCopying(uint lastCopiedBlockSize = 0);
|
void continueCopying(uint lastCopiedBlockSize = 0);
|
||||||
|
Reference in New Issue
Block a user