mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
LP-419 removed unused code
This commit is contained in:
parent
47d9219a09
commit
548a881003
@ -1,86 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file abstractprocess.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef ABSTRACTPROCESS_H
|
||||
#define ABSTRACTPROCESS_H
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
namespace Utils {
|
||||
class QTCREATOR_UTILS_EXPORT AbstractProcess {
|
||||
public:
|
||||
AbstractProcess() {}
|
||||
virtual ~AbstractProcess() {}
|
||||
|
||||
QString workingDirectory() const
|
||||
{
|
||||
return m_workingDir;
|
||||
}
|
||||
void setWorkingDirectory(const QString &dir)
|
||||
{
|
||||
m_workingDir = dir;
|
||||
}
|
||||
|
||||
QStringList environment() const
|
||||
{
|
||||
return m_environment;
|
||||
}
|
||||
void setEnvironment(const QStringList &env)
|
||||
{
|
||||
m_environment = env;
|
||||
}
|
||||
|
||||
virtual bool start(const QString &program, const QStringList &args) = 0;
|
||||
virtual void stop() = 0;
|
||||
|
||||
virtual bool isRunning() const = 0;
|
||||
virtual qint64 applicationPID() const = 0;
|
||||
virtual int exitCode() const = 0;
|
||||
|
||||
// signals:
|
||||
virtual void processError(const QString &error) = 0;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
// Add PATH and SystemRoot environment variables in case they are missing
|
||||
static QStringList fixWinEnvironment(const QStringList &env);
|
||||
// Quote a Windows command line correctly for the "CreateProcess" API
|
||||
static QString createWinCommandline(const QString &program, const QStringList &args);
|
||||
// Create a bytearray suitable to be passed on as environment
|
||||
// to the "CreateProcess" API (0-terminated UTF 16 strings).
|
||||
static QByteArray createWinEnvironment(const QStringList &env);
|
||||
#endif
|
||||
|
||||
private:
|
||||
QString m_workingDir;
|
||||
QStringList m_environment;
|
||||
};
|
||||
} // namespace Utils
|
||||
|
||||
#endif // ABSTRACTPROCESS_H
|
@ -1,119 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file abstractprocess_win.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "abstractprocess.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace Utils {
|
||||
QStringList AbstractProcess::fixWinEnvironment(const QStringList &env)
|
||||
{
|
||||
QStringList envStrings = env;
|
||||
|
||||
// add PATH if necessary (for DLL loading)
|
||||
if (envStrings.filter(QRegExp(QLatin1String("^PATH="), Qt::CaseInsensitive)).isEmpty()) {
|
||||
QByteArray path = qgetenv("PATH");
|
||||
if (!path.isEmpty()) {
|
||||
envStrings.prepend(QString(QLatin1String("PATH=%1")).arg(QString::fromLocal8Bit(path)));
|
||||
}
|
||||
}
|
||||
// add systemroot if needed
|
||||
if (envStrings.filter(QRegExp(QLatin1String("^SystemRoot="), Qt::CaseInsensitive)).isEmpty()) {
|
||||
QByteArray systemRoot = qgetenv("SystemRoot");
|
||||
if (!systemRoot.isEmpty()) {
|
||||
envStrings.prepend(QString(QLatin1String("SystemRoot=%1")).arg(QString::fromLocal8Bit(systemRoot)));
|
||||
}
|
||||
}
|
||||
return envStrings;
|
||||
}
|
||||
|
||||
QString AbstractProcess::createWinCommandline(const QString &program, const QStringList &args)
|
||||
{
|
||||
const QChar doubleQuote = QLatin1Char('"');
|
||||
const QChar blank = QLatin1Char(' ');
|
||||
const QChar backSlash = QLatin1Char('\\');
|
||||
|
||||
QString programName = program;
|
||||
|
||||
if (!programName.startsWith(doubleQuote) && !programName.endsWith(doubleQuote) && programName.contains(blank)) {
|
||||
programName.insert(0, doubleQuote);
|
||||
programName.append(doubleQuote);
|
||||
}
|
||||
// add the prgram as the first arrg ... it works better
|
||||
programName.replace(QLatin1Char('/'), backSlash);
|
||||
QString cmdLine = programName;
|
||||
if (args.empty()) {
|
||||
return cmdLine;
|
||||
}
|
||||
|
||||
cmdLine += blank;
|
||||
for (int i = 0; i < args.size(); ++i) {
|
||||
QString tmp = args.at(i);
|
||||
// in the case of \" already being in the string the \ must also be escaped
|
||||
tmp.replace(QLatin1String("\\\""), QLatin1String("\\\\\""));
|
||||
// escape a single " because the arguments will be parsed
|
||||
tmp.replace(QString(doubleQuote), QLatin1String("\\\""));
|
||||
if (tmp.isEmpty() || tmp.contains(blank) || tmp.contains('\t')) {
|
||||
// The argument must not end with a \ since this would be interpreted
|
||||
// as escaping the quote -- rather put the \ behind the quote: e.g.
|
||||
// rather use "foo"\ than "foo\"
|
||||
QString endQuote(doubleQuote);
|
||||
int i = tmp.length();
|
||||
while (i > 0 && tmp.at(i - 1) == backSlash) {
|
||||
--i;
|
||||
endQuote += backSlash;
|
||||
}
|
||||
cmdLine += QLatin1String(" \"");
|
||||
cmdLine += tmp.left(i);
|
||||
cmdLine += endQuote;
|
||||
} else {
|
||||
cmdLine += blank;
|
||||
cmdLine += tmp;
|
||||
}
|
||||
}
|
||||
return cmdLine;
|
||||
}
|
||||
|
||||
QByteArray AbstractProcess::createWinEnvironment(const QStringList &env)
|
||||
{
|
||||
QByteArray envlist;
|
||||
int pos = 0;
|
||||
|
||||
foreach(const QString &tmp, env) {
|
||||
const uint tmpSize = sizeof(TCHAR) * (tmp.length() + 1);
|
||||
|
||||
envlist.resize(envlist.size() + tmpSize);
|
||||
memcpy(envlist.data() + pos, tmp.utf16(), tmpSize);
|
||||
pos += tmpSize;
|
||||
}
|
||||
envlist.resize(envlist.size() + 2);
|
||||
envlist[pos++] = 0;
|
||||
envlist[pos++] = 0;
|
||||
return envlist;
|
||||
}
|
||||
} // namespace Utils
|
@ -1,83 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file consoleprocess.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "consoleprocess.h"
|
||||
|
||||
namespace Utils {
|
||||
QString ConsoleProcess::modeOption(Mode m)
|
||||
{
|
||||
switch (m) {
|
||||
case Debug:
|
||||
return QLatin1String("debug");
|
||||
|
||||
case Suspend:
|
||||
return QLatin1String("suspend");
|
||||
|
||||
case Run:
|
||||
break;
|
||||
}
|
||||
return QLatin1String("run");
|
||||
}
|
||||
|
||||
QString ConsoleProcess::msgCommChannelFailed(const QString &error)
|
||||
{
|
||||
return tr("Cannot set up communication channel: %1").arg(error);
|
||||
}
|
||||
|
||||
QString ConsoleProcess::msgPromptToClose()
|
||||
{
|
||||
// ! Showed in a terminal which might have
|
||||
// ! a different character set on Windows.
|
||||
return tr("Press <RETURN> to close this window...");
|
||||
}
|
||||
|
||||
QString ConsoleProcess::msgCannotCreateTempFile(const QString &why)
|
||||
{
|
||||
return tr("Cannot create temporary file: %1").arg(why);
|
||||
}
|
||||
|
||||
QString ConsoleProcess::msgCannotCreateTempDir(const QString & dir, const QString &why)
|
||||
{
|
||||
return tr("Cannot create temporary directory '%1': %2").arg(dir, why);
|
||||
}
|
||||
|
||||
QString ConsoleProcess::msgUnexpectedOutput()
|
||||
{
|
||||
return tr("Unexpected output from helper program.");
|
||||
}
|
||||
|
||||
QString ConsoleProcess::msgCannotChangeToWorkDir(const QString & dir, const QString &why)
|
||||
{
|
||||
return tr("Cannot change to working directory '%1': %2").arg(dir, why);
|
||||
}
|
||||
|
||||
QString ConsoleProcess::msgCannotExecute(const QString & p, const QString &why)
|
||||
{
|
||||
return tr("Cannot execute '%1': %2").arg(p, why);
|
||||
}
|
||||
}
|
@ -1,149 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file consoleprocess.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef CONSOLEPROCESS_H
|
||||
#define CONSOLEPROCESS_H
|
||||
|
||||
#include "abstractprocess.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QProcess>
|
||||
|
||||
#include <QtNetwork/QLocalServer>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QWinEventNotifier;
|
||||
QT_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QSettings;
|
||||
class QTemporaryFile;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
class QTCREATOR_UTILS_EXPORT ConsoleProcess : public QObject, public AbstractProcess {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Mode { Run, Debug, Suspend };
|
||||
ConsoleProcess(QObject *parent = 0);
|
||||
~ConsoleProcess();
|
||||
|
||||
bool start(const QString &program, const QStringList &args);
|
||||
void stop();
|
||||
|
||||
void setMode(Mode m)
|
||||
{
|
||||
m_mode = m;
|
||||
}
|
||||
Mode mode() const
|
||||
{
|
||||
return m_mode;
|
||||
}
|
||||
|
||||
bool isRunning() const; // This reflects the state of the console+stub
|
||||
qint64 applicationPID() const
|
||||
{
|
||||
return m_appPid;
|
||||
}
|
||||
int exitCode() const
|
||||
{
|
||||
return m_appCode;
|
||||
} // This will be the signal number if exitStatus == CrashExit
|
||||
QProcess::ExitStatus exitStatus() const
|
||||
{
|
||||
return m_appStatus;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
static QString defaultTerminalEmulator();
|
||||
static QString terminalEmulator(const QSettings &settings);
|
||||
static void setTerminalEmulator(QSettings &settings, const QString &term);
|
||||
#endif
|
||||
|
||||
signals:
|
||||
void processError(const QString &error);
|
||||
// These reflect the state of the actual client process
|
||||
void processStarted();
|
||||
void processStopped();
|
||||
|
||||
// These reflect the state of the console+stub
|
||||
void wrapperStarted();
|
||||
void wrapperStopped();
|
||||
|
||||
private slots:
|
||||
void stubConnectionAvailable();
|
||||
void readStubOutput();
|
||||
void stubExited();
|
||||
#ifdef Q_OS_WIN
|
||||
void inferiorExited();
|
||||
#endif
|
||||
|
||||
private:
|
||||
static QString modeOption(Mode m);
|
||||
static QString msgCommChannelFailed(const QString &error);
|
||||
static QString msgPromptToClose();
|
||||
static QString msgCannotCreateTempFile(const QString &why);
|
||||
static QString msgCannotCreateTempDir(const QString & dir, const QString &why);
|
||||
static QString msgUnexpectedOutput();
|
||||
static QString msgCannotChangeToWorkDir(const QString & dir, const QString &why);
|
||||
static QString msgCannotExecute(const QString & p, const QString &why);
|
||||
|
||||
QString stubServerListen();
|
||||
void stubServerShutdown();
|
||||
#ifdef Q_OS_WIN
|
||||
void cleanupStub();
|
||||
void cleanupInferior();
|
||||
#endif
|
||||
|
||||
Mode m_mode;
|
||||
qint64 m_appPid;
|
||||
int m_appCode;
|
||||
QString m_executable;
|
||||
QProcess::ExitStatus m_appStatus;
|
||||
QLocalServer m_stubServer;
|
||||
QLocalSocket *m_stubSocket;
|
||||
QTemporaryFile *m_tempFile;
|
||||
#ifdef Q_OS_WIN
|
||||
PROCESS_INFORMATION *m_pid;
|
||||
HANDLE m_hInferior;
|
||||
QWinEventNotifier *inferiorFinishedNotifier;
|
||||
QWinEventNotifier *processFinishedNotifier;
|
||||
#else
|
||||
QProcess m_process;
|
||||
QByteArray m_stubServerDir;
|
||||
#endif
|
||||
};
|
||||
} // namespace Utils
|
||||
|
||||
#endif // ifndef CONSOLEPROCESS_H
|
@ -1,270 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file consoleprocess_unix.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "consoleprocess.h"
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtCore/QTemporaryFile>
|
||||
|
||||
#include <QtNetwork/QLocalSocket>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
ConsoleProcess::ConsoleProcess(QObject *parent) :
|
||||
QObject(parent),
|
||||
m_mode(Run),
|
||||
m_appPid(0),
|
||||
m_stubSocket(0),
|
||||
m_settings(0)
|
||||
{
|
||||
connect(&m_stubServer, SIGNAL(newConnection()), SLOT(stubConnectionAvailable()));
|
||||
|
||||
m_process.setProcessChannelMode(QProcess::ForwardedChannels);
|
||||
connect(&m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
|
||||
SLOT(stubExited()));
|
||||
}
|
||||
|
||||
ConsoleProcess::~ConsoleProcess()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
bool ConsoleProcess::start(const QString &program, const QStringList &args)
|
||||
{
|
||||
if (isRunning()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString err = stubServerListen();
|
||||
if (!err.isEmpty()) {
|
||||
emit processError(msgCommChannelFailed(err));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!environment().isEmpty()) {
|
||||
m_tempFile = new QTemporaryFile();
|
||||
if (!m_tempFile->open()) {
|
||||
stubServerShutdown();
|
||||
emit processError(msgCannotCreateTempFile(m_tempFile->errorString()));
|
||||
delete m_tempFile;
|
||||
m_tempFile = 0;
|
||||
return false;
|
||||
}
|
||||
foreach(const QString &var, environment()) {
|
||||
m_tempFile->write(var.toLocal8Bit());
|
||||
m_tempFile->write("", 1);
|
||||
}
|
||||
m_tempFile->flush();
|
||||
}
|
||||
|
||||
QStringList xtermArgs = terminalEmulator(m_settings).split(QLatin1Char(' ')); // FIXME: quoting
|
||||
xtermArgs
|
||||
#ifdef Q_OS_MAC
|
||||
<< (QCoreApplication::applicationDirPath() + QLatin1String("/../Resources/qtcreator_process_stub"))
|
||||
#else
|
||||
<< (QCoreApplication::applicationDirPath() + QLatin1String("/qtcreator_process_stub"))
|
||||
#endif
|
||||
<< modeOption(m_mode)
|
||||
<< m_stubServer.fullServerName()
|
||||
<< msgPromptToClose()
|
||||
<< workingDirectory()
|
||||
<< (m_tempFile ? m_tempFile->fileName() : 0)
|
||||
<< program << args;
|
||||
|
||||
QString xterm = xtermArgs.takeFirst();
|
||||
m_process.start(xterm, xtermArgs);
|
||||
if (!m_process.waitForStarted()) {
|
||||
stubServerShutdown();
|
||||
emit processError(tr("Cannot start the terminal emulator '%1'.").arg(xterm));
|
||||
delete m_tempFile;
|
||||
m_tempFile = 0;
|
||||
return false;
|
||||
}
|
||||
m_executable = program;
|
||||
emit wrapperStarted();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConsoleProcess::stop()
|
||||
{
|
||||
if (!isRunning()) {
|
||||
return;
|
||||
}
|
||||
stubServerShutdown();
|
||||
m_appPid = 0;
|
||||
m_process.terminate();
|
||||
if (!m_process.waitForFinished(1000)) {
|
||||
m_process.kill();
|
||||
}
|
||||
m_process.waitForFinished();
|
||||
}
|
||||
|
||||
bool ConsoleProcess::isRunning() const
|
||||
{
|
||||
return m_process.state() != QProcess::NotRunning;
|
||||
}
|
||||
|
||||
QString ConsoleProcess::stubServerListen()
|
||||
{
|
||||
// We need to put the socket in a private directory, as some systems simply do not
|
||||
// check the file permissions of sockets.
|
||||
QString stubFifoDir;
|
||||
|
||||
forever {
|
||||
{
|
||||
QTemporaryFile tf;
|
||||
if (!tf.open()) {
|
||||
return msgCannotCreateTempFile(tf.errorString());
|
||||
}
|
||||
stubFifoDir = QFile::encodeName(tf.fileName());
|
||||
}
|
||||
// By now the temp file was deleted again
|
||||
m_stubServerDir = QFile::encodeName(stubFifoDir);
|
||||
if (!::mkdir(m_stubServerDir.constData(), 0700)) {
|
||||
break;
|
||||
}
|
||||
if (errno != EEXIST) {
|
||||
return msgCannotCreateTempDir(stubFifoDir, QString::fromLocal8Bit(strerror(errno)));
|
||||
}
|
||||
}
|
||||
const QString stubServer = stubFifoDir + "/stub-socket";
|
||||
if (!m_stubServer.listen(stubServer)) {
|
||||
::rmdir(m_stubServerDir.constData());
|
||||
return tr("Cannot create socket '%1': %2").arg(stubServer, m_stubServer.errorString());
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void ConsoleProcess::stubServerShutdown()
|
||||
{
|
||||
delete m_stubSocket;
|
||||
m_stubSocket = 0;
|
||||
if (m_stubServer.isListening()) {
|
||||
m_stubServer.close();
|
||||
::rmdir(m_stubServerDir.constData());
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleProcess::stubConnectionAvailable()
|
||||
{
|
||||
m_stubSocket = m_stubServer.nextPendingConnection();
|
||||
connect(m_stubSocket, SIGNAL(readyRead()), SLOT(readStubOutput()));
|
||||
}
|
||||
|
||||
static QString errorMsg(int code)
|
||||
{
|
||||
return QString::fromLocal8Bit(strerror(code));
|
||||
}
|
||||
|
||||
void ConsoleProcess::readStubOutput()
|
||||
{
|
||||
while (m_stubSocket->canReadLine()) {
|
||||
QByteArray out = m_stubSocket->readLine();
|
||||
out.chop(1); // \n
|
||||
if (out.startsWith("err:chdir ")) {
|
||||
emit processError(msgCannotChangeToWorkDir(workingDirectory(), errorMsg(out.mid(10).toInt())));
|
||||
} else if (out.startsWith("err:exec ")) {
|
||||
emit processError(msgCannotExecute(m_executable, errorMsg(out.mid(9).toInt())));
|
||||
} else if (out.startsWith("pid ")) {
|
||||
// Will not need it any more
|
||||
delete m_tempFile;
|
||||
m_tempFile = 0;
|
||||
|
||||
m_appPid = out.mid(4).toInt();
|
||||
emit processStarted();
|
||||
} else if (out.startsWith("exit ")) {
|
||||
m_appStatus = QProcess::NormalExit;
|
||||
m_appCode = out.mid(5).toInt();
|
||||
m_appPid = 0;
|
||||
emit processStopped();
|
||||
} else if (out.startsWith("crash ")) {
|
||||
m_appStatus = QProcess::CrashExit;
|
||||
m_appCode = out.mid(6).toInt();
|
||||
m_appPid = 0;
|
||||
emit processStopped();
|
||||
} else {
|
||||
emit processError(msgUnexpectedOutput());
|
||||
m_process.terminate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleProcess::stubExited()
|
||||
{
|
||||
// The stub exit might get noticed before we read the error status.
|
||||
if (m_stubSocket && m_stubSocket->state() == QLocalSocket::ConnectedState) {
|
||||
m_stubSocket->waitForDisconnected();
|
||||
}
|
||||
stubServerShutdown();
|
||||
delete m_tempFile;
|
||||
m_tempFile = 0;
|
||||
if (m_appPid) {
|
||||
m_appStatus = QProcess::CrashExit;
|
||||
m_appCode = -1;
|
||||
m_appPid = 0;
|
||||
emit processStopped(); // Maybe it actually did not, but keep state consistent
|
||||
}
|
||||
emit wrapperStopped();
|
||||
}
|
||||
|
||||
QString ConsoleProcess::defaultTerminalEmulator()
|
||||
{
|
||||
// FIXME: enable this once runInTerminal works nicely
|
||||
#if 0 // def Q_OS_MAC
|
||||
return QDir::cleanPath(QCoreApplication::applicationDirPath()
|
||||
+ QLatin1String("/../Resources/runInTerminal.command"));
|
||||
|
||||
#else
|
||||
return QLatin1String("xterm");
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
QString ConsoleProcess::terminalEmulator(const QSettings &settings)
|
||||
{
|
||||
const QString dflt = defaultTerminalEmulator() + QLatin1String(" -e");
|
||||
|
||||
if (!settings) {
|
||||
return dflt;
|
||||
}
|
||||
return settings.value(QLatin1String("General/TerminalEmulator"), dflt).toString();
|
||||
}
|
||||
|
||||
void ConsoleProcess::setTerminalEmulator(QSettings &settings, const QString &term)
|
||||
{
|
||||
return settings.setValue(QLatin1String("General/TerminalEmulator"), term);
|
||||
}
|
@ -1,265 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file consoleprocess_win.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "consoleprocess.h"
|
||||
#include "winutils.h"
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QTemporaryFile>
|
||||
#include <QtCore/QAbstractEventDispatcher>
|
||||
#include "qwineventnotifier_p.h"
|
||||
|
||||
#include <QtNetwork/QLocalSocket>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
ConsoleProcess::ConsoleProcess(QObject *parent) :
|
||||
QObject(parent),
|
||||
m_mode(Run),
|
||||
m_appPid(0),
|
||||
m_stubSocket(0),
|
||||
m_tempFile(0),
|
||||
m_pid(0),
|
||||
m_hInferior(NULL),
|
||||
inferiorFinishedNotifier(0),
|
||||
processFinishedNotifier(0)
|
||||
{
|
||||
connect(&m_stubServer, SIGNAL(newConnection()), SLOT(stubConnectionAvailable()));
|
||||
}
|
||||
|
||||
ConsoleProcess::~ConsoleProcess()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
bool ConsoleProcess::start(const QString &program, const QStringList &args)
|
||||
{
|
||||
if (isRunning()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString err = stubServerListen();
|
||||
if (!err.isEmpty()) {
|
||||
emit processError(msgCommChannelFailed(err));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!environment().isEmpty()) {
|
||||
m_tempFile = new QTemporaryFile();
|
||||
if (!m_tempFile->open()) {
|
||||
stubServerShutdown();
|
||||
emit processError(msgCannotCreateTempFile(m_tempFile->errorString()));
|
||||
delete m_tempFile;
|
||||
m_tempFile = 0;
|
||||
return false;
|
||||
}
|
||||
QTextStream out(m_tempFile);
|
||||
out.setCodec("UTF-16LE");
|
||||
out.setGenerateByteOrderMark(false);
|
||||
foreach(const QString &var, fixWinEnvironment(environment()))
|
||||
out << var << QChar(0);
|
||||
out << QChar(0);
|
||||
}
|
||||
|
||||
STARTUPINFO si;
|
||||
ZeroMemory(&si, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
|
||||
m_pid = new PROCESS_INFORMATION;
|
||||
ZeroMemory(m_pid, sizeof(PROCESS_INFORMATION));
|
||||
|
||||
QString workDir = QDir::toNativeSeparators(workingDirectory());
|
||||
if (!workDir.isEmpty() && !workDir.endsWith('\\')) {
|
||||
workDir.append('\\');
|
||||
}
|
||||
|
||||
QStringList stubArgs;
|
||||
stubArgs << modeOption(m_mode)
|
||||
<< m_stubServer.fullServerName()
|
||||
<< workDir
|
||||
<< (m_tempFile ? m_tempFile->fileName() : 0)
|
||||
<< createWinCommandline(program, args)
|
||||
<< msgPromptToClose();
|
||||
|
||||
const QString cmdLine = createWinCommandline(
|
||||
QCoreApplication::applicationDirPath() + QLatin1String("/qtcreator_process_stub.exe"), stubArgs);
|
||||
|
||||
bool success = CreateProcessW(0, (WCHAR *)cmdLine.utf16(),
|
||||
0, 0, FALSE, CREATE_NEW_CONSOLE,
|
||||
0, 0,
|
||||
&si, m_pid);
|
||||
|
||||
if (!success) {
|
||||
delete m_pid;
|
||||
m_pid = 0;
|
||||
delete m_tempFile;
|
||||
m_tempFile = 0;
|
||||
stubServerShutdown();
|
||||
emit processError(tr("The process '%1' could not be started: %2").arg(cmdLine, winErrorMessage(GetLastError())));
|
||||
return false;
|
||||
}
|
||||
|
||||
processFinishedNotifier = new QWinEventNotifier(m_pid->hProcess, this);
|
||||
connect(processFinishedNotifier, SIGNAL(activated(HANDLE)), SLOT(stubExited()));
|
||||
emit wrapperStarted();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConsoleProcess::stop()
|
||||
{
|
||||
if (m_hInferior != NULL) {
|
||||
TerminateProcess(m_hInferior, (unsigned)-1);
|
||||
cleanupInferior();
|
||||
}
|
||||
if (m_pid) {
|
||||
TerminateProcess(m_pid->hProcess, (unsigned)-1);
|
||||
WaitForSingleObject(m_pid->hProcess, INFINITE);
|
||||
cleanupStub();
|
||||
}
|
||||
}
|
||||
|
||||
bool ConsoleProcess::isRunning() const
|
||||
{
|
||||
return m_pid != 0;
|
||||
}
|
||||
|
||||
QString ConsoleProcess::stubServerListen()
|
||||
{
|
||||
if (m_stubServer.listen(QString::fromLatin1("creator-%1-%2")
|
||||
.arg(QCoreApplication::applicationPid())
|
||||
.arg(rand()))) {
|
||||
return QString();
|
||||
}
|
||||
return m_stubServer.errorString();
|
||||
}
|
||||
|
||||
void ConsoleProcess::stubServerShutdown()
|
||||
{
|
||||
delete m_stubSocket;
|
||||
m_stubSocket = 0;
|
||||
if (m_stubServer.isListening()) {
|
||||
m_stubServer.close();
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleProcess::stubConnectionAvailable()
|
||||
{
|
||||
m_stubSocket = m_stubServer.nextPendingConnection();
|
||||
connect(m_stubSocket, SIGNAL(readyRead()), SLOT(readStubOutput()));
|
||||
}
|
||||
|
||||
void ConsoleProcess::readStubOutput()
|
||||
{
|
||||
while (m_stubSocket->canReadLine()) {
|
||||
QByteArray out = m_stubSocket->readLine();
|
||||
out.chop(2); // \r\n
|
||||
if (out.startsWith("err:chdir ")) {
|
||||
emit processError(msgCannotChangeToWorkDir(workingDirectory(), winErrorMessage(out.mid(10).toInt())));
|
||||
} else if (out.startsWith("err:exec ")) {
|
||||
emit processError(msgCannotExecute(m_executable, winErrorMessage(out.mid(9).toInt())));
|
||||
} else if (out.startsWith("pid ")) {
|
||||
// Wil not need it any more
|
||||
delete m_tempFile;
|
||||
m_tempFile = 0;
|
||||
|
||||
m_appPid = out.mid(4).toInt();
|
||||
m_hInferior = OpenProcess(
|
||||
SYNCHRONIZE | PROCESS_QUERY_INFORMATION | PROCESS_TERMINATE,
|
||||
FALSE, m_appPid);
|
||||
if (m_hInferior == NULL) {
|
||||
emit processError(tr("Cannot obtain a handle to the inferior: %1")
|
||||
.arg(winErrorMessage(GetLastError())));
|
||||
// Uhm, and now what?
|
||||
continue;
|
||||
}
|
||||
inferiorFinishedNotifier = new QWinEventNotifier(m_hInferior, this);
|
||||
connect(inferiorFinishedNotifier, SIGNAL(activated(HANDLE)), SLOT(inferiorExited()));
|
||||
emit processStarted();
|
||||
} else {
|
||||
emit processError(msgUnexpectedOutput());
|
||||
TerminateProcess(m_pid->hProcess, (unsigned)-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleProcess::cleanupInferior()
|
||||
{
|
||||
delete inferiorFinishedNotifier;
|
||||
inferiorFinishedNotifier = 0;
|
||||
CloseHandle(m_hInferior);
|
||||
m_hInferior = NULL;
|
||||
m_appPid = 0;
|
||||
}
|
||||
|
||||
void ConsoleProcess::inferiorExited()
|
||||
{
|
||||
DWORD chldStatus;
|
||||
|
||||
if (!GetExitCodeProcess(m_hInferior, &chldStatus)) {
|
||||
emit processError(tr("Cannot obtain exit status from inferior: %1")
|
||||
.arg(winErrorMessage(GetLastError())));
|
||||
}
|
||||
cleanupInferior();
|
||||
m_appStatus = QProcess::NormalExit;
|
||||
m_appCode = chldStatus;
|
||||
emit processStopped();
|
||||
}
|
||||
|
||||
void ConsoleProcess::cleanupStub()
|
||||
{
|
||||
stubServerShutdown();
|
||||
delete processFinishedNotifier;
|
||||
processFinishedNotifier = 0;
|
||||
CloseHandle(m_pid->hThread);
|
||||
CloseHandle(m_pid->hProcess);
|
||||
delete m_pid;
|
||||
m_pid = 0;
|
||||
delete m_tempFile;
|
||||
m_tempFile = 0;
|
||||
}
|
||||
|
||||
void ConsoleProcess::stubExited()
|
||||
{
|
||||
// The stub exit might get noticed before we read the pid for the kill.
|
||||
if (m_stubSocket && m_stubSocket->state() == QLocalSocket::ConnectedState) {
|
||||
m_stubSocket->waitForDisconnected();
|
||||
}
|
||||
cleanupStub();
|
||||
if (m_hInferior != NULL) {
|
||||
TerminateProcess(m_hInferior, (unsigned)-1);
|
||||
cleanupInferior();
|
||||
m_appStatus = QProcess::CrashExit;
|
||||
m_appCode = -1;
|
||||
emit processStopped();
|
||||
}
|
||||
emit wrapperStopped();
|
||||
}
|
@ -18,7 +18,6 @@ SOURCES += \
|
||||
linecolumnlabel.cpp \
|
||||
qtcolorbutton.cpp \
|
||||
synchronousprocess.cpp \
|
||||
consoleprocess.cpp \
|
||||
treewidgetcolumnstretcher.cpp \
|
||||
checkablemessagebox.cpp \
|
||||
styledbar.cpp \
|
||||
@ -40,18 +39,8 @@ SOURCES += \
|
||||
logfile.cpp \
|
||||
crc.cpp \
|
||||
mustache.cpp \
|
||||
textbubbleslider.cpp
|
||||
|
||||
SOURCES += xmlconfig.cpp
|
||||
|
||||
win32 {
|
||||
SOURCES += \
|
||||
abstractprocess_win.cpp \
|
||||
consoleprocess_win.cpp \
|
||||
winutils.cpp
|
||||
HEADERS += winutils.h
|
||||
}
|
||||
else:SOURCES += consoleprocess_unix.cpp
|
||||
textbubbleslider.cpp \
|
||||
xmlconfig.cpp
|
||||
|
||||
HEADERS += \
|
||||
utils_global.h \
|
||||
@ -87,9 +76,8 @@ HEADERS += \
|
||||
crc.h \
|
||||
mustache.h \
|
||||
textbubbleslider.h \
|
||||
filelogger.h
|
||||
|
||||
HEADERS += xmlconfig.h
|
||||
filelogger.h \
|
||||
xmlconfig.h
|
||||
|
||||
FORMS += \
|
||||
checkablemessagebox.ui
|
||||
|
@ -1,52 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file winutils.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "winutils.h"
|
||||
#include <windows.h>
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
||||
namespace Utils {
|
||||
QTCREATOR_UTILS_EXPORT QString winErrorMessage(unsigned long error)
|
||||
{
|
||||
QString rc = QString::fromLatin1("#%1: ").arg(error);
|
||||
ushort *lpMsgBuf;
|
||||
|
||||
const int len = FormatMessage(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, error, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
|
||||
|
||||
if (len) {
|
||||
rc = QString::fromUtf16(lpMsgBuf, len);
|
||||
LocalFree(lpMsgBuf);
|
||||
} else {
|
||||
rc += QString::fromLatin1("<unknown error>");
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
} // namespace Utils
|
@ -1,43 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file winutils.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef WINUTILS_H
|
||||
#define WINUTILS_H
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QString;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
// Helper to format a Windows error message, taking the
|
||||
// code as returned by the GetLastError()-API.
|
||||
QTCREATOR_UTILS_EXPORT QString winErrorMessage(unsigned long error);
|
||||
} // namespace Utils
|
||||
#endif // WINUTILS_H
|
@ -33,7 +33,6 @@
|
||||
|
||||
#include <utils/stylehelper.h>
|
||||
#include <utils/qtcolorbutton.h>
|
||||
#include <utils/consoleprocess.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QMessageBox>
|
||||
|
@ -43,7 +43,6 @@
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/consoleprocess.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
Loading…
x
Reference in New Issue
Block a user