#include #include "log.h" #include "config.h" #include "filters.h" #include "logcat_thread.h" #include "windows/logs.h" #include "windows/filters.h" #include "windows/settings.h" #include "windows/main.h" #ifndef NDEBUG #include "windows/debug.h" #endif static inline void check_for_logcat_items(LogcatThread& logcat_thread, const Filters& filters, std::vector& logcat_entries, std::vector& filtered_logcat_entry_offsets) { LogcatThreadItem* logcat_thread_item; while ((logcat_thread_item = logcat_thread.atomic_ring_buffer.get())) { if (std::holds_alternative(*logcat_thread_item)) { log_raw(std::move(std::get(*logcat_thread_item)), false); } else if (std::holds_alternative(*logcat_thread_item)) { logcat_entries.push_back(std::move(std::get(*logcat_thread_item))); if (matches(filters, logcat_entries.back())) { filtered_logcat_entry_offsets.push_back(logcat_entries.size() - 1); } } else { throw std::runtime_error("Cannot handle all possible logcat thread item variants"); } logcat_thread.atomic_ring_buffer.increment_read(); } } void event_loop(ImFont* monospace_font, Config& active_config, Filters& active_filters, LogcatThread& logcat_thread, bool* run_event_loop) { static Config inactive_config; static Filters inactive_filters; static bool show_settings_window = false; static bool show_filters_window = false; static bool show_logs_window = false; static size_t log_entries_read = 0; static std::vector logcat_entries; static std::vector filtered_logcat_entry_offsets; check_for_logcat_items(logcat_thread, active_filters, logcat_entries, filtered_logcat_entry_offsets); #ifndef NDEBUG debug_window(logcat_thread); #endif if (show_settings_window) { settings_window(active_config, inactive_config, &show_settings_window); } if (show_filters_window) { filters_window(active_filters, inactive_filters, logcat_entries, filtered_logcat_entry_offsets, &show_filters_window); } if (show_logs_window) { bool autoscrolling = false; logs_window(monospace_font, &autoscrolling, &show_logs_window); if (autoscrolling) { log_entries_read = log_entries.size(); } } // log_entries must not be mutated until the show logs button main_window(log_entries_read == log_entries.size(), monospace_font, logcat_entries, filtered_logcat_entry_offsets, active_config, inactive_config, active_filters, inactive_filters, &show_settings_window, &show_filters_window, &show_logs_window, run_event_loop); }