LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
IDataParser.hpp
Go to the documentation of this file.
1
8#pragma once
9#include "LogEvent.hpp"
10#include <algorithm>
11#include <cstdint>
12#include <filesystem>
13#include <istream>
14#include <string>
15#include <utility>
16#include <vector>
17
22namespace parser
23{
24
25// Forward declaration for circular dependency resolution
26class IDataParser;
27
52{
53 public:
57 virtual ~IDataParserObserver() = default;
58
68 virtual void ProgressUpdated() = 0;
69
77 virtual void NewEventFound(db::LogEvent&& event) = 0;
78
89 virtual void NewEventBatchFound(
90 std::vector<std::pair<int, db::LogEvent::EventItems>>&& eventBatch) = 0;
91};
92
110{
111 public:
115 virtual ~IDataParser() = default;
116
125 virtual void ParseData(const std::filesystem::path& filepath) = 0;
126
135 virtual void ParseData(std::istream& input) = 0;
136
145 virtual uint32_t GetCurrentProgress() const = 0;
146
153 virtual uint32_t GetTotalProgress() const = 0;
154
161 virtual std::vector<std::pair<std::string, std::string>> GetFileMetadata() const { return {}; }
162
172 {
173 if (observer && std::find(observers.begin(), observers.end(), observer) == observers.end())
174 observers.push_back(observer);
175 }
176
178 {
179 auto it = std::find(observers.begin(), observers.end(), observer);
180 if (it != observers.end())
181 observers.erase(it);
182 }
183
185 {
186 for (auto* observer : observers)
187 {
188 if (!observer) continue;
189 if (observer != observers.back())
190 {
191 db::LogEvent copy(event.getId(), db::LogEvent::EventItems(event.getEventItems()));
192 observer->NewEventFound(std::move(copy));
193 }
194 else
195 {
196 observer->NewEventFound(std::move(event));
197 }
198 }
199 }
200
202 {
203 for (auto* observer : observers)
204 if (observer) observer->ProgressUpdated();
205 }
206
208 std::vector<std::pair<int, db::LogEvent::EventItems>>&& eventBatch)
209 {
210 if (observers.empty()) return;
211
212 for (size_t i = 0; i < observers.size() - 1; ++i)
213 {
214 if (observers[i])
215 {
216 auto copy = eventBatch;
217 observers[i]->NewEventBatchFound(std::move(copy));
218 }
219 }
220 if (observers.back())
221 observers.back()->NewEventBatchFound(std::move(eventBatch));
222 }
223
224 private:
225 std::vector<IDataParserObserver*> observers;
226};
227
228} // namespace parser
Defines the LogEvent class for representing structured log entries.
Represents a single, structured log event with key-value data.
Definition LogEvent.hpp:97
std::vector< std::pair< std::string, std::string > > EventItems
A collection of key-value pairs representing event data (eventFieldName, data).
Definition LogEvent.hpp:101
Observer interface for receiving notifications from data parsers.
Definition IDataParser.hpp:52
virtual ~IDataParserObserver()=default
Virtual destructor for proper cleanup of derived classes.
virtual void NewEventBatchFound(std::vector< std::pair< int, db::LogEvent::EventItems > > &&eventBatch)=0
Called when a batch of new events is discovered during parsing.
virtual void NewEventFound(db::LogEvent &&event)=0
Called when a new event is discovered during parsing.
virtual void ProgressUpdated()=0
Called when parsing progress is updated.
Abstract base class for all data parsing implementations.
Definition IDataParser.hpp:110
virtual void ParseData(const std::filesystem::path &filepath)=0
Parses data from a file path.
virtual uint32_t GetTotalProgress() const =0
Gets the total expected progress value.
void NotifyProgressUpdated()
Definition IDataParser.hpp:201
virtual uint32_t GetCurrentProgress() const =0
Gets the current parsing progress.
void NotifyNewEvent(db::LogEvent &&event)
Definition IDataParser.hpp:184
std::vector< IDataParserObserver * > observers
Definition IDataParser.hpp:225
virtual ~IDataParser()=default
Virtual destructor for proper cleanup of derived classes.
virtual std::vector< std::pair< std::string, std::string > > GetFileMetadata() const
Ordered key → value pairs read from the file header during the last ParseData() call (see db::EventsC...
Definition IDataParser.hpp:161
void RegisterObserver(IDataParserObserver *observer)
Registers an observer to receive parsing notifications.
Definition IDataParser.hpp:171
void UnregisterObserver(IDataParserObserver *observer)
Definition IDataParser.hpp:177
void NotifyNewEventBatch(std::vector< std::pair< int, db::LogEvent::EventItems > > &&eventBatch)
Definition IDataParser.hpp:207
virtual void ParseData(std::istream &input)=0
Parses data from an input stream.
Data parsing components and interfaces.
Definition IControler.hpp:22