Unravel Engine C++ Reference
Loading...
Searching...
No Matches
asset_watcher.h
Go to the documentation of this file.
1#pragma once
2#include <context/context.hpp>
3#include <filesystem/syncer.h>
4#include <ospp/event.h>
5
6#include <deque>
7#include <functional>
8#include <mutex>
9
10namespace unravel
11{
12
14using on_wait_progress_t = std::function<void(size_t completed, size_t total, const std::string& current_job)>;
15
17{
18public:
21
22 auto init(rtti::context& ctx) -> bool;
23 auto deinit(rtti::context& ctx) -> bool;
24
26 const std::string& protocol,
27 bool wait = false,
28 const on_wait_progress_t& on_progress = nullptr);
29 void unwatch_assets(rtti::context& ctx, const std::string& protocol);
30
31 void recreate_meta_files(rtti::context& ctx, const std::string& protocol);
32
33 auto get_pending_jobs_count(rtti::context& ctx) const -> size_t;
34
35private:
36 void on_os_event(rtti::context& ctx, os::event& e);
37
38 void setup_directory(rtti::context& ctx, fs::syncer& syncer);
39 void setup_meta_syncer(rtti::context& ctx,
40 std::vector<uint64_t>& watchers,
41 fs::syncer& syncer,
42 const fs::path& data_dir,
43 const fs::path& meta_dir,
44 bool wait,
45 const on_wait_progress_t& on_progress);
46 void setup_cache_syncer(rtti::context& ctx,
47 std::vector<uint64_t>& watchers,
48 fs::syncer& syncer,
49 const fs::path& meta_dir,
50 const fs::path& cache_dir,
51 bool wait,
52 const on_wait_progress_t& on_progress);
53
54 struct watched
55 {
56 fs::syncer meta_syncer;
57 fs::syncer cache_syncer;
58 std::vector<std::uint64_t> watchers;
59 };
60
61 std::map<std::string, watched> watched_protocols_{};
62 std::shared_ptr<int> sentinel_ = std::make_shared<int>(0);
63
64 std::mutex recreate_meta_files_queue_mutex_{};
65 std::map<std::string, bool> recreate_meta_files_queue_{};
66
67};
68} // namespace unravel
auto deinit(rtti::context &ctx) -> bool
auto get_pending_jobs_count(rtti::context &ctx) const -> size_t
void watch_assets(rtti::context &ctx, const std::string &protocol, bool wait=false, const on_wait_progress_t &on_progress=nullptr)
void recreate_meta_files(rtti::context &ctx, const std::string &protocol)
auto init(rtti::context &ctx) -> bool
void unwatch_assets(rtti::context &ctx, const std::string &protocol)
std::function< void(size_t completed, size_t total, const std::string &current_job)> on_wait_progress_t
Callback invoked after each compilation job completes during a blocking wait.