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
6262 DependencyManager::registerInheritance<EntityActionFactoryInterface, AssignmentActionFactory>();
6363 auto actionFactory = DependencyManager::set<AssignmentActionFactory>();
6464
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+
6576 // make up a uuid for this child so the parent can tell us apart. This id will be changed
6677 // when the domain server hands over an assignment.
6778 QUuid nodeUUID = QUuid::createUuid();
@@ -124,7 +135,6 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri · 56 unmodified lines
124135 packetReceiver.registerListener(PacketType::CreateAssignment, this, "handleCreateAssignmentPacket");
125136 packetReceiver.registerListener(PacketType::StopNode, this, "handleStopNodePacket");
126137 }
127−
128138 void AssignmentClient::stopAssignmentClient() {
129139 qDebug() << "Forced stop of assignment-client.";
130140
@@ -150,6 +160,16 @@ void AssignmentClient::stopAssignmentClient() { · 19 unmodified lines
150160 }
151161 }
152162
163+AssignmentClient::~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+}
153173
154174 void AssignmentClient::aboutToQuit() {
155175 stopAssignmentClient();
@@ -251,9 +271,6 @@ void AssignmentClient::handleCreateAssignmentPacket(QSharedPointer<NLPacket> pac · 95 unmodified lines
251271
252272 _currentAssignment->moveToThread(workerThread);
253273
254− // move the NodeList to the thread used for the _current assignment
255− nodeList->moveToThread(workerThread);
256−
257274 // Starts an event loop, and emits workerThread->started()
258275 workerThread->start();
259276 } else {
@@ -313,6 +330,9 @@ void AssignmentClient::assignmentCompleted() { · 53 unmodified lines
313330
314331 auto nodeList = DependencyManager::get<NodeList>();
315332
333+ // tell the packet receiver to stop dropping packets
334+ nodeList->getPacketReceiver().setShouldDropPackets(false);
335+
316336 // reset our NodeList by switching back to unassigned and clearing the list
317337 nodeList->setOwnerType(NodeType::Unassigned);
318338 nodeList->reset();