for(;;) { if(сameraID == 0) continue; else { std::cout << "StartController::service new camera ID = " << cameraID << std::endl ; break; } }
void StartController::cameraStarted(int id){ cameraID = id; qDebug() << "StartController::cameraStarted: cameraID = " << cameraID;}
void StartController::service(HttpRequest &request, HttpResponse &response) { QJsonObject json; cameraID = 0; newCameraID = 0; QByteArray url = request.getParameter("url"); QByteArray minArea = request.getParameter("minArea"); QByteArray maxArea = request.getParameter("maxArea"); QByteArray startx = request.getParameter("x0"); QByteArray starty = request.getParameter("y0"); QByteArray endx = request.getParameter("x1"); QByteArray endy = request.getParameter("y1"); dbthread = new QThread; impthread = new QThread; worker = new DbWriteWorker(); worker->setInterval(60); worker->moveToThread(dbthread); impworker = new ImageProcessingWorker(0, QString::fromUtf8(startx).toInt(), QString::fromUtf8(starty).toInt(), QString::fromUtf8(endx).toInt(), QString::fromUtf8(endy).toInt(), QString::fromUtf8(minArea).toInt(), QString::fromUtf8(maxArea).toInt(), 1, QString::fromUtf8(url)); impworker->moveToThread(impthread); // Соединяем сигнал started потока, со слотом process "рабочего" класса, т.е. начинается выполнение нужной работы. connect(dbthread, SIGNAL(started()), worker, SLOT(process())); connect(impthread, SIGNAL(started()), impworker, SLOT(process())); // По завершению выходим из потока, и удаляем рабочий класс connect(worker, SIGNAL(finished()), dbthread, SLOT(quit())); connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater())); connect(impworker, SIGNAL(finished()), impthread, SLOT(quit())); connect(impworker, SIGNAL(finished()), impworker, SLOT(deleteLater())); // Удаляем поток, после выполнения операции connect(dbthread, SIGNAL(finished()), dbthread, SLOT(deleteLater())); connect(impthread, SIGNAL(finished()), impthread, SLOT(deleteLater())); connect(impworker, SIGNAL(sendCounters(int,int, int)), worker, SLOT(waitForDB(int,int,int))); //connect(worker, SIGNAL(getDataSignal()), impworker, SLOT(prepareCounters())); dbthread->start(); impthread->start(); std::cout << "Waiting for new camera connection" << std::endl ; for(;;) { if(сameraID == 0) continue; else { std::cout << "StartController::service new camera ID = " << cameraID << std::endl ; break; } } if(cameraID > 0) { json["result"] = "Ok"; } else { json["result"] = "Error"; } json["cameraID"] = cameraID; QJsonDocument saveDoc(json); response.write(saveDoc.toJson(),true);}
C++ (Qt)connect(impworker, SIGNAL(newCameraOpened(int)), this, SLOT(cameraStarted(int))); QEventLoop eventLoop;connect(impworker, SIGNAL(newCameraOpened(int)), &eventLoop, SLOT(quit()));eventLoop.exec(); //Here we know cameraId
C++ (Qt)connect(impworker, SIGNAL(newCameraOpened(int)), [&eventLoop, &cameraId] (int id) {cameraId = id; eventLoop.quit();});
void StopController::service(HttpRequest &request, HttpResponse &response) { QJsonObject json; camSatus = -1; QByteArray par = request.getParameter("id"); qDebug() << "StopController::ID int = " << par.toInt(); procToKill = par.toInt(); for(;;) { if(procToKill == 0) break; } json["result"] = "Ok"; json["value"] = par.toInt(); QJsonDocument saveDoc(json); response.write(saveDoc.toJson(),true);}