Blender V4.3
asset_library_all.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
9#include <memory>
10
14
15#include "asset_library_all.hh"
16
17#include "CLG_log.h"
18
19static CLG_LogRef LOG = {"asset_system.all_asset_library"};
20
21namespace blender::asset_system {
22
24
25void AllAssetLibrary::rebuild_catalogs_from_nested(const bool reload_nested_catalogs)
26{
27 /* Start with empty catalog storage. Don't do this directly in #this.catalog_service to avoid
28 * race conditions. Rather build into a new service and replace the current one when done. */
29 std::unique_ptr<AssetCatalogService> new_catalog_service = std::make_unique<AssetCatalogService>(
31
33 [&](AssetLibrary &nested) {
34 if (reload_nested_catalogs) {
35 nested.catalog_service().reload_catalogs();
36 }
37
38 new_catalog_service->add_from_existing(
39 nested.catalog_service(),
40 /*on_duplicate_items=*/[](const AssetCatalog &existing,
41 const AssetCatalog &to_be_ignored) {
42 if (existing.path == to_be_ignored.path) {
43 CLOG_INFO(&LOG,
44 2,
45 "multiple definitions of catalog %s (path: %s), ignoring duplicate",
46 existing.catalog_id.str().c_str(),
47 existing.path.c_str());
48 }
49 else {
50 CLOG_ERROR(&LOG,
51 "multiple definitions of catalog %s with differing paths (%s vs. %s), "
52 "ignoring second one",
53 existing.catalog_id.str().c_str(),
54 existing.path.c_str(),
55 to_be_ignored.path.c_str());
56 }
57 });
58 },
59 false);
60
61 std::lock_guard lock{catalog_service_mutex_};
62 catalog_service_ = std::move(new_catalog_service);
63 catalogs_dirty_ = false;
64}
65
66void AllAssetLibrary::tag_catalogs_dirty()
67{
68 catalogs_dirty_ = true;
69}
70
71bool AllAssetLibrary::is_catalogs_dirty() const
72{
73 return catalogs_dirty_;
74}
75
76void AllAssetLibrary::refresh_catalogs()
77{
78 this->rebuild_catalogs_from_nested(/*reload_nested_catalogs=*/true);
79}
80
81} // namespace blender::asset_system
@ ASSET_LIBRARY_ALL
static CLG_LogRef LOG
volatile int lock
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)