mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 16:36:54 +02:00
Merge pull request #1583 from birarda/nodelist-container
NodeList container repairs
This commit is contained in:
commit
2fe666aa63
4 changed files with 38 additions and 21 deletions
|
@ -2006,7 +2006,7 @@ void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm::
|
||||||
PerformanceWarning warn(showWarnings, "Application::updateAvatars()");
|
PerformanceWarning warn(showWarnings, "Application::updateAvatars()");
|
||||||
|
|
||||||
foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
|
foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
|
||||||
QMutexLocker(&node->getMutex());
|
QMutexLocker locker(&node->getMutex());
|
||||||
if (node->getLinkedData()) {
|
if (node->getLinkedData()) {
|
||||||
Avatar *avatar = (Avatar *)node->getLinkedData();
|
Avatar *avatar = (Avatar *)node->getLinkedData();
|
||||||
if (!avatar->isInitialized()) {
|
if (!avatar->isInitialized()) {
|
||||||
|
@ -3659,7 +3659,7 @@ void Application::renderAvatars(bool forceRenderHead, bool selfAvatarOnly) {
|
||||||
NodeList* nodeList = NodeList::getInstance();
|
NodeList* nodeList = NodeList::getInstance();
|
||||||
|
|
||||||
foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {
|
foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {
|
||||||
QMutexLocker(&node->getMutex());
|
QMutexLocker locker(&node->getMutex());
|
||||||
|
|
||||||
if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
|
if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
|
||||||
Avatar *avatar = (Avatar *)node->getLinkedData();
|
Avatar *avatar = (Avatar *)node->getLinkedData();
|
||||||
|
|
|
@ -20,12 +20,9 @@ JurisdictionListener::JurisdictionListener(NODE_TYPE type, PacketSenderNotify* n
|
||||||
{
|
{
|
||||||
_nodeType = type;
|
_nodeType = type;
|
||||||
ReceivedPacketProcessor::_dontSleep = true; // we handle sleeping so this class doesn't need to
|
ReceivedPacketProcessor::_dontSleep = true; // we handle sleeping so this class doesn't need to
|
||||||
NodeList* nodeList = NodeList::getInstance();
|
|
||||||
|
|
||||||
connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer)));
|
// connect(nodeList, &NodeList::nodeKilled, this, &JurisdictionListener::nodeKilled);
|
||||||
|
// qDebug("JurisdictionListener::JurisdictionListener(NODE_TYPE type=%c)\n", type);
|
||||||
//qDebug("JurisdictionListener::JurisdictionListener(NODE_TYPE type=%c)\n", type);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JurisdictionListener::nodeKilled(SharedNodePointer node) {
|
void JurisdictionListener::nodeKilled(SharedNodePointer node) {
|
||||||
|
|
|
@ -56,6 +56,7 @@ NodeList* NodeList::getInstance() {
|
||||||
|
|
||||||
NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
|
NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
|
||||||
_nodeHash(),
|
_nodeHash(),
|
||||||
|
_nodeHashMutex(),
|
||||||
_domainHostname(DEFAULT_DOMAIN_HOSTNAME),
|
_domainHostname(DEFAULT_DOMAIN_HOSTNAME),
|
||||||
_domainSockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)),
|
_domainSockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)),
|
||||||
_nodeSocket(),
|
_nodeSocket(),
|
||||||
|
@ -230,7 +231,7 @@ void NodeList::processBulkNodeData(const HifiSockAddr& senderAddress, unsigned c
|
||||||
}
|
}
|
||||||
|
|
||||||
int NodeList::updateNodeWithData(Node *node, const HifiSockAddr& senderSockAddr, unsigned char *packetData, int dataBytes) {
|
int NodeList::updateNodeWithData(Node *node, const HifiSockAddr& senderSockAddr, unsigned char *packetData, int dataBytes) {
|
||||||
QMutexLocker(&node->getMutex());
|
QMutexLocker locker(&node->getMutex());
|
||||||
|
|
||||||
node->setLastHeardMicrostamp(usecTimestampNow());
|
node->setLastHeardMicrostamp(usecTimestampNow());
|
||||||
|
|
||||||
|
@ -266,19 +267,25 @@ SharedNodePointer NodeList::nodeWithAddress(const HifiSockAddr &senderSockAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedNodePointer NodeList::nodeWithUUID(const QUuid& nodeUUID) {
|
SharedNodePointer NodeList::nodeWithUUID(const QUuid& nodeUUID) {
|
||||||
|
QMutexLocker locker(&_nodeHashMutex);
|
||||||
return _nodeHash.value(nodeUUID);
|
return _nodeHash.value(nodeUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NodeHash NodeList::getNodeHash() {
|
||||||
|
QMutexLocker locker(&_nodeHashMutex);
|
||||||
|
return NodeHash(_nodeHash);
|
||||||
|
}
|
||||||
|
|
||||||
void NodeList::clear() {
|
void NodeList::clear() {
|
||||||
qDebug() << "Clearing the NodeList. Deleting all nodes in list.";
|
qDebug() << "Clearing the NodeList. Deleting all nodes in list.";
|
||||||
|
|
||||||
|
QMutexLocker locker(&_nodeHashMutex);
|
||||||
|
|
||||||
NodeHash::iterator nodeItem = _nodeHash.begin();
|
NodeHash::iterator nodeItem = _nodeHash.begin();
|
||||||
|
|
||||||
// iterate the nodes in the list
|
// iterate the nodes in the list
|
||||||
while (nodeItem != _nodeHash.end()) {
|
while (nodeItem != _nodeHash.end()) {
|
||||||
NodeHash::iterator previousNodeItem = nodeItem;
|
nodeItem = killNodeAtHashIterator(nodeItem);
|
||||||
++nodeItem;
|
|
||||||
killNodeAtHashIterator(previousNodeItem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,16 +445,18 @@ void NodeList::processSTUNResponse(unsigned char* packetData, size_t dataBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::killNodeWithUUID(const QUuid& nodeUUID) {
|
void NodeList::killNodeWithUUID(const QUuid& nodeUUID) {
|
||||||
|
QMutexLocker locker(&_nodeHashMutex);
|
||||||
|
|
||||||
NodeHash::iterator nodeItemToKill = _nodeHash.find(nodeUUID);
|
NodeHash::iterator nodeItemToKill = _nodeHash.find(nodeUUID);
|
||||||
if (nodeItemToKill != _nodeHash.end()) {
|
if (nodeItemToKill != _nodeHash.end()) {
|
||||||
killNodeAtHashIterator(nodeItemToKill);
|
killNodeAtHashIterator(nodeItemToKill);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill) {
|
NodeHash::iterator NodeList::killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill) {
|
||||||
qDebug() << "Killed" << *nodeItemToKill.value();
|
qDebug() << "Killed" << *nodeItemToKill.value();
|
||||||
emit nodeKilled(nodeItemToKill.value());
|
emit nodeKilled(nodeItemToKill.value());
|
||||||
_nodeHash.erase(nodeItemToKill);
|
return _nodeHash.erase(nodeItemToKill);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::sendKillNode(const char* nodeTypes, int numNodeTypes) {
|
void NodeList::sendKillNode(const char* nodeTypes, int numNodeTypes) {
|
||||||
|
@ -674,6 +683,8 @@ void NodeList::pingPublicAndLocalSocketsForInactiveNode(Node* node) {
|
||||||
|
|
||||||
SharedNodePointer NodeList::addOrUpdateNode(const QUuid& uuid, char nodeType,
|
SharedNodePointer NodeList::addOrUpdateNode(const QUuid& uuid, char nodeType,
|
||||||
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) {
|
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) {
|
||||||
|
_nodeHashMutex.lock();
|
||||||
|
|
||||||
SharedNodePointer matchingNode = _nodeHash.value(uuid);
|
SharedNodePointer matchingNode = _nodeHash.value(uuid);
|
||||||
|
|
||||||
if (!matchingNode) {
|
if (!matchingNode) {
|
||||||
|
@ -683,13 +694,17 @@ SharedNodePointer NodeList::addOrUpdateNode(const QUuid& uuid, char nodeType,
|
||||||
|
|
||||||
_nodeHash.insert(newNode->getUUID(), newNodeSharedPointer);
|
_nodeHash.insert(newNode->getUUID(), newNodeSharedPointer);
|
||||||
|
|
||||||
|
_nodeHashMutex.unlock();
|
||||||
|
|
||||||
qDebug() << "Added" << *newNode;
|
qDebug() << "Added" << *newNode;
|
||||||
|
|
||||||
emit nodeAdded(newNodeSharedPointer);
|
emit nodeAdded(newNodeSharedPointer);
|
||||||
|
|
||||||
return newNodeSharedPointer;
|
return newNodeSharedPointer;
|
||||||
} else {
|
} else {
|
||||||
QMutexLocker(&matchingNode->getMutex());
|
_nodeHashMutex.unlock();
|
||||||
|
|
||||||
|
QMutexLocker locker(&matchingNode->getMutex());
|
||||||
|
|
||||||
if (matchingNode->getType() == NODE_TYPE_AUDIO_MIXER ||
|
if (matchingNode->getType() == NODE_TYPE_AUDIO_MIXER ||
|
||||||
matchingNode->getType() == NODE_TYPE_VOXEL_SERVER ||
|
matchingNode->getType() == NODE_TYPE_VOXEL_SERVER ||
|
||||||
|
@ -781,24 +796,27 @@ SharedNodePointer NodeList::soloNodeOfType(char nodeType) {
|
||||||
|
|
||||||
void NodeList::removeSilentNodes() {
|
void NodeList::removeSilentNodes() {
|
||||||
|
|
||||||
|
_nodeHashMutex.lock();
|
||||||
|
|
||||||
NodeHash::iterator nodeItem = _nodeHash.begin();
|
NodeHash::iterator nodeItem = _nodeHash.begin();
|
||||||
|
|
||||||
while (nodeItem != _nodeHash.end()) {
|
while (nodeItem != _nodeHash.end()) {
|
||||||
SharedNodePointer node = nodeItem.value();
|
SharedNodePointer node = nodeItem.value();
|
||||||
|
|
||||||
QMutexLocker(&node->getMutex());
|
node->getMutex().lock();
|
||||||
|
|
||||||
if ((usecTimestampNow() - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) {
|
if ((usecTimestampNow() - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) {
|
||||||
// call our private method to kill this node (removes it and emits the right signal)
|
// call our private method to kill this node (removes it and emits the right signal)
|
||||||
NodeHash::iterator previousNodeItem = nodeItem;
|
nodeItem = killNodeAtHashIterator(nodeItem);
|
||||||
++nodeItem;
|
|
||||||
|
|
||||||
killNodeAtHashIterator(previousNodeItem);
|
|
||||||
} else {
|
} else {
|
||||||
// we didn't kill this node, push the iterator forwards
|
// we didn't kill this node, push the iterator forwards
|
||||||
++nodeItem;
|
++nodeItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node->getMutex().unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_nodeHashMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString QSETTINGS_GROUP_NAME = "NodeList";
|
const QString QSETTINGS_GROUP_NAME = "NodeList";
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <unistd.h> // not on windows, not needed for mac or windows
|
#include <unistd.h> // not on windows, not needed for mac or windows
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <QtCore/QMutex>
|
||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
#include <QtNetwork/QHostAddress>
|
#include <QtNetwork/QHostAddress>
|
||||||
|
@ -81,7 +82,7 @@ public:
|
||||||
|
|
||||||
void(*linkedDataCreateCallback)(Node *);
|
void(*linkedDataCreateCallback)(Node *);
|
||||||
|
|
||||||
const NodeHash& getNodeHash() { return _nodeHash; }
|
NodeHash getNodeHash();
|
||||||
int size() const { return _nodeHash.size(); }
|
int size() const { return _nodeHash.size(); }
|
||||||
|
|
||||||
int getNumNoReplyDomainCheckIns() const { return _numNoReplyDomainCheckIns; }
|
int getNumNoReplyDomainCheckIns() const { return _numNoReplyDomainCheckIns; }
|
||||||
|
@ -140,9 +141,10 @@ private:
|
||||||
void processSTUNResponse(unsigned char* packetData, size_t dataBytes);
|
void processSTUNResponse(unsigned char* packetData, size_t dataBytes);
|
||||||
|
|
||||||
void processKillNode(unsigned char* packetData, size_t dataBytes);
|
void processKillNode(unsigned char* packetData, size_t dataBytes);
|
||||||
void killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill);
|
NodeHash::iterator killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill);
|
||||||
|
|
||||||
NodeHash _nodeHash;
|
NodeHash _nodeHash;
|
||||||
|
QMutex _nodeHashMutex;
|
||||||
QString _domainHostname;
|
QString _domainHostname;
|
||||||
HifiSockAddr _domainSockAddr;
|
HifiSockAddr _domainSockAddr;
|
||||||
QUdpSocket _nodeSocket;
|
QUdpSocket _nodeSocket;
|
||||||
|
|
Loading…
Reference in a new issue