void ProcessHandler::onDataWrittenToSocket() { ///always running in the main thread assert( QThread::currentThread() == qApp->thread() ); QString str = QString::fromUtf8(_bgProcessOutputSocket->readLine()); while ( str.endsWith(QLatin1Char('\n')) ) { str.chop(1); } _processLog.append(QString::fromUtf8("Message received: ") + str + QLatin1Char('\n')); if ( str.startsWith(QString::fromUtf8(kFrameRenderedStringShort) )) { str = str.remove(QString::fromUtf8(kFrameRenderedStringShort)); double progressPercent = 0.; int foundProgress = str.lastIndexOf(QString::fromUtf8(kProgressChangedStringShort)); if (foundProgress != -1) { QString progressStr = str.mid(foundProgress); progressStr.remove(QString::fromUtf8(kProgressChangedStringShort)); progressPercent = progressStr.toDouble(); str = str.mid(0, foundProgress); } if (!str.isEmpty()) { //The report does not have extended timer infos Q_EMIT frameRendered(str.toInt(), progressPercent); } } else if ( str.startsWith(QString::fromUtf8(kRenderingFinishedStringShort)) ) { ///don't do anything } else if ( str.startsWith(QString::fromUtf8(kBgProcessServerCreatedShort)) ) { str = str.remove(QString::fromUtf8(kBgProcessServerCreatedShort)); ///the bg process wants us to create the pipe for its input if (!_bgProcessInputSocket) { _bgProcessInputSocket = new QLocalSocket(); QObject::connect( _bgProcessInputSocket, SIGNAL(connected()), this, SLOT(onInputPipeConnectionMade()) ); _bgProcessInputSocket->connectToServer(str,QLocalSocket::ReadWrite); } } else if ( str.startsWith(QString::fromUtf8(kRenderingStartedShort)) ) { ///if the user pressed cancel prior to the pipe being created, wait for it to be created and send the abort ///message right away if (_earlyCancel) { _bgProcessInputSocket->waitForConnected(5000); _earlyCancel = false; onProcessCanceled(); } } else { _processLog.append(QString::fromUtf8("Error: Unable to interpret message.\n")); throw std::runtime_error("ProcessHandler::onDataWrittenToSocket() received erroneous message"); } }
void ProcessHandler::onDataWrittenToSocket() { ///always running in the main thread assert(QThread::currentThread() == qApp->thread()); QString str = _bgProcessOutputSocket->readLine(); while(str.endsWith('\n')) { str.chop(1); } _processLog.append("Message received: " + str + '\n'); if (str.startsWith(kFrameRenderedStringShort)) { str = str.remove(kFrameRenderedStringShort); emit frameRendered(str.toInt()); } else if (str.startsWith(kRenderingFinishedStringShort)) { ///don't do anything } else if (str.startsWith(kProgressChangedStringShort)) { str = str.remove(kProgressChangedStringShort); emit frameProgress(str.toInt()); } else if (str.startsWith(kBgProcessServerCreatedShort)) { str = str.remove(kBgProcessServerCreatedShort); ///the bg process wants us to create the pipe for its input if (!_bgProcessInputSocket) { _bgProcessInputSocket = new QLocalSocket(); QObject::connect(_bgProcessInputSocket, SIGNAL(connected()), this, SLOT(onInputPipeConnectionMade())); _bgProcessInputSocket->connectToServer(str,QLocalSocket::ReadWrite); } } else if(str.startsWith(kRenderingStartedShort)) { ///if the user pressed cancel prior to the pipe being created, wait for it to be created and send the abort ///message right away if (_earlyCancel) { _bgProcessInputSocket->waitForConnected(5000); _earlyCancel = false; onProcessCanceled(); } } else { _processLog.append("Error: Unable to interpret message.\n"); throw std::runtime_error("ProcessHandler::onDataWrittenToSocket() received erroneous message"); } }