Blender V5.3
AS_remote_library.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <chrono>
12#include <filesystem>
13#include <optional>
14
15#include "BLI_function_ref.hh"
16#include "BLI_string_ref.hh"
17#include "BLI_vector.hh"
18
20
21namespace blender {
22struct bContext;
24struct Main;
25struct ReportList;
26
27namespace asset_system {
28
42
43constexpr StringRefNull REMOTE_LIBRARY_TOP_META_FILE_NAME = "_asset-library-meta.json";
45 "/_asset-library-meta.json";
46
52
54
62
67 std::string url;
69 std::string hash;
70};
71
83
96 std::optional<URLWithHash> preview_url;
97
112};
113
115
119
124void remote_library_request_download(const RemoteLibraryDefinitionRef &library_definition);
126
128 const AssetRepresentation &asset,
129 ReportList *reports);
131 const AssetRepresentation &asset,
132 const StringRef dst_filepath,
133 ReportList *reports);
134
136
146std::string remote_library_cache_directory_path(StringRefNull library_dirname);
161
181
195 public:
202 using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
203 using FileSystemTimePoint = std::filesystem::file_time_type;
204
205 private:
206 float timeout_ = 0.0f;
207 FileSystemTimePoint loading_start_time_point_ = {};
208 TimePoint last_updated_time_point_ = {};
209 /* See #RemoteLibraryLoadingStatus::handle_timeout(). */
210 TimePoint last_timeout_handled_time_point_ = {};
211 TimePoint last_new_pages_time_point_ = {};
212
213 std::optional<Status> status_ = std::nullopt;
214 std::optional<StringRefNull> failure_message_ = std::nullopt;
215 bool metafiles_in_place_ = false;
216
217 public:
218 static void begin_loading(StringRef url, float timeout);
220 static void ping_still_loading(StringRef url);
221 static void ping_new_pages(StringRef url);
222 static void ping_new_preview(const bContext &C, StringRef preview_full_filepath);
223 static void ping_asset_file_progress(StringRef absolute_file_url, int64_t size_in_bytes);
225 static void ping_asset_file_download_succeeded(const bContext &C,
226 StringRef library_url,
227 StringRef absolute_file_url,
228 StringRef local_file_abspath);
233 static void ping_asset_file_download_failed(const bContext &C,
234 StringRef library_url,
235 StringRef absolute_file_url,
236 StringRef local_file_abspath);
241 static void ping_download_queue_done(const bContext &C);
242 static void ping_metafiles_in_place(StringRef url);
243 static void set_finished(StringRef url);
244 static void set_cancelled(const StringRef url);
245 static void set_failure(StringRef url, std::optional<StringRefNull> failure_message);
246
247 static std::optional<StringRefNull> failure_message(StringRef url);
248 static std::optional<RemoteLibraryLoadingStatus::Status> status(StringRef url);
249 static std::optional<bool> metafiles_in_place(StringRef url);
250 static std::optional<FileSystemTimePoint> loading_start_time(const StringRef url);
251 static std::optional<TimePoint> last_new_pages_time(StringRef url);
252
263 static bool handle_timeout(StringRef url);
264
265 private:
267 void reset_timeout();
268};
269
270} // namespace asset_system
271} // namespace blender
#define C
Definition RandGen.cpp:29
static void ping_asset_file_download_succeeded(const bContext &C, StringRef library_url, StringRef absolute_file_url, StringRef local_file_abspath)
static void set_failure(StringRef url, std::optional< StringRefNull > failure_message)
static std::optional< bool > metafiles_in_place(StringRef url)
std::chrono::time_point< std::chrono::steady_clock > TimePoint
static std::optional< StringRefNull > failure_message(StringRef url)
static void begin_loading(StringRef url, float timeout)
static std::optional< RemoteLibraryLoadingStatus::Status > status(StringRef url)
static std::optional< TimePoint > last_new_pages_time(StringRef url)
static void ping_download_queue_done(const bContext &C)
static void ping_asset_file_download_failed(const bContext &C, StringRef library_url, StringRef absolute_file_url, StringRef local_file_abspath)
static void ping_asset_file_progress(StringRef absolute_file_url, int64_t size_in_bytes)
static void set_cancelled(const StringRef url)
static std::optional< FileSystemTimePoint > loading_start_time(const StringRef url)
static void ping_new_preview(const bContext &C, StringRef preview_full_filepath)
bool remote_library_has_unfinished_asset_downloads()
void foreach_registered_user_remote_library(FunctionRef< void(bUserAssetLibrary &)> fn)
float remote_library_total_asset_downloads_progress()
void remote_library_cancel_all_listing_downloads(const bContext &C)
void remote_library_request_preview_download(const bContext &C, const AssetRepresentation &asset, const StringRef dst_filepath, ReportList *reports)
std::string remote_library_asset_preview_path(const AssetRepresentation &asset)
constexpr StringRefNull REMOTE_LIBRARY_TOP_META_FILE_NAME
void remote_library_cancel_all_asset_downloads(bContext &C)
std::string remote_library_cache_directory_path(StringRefNull library_dirname)
void remote_library_request_asset_download(const bContext &C, const AssetRepresentation &asset, ReportList *reports)
constexpr StringRefNull REMOTE_LIBRARY_TOP_META_FILE_NAME_LEADING_SLASH
void remote_library_request_download(const RemoteLibraryDefinitionRef &library_definition)
std::string remote_library_top_meta_file_path(const RemoteLibraryDefinitionRef &library)
bool remote_library_url_ends_with_top_meta_file_name(const StringRef url)
std::string remote_library_cache_directory_path_from_url(StringRef remote_url)
Clock::time_point TimePoint
Definition BLI_timeit.hh:20
BMesh Iterators.
__int64 int64_t
Definition BKE_text.h:90
std::optional< URLWithHash > preview_url
RemoteLibraryDefinitionRef(StringRefNull remote_url, StringRefNull cache_dirpath, std::optional< StringRefNull > auth_token=std::nullopt)
RemoteLibraryDefinitionRef(const bUserAssetLibrary &library_definition)