| 364 | } |
| 365 | |
| 366 | void |
| 367 | ProcessInputChannel::initialize() |
| 368 | { |
| 369 | _backgroundOutputPipe = new QLocalSocket(); |
| 370 | QObject::connect( _backgroundOutputPipe, SIGNAL(connected()), this, SLOT(onOutputPipeConnectionMade()) ); |
| 371 | _backgroundOutputPipe->connectToServer(_mainProcessServerName, QLocalSocket::ReadWrite); |
| 372 | std::cout << "Attempting connection to " << _mainProcessServerName.toStdString() << std::endl; |
| 373 | |
| 374 | _backgroundIPCServer = new QLocalServer(); |
| 375 | QObject::connect( _backgroundIPCServer, SIGNAL(newConnection()), this, SLOT(onNewConnectionPending()) ); |
| 376 | QString tmpFileName; |
| 377 | #if defined(Q_OS_WIN) |
| 378 | tmpFileName += QString::fromUtf8("//./pipe"); |
| 379 | tmpFileName += QLatin1Char('/'); |
| 380 | tmpFileName += QString::fromUtf8(NATRON_APPLICATION_NAME); |
| 381 | tmpFileName += QString::fromUtf8("_INPUT_SOCKET"); |
| 382 | #endif |
| 383 | |
| 384 | { |
| 385 | #if defined(Q_OS_UNIX) |
| 386 | QTemporaryFile tmpf(tmpFileName); |
| 387 | tmpf.open(); |
| 388 | tmpFileName = tmpf.fileName(); |
| 389 | tmpf.remove(); |
| 390 | #else |
| 391 | QTemporaryFile tmpf; |
| 392 | tmpf.open(); |
| 393 | QString tmpFilePath = tmpf.fileName(); |
| 394 | QString baseName; |
| 395 | int lastSlash = tmpFilePath.lastIndexOf( QLatin1Char('/') ); |
| 396 | if ( (lastSlash != -1) && (lastSlash < tmpFilePath.size() - 1) ) { |
| 397 | baseName = tmpFilePath.mid(lastSlash + 1); |
| 398 | } else { |
| 399 | baseName = tmpFilePath; |
| 400 | } |
| 401 | tmpFileName += baseName; |
| 402 | tmpf.remove(); |
| 403 | #endif |
| 404 | } |
| 405 | _backgroundIPCServer->listen(tmpFileName); |
| 406 | |
| 407 | if ( !_backgroundOutputPipe->waitForConnected(5000) ) { //< blocking, we wait for the server to respond |
| 408 | std::cout << "WARNING: The GUI application failed to respond, canceling this process will not be possible" |
| 409 | " unless it finishes or you kill it." << std::endl; |
| 410 | } |
| 411 | writeToOutputChannel( QString::fromUtf8(kBgProcessServerCreatedShort) + tmpFileName ); |
| 412 | |
| 413 | ///we wait for the GUI app to connect its socket to this server, we let it 5 sec to reply |
| 414 | _backgroundIPCServer->waitForNewConnection(5000); |
| 415 | |
| 416 | ///since we're still not returning the event loop, just process them manually in case |
| 417 | ///Qt didn't caught the new connection pending. |
| 418 | QCoreApplication::processEvents(); |
| 419 | } // ProcessInputChannel::initialize |
| 420 | |
| 421 | void |
| 422 | ProcessInputChannel::onOutputPipeConnectionMade() |
nothing calls this directly
no test coverage detected