Commit 51f997d6 authored by Robert Loehning's avatar Robert Loehning
Browse files

Trk: Controlling Launcher using an enum.

parent 49dc9629
......@@ -624,7 +624,7 @@ void S60DeviceRunControlBase::signsisProcessFinished()
emit finished();
return;
}
m_launcher = new trk::Launcher;
m_launcher = new trk::Launcher(trk::Launcher::ActionCopyInstallRun);
connect(m_launcher, SIGNAL(finished()), this, SLOT(launcherFinished()));
connect(m_launcher, SIGNAL(copyingStarted()), this, SLOT(printCopyingNotice()));
connect(m_launcher, SIGNAL(canNotCreateFile(QString,QString)), this, SLOT(printCreateFileFailed(QString,QString)));
......
......@@ -63,6 +63,7 @@ struct LauncherPrivate {
QString m_fileName;
QString m_installFileName;
int m_verbose;
Launcher::Actions m_startupActions;
};
LauncherPrivate::LauncherPrivate() :
......@@ -70,9 +71,10 @@ LauncherPrivate::LauncherPrivate() :
{
}
Launcher::Launcher() :
Launcher::Launcher(Actions startupActions) :
d(new LauncherPrivate)
{
d->m_startupActions = startupActions;
connect(&d->m_device, SIGNAL(messageReceived(trk::TrkResult)), this, SLOT(handleResult(trk::TrkResult)));
}
......@@ -82,6 +84,11 @@ Launcher::~Launcher()
delete d;
}
void Launcher::addStartupActions(trk::Launcher::Actions startupActions)
{
d->m_startupActions = Actions(d->m_startupActions | startupActions);
}
void Launcher::setTrkServerName(const QString &name)
{
d->m_trkServerName = name;
......@@ -120,6 +127,23 @@ bool Launcher::startServer(QString *errorMessage)
.arg(d->m_trkServerName, d->m_fileName, d->m_copyState.sourceFileName, d->m_copyState.destinationFileName, d->m_installFileName);
logMessage(msg);
}
if (d->m_startupActions & ActionCopy) {
if (d->m_copyState.sourceFileName.isEmpty()) {
qWarning("No local filename given for copying package.");
return false;
} else if (d->m_copyState.destinationFileName.isEmpty()) {
qWarning("No remote filename given for copying package.");
return false;
}
}
if (d->m_startupActions & ActionInstall && d->m_installFileName.isEmpty()) {
qWarning("No package name given for installing.");
return false;
}
if (d->m_startupActions & ActionRun && d->m_fileName.isEmpty()) {
qWarning("No remote executable given for running.");
return false;
}
if (!d->m_device.open(d->m_trkServerName, errorMessage))
return false;
d->m_device.sendTrkInitialPing();
......@@ -127,10 +151,13 @@ bool Launcher::startServer(QString *errorMessage)
d->m_device.sendTrkMessage(TrkSupported, TrkCallback(this, &Launcher::handleSupportMask));
d->m_device.sendTrkMessage(TrkCpuType, TrkCallback(this, &Launcher::handleCpuType));
d->m_device.sendTrkMessage(TrkVersions, TrkCallback(this, &Launcher::handleTrkVersion));
if (d->m_copyState.sourceFileName.isEmpty() || d->m_copyState.destinationFileName.isEmpty())
installAndRun();
else
if (d->m_startupActions & ActionCopy)
copyFileToRemote();
else if (d->m_startupActions & ActionInstall)
installRemotePackageSilently(d->m_installFileName);
else if (d->m_startupActions & ActionRun)
startInferiorIfNeeded();
return true;
}
......@@ -140,14 +167,6 @@ void Launcher::setVerbose(int v)
d->m_device.setVerbose(v);
}
void Launcher::installAndRun()
{
if (d->m_installFileName.isEmpty())
startInferiorIfNeeded();
else
installRemotePackageSilently(d->m_installFileName);
}
void Launcher::logMessage(const QString &msg)
{
if (d->m_verbose)
......@@ -285,7 +304,7 @@ void Launcher::handleTrkVersion(const TrkResult &result)
const int protocolMajor = result.data.at(3);
const int protocolMinor = result.data.at(4);
// Ping mode: Log & Terminate
if (d->m_fileName.isEmpty()) {
if (d->m_startupActions == ActionPingOnly) {
QString msg;
QTextStream(&msg) << "CPU: " << d->m_session.cpuMajor << '.' << d->m_session.cpuMinor << ' '
<< (d->m_session.bigEndian ? "big endian" : "little endian")
......@@ -293,6 +312,7 @@ void Launcher::handleTrkVersion(const TrkResult &result)
<< " float size: " << d->m_session.fpTypeSize
<< " Trk: v" << trkMajor << '.' << trkMinor << " Protocol: " << protocolMajor << '.' << protocolMinor;
qWarning("%s", qPrintable(msg));
emit finished();
}
}
......@@ -358,7 +378,12 @@ void Launcher::closeRemoteFile(bool failed)
void Launcher::handleFileCopied(const TrkResult &result)
{
Q_UNUSED(result)
installAndRun();
if (d->m_startupActions & ActionInstall)
installRemotePackageSilently(d->m_installFileName);
else if (d->m_startupActions & ActionRun)
startInferiorIfNeeded();
else
emit finished();
}
void Launcher::handleCpuType(const TrkResult &result)
......@@ -504,18 +529,14 @@ void Launcher::installRemotePackageSilently(const QString &fileName)
void Launcher::handleInstallPackageFinished(const TrkResult &)
{
if (d->m_fileName.isEmpty())
emit finished();
else
if (d->m_startupActions & ActionRun)
startInferiorIfNeeded();
else
emit finished();
}
void Launcher::startInferiorIfNeeded()
{
if (d->m_fileName.isEmpty()) {
d->m_device.sendTrkMessage(TrkPing, TrkCallback(this, &Launcher::waitForTrkFinished));
return;
}
emit startingApplication();
if (d->m_session.pid != 0) {
logMessage("Process already 'started'");
......
......@@ -44,8 +44,20 @@ class Launcher : public QObject
public:
typedef void (Launcher::*TrkCallBack)(const TrkResult &);
Launcher();
enum Actions {
ActionPingOnly = 0x0,
ActionCopy = 0x1,
ActionInstall = 0x2,
ActionCopyInstall = ActionCopy | ActionInstall,
ActionRun = 0x4,
ActionCopyRun = ActionCopy | ActionRun,
ActionInstallRun = ActionInstall | ActionRun,
ActionCopyInstallRun = ActionCopy | ActionInstall | ActionRun
};
Launcher(trk::Launcher::Actions startupActions = trk::Launcher::ActionPingOnly);
~Launcher();
void addStartupActions(trk::Launcher::Actions startupActions);
void setTrkServerName(const QString &name);
void setFileName(const QString &name);
void setCopyFileName(const QString &srcName, const QString &dstName);
......@@ -93,7 +105,6 @@ private:
void copyFileToRemote();
void installRemotePackageSilently(const QString &filename);
void installAndRun();
void startInferiorIfNeeded();
void logMessage(const QString &msg);
......
......@@ -50,9 +50,11 @@ static bool parseArguments(const QStringList &arguments, trk::Launcher &launcher
break;verbosity++;
case 'i':
install = true;
launcher.addStartupActions(trk::Launcher::ActionInstall);
break;
case 'I':
customInstall = true;
launcher.addStartupActions(trk::Launcher::ActionCopyInstall);
break;
default:
return false;
......@@ -68,23 +70,28 @@ static bool parseArguments(const QStringList &arguments, trk::Launcher &launcher
}
if (remainingArgsCount == 2 && !install && !customInstall) {
// remote exec
launcher.setTrkServerName(arguments.at(a)); // ping
launcher.addStartupActions(trk::Launcher::ActionRun);
launcher.setTrkServerName(arguments.at(a));
launcher.setFileName(arguments.at(a + 1));
return true;
}
if ((remainingArgsCount == 3 || remainingArgsCount == 2) && install && !customInstall) {
launcher.setTrkServerName(arguments.at(a)); // ping
launcher.setInstallFileName(arguments.at(a + 1));
if (remainingArgsCount == 3)
if (remainingArgsCount == 3) {
launcher.addStartupActions(trk::Launcher::ActionRun);
launcher.setFileName(arguments.at(a + 2));
}
return true;
}
if ((remainingArgsCount == 4 || remainingArgsCount == 3) && !install && customInstall) {
launcher.setTrkServerName(arguments.at(a)); // ping
launcher.setCopyFileName(arguments.at(a + 1), arguments.at(a + 2));
launcher.setInstallFileName(arguments.at(a + 2));
if (remainingArgsCount == 4)
if (remainingArgsCount == 4) {
launcher.addStartupActions(trk::Launcher::ActionRun);
launcher.setFileName(arguments.at(a + 3));
}
return true;
}
return false;
......
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