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/domain/badge_definition.hpp"
31#include "ores.dq.api/messaging/badge_protocol.hpp"
32
33namespace ores::qt {
34
46class BadgeCache final : public QObject {
47 Q_OBJECT
48
49private:
50 inline static std::string_view logger_name = "ores.qt.badge_cache";
51
52 [[nodiscard]] static auto& lg() {
53 using namespace ores::logging;
54 static auto instance = make_logger(logger_name);
55 return instance;
56 }
57
58public:
59 explicit BadgeCache(ClientManager* clientManager, QObject* parent = nullptr);
60 ~BadgeCache() override = default;
61
68 void loadAll();
69
73 bool isLoaded() const { return is_loaded_; }
74
86 const std::string& code_domain_code,
87 const std::string& entity_code) const;
88
89signals:
93 void loaded();
94
98 void loadError(const QString& error_message);
99
100private slots:
101 void onDefinitionsLoaded();
102 void onMappingsLoaded();
103
104private:
105 void loadDefinitions();
106 void loadMappings();
107 void buildIndex();
108
109 struct DefinitionsResult {
110 bool success;
111 std::vector<dq::domain::badge_definition> definitions;
112 };
113
114 struct MappingsResult {
115 bool success;
116 std::vector<dq::messaging::badge_mapping> mappings;
117 };
118
119 ClientManager* clientManager_;
120
121 std::vector<dq::domain::badge_definition> definitions_;
122 std::vector<dq::messaging::badge_mapping> mappings_;
123
124 // (code_domain_code + '\0' + entity_code) -> index into definitions_
125 std::unordered_map<std::string, std::size_t> index_;
126
127 // badge_code -> index into definitions_
128 std::unordered_map<std::string, std::size_t> definition_index_;
129
130 bool is_loaded_{false};
131 bool is_loading_{false};
132 bool definitions_loaded_{false};
133 bool mappings_loaded_{false};
134
135 QFutureWatcher<DefinitionsResult>* definitions_watcher_;
136 QFutureWatcher<MappingsResult>* mappings_watcher_;
137};
138
139}
140
141#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
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:46
void loaded()
Emitted when both definitions and mappings are loaded.
const dq::domain::badge_definition * resolve(const std::string &code_domain_code, const std::string &entity_code) const
Resolve a badge definition for a given (code_domain, entity_code) pair.
Definition BadgeCache.cpp:164
void loadAll()
Load badge definitions and mappings from the server.
Definition BadgeCache.cpp:42
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:73
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109