diff --git a/include/openspace/engine/downloadmanager.h b/include/openspace/engine/downloadmanager.h index ad9f6ec105..cabcf0a14b 100644 --- a/include/openspace/engine/downloadmanager.h +++ b/include/openspace/engine/downloadmanager.h @@ -25,8 +25,6 @@ #ifndef __DOWNLOADMANAGER_H__ #define __DOWNLOADMANAGER_H__ -#include - #include #include @@ -39,7 +37,7 @@ namespace openspace { // Multithreaded -class DownloadManager : public ghoul::Singleton { +class DownloadManager { public: struct FileFuture { // Since the FileFuture object will be used from multiple threads, we have to be @@ -119,8 +117,6 @@ private: bool _useMultithreadedDownload; }; -#define DlManager (openspace::DownloadManager::ref()) - } // namespace openspace #endif // __DOWNLOADMANAGER_H__ diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index f8b614b8ad..2261ba879a 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -43,6 +43,7 @@ namespace fontrendering { class FontManager; } namespace openspace { class ConfigurationManager; +class DownloadManager; class LuaConsole; class NetworkEngine; class GUI; @@ -84,6 +85,7 @@ public: properties::PropertyOwner& globalPropertyOwner(); WindowWrapper& windowWrapper(); ghoul::fontrendering::FontManager& fontManager(); + DownloadManager& downloadManager(); #ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED gui::GUI& gui(); @@ -132,6 +134,7 @@ private: std::unique_ptr _console; std::unique_ptr _moduleEngine; std::unique_ptr _settingsEngine; + std::unique_ptr _downloadManager; #ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED std::unique_ptr _gui; #endif diff --git a/modules/base/rendering/screenspaceimage.cpp b/modules/base/rendering/screenspaceimage.cpp index f77f81ee4e..bf2dc21cbe 100644 --- a/modules/base/rendering/screenspaceimage.cpp +++ b/modules/base/rendering/screenspaceimage.cpp @@ -171,7 +171,7 @@ void ScreenSpaceImage::updateTexture() { std::future ScreenSpaceImage::downloadImageToMemory( std::string url) { - return std::move(DlManager.fetchFile( + return std::move(OsEng.downloadManager().fetchFile( url, [url](const DownloadManager::MemoryFile& file) { LDEBUG("Download to memory finished for screen space image"); diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index 2c09988a24..2b0728698b 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -84,7 +84,7 @@ IswaManager::IswaManager() _geom[CygnetGeometry::Plane] = "Plane"; _geom[CygnetGeometry::Sphere] = "Sphere"; - DlManager.fetchFile( + OsEng.downloadManager().fetchFile( "http://iswa3.ccmc.gsfc.nasa.gov/IswaSystemWebApp/CygnetHealthServlet", [this](const DownloadManager::MemoryFile& file){ fillCygnetInfo(std::string(file.buffer)); @@ -146,7 +146,7 @@ void IswaManager::addIswaCygnet(int id, std::string type, std::string group){ }; // Download metadata - DlManager.fetchFile( + OsEng.downloadManager().fetchFile( baseUrl + std::to_string(-id), metadataCallback, [id](const std::string& err){ @@ -170,7 +170,7 @@ void IswaManager::addKameleonCdf(std::string groupName, int pos){ } std::future IswaManager::fetchImageCygnet(int id, double timestamp){ - return std::move( DlManager.fetchFile( + return std::move(OsEng.downloadManager().fetchFile( iswaUrl(id, timestamp, "image"), [id](const DownloadManager::MemoryFile& file){ LDEBUG("Download to memory finished for image cygnet with id: " + std::to_string(id)); @@ -182,7 +182,7 @@ std::future IswaManager::fetchImageCygnet(int id, d } std::future IswaManager::fetchDataCygnet(int id, double timestamp){ - return std::move( DlManager.fetchFile( + return std::move(OsEng.downloadManager().fetchFile( iswaUrl(id, timestamp, "data"), [id](const DownloadManager::MemoryFile& file){ LDEBUG("Download to memory finished for data cygnet with id: " + std::to_string(id)); @@ -261,7 +261,7 @@ std::shared_ptr IswaManager::downloadMetadata(int id){ std::shared_ptr metaFuture = std::make_shared(); metaFuture->id = id; - DlManager.fetchFile( + OsEng.downloadManager().fetchFile( baseUrl + std::to_string(-id), [&metaFuture](const DownloadManager::MemoryFile& file){ metaFuture->json = std::string(file.buffer, file.size); diff --git a/src/engine/downloadmanager.cpp b/src/engine/downloadmanager.cpp index ce3f731edd..623d0f2089 100644 --- a/src/engine/downloadmanager.cpp +++ b/src/engine/downloadmanager.cpp @@ -160,9 +160,9 @@ std::shared_ptr DownloadManager::downloadFile( return nullptr; std::shared_ptr future = std::make_shared(file.filename()); - errno = 0; + errno = 0; FILE* fp = fopen(file.path().c_str(), "wb"); // write binary - ghoul_assert(fp != nullptr, "Could not open/create file:\n" << file.path().c_str() << " \nerrno: " << errno); + ghoul_assert(fp != nullptr, "Could not open/create file:\n" << file.path().c_str() << " \nerrno: " << errno); //LDEBUG("Start downloading file: '" << url << "' into file '" << file.path() << "'"); @@ -293,7 +293,7 @@ std::vector> DownloadManager::downl LDEBUG("Request File: " << requestFile); bool isFinished = false; - auto callback = [&futures, destination, &progressCallback, &isFinished, requestFile, overrideFiles](const FileFuture& f) { + auto callback = [&](const FileFuture& f) { LDEBUG("Finished: " << requestFile); std::ifstream temporary(requestFile); std::string line; @@ -310,7 +310,7 @@ std::vector> DownloadManager::downl LDEBUG("\tLine: " << line << " ; Dest: " << destination.path() + "/" + file); - std::shared_ptr future = DlManager.downloadFile( + std::shared_ptr future = downloadFile( line, destination.path() + "/" + file, overrideFiles, diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 82da0b23c4..2cf8464123 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -130,6 +130,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName, , _console(new LuaConsole) , _moduleEngine(new ModuleEngine) , _settingsEngine(new SettingsEngine) + , _downloadManager(nullptr) #ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED , _gui(new gui::GUI) #endif @@ -364,8 +365,9 @@ bool OpenSpaceEngine::initialize() { std::string requestURL = ""; bool success = configurationManager().getValue(ConfigurationManager::KeyDownloadRequestURL, requestURL); - if (success) - DownloadManager::initialize(requestURL, DownloadVersion); + if (success) { + _downloadManager = std::make_unique(requestURL, DownloadVersion); + } // Load SPICE time kernel success = loadSpiceKernels(); @@ -1006,4 +1008,10 @@ ghoul::fontrendering::FontManager& OpenSpaceEngine::fontManager() { return *_fontManager; } +DownloadManager& OpenSpaceEngine::downloadManager() { + ghoul_assert(_downloadManager, "Download Manager must not be nullptr"); + return *_downloadManager; +} + + } // namespace openspace