Updated Nodelist class

This commit is contained in:
Atlante45 2014-12-17 15:27:35 -08:00
parent ce7f72d2cd
commit 52f2033dce
2 changed files with 13 additions and 30 deletions

View file

@ -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<LimitedNodeList>(new NodeList(ownerType, socketListenPort, dtlsPort));
// register the SharedNodePointer meta-type for signals/slots
qRegisterMetaType<SharedNodePointer>();
return static_cast<NodeList*>(_sharedInstance.get());
}
NodeList* NodeList::getInstance() {
if (!_sharedInstance.get()) {
qDebug("NodeList getInstance called before call to createInstance. Returning NULL pointer.");
}
return static_cast<NodeList*>(_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<SharedNodePointer>();
firstCall = false;
}
// clear our NodeList when the domain changes
connect(&_domainHandler, &DomainHandler::disconnectedFromDomain, this, &NodeList::reset);

View file

@ -14,6 +14,7 @@
#include <stdint.h>
#include <iterator>
#include <assert.h>
#ifndef _WIN32
#include <unistd.h> // 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