mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-23 05:19:18 -06:00
Make the DownloadManager not a singleton (closing #43)
This commit is contained in:
@@ -25,8 +25,6 @@
|
||||
#ifndef __DOWNLOADMANAGER_H__
|
||||
#define __DOWNLOADMANAGER_H__
|
||||
|
||||
#include <ghoul/designpattern/singleton.h>
|
||||
|
||||
#include <ghoul/filesystem/file.h>
|
||||
#include <ghoul/filesystem/directory.h>
|
||||
|
||||
@@ -39,7 +37,7 @@
|
||||
namespace openspace {
|
||||
|
||||
// Multithreaded
|
||||
class DownloadManager : public ghoul::Singleton<DownloadManager> {
|
||||
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__
|
||||
|
||||
@@ -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<LuaConsole> _console;
|
||||
std::unique_ptr<ModuleEngine> _moduleEngine;
|
||||
std::unique_ptr<SettingsEngine> _settingsEngine;
|
||||
std::unique_ptr<DownloadManager> _downloadManager;
|
||||
#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED
|
||||
std::unique_ptr<gui::GUI> _gui;
|
||||
#endif
|
||||
|
||||
@@ -171,7 +171,7 @@ void ScreenSpaceImage::updateTexture() {
|
||||
std::future<DownloadManager::MemoryFile> 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");
|
||||
|
||||
@@ -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<DownloadManager::MemoryFile> 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<DownloadManager::MemoryFile> IswaManager::fetchImageCygnet(int id, d
|
||||
}
|
||||
|
||||
std::future<DownloadManager::MemoryFile> 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<MetadataFuture> IswaManager::downloadMetadata(int id){
|
||||
std::shared_ptr<MetadataFuture> metaFuture = std::make_shared<MetadataFuture>();
|
||||
|
||||
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);
|
||||
|
||||
@@ -160,9 +160,9 @@ std::shared_ptr<DownloadManager::FileFuture> DownloadManager::downloadFile(
|
||||
return nullptr;
|
||||
|
||||
std::shared_ptr<FileFuture> future = std::make_shared<FileFuture>(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<std::shared_ptr<DownloadManager::FileFuture>> 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<std::shared_ptr<DownloadManager::FileFuture>> DownloadManager::downl
|
||||
|
||||
LDEBUG("\tLine: " << line << " ; Dest: " << destination.path() + "/" + file);
|
||||
|
||||
std::shared_ptr<FileFuture> future = DlManager.downloadFile(
|
||||
std::shared_ptr<FileFuture> future = downloadFile(
|
||||
line,
|
||||
destination.path() + "/" + file,
|
||||
overrideFiles,
|
||||
|
||||
@@ -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<DownloadManager>(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
|
||||
|
||||
Reference in New Issue
Block a user