SystemcallPrivate::SystemcallPrivate(const std::string& of) :
process_(new QProcess),
- outIndex_(0),
- errIndex_(0),
- outFile_(of),
- terminalOutExists_(os::is_terminal(os::STDOUT)),
- terminalErrExists_(os::is_terminal(os::STDERR)),
- processEvents_(false)
+ out_index_(0),
+ err_index_(0),
+ out_file_(of),
+ process_events_(false)
{
- if (!outFile_.empty()) {
+ if (!out_file_.empty()) {
// Check whether we have to simply throw away the output.
- if (outFile_ != os::nulldev())
- process_->setStandardOutputFile(toqstr(outFile_));
+ if (out_file_ != os::nulldev())
+ process_->setStandardOutputFile(toqstr(out_file_));
}
connect(process_, SIGNAL(readyReadStandardOutput()), SLOT(stdOut()));
void SystemcallPrivate::processEvents()
{
- if(processEvents_) {
+ if(process_events_) {
QCoreApplication::processEvents(/*QEventLoop::ExcludeUserInputEvents*/);
}
}
if (!process_)
return false;
- process_events = process_events;
+ process_events_ = process_events;
// Block GUI while waiting,
// relay on QProcess' wait functions
- if (!process_events) {
+ if (!process_events_) {
if (waitwhile == Starting)
return process_->waitForStarted(timeout);
if (waitwhile == Running)
SystemcallPrivate::~SystemcallPrivate()
{
- flush();
-
- if (outIndex_) {
- outData_[outIndex_] = '\0';
- outIndex_ = 0;
- if (terminalOutExists_)
- cout << outData_;
+ if (out_index_) {
+ out_data_[out_index_] = '\0';
+ out_index_ = 0;
+ cout << out_data_;
}
cout.flush();
- if (errIndex_) {
- errData_[errIndex_] = '\0';
- errIndex_ = 0;
- if (terminalErrExists_)
- cerr << errData_;
+ if (err_index_) {
+ err_data_[err_index_] = '\0';
+ err_index_ = 0;
+ cerr << err_data_;
}
cerr.flush();
}
-void SystemcallPrivate::flush()
-{
- if (process_) {
- // If the output has been redirected, we write it all at once.
- // Even if we are not running in a terminal, the output could go
- // to some log file, for example ~/.xsession-errors on *nix.
-
- QString data = QString::fromLocal8Bit(process_->readAllStandardOutput().data());
- ProgressInterface::instance()->appendMessage(data);
- if (!terminalOutExists_ && outFile_.empty())
- cout << fromqstr(data);
-
- data = QString::fromLocal8Bit(process_->readAllStandardError().data());
- ProgressInterface::instance()->appendError(data);
- if (!terminalErrExists_)
- cerr << fromqstr(data);
- }
-}
-
-
void SystemcallPrivate::stdOut()
{
if (process_) {
char c;
process_->setReadChannel(QProcess::StandardOutput);
while (process_->getChar(&c)) {
- outData_[outIndex_++] = c;
- if (c == '\n' || outIndex_ + 1 == bufferSize_) {
- outData_[outIndex_] = '\0';
- outIndex_ = 0;
- ProgressInterface::instance()->appendMessage(QString::fromLocal8Bit(outData_));
- if (terminalOutExists_)
- cout << outData_;
+ out_data_[out_index_++] = c;
+ if (c == '\n' || out_index_ + 1 == buffer_size_) {
+ out_data_[out_index_] = '\0';
+ out_index_ = 0;
+ ProgressInterface::instance()->appendMessage(QString::fromLocal8Bit(out_data_));
+ cout << out_data_;
}
}
}
char c;
process_->setReadChannel(QProcess::StandardError);
while (process_->getChar(&c)) {
- errData_[errIndex_++] = c;
- if (c == '\n' || errIndex_ + 1 == bufferSize_) {
- errData_[errIndex_] = '\0';
- errIndex_ = 0;
- ProgressInterface::instance()->appendError(QString::fromLocal8Bit(errData_));
- if (terminalErrExists_)
- cerr << errData_;
+ err_data_[err_index_++] = c;
+ if (c == '\n' || err_index_ + 1 == buffer_size_) {
+ err_data_[err_index_] = '\0';
+ err_index_ = 0;
+ ProgressInterface::instance()->appendError(QString::fromLocal8Bit(err_data_));
+ cerr << err_data_;
}
}
}