void ProcessInputChannel::initialize() { _backgroundOutputPipe = new QLocalSocket(); QObject::connect(_backgroundOutputPipe, SIGNAL(connected()), this, SLOT(onOutputPipeConnectionMade())); _backgroundOutputPipe->connectToServer(_mainProcessServerName,QLocalSocket::ReadWrite); _backgroundIPCServer = new QLocalServer(); QObject::connect(_backgroundIPCServer,SIGNAL(newConnection()),this,SLOT(onNewConnectionPending())); QString serverName; { QTemporaryFile tmpf(QDir::tempPath() + QDir::separator() + NATRON_APPLICATION_NAME "_INPUT_SOCKET" + QString::number(QCoreApplication::applicationPid())); tmpf.open(); serverName = tmpf.fileName(); } _backgroundIPCServer->listen(serverName); if(!_backgroundOutputPipe->waitForConnected(5000)){ //< blocking, we wait for the server to respond std::cout << "WARNING: The GUI application failed to respond, canceling this process will not be possible" " unless it finishes or you kill it." << std::endl; } writeToOutputChannel(QString(kBgProcessServerCreatedShort) + _backgroundIPCServer->fullServerName()); ///we wait for the GUI app to connect its socket to this server, we let it 5 sec to reply _backgroundIPCServer->waitForNewConnection(5000); ///since we're still not returning the event loop, just process them manually in case ///Qt didn't caught the new connection pending. QCoreApplication::processEvents(); }
void ProcessInputChannel::initialize() { _backgroundOutputPipe = new QLocalSocket(); QObject::connect( _backgroundOutputPipe, SIGNAL(connected()), this, SLOT(onOutputPipeConnectionMade()) ); _backgroundOutputPipe->connectToServer(_mainProcessServerName,QLocalSocket::ReadWrite); std::cout << "Attempting connection to " << _mainProcessServerName.toStdString() << std::endl; _backgroundIPCServer = new QLocalServer(); QObject::connect( _backgroundIPCServer,SIGNAL(newConnection()),this,SLOT(onNewConnectionPending()) ); QString tmpFileName; #if defined(Q_OS_WIN) tmpFileName += QString::fromUtf8("//./pipe"); tmpFileName += QLatin1Char('/'); tmpFileName += QString::fromUtf8(NATRON_APPLICATION_NAME); tmpFileName += QString::fromUtf8("_INPUT_SOCKET"); #endif { #if defined(Q_OS_UNIX) QTemporaryFile tmpf(tmpFileName); tmpFileName = tmpf.fileName(); tmpf.remove(); #else QTemporaryFile tmpf; tmpf.open(); QString tmpFilePath = tmpf.fileName(); QString baseName; int lastSlash = tmpFilePath.lastIndexOf(QLatin1Char('/')); if (lastSlash != -1 && lastSlash < tmpFilePath.size() - 1) { baseName = tmpFilePath.mid(lastSlash + 1); } else { baseName = tmpFilePath; } tmpFileName += baseName; tmpf.remove(); #endif } _backgroundIPCServer->listen(tmpFileName); if ( !_backgroundOutputPipe->waitForConnected(5000) ) { //< blocking, we wait for the server to respond std::cout << "WARNING: The GUI application failed to respond, canceling this process will not be possible" " unless it finishes or you kill it." << std::endl; } writeToOutputChannel( QString::fromUtf8(kBgProcessServerCreatedShort) + tmpFileName ); ///we wait for the GUI app to connect its socket to this server, we let it 5 sec to reply _backgroundIPCServer->waitForNewConnection(5000); ///since we're still not returning the event loop, just process them manually in case ///Qt didn't caught the new connection pending. QCoreApplication::processEvents(); }