History

Merge branch 'atp' of github.com:birarda/hifi into receive_packets

Ryan Huffman committed 11 years ago

Commit bd345cd2 parents e99df5b 5edb80916 files · +97 −198Browse files

Showing the changes to assignment-client/src/AssignmentClient.cpp (1 of 16 files). Show all

Unified · Split

assignment-client/src/AssignmentClient.cpp+24−4
@@ -62,6 +62,17 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri · 61 unmodified lines
62 DependencyManager::registerInheritance<EntityActionFactoryInterface, AssignmentActionFactory>();62 DependencyManager::registerInheritance<EntityActionFactoryInterface, AssignmentActionFactory>();
63 auto actionFactory = DependencyManager::set<AssignmentActionFactory>();63 auto actionFactory = DependencyManager::set<AssignmentActionFactory>();
64 64
65 // setup a thread for the NodeList and its PacketReceiver
66 QThread* nodeThread = new QThread(this);
67 nodeThread->setObjectName("NodeList Thread");
68 nodeThread->start();
69
70 // make sure the node thread is given highest priority
71 nodeThread->setPriority(QThread::TimeCriticalPriority);
72
73 // put the NodeList on the node thread
74 nodeList->moveToThread(nodeThread);
75
65 // make up a uuid for this child so the parent can tell us apart. This id will be changed76 // make up a uuid for this child so the parent can tell us apart. This id will be changed
66 // when the domain server hands over an assignment.77 // when the domain server hands over an assignment.
67 QUuid nodeUUID = QUuid::createUuid();78 QUuid nodeUUID = QUuid::createUuid();
@@ -124,7 +135,6 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri · 56 unmodified lines
124 packetReceiver.registerListener(PacketType::CreateAssignment, this, "handleCreateAssignmentPacket");135 packetReceiver.registerListener(PacketType::CreateAssignment, this, "handleCreateAssignmentPacket");
125 packetReceiver.registerListener(PacketType::StopNode, this, "handleStopNodePacket");136 packetReceiver.registerListener(PacketType::StopNode, this, "handleStopNodePacket");
126}137}
127
128void AssignmentClient::stopAssignmentClient() {138void AssignmentClient::stopAssignmentClient() {
129 qDebug() << "Forced stop of assignment-client.";139 qDebug() << "Forced stop of assignment-client.";
130 140
@@ -150,6 +160,16 @@ void AssignmentClient::stopAssignmentClient() { · 19 unmodified lines
150 }160 }
151}161}
152 162
163AssignmentClient::~AssignmentClient() {
164 QThread* nodeThread = DependencyManager::get<NodeList>()->thread();
165
166 // remove the NodeList from the DependencyManager
167 DependencyManager::destroy<NodeList>();
168
169 // ask the node thread to quit and wait until it is done
170 nodeThread->quit();
171 nodeThread->wait();
172}
153 173
154void AssignmentClient::aboutToQuit() {174void AssignmentClient::aboutToQuit() {
155 stopAssignmentClient();175 stopAssignmentClient();
@@ -251,9 +271,6 @@ void AssignmentClient::handleCreateAssignmentPacket(QSharedPointer<NLPacket> pac · 95 unmodified lines
251 271
252 _currentAssignment->moveToThread(workerThread);272 _currentAssignment->moveToThread(workerThread);
253 273
254 // move the NodeList to the thread used for the _current assignment
255 nodeList->moveToThread(workerThread);
256
257 // Starts an event loop, and emits workerThread->started()274 // Starts an event loop, and emits workerThread->started()
258 workerThread->start();275 workerThread->start();
259 } else {276 } else {
@@ -313,6 +330,9 @@ void AssignmentClient::assignmentCompleted() { · 53 unmodified lines
313 330
314 auto nodeList = DependencyManager::get<NodeList>();331 auto nodeList = DependencyManager::get<NodeList>();
315 332
333 // tell the packet receiver to stop dropping packets
334 nodeList->getPacketReceiver().setShouldDropPackets(false);
335
316 // reset our NodeList by switching back to unassigned and clearing the list336 // reset our NodeList by switching back to unassigned and clearing the list
317 nodeList->setOwnerType(NodeType::Unassigned);337 nodeList->setOwnerType(NodeType::Unassigned);
318 nodeList->reset();338 nodeList->reset();