Horizon
Loading...
Searching...
No Matches
pool_status_provider.hpp
1#pragma once
2#include <string>
3#include "util/uuid.hpp"
4#include "common/common.hpp"
5#include "nlohmann/json.hpp"
6#include "util/changeable.hpp"
7#include <glibmm/dispatcher.h>
8#include <filesystem>
9#include <thread>
10#include <mutex>
11
12namespace horizon {
13using json = nlohmann::json;
14
16public:
17 enum class Status { BUSY, DONE };
18 Status status = Status::BUSY;
19 virtual std::string get_brief() const
20 {
21 return msg;
22 }
23 std::string msg = "Loading…";
24
25 virtual ~PoolStatusBase()
26 {
27 }
28};
29
31public:
32 class ItemInfo {
33 public:
34 enum class ItemState {
35 CURRENT,
36 LOCAL_ONLY,
37 REMOTE_ONLY,
38 MOVED,
39 CHANGED,
40 MOVED_CHANGED,
41 };
42
43 std::string name;
44 std::string filename_local;
45 std::string filename_remote;
46 ObjectType type;
47 UUID uuid;
48 json delta;
49 bool merge;
50 ItemState state;
51 };
52 std::vector<ItemInfo> items;
53
54 enum class UpdateState { NO, REQUIRED, OPTIONAL };
55
56 UpdateState pool_info_needs_update = UpdateState::NO;
57 UpdateState layer_help_needs_update = UpdateState::NO;
58 UpdateState tables_needs_update = UpdateState::NO;
59
60 bool can_update() const;
61
62 std::string get_brief() const override;
63};
64
65
67public:
68 PoolStatusProviderBase(const std::string &bp);
69 const PoolStatusBase &get();
70 void refresh();
71 virtual void check_for_updates() = 0;
73
74protected:
75 void start_worker();
76 const std::filesystem::path base_path;
77 virtual void worker() = 0;
78 void worker_wrapper();
79 std::unique_ptr<PoolStatusBase> pool_status_thread;
80 std::mutex mutex;
81 Glib::Dispatcher dispatcher;
82 virtual void reset()
83 {
84 }
85 void join_thread();
86
87private:
88 std::unique_ptr<PoolStatusBase> pool_status;
89 std::thread thread;
90};
91
93public:
94 PoolStatusProviderPoolManager(const std::string &bp);
95 void apply_update(const PoolStatusPoolManager &st);
96 void check_for_updates() override;
98
99protected:
100 const std::filesystem::path remote_path;
101 std::optional<PoolStatusPoolManager> st_update;
102 bool do_check_updates = false;
103 void worker() override;
104 void reset() override;
105 void apply_update();
106 void check_update();
107};
108
109} // namespace horizon
Definition changeable.hpp:5
Definition pool_status_provider.hpp:15
Definition pool_status_provider.hpp:32
Definition pool_status_provider.hpp:30
Definition pool_status_provider.hpp:66
Definition pool_status_provider.hpp:92
This class encapsulates a UUID and allows it to be uses as a value type.
Definition uuid.hpp:16
a class to store JSON values
Definition json.hpp:177
basic_json<> json
default JSON class
Definition json_fwd.hpp:62