mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 03:48:44 +02:00
use auto_ptr in NodeList and LimitedNodeList for cleaner mem management
This commit is contained in:
parent
fed7dad2b6
commit
9950ed9f9f
5 changed files with 26 additions and 34 deletions
|
@ -232,6 +232,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
|
|
||||||
// put the NodeList and datagram processing on the node thread
|
// put the NodeList and datagram processing on the node thread
|
||||||
NodeList* nodeList = NodeList::createInstance(NodeType::Agent, listenPort);
|
NodeList* nodeList = NodeList::createInstance(NodeType::Agent, listenPort);
|
||||||
|
|
||||||
|
qDebug() << "NL pointer is" << nodeList;
|
||||||
|
|
||||||
nodeList->moveToThread(_nodeThread);
|
nodeList->moveToThread(_nodeThread);
|
||||||
_datagramProcessor.moveToThread(_nodeThread);
|
_datagramProcessor.moveToThread(_nodeThread);
|
||||||
|
|
|
@ -35,29 +35,26 @@ const char SOLO_NODE_TYPES[2] = {
|
||||||
|
|
||||||
const QUrl DEFAULT_NODE_AUTH_URL = QUrl("https://data.highfidelity.io");
|
const QUrl DEFAULT_NODE_AUTH_URL = QUrl("https://data.highfidelity.io");
|
||||||
|
|
||||||
LimitedNodeList* LimitedNodeList::_sharedInstance = NULL;
|
std::auto_ptr<LimitedNodeList> LimitedNodeList::_sharedInstance;
|
||||||
|
|
||||||
LimitedNodeList* LimitedNodeList::createInstance(unsigned short socketListenPort, unsigned short dtlsPort) {
|
LimitedNodeList* LimitedNodeList::createInstance(unsigned short socketListenPort, unsigned short dtlsPort) {
|
||||||
if (!_sharedInstance) {
|
NodeType::init();
|
||||||
NodeType::init();
|
|
||||||
|
delete _sharedInstance.release();
|
||||||
_sharedInstance = new LimitedNodeList(socketListenPort, dtlsPort);
|
_sharedInstance = std::auto_ptr<LimitedNodeList>(new LimitedNodeList(socketListenPort, dtlsPort));
|
||||||
|
|
||||||
|
// register the SharedNodePointer meta-type for signals/slots
|
||||||
|
qRegisterMetaType<SharedNodePointer>();
|
||||||
|
|
||||||
// register the SharedNodePointer meta-type for signals/slots
|
return _sharedInstance.get();
|
||||||
qRegisterMetaType<SharedNodePointer>();
|
|
||||||
} else {
|
|
||||||
qDebug("LimitedNodeList createInstance called with existing instance.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return _sharedInstance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LimitedNodeList* LimitedNodeList::getInstance() {
|
LimitedNodeList* LimitedNodeList::getInstance() {
|
||||||
if (!_sharedInstance) {
|
if (!_sharedInstance.get()) {
|
||||||
qDebug("LimitedNodeList getInstance called before call to createInstance. Returning NULL pointer.");
|
qDebug("LimitedNodeList getInstance called before call to createInstance. Returning NULL pointer.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return _sharedInstance;
|
return _sharedInstance.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ signals:
|
||||||
void nodeKilled(SharedNodePointer);
|
void nodeKilled(SharedNodePointer);
|
||||||
void publicSockAddrChanged(const HifiSockAddr& publicSockAddr);
|
void publicSockAddrChanged(const HifiSockAddr& publicSockAddr);
|
||||||
protected:
|
protected:
|
||||||
static LimitedNodeList* _sharedInstance;
|
static std::auto_ptr<LimitedNodeList> _sharedInstance;
|
||||||
|
|
||||||
LimitedNodeList(unsigned short socketListenPort, unsigned short dtlsListenPort);
|
LimitedNodeList(unsigned short socketListenPort, unsigned short dtlsListenPort);
|
||||||
LimitedNodeList(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton
|
LimitedNodeList(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||||
|
|
|
@ -24,30 +24,25 @@
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
#include "UUID.h"
|
#include "UUID.h"
|
||||||
|
|
||||||
NodeList* NodeList::_sharedInstance = NULL;
|
|
||||||
|
|
||||||
NodeList* NodeList::createInstance(char ownerType, unsigned short socketListenPort, unsigned short dtlsPort) {
|
NodeList* NodeList::createInstance(char ownerType, unsigned short socketListenPort, unsigned short dtlsPort) {
|
||||||
if (!_sharedInstance) {
|
|
||||||
NodeType::init();
|
NodeType::init();
|
||||||
|
|
||||||
_sharedInstance = new NodeList(ownerType, socketListenPort, dtlsPort);
|
delete _sharedInstance.release();
|
||||||
LimitedNodeList::_sharedInstance = _sharedInstance;
|
_sharedInstance = std::auto_ptr<LimitedNodeList>(new NodeList(ownerType, socketListenPort, dtlsPort));
|
||||||
|
|
||||||
// register the SharedNodePointer meta-type for signals/slots
|
// register the SharedNodePointer meta-type for signals/slots
|
||||||
qRegisterMetaType<SharedNodePointer>();
|
qRegisterMetaType<SharedNodePointer>();
|
||||||
} else {
|
|
||||||
qDebug("NodeList createInstance called with existing instance.");
|
return static_cast<NodeList*>(_sharedInstance.get());
|
||||||
}
|
|
||||||
|
|
||||||
return _sharedInstance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeList* NodeList::getInstance() {
|
NodeList* NodeList::getInstance() {
|
||||||
if (!_sharedInstance) {
|
if (!_sharedInstance.get()) {
|
||||||
qDebug("NodeList getInstance called before call to createInstance. Returning NULL pointer.");
|
qDebug("NodeList getInstance called before call to createInstance. Returning NULL pointer.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return _sharedInstance;
|
return static_cast<NodeList*>(_sharedInstance.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned short dtlsListenPort) :
|
NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned short dtlsListenPort) :
|
||||||
|
|
|
@ -84,8 +84,6 @@ public slots:
|
||||||
signals:
|
signals:
|
||||||
void limitOfSilentDomainCheckInsReached();
|
void limitOfSilentDomainCheckInsReached();
|
||||||
private:
|
private:
|
||||||
static NodeList* _sharedInstance;
|
|
||||||
|
|
||||||
NodeList(char ownerType, unsigned short socketListenPort, unsigned short dtlsListenPort);
|
NodeList(char ownerType, unsigned short socketListenPort, unsigned short dtlsListenPort);
|
||||||
NodeList(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
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
|
void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||||
|
|
Loading…
Reference in a new issue