ORE Studio 0.0.4
Loading...
Searching...
No Matches
BadgeCache.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_BADGE_CACHE_HPP
21#define ORES_QT_BADGE_CACHE_HPP
22
23#include <string>
24#include <unordered_map>
25#include <vector>
26#include <QObject>
27#include <QFutureWatcher>
28#include "ores.qt/ClientManager.hpp"
29#include "ores.logging/make_logger.hpp"
30#include "ores.dq.api/domain/badge_definition.hpp"
31#include "ores.dq.api/messaging/badge_protocol.hpp"
32#include "ores.qt/export.hpp"
33
34namespace ores::qt {
35
47class ORES_QT_API BadgeCache final : public QObject {
48 Q_OBJECT
49
50private:
51 inline static std::string_view logger_name = "ores.qt.badge_cache";
52
53 [[nodiscard]] static auto& lg() {
54 using namespace ores::logging;
55 static auto instance = make_logger(logger_name);
56 return instance;
57 }
58
59public:
60 explicit BadgeCache(ClientManager* clientManager, QObject* parent = nullptr);
61 ~BadgeCache() override = default;
62
69 void loadAll();
70
74 bool isLoaded() const { return is_loaded_; }
75
82 void populate_for_testing(
83 std::vector<dq::domain::badge_definition> definitions,
84 std::vector<dq::messaging::badge_mapping> mappings);
85
96 const dq::domain::badge_definition* resolve(
97 const std::string& code_domain_code,
98 const std::string& entity_code) const;
99
100signals:
104 void loaded();
105
109 void loadError(const QString& error_message);
110
111private slots:
112 void onDefinitionsLoaded();
113 void onMappingsLoaded();
114
115private:
116 void loadDefinitions();
117 void loadMappings();
118 void buildIndex();
119
120 struct DefinitionsResult {
121 bool success;
122 std::vector<dq::domain::badge_definition> definitions;
123 };
124
125 struct MappingsResult {
126 bool success;
127 std::vector<dq::messaging::badge_mapping> mappings;
128 };
129
130 ClientManager* clientManager_;
131
132 std::vector<dq::domain::badge_definition> definitions_;
133 std::vector<dq::messaging::badge_mapping> mappings_;
134
135 // (code_domain_code + '\0' + entity_code) -> index into definitions_
136 std::unordered_map<std::string, std::size_t> index_;
137
138 // badge_code -> index into definitions_
139 std::unordered_map<std::string, std::size_t> definition_index_;
140
141 bool is_loaded_{false};
142 bool is_loading_{false};
143 bool definitions_loaded_{false};
144 bool mappings_loaded_{false};
145
146 QFutureWatcher<DefinitionsResult>* definitions_watcher_;
147 QFutureWatcher<MappingsResult>* mappings_watcher_;
148};
149
150}
151
152#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
Visual definition for a badge, including colours, label, and severity.
Definition badge_definition.hpp:41
Client-side cache of badge definitions and mappings.
Definition BadgeCache.hpp:47
void loaded()
Emitted when both definitions and mappings are loaded.
void loadError(const QString &error_message)
Emitted when an error occurs during loading.
bool isLoaded() const
Returns true once both definitions and mappings are loaded.
Definition BadgeCache.hpp:74
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:123