示例#1
0
void ScProcess::stopLanguage (void)
{
    if(state() != QProcess::Running) {
        emit statusMessage(tr("Interpreter is not running!"));
        return;
    }

    evaluateCode("0.exit", true);
    closeWriteChannel();
    
    mCompiled = false;
    mTerminationRequested   = true;
    mTerminationRequestTime = QDateTime::currentDateTimeUtc();

    bool finished = waitForFinished(200);
    if ( !finished && (state() != QProcess::NotRunning) ) {
#ifdef Q_OS_WIN32
        kill();
#else
        terminate();
#endif
        bool reallyFinished = waitForFinished(200);
        if (!reallyFinished)
            emit statusMessage(tr("Failed to stop interpreter!"));
    }
    mTerminationRequested = false;
}
示例#2
0
void Udisks2Lister::UnmountDevice(const QString& id) {
  QReadLocker locker(&device_data_lock_);
  if (!device_data_.contains(id)) return;

  OrgFreedesktopUDisks2FilesystemInterface filesystem(
      udisks2_service_, device_data_[id].dbus_path,
      QDBusConnection::systemBus());

  if (filesystem.isValid()) {
    auto unmount_result = filesystem.Unmount(QVariantMap());
    unmount_result.waitForFinished();

    if (unmount_result.isError()) {
      qLog(Warning) << "Failed to unmount " << id << ": "
                    << unmount_result.error();
      return;
    }

    OrgFreedesktopUDisks2DriveInterface drive(udisks2_service_,
                                              device_data_[id].dbus_drive_path,
                                              QDBusConnection::systemBus());

    if (drive.isValid()) {
      auto eject_result = drive.Eject(QVariantMap());
      eject_result.waitForFinished();

      if (eject_result.isError())
        qLog(Warning) << "Failed to eject " << id << ": "
                      << eject_result.error();
    }

    device_data_.remove(id);
    DeviceRemoved(id);
  }
}
示例#3
0
void WavePlayer::stop()
{
    terminate();
    if (!waitForFinished(3000))
    {
        kill();
        waitForFinished(3000);
    }
}
示例#4
0
//TODO: add support of URL
void Translator::translateHtml(QString filePath, QDir &docDir)
{
    QFileInfo fileInfo(filePath);
    auto cmd = new QProcess(this);

    QTemporaryFile tmpDoc("document.html");
    cmd->setWorkingDirectory(QDir(DATALOCATION).absoluteFilePath("apertium-all-dev/bin"));
    QStringList args;
    qApp->processEvents();
    //deshtml
#ifdef Q_OS_WIN
    //windows bug with backslash
    //use replace to fix windows bug
    args << "/u" << "/c" << "type" << "\"" + filePath.replace('/', QDir::separator()) + "\""
         << "|" << "apertium-deshtml";
    cmd->setNativeArguments(args.join(' '));
    cmd->start("cmd.exe");
#endif
    cmd->waitForFinished();
    cmd->waitForReadyRead();
    if (!tmpDoc.open()) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    tmpDoc.setTextModeEnabled(true);
    tmpDoc.write(notLinuxTranslate(cmd->readAllStandardOutput()).toUtf8());
    tmpDoc.close();
    //rehtml
    //FIXME: rehtml or rehtml-noent???
    args.clear();
#ifdef Q_OS_WIN
    args << "/u" << "/c" << "type" << "\"" + tmpDoc.fileName().replace('/', QDir::separator()) + "\""
         << "|" << "apertium-rehtml";
    cmd->setNativeArguments(args.join(' '));
    cmd->start("cmd.exe");
#endif
    cmd->waitForFinished();
    cmd->waitForReadyRead();
    QString trFilePath = docDir.absoluteFilePath(fileInfo.baseName() + "_" +
                                                 parent->getCurrentSourceLang()
                                                 + "-" + parent->getCurrentTargetLang() + "." + fileInfo.suffix());
    QFile newDoc(trFilePath);
    if (!newDoc.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    newDoc.write(cmd->readAllStandardOutput());
    newDoc.close();
    emit fileTranslated(trFilePath);
    cmd->deleteLater();
    //#else
    //    // cmd->start("ar", QStringList() << "x" << "data.tmp");
    //#endif
}
示例#5
0
文件: kprocess.cpp 项目: vasi/kdelibs
int KProcess::execute(int msecs)
{
    start();
    if (!waitForFinished(msecs)) {
        kill();
        waitForFinished(-1);
        return -2;
    }
    return (exitStatus() == QProcess::NormalExit) ? exitCode() : -1;
}
示例#6
0
void CommandProcess::end()
{
    // Exiting MS-DOS
    if(state() == QProcess::Running)
    {
        write(EXIT_COMMAND);
        if(!waitForFinished(EXIT_TIMEOUT)) // Failed to exit properly
            terminate();
    }
    
    if(!waitForFinished(EXIT_TIMEOUT)) // Process is stuck
        kill(); // Force exit
    waitForFinished();
    disconnect();
}
示例#7
0
  void pauseRunManager(openstudio::runmanager::RunManager& rm)
  {
    rm.setPaused(true);

    std::vector<openstudio::runmanager::Job> jobs = rm.getJobs();

    for (auto itr = jobs.begin();
         itr != jobs.end();
         ++itr)
    {
      itr->setCanceled(true);
    }

    for (auto itr = jobs.begin();
         itr != jobs.end();
         ++itr)
    { 
      itr->requestStop();
    }

    for (auto itr = jobs.begin();
         itr != jobs.end();
         ++itr)
    {
      itr->waitForFinished();
    }
  }
示例#8
0
文件: main.cpp 项目: cjp256/qtdbd
int main(int argc, char *argv[])
{
    qInstallMessageHandler(DbdLogging::logOutput);

    QCoreApplication app(argc, argv);
    QCoreApplication::setApplicationName("db-rm");
    QCoreApplication::setApplicationVersion("3.0");

    parseCommandLine(app, &g_cmdLineOptions);

    if (!QDBusConnection::systemBus().isConnected())
    {
        qCritical("failed to connect to dbus");
        exit(1);
    }

    auto dbClient = new ComCitrixXenclientDbInterface("com.citrix.xenclient.db", "/", QDBusConnection::systemBus(), &app);
    auto reply = dbClient->rm(g_cmdLineOptions.key);

    // wait until the dbus reply is ready
    reply.waitForFinished();

    // if it's valid, print it
    if (!reply.isValid())
    {
        qCritical("dbus not responding!");
        exit(1);
    }

    return 0;
}
示例#9
0
bool MyProcess::runSync(SCRef rc, QByteArray* ro, QObject* rcv, SCRef buf) {
	async = false;
	runCmd = rc;
	runOutput = ro;
	receiver = rcv;
	if (runOutput)
		runOutput->clear();

	setupSignals();
	if (!launchMe(runCmd, buf))
		return false;

	QTime t;
	t.start();

	busy = true; // we have to wait here until we exit

	while (busy) {
		waitForFinished(20); // suspend 20ms to let OS reschedule

		if (t.elapsed() > 200) {
			EM_PROCESS_EVENTS;
			t.restart();
		}
	}
	return !isErrorExit;
}
示例#10
0
bool Process::done(text *errors, text *output)
// ----------------------------------------------------------------------------
//    Return true if the process was successful
// ----------------------------------------------------------------------------
{
    bool ok = true;

    // Flush streambuf
    if (pbase())
        if (sync())
            ok = false;
    delete[] pbase();
    setp(NULL, NULL);

    // Close QProcess
    closeWriteChannel();
    if (state() != NotRunning)
        if (!waitForFinished())
            ok = false;

    int rc = exitCode();
    if (rc)
        ok = false;

    if (output)
        *output = +out;
    if (errors)
        *errors = +err;

    return ok;
}
示例#11
0
文件: qmacro.cpp 项目: cxl000/timed
qdbus_pending_reply_wrapper<T>::operator T & () 
{
  waitForFinished() ;
  if(!isValid())
    throw Maemo::Timed::Exception(__PRETTY_FUNCTION__, "invalid io_reply") ;
  return *p ;
}
示例#12
0
文件: Display.cpp 项目: peremen/sddm
    void Display::startAuth(const QString &user, const QString &password, const Session &session) {
        m_passPhrase = password;

        // sanity check
        if (!session.isValid()) {
            qCritical() << "Invalid session" << session.fileName();
            return;
        }
        if (session.xdgSessionType().isEmpty()) {
            qCritical() << "Failed to find XDG session type for session" << session.fileName();
            return;
        }
        if (session.exec().isEmpty()) {
            qCritical() << "Failed to find command for session" << session.fileName();
            return;
        }

        m_reuseSessionId = QString();

        if (Logind::isAvailable() && mainConfig.Users.ReuseSession.get()) {
            OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(), Logind::managerPath(), QDBusConnection::systemBus());
            auto reply = manager.ListSessions();
            reply.waitForFinished();

            foreach(const SessionInfo &s, reply.value()) {
                if (s.userName == user) {
                    OrgFreedesktopLogin1SessionInterface session(Logind::serviceName(), s.sessionPath.path(), QDBusConnection::systemBus());
                    if (session.service() == QLatin1String("sddm")) {
                        m_reuseSessionId =  s.sessionId;
                        break;
                    }
                }
            }
        }
示例#13
0
文件: action.cpp 项目: Mic92/CopyQ
void Action::terminate()
{
    // try to terminate process
    QProcess::terminate();
    // if process still running: kill it
    if ( !waitForFinished(5000) )
        kill();
}
			~VisualizerProcess()
			{
				if(state() == QProcess::Running)
				{
					closeWriteChannel();
					// 1 day. If you're debugging for longer, you have some real issues
					waitForFinished(86400000);
				}
			}
示例#15
0
/*!
    Closes all communication with the process. After calling this
    function, QProcess will no longer emit readyRead(), and data can no
    longer be read or written.
*/
void QProcess::close()
{
    emit aboutToClose();
    while (waitForBytesWritten(-1))
        ;
    kill();
    waitForFinished(-1);
    setOpenMode(QIODevice::NotOpen);
}
示例#16
0
/*!
 * \brief Translates text on not Linux paltforms.
 */
QString Translator::notLinuxTranslate(QString text)
{
    QString name = parent->getCurrentSourceLang() + "-" + parent->getCurrentTargetLang();
    if (name.isEmpty())
        return "";

    QDir dir(QDir(DATALOCATION).absoluteFilePath("usr/share/apertium/modes"));
    if (!dir.exists() || !dir.exists(name + ".mode"))
        return "";

    QFile file(dir.absoluteFilePath(name + ".mode"));
    if (file.open(QIODevice::ReadOnly) == false) {
        return "";
    }
    QString mode = file.readAll();
    file.close();

    mode = mode.trimmed();
    if (mode.isEmpty()) {
        return "";
    }
    mode.replace("$1", "-g");
    mode.remove("$2");
    if (mode.indexOf("'/usr/share") == -1) {
        mode.replace(QRegularExpression("(\\s*)(/usr/share/\\S+)(\\s*)"), "\\1\"\\2\"\\3");
    }
    mode.replace("/usr/share", QDir(DATALOCATION).absolutePath() + "/usr/share");
#ifdef Q_OS_WIN
    // Windows can't handle C:/ paths in ' quotes
    mode.replace("'", "\"");
#define OS_SEP ";"
#else
#define OS_SEP ":"
#endif

    auto env = QProcessEnvironment::systemEnvironment();
    env.insert("PATH", QDir(DATALOCATION).absoluteFilePath("apertium-all-dev/bin") + OS_SEP +
               env.value("PATH"));
    env.insert("LC_ALL", "en_US.UTF-8");

    auto run = new QProcess(this);
    run->setProcessEnvironment(env);
    run->setProcessChannelMode(QProcess::MergedChannels);
#ifdef Q_OS_WIN
    run->setNativeArguments(mode);
    run->start("cmd", QStringList() << "/D" << "/Q" << "/S" << "/C");
#else
    run->start("/bin/sh", QStringList() << "-c" << mode);
#endif
    run->waitForStarted();
    run->write(text.toUtf8() + "  ");
    run->closeWriteChannel();
    run->waitForFinished();
    run->deleteLater();
    return QString::fromUtf8(run->readAll());
}
示例#17
0
EngineProcess::~EngineProcess()
{
	if (m_started)
	{
		qWarning("EngineProcess: Destroyed while process is still running.");
		kill();
		waitForFinished();
	}
	cleanup();
}
示例#18
0
/*!
 * \brief Translating txt files not on Linux.
 *
 * \warning There are some problems with translating of documents
 * on Windows platform. All document translation functions should be rewrited.
 */
void Translator::translateTxt(QString filePath, QDir &docDir)
{
    QFile f(filePath);
    QFileInfo fileInfo(filePath);
    QTemporaryFile tmpDoc(fileInfo.baseName());
    auto cmd = new QProcess(this);
#ifdef Q_OS_WIN
    cmd->setWorkingDirectory(QDir(DATALOCATION).absoluteFilePath("apertium-all-dev/bin"));
#endif
    qApp->processEvents();
    //destxt
    cmd->start("cmd.exe", QStringList() << "/u" << "/c" << "type" << "\"" + filePath.replace('/',
                                                                                             QDir::separator()) + "\""
               << "|" << "apertium-destxt");
    cmd->waitForFinished();
    cmd->waitForReadyRead();
    if (!tmpDoc.open()) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    tmpDoc.setTextModeEnabled(true);
    tmpDoc.write(notLinuxTranslate(cmd->readAllStandardOutput()).toUtf8());
    //retxt
    cmd->start("cmd.exe", QStringList() << "/u" << "/c" << "type" << "\"" +
               tmpDoc.fileName().replace('/', QDir::separator())
               + "\"" << "|" << "apertium-retxt");
    cmd->waitForFinished();
    cmd->waitForReadyRead();
    QString trFilePath = docDir.absoluteFilePath(fileInfo.baseName() + "_" +
                                                 parent->getCurrentSourceLang()
                                                 + "-" + parent->getCurrentTargetLang() + "." + fileInfo.suffix());
    QFile newDoc(trFilePath);
    if (!newDoc.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
        emit fileTranslateRejected();
        cmd->deleteLater();
        return;
    }
    newDoc.write(cmd->readAllStandardOutput());
    newDoc.close();
    emit fileTranslated(trFilePath);
    cmd->deleteLater();
}
示例#19
0
void MyProcess::on_cancel()
{
	canceling = true;

#ifdef Q_OS_WIN32
	kill(); // uses TerminateProcess
#else
	terminate(); // uses SIGTERM signal
#endif
	waitForFinished();
}
示例#20
0
void EngineProcess::close()
{
	if (!m_started)
		return;

	emit aboutToClose();
	kill();
	waitForFinished(-1);
	cleanup();
	QIODevice::close();
}
示例#21
0
void Process::stop(int ms)
{
    if (isStop()) {
        return;
    }
    terminate();
    closeReadChannel(QProcess::StandardOutput);
    closeReadChannel(QProcess::StandardError);
    if (!waitForFinished(ms)) {
        kill();
    }
}
示例#22
0
文件: action.cpp 项目: amosbird/CopyQ
void Action::terminate()
{
    if (m_processes.empty())
        return;

    for (auto p : m_processes)
        p->terminate();

    waitForFinished(5000);
    for (auto p : m_processes)
        terminateProcess(p);
}
示例#23
0
void IBMediaControlC::stop()
{
    bool res =false;
    d->m_current_play_state = MEDIA_RUNNING_STATE_STOP;

    kill();

    res =  waitForFinished(3000);
    if(!res)
    {
        trace((char *)"stop quit error,kill mplayer\n ");
        system("killall mplayer");
    }
    return;
    sendCommand("quit");
   res =  waitForFinished(3000);
   if(!res)
   {
       trace((char *)"stop quit error,kill mplayer\n ");
       system("killall mplayer");
   }
}
示例#24
0
/*!
    Destructs the QProcess object.
*/
QProcess::~QProcess()
{
    Q_D(QProcess);
    if (d->processState != NotRunning) {
        qWarning("QProcess object destroyed while process is still running.");
        kill();
        waitForFinished();
    }
#ifdef Q_OS_UNIX
    // make sure the process manager removes this entry
    d->findExitCode();
#endif
    d->cleanup();
}
示例#25
0
void MPlayerProcess::stop() {
	if (!isRunning()) {
		qWarning() << __FUNCTION__ << "MPlayer not running";
		return;
	}

	sendCommand("quit");

	qDebug() << __FUNCTION__ << "Finishing MPlayer...";
	if (!waitForFinished(5000)) {
		kill();
	}

	qDebug() << __FUNCTION__ << "MPlayer finished";
}
示例#26
0
/**
 * Executes the back-end process.
 * @param	sName		The name of the process (for error messages)
 * @param	slArgs		A list containing the command-line arguments
 * @param	sWorkDir	(Optional) working directory
 * @param	bBlock		(Optional) true to block, false otherwise
 * @return	true if the process was executed successfully, false otherwise
 */
bool Frontend::run(const QString& sName, const QStringList& slArgs,
		   const QString& incDirs, const QString& srcDirs,
		   const QString& sWorkDir, bool bBlock)
{
	// Cannot start if another controlled process is currently running
	if (QProcess::state() == QProcess::Running) {
		m_sError = i18n("Cannot restart while another process is still "
			"running");
		return false;
	}

	// Reset variables
	m_nRecords = 0;
	m_bKilled = false;

	// Setup the command-line arguments
	clearProgram();

	if (m_bUseShell)
		// Execute inside a shell; join all arguments in a single QString
		setShellCommand(slArgs.join(" "));
	else
		// Or setup args directly
		setProgram(slArgs);

	// Set the working directory, if requested
	if (!sWorkDir.isEmpty())
		setWorkingDirectory(sWorkDir);

	// Set environment variables (INCLUDEDIRS & SOURCEDIRS) if required
	if (! incDirs.isEmpty()) {
		setEnv("INCLUDEDIRS", incDirs);
	}
	if (! srcDirs.isEmpty()) {
		setEnv("SOURCEDIRS", srcDirs);
	}

	// Execute the child process
	setOutputChannelMode( KProcess::SeparateChannels );
	start();
	if (! ( bBlock ? waitForFinished( -1 ) : waitForStarted ( -1 ))) {
		m_sError = sName + i18n(": Failed to start process");
		return false;
	}

	m_sError = i18n("No error");
	return true;
}
示例#27
0
QString IpProcess::executeSynchronous(const QString &program, const QStringList &arguments)
{
    QString empty("");
    QString result("");

    printCmdLine(program, arguments);

    if (arguments.count() > 0)
    {
        start(program, arguments);
    }
    else
    {
        start(program);
    }

    if (! waitForStarted())
        return empty;

    closeWriteChannel();

    int secondsToWait = 30;
    if (! waitForFinished(secondsToWait * 1000))
        return empty;

    // exit code of zero means command completed ok
    // and that output is from stdout - error output is on stderrs
    if ( (exitCode() == 0) && (errStr.isEmpty()) )
    {
        result = QString(QString(readAllStandardOutput()));
    }
    else
    {
        result = QString(QString(readAllStandardError()));
    }

    if (result.isEmpty())
    {
        // result = parseErrorCode();
    }

    // Send the result of executing the command
    emit cmdOutput(program, arguments, exitCode(), result);

    return QString(result);
}
示例#28
0
文件: future.cpp 项目: delgor/Core
const QVariant &Nuria::FutureBase::variant () const {
	this->d->mutex.lock ();
	
	// Finished?
	if (this->d->value.isValid ()) {
		this->d->mutex.unlock ();
		return this->d->value;
	}
	
	// 
	this->d->mutex.unlock ();
	
	// Wait
	waitForFinished ();
	
	// 
	return this->d->value;
}
示例#29
0
/**
 * Convert input, returning output.
 * @param inputText         Input text.
 * @param talkerCode        TalkerCode structure for the talker that KTTSD intends to
 *                          use for synthing the text.  Useful for extracting hints about
 *                          how to filter the text.  For example, languageCode.
 * @param appId             The DCOP appId of the application that queued the text.
 *                          Also useful for hints about how to do the filtering.
 */
/*virtual*/ QString XmlTransformerProc::convert(const QString& inputText, TalkerCode* talkerCode,
    const QCString& appId)
{
    // kdDebug() << "XmlTransformerProc::convert: Running." << endl;
    // If not properly configured, do nothing.
    if ( m_xsltFilePath.isEmpty() || m_xsltprocPath.isEmpty() )
    {
        kdDebug() << "XmlTransformerProc::convert: not properly configured" << endl;
        return inputText;
    }
    // Asynchronously convert and wait for completion.
    if (asyncConvert(inputText, talkerCode, appId))
    {
        waitForFinished();
        m_state = fsIdle;
        return m_text;
    } else
        return inputText;
}
示例#30
0
/**
 * Executes a grep process using the given command line arguments.
 * The full path to the grep executable should be set in the "Path" key
 * under the "grep" group.
 * @param	slArgs	Command line arguments for grep
 * @return	true if successful, false otherwise
 */
bool GrepFrontend::run(const QStringList& slArgs)
{
	// qDebug() << "GrepFrontend.run() \n";
	QStringList slCmdLine;

	// Set the command line arguments
	slCmdLine += slArgs;

	setOutputChannelMode(KProcess::MergedChannels);
	
	#if 0
	// Use verbose mode, if supported
	// if (s_nSupArgs & VerboseOut)
		//slCmdLine << "-v";
		
	// Project-specific options
	if (s_nProjArgs & Kernel)
		slCmdLine << "-k";
	if (s_nProjArgs & InvIndex)
		slCmdLine << "-q";
	if (s_nProjArgs & NoCompression)
		slCmdLine << "-c";
	if (s_nProjArgs & s_nSupArgs & SlowPathDef)
		slCmdLine << "-D";
	#endif

	// slCmdLine << "/var/log/Xorg.0.log";
	// slCmdLine << "hi";
		
	qDebug() << "testing! " << slCmdLine << s_sProjPath;
	// Run a new process
	if (!Frontend::run("ls", slCmdLine, s_sProjPath)) {
		emit aborted();
		return false;
	}
	
	waitForFinished();
	
	qDebug() << "done";

	return true;
}