mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:35:08 +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
|
||||
NodeList* nodeList = NodeList::createInstance(NodeType::Agent, listenPort);
|
||||
|
||||
qDebug() << "NL pointer is" << nodeList;
|
||||
|
||||
nodeList->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");
|
||||
|
||||
LimitedNodeList* LimitedNodeList::_sharedInstance = NULL;
|
||||
std::auto_ptr<LimitedNodeList> LimitedNodeList::_sharedInstance;
|
||||
|
||||
LimitedNodeList* LimitedNodeList::createInstance(unsigned short socketListenPort, unsigned short dtlsPort) {
|
||||
if (!_sharedInstance) {
|
||||
NodeType::init();
|
||||
|
||||
_sharedInstance = new LimitedNodeList(socketListenPort, dtlsPort);
|
||||
NodeType::init();
|
||||
|
||||
delete _sharedInstance.release();
|
||||
_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
|
||||
qRegisterMetaType<SharedNodePointer>();
|
||||
} else {
|
||||
qDebug("LimitedNodeList createInstance called with existing instance.");
|
||||
}
|
||||
|
||||
return _sharedInstance;
|
||||
return _sharedInstance.get();
|
||||
}
|
||||
|
||||
LimitedNodeList* LimitedNodeList::getInstance() {
|
||||
if (!_sharedInstance) {
|
||||
if (!_sharedInstance.get()) {
|
||||
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 publicSockAddrChanged(const HifiSockAddr& publicSockAddr);
|
||||
protected:
|
||||
static LimitedNodeList* _sharedInstance;
|
||||
static std::auto_ptr<LimitedNodeList> _sharedInstance;
|
||||
|
||||
LimitedNodeList(unsigned short socketListenPort, unsigned short dtlsListenPort);
|
||||
LimitedNodeList(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||
|
|
|
@ -24,30 +24,25 @@
|
|||
#include "SharedUtil.h"
|
||||
#include "UUID.h"
|
||||
|
||||
NodeList* NodeList::_sharedInstance = NULL;
|
||||
|
||||
NodeList* NodeList::createInstance(char ownerType, unsigned short socketListenPort, unsigned short dtlsPort) {
|
||||
if (!_sharedInstance) {
|
||||
NodeType::init();
|
||||
|
||||
_sharedInstance = new NodeList(ownerType, socketListenPort, dtlsPort);
|
||||
LimitedNodeList::_sharedInstance = _sharedInstance;
|
||||
|
||||
// register the SharedNodePointer meta-type for signals/slots
|
||||
qRegisterMetaType<SharedNodePointer>();
|
||||
} else {
|
||||
qDebug("NodeList createInstance called with existing instance.");
|
||||
}
|
||||
|
||||
return _sharedInstance;
|
||||
|
||||
NodeType::init();
|
||||
|
||||
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) {
|
||||
if (!_sharedInstance.get()) {
|
||||
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) :
|
||||
|
|
|
@ -84,8 +84,6 @@ public slots:
|
|||
signals:
|
||||
void limitOfSilentDomainCheckInsReached();
|
||||
private:
|
||||
static NodeList* _sharedInstance;
|
||||
|
||||
NodeList(char ownerType, unsigned short socketListenPort, unsigned short dtlsListenPort);
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue