diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index bf992e7b88..f7820c9ee8 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -25,33 +25,6 @@ #include "SharedUtil.h" #include "UUID.h" -NodeList* NodeList::createInstance(char ownerType, unsigned short socketListenPort, unsigned short dtlsPort) { - - NodeType::init(); - - if (_sharedInstance.get()) { - qDebug() << "NodeList called with existing instance." << - "Releasing auto_ptr, deleting existing instance and creating a new one."; - - delete _sharedInstance.release(); - } - - _sharedInstance = std::auto_ptr(new NodeList(ownerType, socketListenPort, dtlsPort)); - - // register the SharedNodePointer meta-type for signals/slots - qRegisterMetaType(); - - return static_cast(_sharedInstance.get()); -} - -NodeList* NodeList::getInstance() { - if (!_sharedInstance.get()) { - qDebug("NodeList getInstance called before call to createInstance. Returning NULL pointer."); - } - - return static_cast(_sharedInstance.get()); -} - NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned short dtlsListenPort) : LimitedNodeList(socketListenPort, dtlsListenPort), _ownerType(newOwnerType), @@ -62,6 +35,14 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned _hasCompletedInitialSTUNFailure(false), _stunRequestsSinceSuccess(0) { + static bool firstCall = true; + if (firstCall) { + NodeType::init(); + // register the SharedNodePointer meta-type for signals/slots + qRegisterMetaType(); + firstCall = false; + } + // clear our NodeList when the domain changes connect(&_domainHandler, &DomainHandler::disconnectedFromDomain, this, &NodeList::reset); diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index 78f2f8e457..3a9ecf2405 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -14,6 +14,7 @@ #include #include +#include #ifndef _WIN32 #include // not on windows, not needed for mac or windows @@ -41,9 +42,9 @@ class Assignment; class NodeList : public LimitedNodeList { Q_OBJECT + SINGLETON_DEPENDENCY(NodeList, true) + public: - static NodeList* createInstance(char ownerType, unsigned short socketListenPort = 0, unsigned short dtlsPort = 0); - static NodeList* getInstance(); NodeType_t getOwnerType() const { return _ownerType; } void setOwnerType(NodeType_t ownerType) { _ownerType = ownerType; } @@ -72,7 +73,8 @@ public slots: signals: void limitOfSilentDomainCheckInsReached(); private: - NodeList(char ownerType, unsigned short socketListenPort, unsigned short dtlsListenPort); + NodeList() : LimitedNodeList(0, 0) { assert(false); } // Not implemented, needed for DependencyManager templates compile + NodeList(char ownerType, unsigned short socketListenPort = 0, unsigned short dtlsListenPort = 0); NodeList(NodeList const&); // Don't implement, needed to avoid copies of singleton void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton