| 151 | } |
| 152 | |
| 153 | void |
| 154 | ProcessHandler::onDataWrittenToSocket() |
| 155 | { |
| 156 | ///always running in the main thread |
| 157 | assert( QThread::currentThread() == qApp->thread() ); |
| 158 | |
| 159 | QString str = QString::fromUtf8( _bgProcessOutputSocket->readLine() ); |
| 160 | while ( str.endsWith( QLatin1Char('\n') ) ) { |
| 161 | str.chop(1); |
| 162 | } |
| 163 | _processLog.append( QString::fromUtf8("Message received: ") + str + QLatin1Char('\n') ); |
| 164 | if ( str.startsWith( QString::fromUtf8(kFrameRenderedStringShort) ) ) { |
| 165 | str = str.remove( QString::fromUtf8(kFrameRenderedStringShort) ); |
| 166 | |
| 167 | double progressPercent = 0.; |
| 168 | int foundProgress = str.lastIndexOf( QString::fromUtf8(kProgressChangedStringShort) ); |
| 169 | if (foundProgress != -1) { |
| 170 | QString progressStr = str.mid(foundProgress); |
| 171 | progressStr.remove( QString::fromUtf8(kProgressChangedStringShort) ); |
| 172 | progressPercent = progressStr.toDouble(); |
| 173 | str = str.mid(0, foundProgress); |
| 174 | } |
| 175 | if ( !str.isEmpty() ) { |
| 176 | //The report does not have extended timer infos |
| 177 | Q_EMIT frameRendered(str.toInt(), progressPercent); |
| 178 | } |
| 179 | } else if ( str.startsWith( QString::fromUtf8(kRenderingFinishedStringShort) ) ) { |
| 180 | ///don't do anything |
| 181 | } else if ( str.startsWith( QString::fromUtf8(kBgProcessServerCreatedShort) ) ) { |
| 182 | str = str.remove( QString::fromUtf8(kBgProcessServerCreatedShort) ); |
| 183 | ///the bg process wants us to create the pipe for its input |
| 184 | if (!_bgProcessInputSocket) { |
| 185 | _bgProcessInputSocket = new QLocalSocket(); |
| 186 | QObject::connect( _bgProcessInputSocket, SIGNAL(connected()), this, SLOT(onInputPipeConnectionMade()) ); |
| 187 | _bgProcessInputSocket->connectToServer(str, QLocalSocket::ReadWrite); |
| 188 | } |
| 189 | } else if ( str.startsWith( QString::fromUtf8(kRenderingStartedShort) ) ) { |
| 190 | ///if the user pressed cancel prior to the pipe being created, wait for it to be created and send the abort |
| 191 | ///message right away |
| 192 | if (_earlyCancel) { |
| 193 | _bgProcessInputSocket->waitForConnected(5000); |
| 194 | _earlyCancel = false; |
| 195 | onProcessCanceled(); |
| 196 | } |
| 197 | } else { |
| 198 | _processLog.append( QString::fromUtf8("Error: Unable to interpret message.\n") ); |
| 199 | throw std::runtime_error("ProcessHandler::onDataWrittenToSocket() received erroneous message"); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | void |
| 204 | ProcessHandler::onInputPipeConnectionMade() |