mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 03:29:44 -06:00
Issue/591 add assets file browsing (#3798)
* create download event topic wip * Make topic connection thread safe & rate limit downloadeventtopic data to reduce traffic * add LDEBUG and LERROR on donwload start/finish/failed * Add new AssetLoadingEvent event * fix pr comments
This commit is contained in:
@@ -35,6 +35,7 @@ namespace openspace {
|
||||
struct Configuration;
|
||||
class Dashboard;
|
||||
class DeferredcasterManager;
|
||||
class DownloadEventEngine;
|
||||
class DownloadManager;
|
||||
class EventEngine;
|
||||
class LuaConsole;
|
||||
@@ -72,6 +73,7 @@ namespace global {
|
||||
inline ghoul::fontrendering::FontManager* fontManager;
|
||||
inline Dashboard* dashboard;
|
||||
inline DeferredcasterManager* deferredcasterManager;
|
||||
inline DownloadEventEngine* downloadEventEngine;
|
||||
inline DownloadManager* downloadManager;
|
||||
inline EventEngine* eventEngine;
|
||||
inline LuaConsole* luaConsole;
|
||||
|
||||
@@ -60,7 +60,7 @@ struct Event {
|
||||
enum class Type : uint8_t {
|
||||
ParallelConnection,
|
||||
ProfileLoadingFinished,
|
||||
AssetLoadingFinished,
|
||||
AssetLoading,
|
||||
ApplicationShutdown,
|
||||
CameraFocusTransition,
|
||||
TimeOfInterestReached,
|
||||
@@ -152,17 +152,32 @@ struct EventProfileLoadingFinished : public Event {
|
||||
};
|
||||
|
||||
/**
|
||||
* This event is created when the loading of all assets are finished. This is emitted
|
||||
* regardless of whether it is the initial startup of a profile, or any subsequent asset
|
||||
* being loaded e.g., through add or drag-and-drop.
|
||||
* This event is created whenever the loading state of an assets changes. An asset can
|
||||
* enter one of four states: `Loading`, `Loaded`, `Unloaded`, or `Error`. This event is
|
||||
* emitted regardless of whether it is the initial startup of a profile, or any subsequent
|
||||
* asset being added or revmoed e.g., through add or drag-and-drop.
|
||||
*/
|
||||
struct EventAssetLoadingFinished : public Event {
|
||||
static constexpr Type Type = Event::Type::AssetLoadingFinished;
|
||||
struct EventAssetLoading : public Event {
|
||||
static constexpr Type Type = Event::Type::AssetLoading;
|
||||
|
||||
enum class State {
|
||||
Loaded,
|
||||
Loading,
|
||||
Unloaded,
|
||||
Error
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an instance of an AssetLoadingFinished event.
|
||||
* Creates an instance of an AssetLoading event.
|
||||
*
|
||||
* \param assetPath_ The path to the asset
|
||||
* \param state_ The new state of the asset given by 'asstPath_'; is one of `Loading`,
|
||||
* `Loaded`, `Unloaded`, or `Error`
|
||||
*/
|
||||
EventAssetLoadingFinished();
|
||||
EventAssetLoading(const std::filesystem::path& assetPath_, State newState);
|
||||
|
||||
std::filesystem::path assetPath;
|
||||
State state;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -207,6 +207,14 @@ public:
|
||||
*/
|
||||
bool hasInitializedParent() const;
|
||||
|
||||
/**
|
||||
* Returns a list of the parents of this Asset that is currently in an initialized
|
||||
* state, meaning any parent that is still interested in this Asset at all.
|
||||
*
|
||||
* \return A list of parent filepaths that are interested in this asset
|
||||
*/
|
||||
std::vector<std::filesystem::path> initializedParents() const;
|
||||
|
||||
/**
|
||||
* Deinitializes this Asset and recursively deinitializes the required assets if this
|
||||
* Asset was their ownly initialized parent. If the Asset was already deinitialized,
|
||||
|
||||
72
include/openspace/util/downloadeventengine.h
Normal file
72
include/openspace/util/downloadeventengine.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2025 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_MODULE_SYNC___DOWNLOAD_EVENT_ENGINE___H__
|
||||
#define __OPENSPACE_MODULE_SYNC___DOWNLOAD_EVENT_ENGINE___H__
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
// @TODO (anden88 2025-10-10): This class was specifically written for the multi-threaded
|
||||
// url- and httpSynchronization events. In the future we should make this more general
|
||||
// purposed.
|
||||
class DownloadEventEngine {
|
||||
public:
|
||||
struct DownloadEvent {
|
||||
enum class Type {
|
||||
Started,
|
||||
Progress,
|
||||
Finished,
|
||||
Failed
|
||||
};
|
||||
|
||||
Type type;
|
||||
std::string id;
|
||||
int64_t downloadedBytes;
|
||||
std::optional<int64_t> totalBytes;
|
||||
};
|
||||
|
||||
using Callback = std::function<void(const DownloadEvent&)>;
|
||||
|
||||
int subscribe(Callback cb);
|
||||
void unsubscribe(int id);
|
||||
|
||||
void publish(const DownloadEvent& event);
|
||||
void publish(const std::string& id, DownloadEvent::Type type,
|
||||
int64_t downloadedBytes = 0, std::optional<int64_t> totalBytes = std::nullopt);
|
||||
|
||||
private:
|
||||
std::mutex _mutex;
|
||||
int _id = 0;
|
||||
std::unordered_map<int, Callback> _subscribers;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_SYNC___DOWNLOAD_EVENT_ENGINE___H__
|
||||
Reference in New Issue
Block a user