| 27 | } |
| 28 | |
| 29 | void RasterStreamView::start(const QString& helper_path, const QString& wad_path) { |
| 30 | if (helper_path.isEmpty() || wad_path.isEmpty()) { |
| 31 | endSession(); |
| 32 | return; |
| 33 | } |
| 34 | const QString unique = QUuid::createUuid().toString(QUuid::Id128); |
| 35 | const QString shm_key = QStringLiteral("pjr-shm-") + unique; |
| 36 | const QString sock_name = QStringLiteral("pjr-sock-") + unique; |
| 37 | |
| 38 | shm_ = new QSharedMemory(shm_key, this); |
| 39 | const int total = static_cast<int>(pj_raster::shmTotalSize(kWidth, kHeight, pj_raster::kBytesPerPixel)); |
| 40 | if (!shm_->create(total)) { |
| 41 | endSession(); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | server_ = new QLocalServer(this); |
| 46 | connect(server_, &QLocalServer::newConnection, this, &RasterStreamView::onHelperConnected); |
| 47 | QLocalServer::removeServer(sock_name); |
| 48 | if (!server_->listen(sock_name)) { |
| 49 | endSession(); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | process_ = new QProcess(this); |
| 54 | connect(process_, &QProcess::finished, this, [this](int, QProcess::ExitStatus) { endSession(); }); |
| 55 | connect(process_, &QProcess::errorOccurred, this, [this](QProcess::ProcessError) { endSession(); }); |
| 56 | process_->start( |
| 57 | helper_path, |
| 58 | {QStringLiteral("--shm"), shm_key, QStringLiteral("--sock"), sock_name, QStringLiteral("--wad"), wad_path}); |
| 59 | } |
| 60 | |
| 61 | void RasterStreamView::setKeyTranslator(std::function<int(int)> translator) { |
| 62 | key_translator_ = translator ? std::move(translator) : std::function<int(int)>([](int key) { return key; }); |