properly emit signal on silent node removal

This commit is contained in:
Stephen Birarda 2014-01-14 10:28:41 -08:00
parent 57f977668f
commit ed0ed96029
5 changed files with 19 additions and 16 deletions

View file

@ -77,7 +77,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
// Start the web server.
mg_start(&callbacks, NULL, options);
connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer)));
connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), this, SLOT(nodeKilled(SharedNodePointer)));
if (!_staticAssignmentFile.exists() || _voxelServerConfig) {
@ -492,7 +492,7 @@ void DomainServer::addReleasedAssignmentBackToQueue(Assignment* releasedAssignme
}
}
void DomainServer::nodeKilled(Node* node) {
void DomainServer::nodeKilled(SharedNodePointer node) {
// if this node has linked data it was from an assignment
if (node->getLinkedData()) {
Assignment* nodeAssignment = (Assignment*) node->getLinkedData();

View file

@ -33,7 +33,7 @@ public:
public slots:
/// Called by NodeList to inform us that a node has been killed.
void nodeKilled(Node* node);
void nodeKilled(SharedNodePointer node);
private:
static int civetwebRequestHandler(struct mg_connection *connection);

View file

@ -24,6 +24,7 @@
/// Handles assignments of type OctreeServer - sending octrees to various clients.
class OctreeServer : public ThreadedAssignment {
Q_OBJECT
public:
OctreeServer(const unsigned char* dataBuffer, int numBytes);
~OctreeServer();

View file

@ -442,13 +442,18 @@ void NodeList::processSTUNResponse(unsigned char* packetData, size_t dataBytes)
}
void NodeList::killNodeWithUUID(const QUuid& nodeUUID) {
NodeHash::iterator nodeToKill = _nodeHash.find(nodeUUID);
if (nodeToKill != _nodeHash.end()) {
emit nodeKilled(nodeToKill.value());
_nodeHash.erase(nodeToKill);
NodeHash::iterator nodeItemToKill = _nodeHash.find(nodeUUID);
if (nodeItemToKill != _nodeHash.end()) {
killNodeAtHashIterator(nodeItemToKill);
}
}
void NodeList::killNodeAtHashIterator(NodeHash::iterator nodeItemToKill) {
emit nodeKilled(nodeItemToKill.value());
_nodeHash.erase(nodeItemToKill);
}
void NodeList::sendKillNode(const char* nodeTypes, int numNodeTypes) {
unsigned char packet[MAX_PACKET_SIZE];
unsigned char* packetPosition = packet;
@ -474,12 +479,8 @@ void NodeList::processKillNode(unsigned char* packetData, size_t dataBytes) {
packetData += NUM_BYTES_RFC4122_UUID;
dataBytes -= NUM_BYTES_RFC4122_UUID;
// make sure the node exists
NodeHash::iterator nodeToKill = _nodeHash.find(nodeUUID);
if (nodeToKill != _nodeHash.end()) {
emit nodeKilled(nodeToKill.value());
_nodeHash.erase(nodeToKill);
}
// kill the node with this UUID, if it exists
killNodeWithUUID(nodeUUID);
}
void NodeList::sendDomainServerCheckIn() {
@ -795,9 +796,8 @@ void NodeList::removeSilentNodes() {
QMutexLocker(&node->getMutex());
if ((usecTimestampNow() - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) {
// kill this node, don't lock - we already did it
_nodeHash.erase(nodeItem);
// call our private method to kill this node (removes it and emits the right signal)
killNodeAtHashIterator(nodeItem);
}
nodeItem++;

View file

@ -144,6 +144,8 @@ private:
void processKillNode(unsigned char* packetData, size_t dataBytes);
void killNodeAtHashIterator(NodeHash::iterator nodeItemToKill);
NodeHash _nodeHash;
QString _domainHostname;
HifiSockAddr _domainSockAddr;