Commit 2488533fbadcd89b7e9d0c4f33eee9aa98e99a26
1 parent
b3411eda
More nonsense to get around Qt's one object one thread policies
Currently, no QtWarnings generated on windows, how exciting.
Showing
1 changed file
with
62 additions
and
25 deletions
openbr/plugins/process.cpp
| @@ -25,11 +25,13 @@ public: | @@ -25,11 +25,13 @@ public: | ||
| 25 | CommunicationManager() | 25 | CommunicationManager() |
| 26 | { | 26 | { |
| 27 | basis = new QThread; | 27 | basis = new QThread; |
| 28 | + basis->moveToThread(QCoreApplication::instance()->thread()); | ||
| 28 | moveToThread(basis); | 29 | moveToThread(basis); |
| 29 | server.moveToThread(basis); | 30 | server.moveToThread(basis); |
| 30 | outbound.moveToThread(basis); | 31 | outbound.moveToThread(basis); |
| 31 | 32 | ||
| 32 | // signals for our sever | 33 | // signals for our sever |
| 34 | + connect(this, SIGNAL(pulseEndThread()), basis, SLOT(quit() )); | ||
| 33 | connect(&server, SIGNAL(newConnection()), this, SLOT(receivedConnection() )); | 35 | connect(&server, SIGNAL(newConnection()), this, SLOT(receivedConnection() )); |
| 34 | connect(this, SIGNAL(pulseStartServer(QString)), this, SLOT(startServerInternal(QString)), Qt::BlockingQueuedConnection); | 36 | connect(this, SIGNAL(pulseStartServer(QString)), this, SLOT(startServerInternal(QString)), Qt::BlockingQueuedConnection); |
| 35 | connect(this, SIGNAL(pulseOutboundConnect(QString)), this, SLOT(startConnectInternal(QString) ), Qt::BlockingQueuedConnection); | 37 | connect(this, SIGNAL(pulseOutboundConnect(QString)), this, SLOT(startConnectInternal(QString) ), Qt::BlockingQueuedConnection); |
| @@ -55,6 +57,12 @@ public: | @@ -55,6 +57,12 @@ public: | ||
| 55 | 57 | ||
| 56 | ~CommunicationManager() | 58 | ~CommunicationManager() |
| 57 | { | 59 | { |
| 60 | + | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + void shutDownThread() | ||
| 64 | + { | ||
| 65 | + emit pulseEndThread(); | ||
| 58 | basis->quit(); | 66 | basis->quit(); |
| 59 | basis->wait(); | 67 | basis->wait(); |
| 60 | delete basis; | 68 | delete basis; |
| @@ -268,6 +276,7 @@ signals: | @@ -268,6 +276,7 @@ signals: | ||
| 268 | void pulseSendSerialized(); | 276 | void pulseSendSerialized(); |
| 269 | void pulseShutdown(); | 277 | void pulseShutdown(); |
| 270 | void pulseOutboundConnect(QString serverName); | 278 | void pulseOutboundConnect(QString serverName); |
| 279 | + void pulseEndThread(); | ||
| 271 | 280 | ||
| 272 | 281 | ||
| 273 | public: | 282 | public: |
| @@ -375,6 +384,8 @@ public: | @@ -375,6 +384,8 @@ public: | ||
| 375 | ~EnrollmentWorker() | 384 | ~EnrollmentWorker() |
| 376 | { | 385 | { |
| 377 | delete transform; | 386 | delete transform; |
| 387 | + | ||
| 388 | + comm->shutDownThread(); | ||
| 378 | delete comm; | 389 | delete comm; |
| 379 | } | 390 | } |
| 380 | 391 | ||
| @@ -423,15 +434,49 @@ void WorkerProcess::mainLoop() | @@ -423,15 +434,49 @@ void WorkerProcess::mainLoop() | ||
| 423 | delete processInterface; | 434 | delete processInterface; |
| 424 | } | 435 | } |
| 425 | 436 | ||
| 426 | -void shutUp(QtMsgType type, const QMessageLogContext &context, const QString &msg) | 437 | +class ProcessInterface : public QObject |
| 427 | { | 438 | { |
| 428 | - // Qt you have no idea how much I don't care about you. | ||
| 429 | - // Please tell me more about how you want every single god damn thing to be created from and used by exactly one thread. | ||
| 430 | - // It does not matter, so shut up already. | ||
| 431 | - // p.s. I hope you die. | ||
| 432 | - (void) type; (void) context; (void) msg; | ||
| 433 | -} | 439 | + Q_OBJECT |
| 440 | +public: | ||
| 441 | + ProcessInterface() | ||
| 442 | + { | ||
| 443 | + this->moveToThread(QCoreApplication::instance()->thread()); | ||
| 444 | + workerProcess.moveToThread(QCoreApplication::instance()->thread()); | ||
| 445 | + connect(this, SIGNAL(pulseEnd()), this, SLOT(endProcessInternal()), Qt::BlockingQueuedConnection); | ||
| 446 | + connect(this, SIGNAL(pulseStart(QStringList)), this, SLOT(startProcessInternal(QStringList)), Qt::BlockingQueuedConnection); | ||
| 447 | + } | ||
| 448 | + QProcess workerProcess; | ||
| 449 | + void endProcess() | ||
| 450 | + { | ||
| 451 | + if (QThread::currentThread() != QCoreApplication::instance()->thread()) | ||
| 452 | + emit pulseEnd(); | ||
| 453 | + else | ||
| 454 | + endProcessInternal(); | ||
| 455 | + } | ||
| 456 | + void startProcess(QStringList arguments) | ||
| 457 | + { | ||
| 458 | + if (QThread::currentThread() != QCoreApplication::instance()->thread() ) | ||
| 459 | + emit pulseStart(arguments); | ||
| 460 | + else | ||
| 461 | + startProcessInternal(arguments); | ||
| 462 | + } | ||
| 463 | +signals: | ||
| 464 | + void pulseEnd(); | ||
| 465 | + void pulseStart(QStringList); | ||
| 434 | 466 | ||
| 467 | +protected slots: | ||
| 468 | + void endProcessInternal() | ||
| 469 | + { | ||
| 470 | + workerProcess.waitForFinished(-1); | ||
| 471 | + } | ||
| 472 | + | ||
| 473 | + void startProcessInternal(QStringList arguments) | ||
| 474 | + { | ||
| 475 | + workerProcess.setProcessChannelMode(QProcess::ForwardedChannels); | ||
| 476 | + workerProcess.start("br", arguments); | ||
| 477 | + workerProcess.waitForStarted(-1); | ||
| 478 | + } | ||
| 479 | +}; | ||
| 435 | 480 | ||
| 436 | /*! | 481 | /*! |
| 437 | * \ingroup transforms | 482 | * \ingroup transforms |
| @@ -447,7 +492,7 @@ class ProcessWrapperTransform : public TimeVaryingTransform | @@ -447,7 +492,7 @@ class ProcessWrapperTransform : public TimeVaryingTransform | ||
| 447 | 492 | ||
| 448 | QString baseKey; | 493 | QString baseKey; |
| 449 | 494 | ||
| 450 | - QProcess * workerProcess; | 495 | + ProcessInterface workerProcess; |
| 451 | CommunicationManager * comm; | 496 | CommunicationManager * comm; |
| 452 | 497 | ||
| 453 | void projectUpdate(const TemplateList &src, TemplateList &dst) | 498 | void projectUpdate(const TemplateList &src, TemplateList &dst) |
| @@ -490,8 +535,10 @@ class ProcessWrapperTransform : public TimeVaryingTransform | @@ -490,8 +535,10 @@ class ProcessWrapperTransform : public TimeVaryingTransform | ||
| 490 | argumentList.append("0"); | 535 | argumentList.append("0"); |
| 491 | argumentList.append("-algorithm"); | 536 | argumentList.append("-algorithm"); |
| 492 | argumentList.append(transform); | 537 | argumentList.append(transform); |
| 493 | - argumentList.append("-path"); | ||
| 494 | - argumentList.append(Globals->path); | 538 | + if (!Globals->path.isEmpty()) { |
| 539 | + argumentList.append("-path"); | ||
| 540 | + argumentList.append(Globals->path); | ||
| 541 | + } | ||
| 495 | argumentList.append("-parallelism"); | 542 | argumentList.append("-parallelism"); |
| 496 | argumentList.append(QString::number(0)); | 543 | argumentList.append(QString::number(0)); |
| 497 | argumentList.append("-slave"); | 544 | argumentList.append("-slave"); |
| @@ -500,12 +547,7 @@ class ProcessWrapperTransform : public TimeVaryingTransform | @@ -500,12 +547,7 @@ class ProcessWrapperTransform : public TimeVaryingTransform | ||
| 500 | comm->key = "master_"+baseKey.mid(1,5); | 547 | comm->key = "master_"+baseKey.mid(1,5); |
| 501 | 548 | ||
| 502 | comm->startServer(baseKey+"_master"); | 549 | comm->startServer(baseKey+"_master"); |
| 503 | - | ||
| 504 | - workerProcess = new QProcess(); | ||
| 505 | - workerProcess->setProcessChannelMode(QProcess::ForwardedChannels); | ||
| 506 | - workerProcess->start("br", argumentList); | ||
| 507 | - workerProcess->waitForStarted(-1); | ||
| 508 | - | 550 | + workerProcess.startProcess(argumentList); |
| 509 | comm->waitForInbound(); | 551 | comm->waitForInbound(); |
| 510 | comm->connectToRemote(baseKey+"_worker"); | 552 | comm->connectToRemote(baseKey+"_worker"); |
| 511 | } | 553 | } |
| @@ -520,16 +562,11 @@ class ProcessWrapperTransform : public TimeVaryingTransform | @@ -520,16 +562,11 @@ class ProcessWrapperTransform : public TimeVaryingTransform | ||
| 520 | if (this->processActive) { | 562 | if (this->processActive) { |
| 521 | comm->sendSignal(CommunicationManager::SHOULD_END); | 563 | comm->sendSignal(CommunicationManager::SHOULD_END); |
| 522 | 564 | ||
| 523 | - // I don't even want to talk about it. | ||
| 524 | - qInstallMessageHandler(shutUp); | ||
| 525 | - workerProcess->waitForFinished(-1); | ||
| 526 | - delete workerProcess; | ||
| 527 | - qInstallMessageHandler(0); | ||
| 528 | - | 565 | + workerProcess.endProcess(); |
| 529 | processActive = false; | 566 | processActive = false; |
| 530 | - comm->inbound->abort(); | ||
| 531 | - comm->outbound.abort(); | ||
| 532 | - comm->server.close(); | 567 | + comm->shutdown(); |
| 568 | + comm->shutDownThread(); | ||
| 569 | + | ||
| 533 | delete comm; | 570 | delete comm; |
| 534 | } | 571 | } |
| 535 | } | 572 | } |