From 77a78148549f27448cf4dab496fbf72d52d6bf96 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 24 Sep 2015 18:48:26 +0200 Subject: [PATCH] Move sendPingPackets --- interface/src/Application.cpp | 54 ++++++-------------- interface/src/Application.h | 2 - libraries/networking/src/LimitedNodeList.cpp | 16 ++++++ libraries/networking/src/LimitedNodeList.h | 1 + 4 files changed, 34 insertions(+), 39 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ef9b91e639..f5c87e1b96 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -163,22 +163,6 @@ extern "C" { } #endif -enum CustomEventTypes { - Lambda = QEvent::User + 1 -}; - -class LambdaEvent : public QEvent { - std::function _fun; -public: - LambdaEvent(const std::function & fun) : - QEvent(static_cast(Lambda)), _fun(fun) { - } - LambdaEvent(std::function && fun) : - QEvent(static_cast(Lambda)), _fun(fun) { - } - void call() { _fun(); } -}; - using namespace std; static QTimer* locationUpdateTimer = NULL; @@ -239,6 +223,22 @@ public: }; #endif +enum CustomEventTypes { + Lambda = QEvent::User + 1 +}; + +class LambdaEvent : public QEvent { + std::function _fun; +public: + LambdaEvent(const std::function & fun) : + QEvent(static_cast(Lambda)), _fun(fun) { + } + LambdaEvent(std::function && fun) : + QEvent(static_cast(Lambda)), _fun(fun) { + } + void call() { _fun(); } +}; + void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message); @@ -2090,29 +2090,10 @@ bool Application::acceptSnapshot(const QString& urlString) { return true; } -void Application::sendPingPackets() { - - auto nodeList = DependencyManager::get(); - - nodeList->eachMatchingNode([](const SharedNodePointer& node)->bool { - switch (node->getType()) { - case NodeType::AvatarMixer: - case NodeType::AudioMixer: - case NodeType::EntityServer: - case NodeType::AssetServer: - return true; - default: - return false; - } - }, [nodeList](const SharedNodePointer& node) { - nodeList->sendPacket(nodeList->constructPingPacket(), *node); - }); -} - // Every second, check the frame rates and other stuff void Application::checkFPS() { if (Menu::getInstance()->isOptionChecked(MenuOption::TestPing)) { - sendPingPackets(); + DependencyManager::get()->sendPingPackets(); } float diffTime = (float)_timerStart.nsecsElapsed() / 1000000000.0f; @@ -3804,7 +3785,6 @@ void Application::clearDomainOctreeDetails() { // reset the model renderer _entities.clear(); - } void Application::domainChanged(const QString& domainHostname) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 176e2524e0..5ae8219b99 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -464,8 +464,6 @@ private slots: private: void resetCameras(Camera& camera, const glm::uvec2& size); - void sendPingPackets(); - void initDisplay(); void init(); diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index c13a82f821..630c4c79bf 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -661,6 +661,22 @@ void LimitedNodeList::sendSTUNRequest() { _nodeSocket.writeDatagram(stunRequestPacket, sizeof(stunRequestPacket), _stunSockAddr); } +void LimitedNodeList::sendPingPackets() { + eachMatchingNode([](const SharedNodePointer& node)->bool { + switch (node->getType()) { + case NodeType::AvatarMixer: + case NodeType::AudioMixer: + case NodeType::EntityServer: + case NodeType::AssetServer: + return true; + default: + return false; + } + }, [&](const SharedNodePointer& node) { + sendPacket(constructPingPacket(), *node); + }); +} + void LimitedNodeList::processSTUNResponse(std::unique_ptr packet) { // check the cookie to make sure this is actually a STUN response // and read the first attribute and make sure it is a XOR_MAPPED_ADDRESS diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index abf292e65e..40c5390c7e 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -230,6 +230,7 @@ public slots: void startSTUNPublicSocketUpdate(); virtual void sendSTUNRequest(); + void sendPingPackets(); void killNodeWithUUID(const QUuid& nodeUUID);