ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientTelemetryLogModel.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 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_CLIENT_TELEMETRY_LOG_MODEL_HPP
21#define ORES_QT_CLIENT_TELEMETRY_LOG_MODEL_HPP
22
23#include <vector>
24#include <optional>
25#include <QFutureWatcher>
26#include <QAbstractTableModel>
27#include <boost/uuid/uuid.hpp>
28#include "ores.qt/ClientManager.hpp"
29#include "ores.logging/make_logger.hpp"
30#include "ores.telemetry/domain/telemetry_log_entry.hpp"
31
32namespace ores::qt {
33
40class ClientTelemetryLogModel final : public QAbstractTableModel {
41 Q_OBJECT
42
43private:
44 inline static std::string_view logger_name =
45 "ores.qt.client_telemetry_log_model";
46
47 [[nodiscard]] static auto& lg() {
48 using namespace ores::logging;
49 static auto instance = make_logger(logger_name);
50 return instance;
51 }
52
53public:
54 enum Column {
55 Timestamp,
56 Level,
57 Source,
58 Component,
59 Tag,
60 Message,
61 ColumnCount
62 };
63
64 explicit ClientTelemetryLogModel(ClientManager* clientManager,
65 QObject* parent = nullptr);
66 ~ClientTelemetryLogModel() override = default;
67
68 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
69 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
70 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
71 QVariant headerData(int section, Qt::Orientation orientation,
72 int role = Qt::DisplayRole) const override;
73
79 void load_session_logs(const boost::uuids::uuid& session_id);
80
87 void load_logs(std::chrono::system_clock::time_point start_time,
88 std::chrono::system_clock::time_point end_time);
89
96 void load_page(std::uint32_t offset, std::uint32_t limit);
97
101 void clear();
102
107
111 std::uint32_t page_size() const { return page_size_; }
112
116 void set_page_size(std::uint32_t size);
117
121 std::uint64_t total_available_count() const { return total_available_count_; }
122
128 void set_min_level(const std::optional<std::string>& level);
129
135 void set_message_filter(const std::optional<std::string>& text);
136
140 std::optional<boost::uuids::uuid> current_session_id() const {
141 return current_session_id_;
142 }
143
144signals:
145 void dataLoaded();
146 void loadError(const QString& error_message, const QString& details = {});
147
148private slots:
149 void onLogsLoaded();
150
151private:
152 struct FetchResult {
153 bool success;
154 std::vector<telemetry::domain::telemetry_log_entry> entries;
155 std::uint64_t total_count;
156 QString error_message;
157 QString error_details;
158 };
159
160 void fetch_logs();
161
162 ClientManager* clientManager_;
163 std::vector<telemetry::domain::telemetry_log_entry> entries_;
164 QFutureWatcher<FetchResult>* watcher_;
165
166 std::optional<boost::uuids::uuid> current_session_id_;
167 std::chrono::system_clock::time_point start_time_;
168 std::chrono::system_clock::time_point end_time_;
169 std::optional<std::string> min_level_;
170 std::optional<std::string> message_filter_;
171
172 std::uint32_t page_size_{100};
173 std::uint32_t current_offset_{0};
174 std::uint64_t total_available_count_{0};
175 bool is_fetching_{false};
176};
177
178}
179
180#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:90
Model for displaying telemetry log entries from the server.
Definition ClientTelemetryLogModel.hpp:40
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientTelemetryLogModel.cpp:156
void set_min_level(const std::optional< std::string > &level)
Set the minimum log level filter.
Definition ClientTelemetryLogModel.cpp:167
const telemetry::domain::telemetry_log_entry * get_entry(int row) const
Get log entry at the specified row.
Definition ClientTelemetryLogModel.cpp:150
void load_logs(std::chrono::system_clock::time_point start_time, std::chrono::system_clock::time_point end_time)
Load logs within a time range.
Definition ClientTelemetryLogModel.cpp:122
std::optional< boost::uuids::uuid > current_session_id() const
Get the currently filtered session ID.
Definition ClientTelemetryLogModel.hpp:140
void set_message_filter(const std::optional< std::string > &text)
Set the message search filter.
Definition ClientTelemetryLogModel.cpp:172
void load_session_logs(const boost::uuids::uuid &session_id)
Load logs for a specific session.
Definition ClientTelemetryLogModel.cpp:113
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of log data.
Definition ClientTelemetryLogModel.cpp:132
std::uint64_t total_available_count() const
Get the total number of records available on the server.
Definition ClientTelemetryLogModel.hpp:121
void clear()
Clear all log entries.
Definition ClientTelemetryLogModel.cpp:140
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientTelemetryLogModel.hpp:111
A persisted telemetry log entry.
Definition telemetry_log_entry.hpp:41