Blender V5.3
all_library.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <memory>
10
11/* For getting the experimental flag for remote library support. */
12#include "DNA_userdef_types.h"
13
14#include "AS_remote_library.hh"
15
16#include "all_library.hh"
17
18#include "CLG_log.h"
19
20namespace blender {
21
22static CLG_LogRef LOG = {"asset.library"};
23
24namespace asset_system {
25
31
33{
34 /* This includes the online essentials as a separate library, if loaded. */
36 [&](AssetLibrary &nested) {
37 const std::optional<StringRefNull> url = nested.remote_url();
38 if (url.has_value()) {
40 RemoteLibraryDefinitionRef{*url, nested.root_path(), nested.auth_token()});
41 }
42 },
43 /*include_all_library=*/false);
44}
45
46std::optional<AssetLibraryReference> AllAssetLibrary::library_reference() const
47{
48 return all_library_reference();
49}
50
51std::optional<eAssetImportMethod> AllAssetLibrary::import_method() const
52{
53 return {};
54}
55
56void AllAssetLibrary::rebuild_catalogs_from_nested(const bool reload_nested_catalogs)
57{
58 /* Only one thread should rebuild at a time. If another thread is already rebuilding, wait for it
59 * to finish and then skip rebuilding. The result would effectively be the same, so re-running
60 * would just be wasted work. Waiting (rather than returning early) ensures callers don't see
61 * partially rebuilt catalogs. */
62 std::unique_lock rebuild_lock{rebuild_mutex_, std::try_to_lock};
63 if (!rebuild_lock.owns_lock()) {
64 /* Another thread holds the lock and is rebuilding. Block until it is done, then return. */
65 rebuild_lock.lock();
66 return;
67 }
68
69 /* Start with empty catalog storage. Don't do this directly in #this.catalog_service to avoid
70 * race conditions. Rather build into a new service and replace the current one when done. */
71 std::unique_ptr<AssetCatalogService> new_catalog_service = std::make_unique<AssetCatalogService>(
73
74 const bool skip_remote_libraries = !USER_EXPERIMENTAL_TEST(&U, use_remote_asset_libraries);
75
77 [&](AssetLibrary &nested) {
78 const bool is_online_lib = nested.remote_url().has_value();
79 if (is_online_lib && skip_remote_libraries) {
80 return;
81 }
82
83 if (reload_nested_catalogs) {
85 }
86
87 new_catalog_service->add_from_existing(
88 nested.catalog_service(),
89 /*on_duplicate_items=*/[](const AssetCatalog &existing,
90 const AssetCatalog &to_be_ignored) {
91 if (existing.path == to_be_ignored.path) {
92 CLOG_DEBUG(&LOG,
93 "multiple definitions of catalog %s (path: %s), ignoring duplicate",
94 existing.catalog_id.str().c_str(),
95 existing.path.c_str());
96 }
97 else {
98 /* This is bound to happen at some point, for example with the Online Essentials
99 * catalogs diverging from this Blender version's bundled Essentials catalogs. */
100 CLOG_INFO(&LOG,
101 "multiple definitions of catalog %s with differing paths (%s vs. %s), "
102 "ignoring second one",
103 existing.catalog_id.str().c_str(),
104 existing.path.c_str(),
105 to_be_ignored.path.c_str());
106 }
107 });
108 },
109 false);
110
111 std::lock_guard lock{catalog_service_mutex_};
112 catalog_service_ = std::move(new_catalog_service);
113 catalogs_dirty_ = false;
114}
115
117{
118 catalogs_dirty_ = true;
119}
120
122{
123 return catalogs_dirty_;
124}
125
127{
128 this->rebuild_catalogs_from_nested(/*reload_nested_catalogs=*/true);
129}
130
131} // namespace asset_system
132
133} // namespace blender
#define USER_EXPERIMENTAL_TEST(userdef, member)
volatile int lock
std::optional< AssetLibraryReference > library_reference() const override
std::optional< eAssetImportMethod > import_method() const override
void force_remote_listing_download() const override
void rebuild_catalogs_from_nested(bool reload_nested_catalogs)
virtual std::optional< StringRefNull > remote_url() const
AssetLibrary(eAssetLibraryType library_type, bool is_read_only, StringRef name="", StringRef root_path="")
AssetCatalogService & catalog_service() const
static void foreach_loaded(FunctionRef< void(AssetLibrary &)> fn, bool include_all_library)
virtual std::optional< StringRefNull > auth_token() const
AssetLibraryReference all_library_reference()
void remote_library_request_download(const RemoteLibraryDefinitionRef &library_definition)
BMesh Iterators.
UserDef U
Definition blender.cc:58
static CLG_LogRef LOG
Definition logging.cpp:12