diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f1aa0ee873..517c229185 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -201,6 +201,7 @@ bool setupEssentials(int& argc, char** argv) { auto lodManager = DependencyManager::set(); auto jsConsole = DependencyManager::set(); auto dialogsManager = DependencyManager::set(); + auto bandwidthRecorder = DependencyManager::set(); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) auto speechRecognizer = DependencyManager::set(); #endif @@ -434,10 +435,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(this, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit())); // hook up bandwidth estimator + QSharedPointer bandwidthRecorder = DependencyManager::get(); connect(nodeList.data(), SIGNAL(dataSent(const quint8, const int)), - &_bandwidthRecorder, SLOT(updateOutboundData(const quint8, const int))); + &*bandwidthRecorder, SLOT(updateOutboundData(const quint8, const int))); connect(nodeList.data(), SIGNAL(dataReceived(const quint8, const int)), - &_bandwidthRecorder, SLOT(updateInboundData(const quint8, const int))); + &*bandwidthRecorder, SLOT(updateInboundData(const quint8, const int))); // check first run... bool firstRun = SettingHandles::firstRun.get(); diff --git a/interface/src/Application.h b/interface/src/Application.h index 510843758b..dee323aa52 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -202,7 +202,6 @@ public: bool getLastMouseMoveWasSimulated() const { return _lastMouseMoveWasSimulated; } FaceTracker* getActiveFaceTracker(); - BandwidthRecorder* getBandwidthRecorder() { return &_bandwidthRecorder; } QSystemTrayIcon* getTrayIcon() { return _trayIcon; } ApplicationOverlay& getApplicationOverlay() { return _applicationOverlay; } Overlays& getOverlays() { return _overlays; } @@ -484,9 +483,6 @@ private: OctreeQuery _octreeQuery; // NodeData derived class for querying octee cells from octree servers - BandwidthRecorder _bandwidthRecorder; - - AvatarManager _avatarManager; MyAvatar* _myAvatar; // TODO: move this and relevant code to AvatarManager (or MyAvatar as the case may be) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 818aab4a92..f63afb5aee 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -904,7 +904,7 @@ void ApplicationOverlay::renderAudioMeter() { void ApplicationOverlay::renderStatsAndLogs() { Application* application = Application::getInstance(); - BandwidthRecorder* bandwidthRecorder = Application::getInstance()->getBandwidthRecorder(); + QSharedPointer bandwidthRecorder = DependencyManager::get(); auto glCanvas = DependencyManager::get(); const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor(); diff --git a/interface/src/ui/BandwidthDialog.cpp b/interface/src/ui/BandwidthDialog.cpp index 0a1bf78871..c22bd5dec7 100644 --- a/interface/src/ui/BandwidthDialog.cpp +++ b/interface/src/ui/BandwidthDialog.cpp @@ -52,9 +52,8 @@ void BandwidthChannelDisplay::Paint() { -BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthRecorder* model) : - QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint), - _model(model) { +BandwidthDialog::BandwidthDialog(QWidget* parent) : + QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) { this->setWindowTitle("Bandwidth Details"); @@ -62,12 +61,14 @@ BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthRecorder* model) : QFormLayout* form = new QFormLayout(); this->QDialog::setLayout(form); - _allChannelDisplays[0] = _audioChannelDisplay = new BandwidthChannelDisplay(&_model->audioChannel, form); - _allChannelDisplays[1] = _avatarsChannelDisplay = new BandwidthChannelDisplay(&_model->avatarsChannel, form); - _allChannelDisplays[2] = _octreeChannelDisplay = new BandwidthChannelDisplay(&_model->octreeChannel, form); - _allChannelDisplays[3] = _metavoxelsChannelDisplay = new BandwidthChannelDisplay(&_model->metavoxelsChannel, form); - _allChannelDisplays[4] = _otherChannelDisplay = new BandwidthChannelDisplay(&_model->otherChannel, form); - _allChannelDisplays[5] = _totalChannelDisplay = new BandwidthChannelDisplay(&_model->totalChannel, form); + QSharedPointer bandwidthRecorder = DependencyManager::get(); + + _allChannelDisplays[0] = _audioChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->audioChannel, form); + _allChannelDisplays[1] = _avatarsChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->avatarsChannel, form); + _allChannelDisplays[2] = _octreeChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->octreeChannel, form); + _allChannelDisplays[3] = _metavoxelsChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->metavoxelsChannel,form); + _allChannelDisplays[4] = _otherChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->otherChannel, form); + _allChannelDisplays[5] = _totalChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->totalChannel, form); connect(averageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateTimerTimeout())); averageUpdateTimer->start(1000); diff --git a/interface/src/ui/BandwidthDialog.h b/interface/src/ui/BandwidthDialog.h index ecf087cf63..27d58dc1a3 100644 --- a/interface/src/ui/BandwidthDialog.h +++ b/interface/src/ui/BandwidthDialog.h @@ -27,10 +27,8 @@ class BandwidthChannelDisplay : public QObject { void Paint(); private: - BandwidthRecorder::Channel *ch; QLabel* label; - // std::string strBuf; QString strBuf; public slots: @@ -41,8 +39,7 @@ class BandwidthChannelDisplay : public QObject { class BandwidthDialog : public QDialog { Q_OBJECT public: - // Sets up the UI based on the configuration of the BandwidthRecorder - BandwidthDialog(QWidget* parent, BandwidthRecorder* model); + BandwidthDialog(QWidget* parent); ~BandwidthDialog(); void paintEvent(QPaintEvent*); @@ -75,7 +72,6 @@ protected: void closeEvent(QCloseEvent*); private: - BandwidthRecorder* _model; QTimer *averageUpdateTimer = new QTimer(this); }; diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index fa04429bf2..752e205a6a 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -102,7 +102,7 @@ void DialogsManager::editAnimations() { void DialogsManager::bandwidthDetails() { if (! _bandwidthDialog) { - _bandwidthDialog = new BandwidthDialog(qApp->getWindow(), qApp->getBandwidthRecorder()); + _bandwidthDialog = new BandwidthDialog(qApp->getWindow()); connect(_bandwidthDialog, SIGNAL(closed()), _bandwidthDialog, SLOT(deleteLater())); if (_hmdToolsDialog) { diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 746c2fafbe..a29722825f 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -25,6 +25,7 @@ #include #include "Stats.h" +#include "BandwidthRecorder.h" #include "InterfaceConfig.h" #include "Menu.h" #include "Util.h" @@ -216,7 +217,7 @@ void Stats::display( QLocale locale(QLocale::English); std::stringstream octreeStats; - BandwidthRecorder* bandwidthRecorder = Application::getInstance()->getBandwidthRecorder(); + QSharedPointer bandwidthRecorder = DependencyManager::get(); if (_lastHorizontalOffset != horizontalOffset) { resetWidth(glCanvas->width(), horizontalOffset); diff --git a/libraries/networking/src/BandwidthRecorder.h b/libraries/networking/src/BandwidthRecorder.h index 63b8f7e163..5837702783 100644 --- a/libraries/networking/src/BandwidthRecorder.h +++ b/libraries/networking/src/BandwidthRecorder.h @@ -17,6 +17,7 @@ #include #include #include +#include "DependencyManager.h" #include "Node.h" #include "SimpleMovingAverage.h" @@ -27,8 +28,9 @@ const unsigned int COLOR1 = 0xffef40c0; const unsigned int COLOR2 = 0xd0d0d0a0; -class BandwidthRecorder : public QObject { +class BandwidthRecorder : public QObject, public Dependency { Q_OBJECT + SINGLETON_DEPENDENCY public: BandwidthRecorder();