From 50532bc67d07076aa3039ecd63435ab15ac23841 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 20 Aug 2013 11:42:30 -0700 Subject: [PATCH] added NodeListHook to JurisdictionListener to properly remove nodes that are killed --- libraries/voxels/src/JurisdictionListener.cpp | 15 +++++++++++++++ libraries/voxels/src/JurisdictionListener.h | 10 +++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/libraries/voxels/src/JurisdictionListener.cpp b/libraries/voxels/src/JurisdictionListener.cpp index ceb2fbcf0c..ea8bea3a2d 100644 --- a/libraries/voxels/src/JurisdictionListener.cpp +++ b/libraries/voxels/src/JurisdictionListener.cpp @@ -19,6 +19,21 @@ JurisdictionListener::JurisdictionListener(PacketSenderNotify* notify) : PacketSender(notify, JurisdictionListener::DEFAULT_PACKETS_PER_SECOND) { + NodeList* nodeList = NodeList::getInstance(); + nodeList->addHook(this); +} + +JurisdictionListener::~JurisdictionListener() { + NodeList* nodeList = NodeList::getInstance(); + nodeList->removeHook(this); +} + +void JurisdictionListener::nodeAdded(Node* node) { + // nothing to do. But need to implement it. +} + +void JurisdictionListener::nodeKilled(Node* node) { + _jurisdictions.erase(_jurisdictions.find(node->getNodeID())); } bool JurisdictionListener::queueJurisdictionRequest() { diff --git a/libraries/voxels/src/JurisdictionListener.h b/libraries/voxels/src/JurisdictionListener.h index 4b5d2d1fa4..0a614446ed 100644 --- a/libraries/voxels/src/JurisdictionListener.h +++ b/libraries/voxels/src/JurisdictionListener.h @@ -11,6 +11,7 @@ #ifndef __shared__JurisdictionListener__ #define __shared__JurisdictionListener__ +#include #include #include @@ -20,15 +21,22 @@ /// the PACKET_TYPE_VOXEL_JURISDICTION packets it receives in order to maintain an accurate state of all jurisidictions /// within the domain. As with other ReceivedPacketProcessor classes the user is responsible for reading inbound packets /// and adding them to the processing queue by calling queueReceivedPacket() -class JurisdictionListener : public PacketSender, public ReceivedPacketProcessor { +class JurisdictionListener : public NodeListHook, public PacketSender, public ReceivedPacketProcessor { public: static const int DEFAULT_PACKETS_PER_SECOND = 1; JurisdictionListener(PacketSenderNotify* notify = NULL); + ~JurisdictionListener(); + virtual bool process(); NodeToJurisdictionMap* getJurisdictions() { return &_jurisdictions; }; + /// Called by NodeList to inform us that a node has been added. + void nodeAdded(Node* node); + /// Called by NodeList to inform us that a node has been killed. + void nodeKilled(Node* node); + protected: /// Callback for processing of received packets. Will process any queued PACKET_TYPE_VOXEL_JURISDICTION and update the /// jurisdiction map member variable