Showing the changes to assignment-client/src/AssignmentClient.cpp (1 of 5 files). Show all
Unified · Split
| @@ -124,32 +124,36 @@ void AssignmentClient::readPendingDatagrams() { · 123 unmodified lines | ||
| 124 | 124 | // construct the deployed assignment from the packet data |
| 125 | 125 | _currentAssignment = AssignmentFactory::unpackAssignment(receivedPacket); |
| 126 | 126 | |
| 127 | − qDebug() << "Received an assignment -" << *_currentAssignment; | |
| 128 | − | |
| 129 | − // switch our nodelist domain IP and port to whoever sent us the assignment | |
| 130 | − | |
| 131 | − nodeList->setDomainSockAddr(senderSockAddr); | |
| 132 | − nodeList->setOwnerUUID(_currentAssignment->getUUID()); | |
| 133 | − | |
| 134 | − qDebug() << "Destination IP for assignment is" << nodeList->getDomainIP().toString(); | |
| 135 | − | |
| 136 | − // start the deployed assignment | |
| 137 | − QThread* workerThread = new QThread(this); | |
| 138 | − | |
| 139 | − connect(workerThread, SIGNAL(started()), _currentAssignment, SLOT(run())); | |
| 140 | − | |
| 141 | − connect(_currentAssignment, SIGNAL(finished()), this, SLOT(assignmentCompleted())); | |
| 142 | − connect(_currentAssignment, SIGNAL(finished()), workerThread, SLOT(quit())); | |
| 143 | − connect(_currentAssignment, SIGNAL(finished()), _currentAssignment, SLOT(deleteLater())); | |
| 144 | − connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater())); | |
| 145 | − | |
| 146 | − _currentAssignment->moveToThread(workerThread); | |
| 147 | − | |
| 148 | − // move the NodeList to the thread used for the _current assignment | |
| 149 | − nodeList->moveToThread(workerThread); | |
| 150 | − | |
| 151 | − // Starts an event loop, and emits workerThread->started() | |
| 152 | − workerThread->start(); | |
| 127 | + if (_currentAssignment) { | |
| 128 | + qDebug() << "Received an assignment -" << *_currentAssignment; | |
| 129 | + | |
| 130 | + // switch our nodelist domain IP and port to whoever sent us the assignment | |
| 131 | + | |
| 132 | + nodeList->setDomainSockAddr(senderSockAddr); | |
| 133 | + nodeList->setOwnerUUID(_currentAssignment->getUUID()); | |
| 134 | + | |
| 135 | + qDebug() << "Destination IP for assignment is" << nodeList->getDomainIP().toString(); | |
| 136 | + | |
| 137 | + // start the deployed assignment | |
| 138 | + QThread* workerThread = new QThread(this); | |
| 139 | + | |
| 140 | + connect(workerThread, SIGNAL(started()), _currentAssignment, SLOT(run())); | |
| 141 | + | |
| 142 | + connect(_currentAssignment, SIGNAL(finished()), this, SLOT(assignmentCompleted())); | |
| 143 | + connect(_currentAssignment, SIGNAL(finished()), workerThread, SLOT(quit())); | |
| 144 | + connect(_currentAssignment, SIGNAL(finished()), _currentAssignment, SLOT(deleteLater())); | |
| 145 | + connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater())); | |
| 146 | + | |
| 147 | + _currentAssignment->moveToThread(workerThread); | |
| 148 | + | |
| 149 | + // move the NodeList to the thread used for the _current assignment | |
| 150 | + nodeList->moveToThread(workerThread); | |
| 151 | + | |
| 152 | + // Starts an event loop, and emits workerThread->started() | |
| 153 | + workerThread->start(); | |
| 154 | + } else { | |
| 155 | + qDebug() << "Received an assignment that could not be unpacked. Re-requesting."; | |
| 156 | + } | |
| 153 | 157 | } |
| 154 | 158 | } else { |
| 155 | 159 | // have the NodeList attempt to handle it |