logmeow/event_loop.cpp

78 lines
2.9 KiB
C++
Raw Normal View History

#include <imgui.h>
2023-01-22 14:28:14 +00:00
2023-01-05 10:27:14 +00:00
#include "log.h"
#include "config.h"
2023-01-28 14:11:46 +00:00
#include "filters.h"
2023-01-18 16:34:17 +00:00
#include "logcat_thread.h"
2023-01-23 08:44:16 +00:00
#include "windows/logs.h"
2023-01-28 14:11:46 +00:00
#include "windows/filters.h"
2023-02-01 15:22:08 +00:00
#include "windows/exclusions.h"
2023-01-23 08:44:16 +00:00
#include "windows/settings.h"
#include "windows/main.h"
#ifndef NDEBUG
#include "windows/debug.h"
#endif
2023-01-21 08:52:55 +00:00
2023-02-01 15:22:08 +00:00
static inline void check_for_logcat_items(LogcatThread& logcat_thread, const Config& active_config,
2023-01-28 14:11:46 +00:00
std::vector<LogcatEntry>& logcat_entries, std::vector<size_t>& filtered_logcat_entry_offsets) {
2023-01-18 16:34:17 +00:00
LogcatThreadItem* logcat_thread_item;
while ((logcat_thread_item = logcat_thread.atomic_ring_buffer.get())) {
2023-01-29 08:21:22 +00:00
if (std::holds_alternative<LogEntry>(*logcat_thread_item)) {
log(std::move(std::get<LogEntry>(*logcat_thread_item)), false);
2023-01-19 16:34:03 +00:00
} else if (std::holds_alternative<LogcatEntry>(*logcat_thread_item)) {
2023-01-28 14:11:46 +00:00
logcat_entries.push_back(std::move(std::get<LogcatEntry>(*logcat_thread_item)));
2023-02-01 15:22:08 +00:00
if (matches(logcat_entries.back(), active_config.filters, active_config.exclusions)) {
2023-01-28 14:11:46 +00:00
filtered_logcat_entry_offsets.push_back(logcat_entries.size() - 1);
}
2023-01-18 16:34:17 +00:00
} else {
throw std::runtime_error("Cannot handle all possible logcat thread item variants");
}
logcat_thread.atomic_ring_buffer.increment_read();
}
}
2023-01-05 10:27:14 +00:00
2023-02-04 07:31:50 +00:00
void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& logcat_thread) {
2023-01-24 05:17:05 +00:00
static Config inactive_config;
2023-01-05 09:05:09 +00:00
static bool show_settings_window = false;
2023-01-28 14:11:46 +00:00
static bool show_filters_window = false;
2023-02-01 15:22:08 +00:00
static bool show_exclusions_window = false;
2023-01-05 10:27:14 +00:00
static bool show_logs_window = false;
static size_t log_entries_read = 0;
2023-01-28 14:11:46 +00:00
static std::vector<LogcatEntry> logcat_entries;
static std::vector<size_t> filtered_logcat_entry_offsets;
2023-01-05 09:05:09 +00:00
2023-02-01 15:22:08 +00:00
check_for_logcat_items(logcat_thread, active_config, logcat_entries, filtered_logcat_entry_offsets);
2023-01-18 16:34:17 +00:00
2023-01-18 16:37:37 +00:00
#ifndef NDEBUG
debug_window(logcat_thread);
2023-01-18 16:37:37 +00:00
#endif
2023-01-05 10:27:14 +00:00
if (show_settings_window) {
2023-01-24 05:17:05 +00:00
settings_window(active_config, inactive_config, &show_settings_window);
}
2023-01-28 14:11:46 +00:00
if (show_filters_window) {
filters_window(active_config, inactive_config, logcat_entries, filtered_logcat_entry_offsets, &show_filters_window);
2023-01-28 14:11:46 +00:00
}
2023-02-01 15:22:08 +00:00
if (show_exclusions_window) {
exclusions_window(active_config, inactive_config, logcat_entries, filtered_logcat_entry_offsets, &show_exclusions_window);
}
2023-01-28 14:11:46 +00:00
2023-01-05 10:27:14 +00:00
if (show_logs_window) {
bool autoscrolling = false;
2023-01-06 16:27:39 +00:00
logs_window(monospace_font, &autoscrolling, &show_logs_window);
if (autoscrolling) {
log_entries_read = log_entries.size();
}
2023-01-05 10:27:14 +00:00
}
// log_entries must not be mutated until the show logs button
2023-02-02 12:50:28 +00:00
main_window(log_entries_read == log_entries.size(), monospace_font, logcat_thread,
2023-01-28 14:11:46 +00:00
logcat_entries, filtered_logcat_entry_offsets,
active_config, inactive_config,
2023-02-04 07:31:50 +00:00
&show_settings_window, &show_filters_window, &show_exclusions_window, &show_logs_window);
}