Blender V5.0
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
14
15#include "all_library.hh"
16
17#include "CLG_log.h"
18
19static CLG_LogRef LOG = {"asset.library"};
20
21namespace blender::asset_system {
22
24
25std::optional<AssetLibraryReference> AllAssetLibrary::library_reference() const
26{
27 return all_library_reference();
28}
29
30void AllAssetLibrary::rebuild_catalogs_from_nested(const bool reload_nested_catalogs)
31{
32 /* Start with empty catalog storage. Don't do this directly in #this.catalog_service to avoid
33 * race conditions. Rather build into a new service and replace the current one when done. */
34 std::unique_ptr<AssetCatalogService> new_catalog_service = std::make_unique<AssetCatalogService>(
36
38 [&](AssetLibrary &nested) {
39 if (reload_nested_catalogs) {
41 }
42
43 new_catalog_service->add_from_existing(
44 nested.catalog_service(),
45 /*on_duplicate_items=*/[](const AssetCatalog &existing,
46 const AssetCatalog &to_be_ignored) {
47 if (existing.path == to_be_ignored.path) {
48 CLOG_DEBUG(&LOG,
49 "multiple definitions of catalog %s (path: %s), ignoring duplicate",
50 existing.catalog_id.str().c_str(),
51 existing.path.c_str());
52 }
53 else {
54 CLOG_ERROR(&LOG,
55 "multiple definitions of catalog %s with differing paths (%s vs. %s), "
56 "ignoring second one",
57 existing.catalog_id.str().c_str(),
58 existing.path.c_str(),
59 to_be_ignored.path.c_str());
60 }
61 });
62 },
63 false);
64
65 std::lock_guard lock{catalog_service_mutex_};
66 catalog_service_ = std::move(new_catalog_service);
67 catalogs_dirty_ = false;
68}
69
71{
72 catalogs_dirty_ = true;
73}
74
76{
77 return catalogs_dirty_;
78}
79
81{
82 this->rebuild_catalogs_from_nested(/*reload_nested_catalogs=*/true);
83}
84
85} // namespace blender::asset_system
@ ASSET_LIBRARY_ALL
volatile int lock
std::optional< AssetLibraryReference > library_reference() const override
void rebuild_catalogs_from_nested(bool reload_nested_catalogs)
AssetCatalogService & catalog_service() const
static void foreach_loaded(FunctionRef< void(AssetLibrary &)> fn, bool include_all_library)
AssetLibrary(eAssetLibraryType library_type, StringRef name="", StringRef root_path="")
#define LOG(level)
Definition log.h:97
AssetLibraryReference all_library_reference()