From 4295c6cc534d9c47aef1446eb4c29f3f406c9064 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Tue, 11 Jun 2024 09:45:52 +0200 Subject: [PATCH] separate out the log parsing, will throw events --- plugins/plugin_factorio.cpp | 5 +++++ src/CMakeLists.txt | 2 ++ src/factorio.cpp | 9 +-------- src/factorio.hpp | 9 --------- src/factorio_log_parser.cpp | 19 +++++++++++++++++++ src/factorio_log_parser.hpp | 17 +++++++++++++++++ 6 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 src/factorio_log_parser.cpp create mode 100644 src/factorio_log_parser.hpp diff --git a/plugins/plugin_factorio.cpp b/plugins/plugin_factorio.cpp index cbf1dcc..6383ae5 100644 --- a/plugins/plugin_factorio.cpp +++ b/plugins/plugin_factorio.cpp @@ -3,10 +3,12 @@ #include #include +#include "factorio_log_parser.hpp" #include "factorio.hpp" #include +static std::unique_ptr g_flp = nullptr; static std::unique_ptr g_f = nullptr; constexpr const char* plugin_name = "Factorio"; @@ -34,9 +36,11 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) // static store, could be anywhere tho // construct with fetched dependencies + g_flp = std::make_unique(); g_f = std::make_unique(*cr, *rmm); // register types + PLUG_PROVIDE_INSTANCE(FactorioLogParser, plugin_name, g_flp.get()); PLUG_PROVIDE_INSTANCE(Factorio, plugin_name, g_f.get()); } catch (const ResolveException& e) { std::cerr << "PLUGIN " << plugin_name << " " << e.what << "\n"; @@ -50,6 +54,7 @@ SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) { std::cout << "PLUGIN " << plugin_name << " STOP()\n"; g_f.reset(); + g_flp.reset(); } SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float) { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e76d418..c6d80f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,6 +5,8 @@ project(solanaceae) add_library(solanaceae_factorio ./log_parse.hpp ./log_parse.cpp + ./factorio_log_parser.hpp + ./factorio_log_parser.cpp ./factorio.hpp ./factorio.cpp ) diff --git a/src/factorio.cpp b/src/factorio.cpp index d55057f..df8ed78 100644 --- a/src/factorio.cpp +++ b/src/factorio.cpp @@ -3,12 +3,9 @@ #include #include -#include "./log_parse.hpp" - Factorio::Factorio(Contact3Registry& cr, RegistryMessageModel& rmm) : _cr(cr), - _rmm(rmm), - _fw("test.txt", [this](const auto& path, const auto event){ this->onFileEvent(path, event);}) + _rmm(rmm) { @@ -22,7 +19,3 @@ bool Factorio::onEvent(const Message::Events::MessageConstruct& e) { return false; } -void Factorio::onFileEvent(const std::string& path, const filewatch::Event change_type) { - std::cout << "file even " << filewatch::event_to_string(change_type) << " on '" << path << "'\n"; -} - diff --git a/src/factorio.hpp b/src/factorio.hpp index 4aba344..ea7c960 100644 --- a/src/factorio.hpp +++ b/src/factorio.hpp @@ -2,24 +2,15 @@ #include -#include - -#include - class Factorio : public RegistryMessageModelEventI { Contact3Registry& _cr; RegistryMessageModel& _rmm; - filewatch::FileWatch _fw; - public: Factorio(Contact3Registry& cr, RegistryMessageModel& rmm); virtual ~Factorio(void); protected: // rmm bool onEvent(const Message::Events::MessageConstruct& e) override; - - protected: - void onFileEvent(const std::string& path, const filewatch::Event change_type); }; diff --git a/src/factorio_log_parser.cpp b/src/factorio_log_parser.cpp new file mode 100644 index 0000000..e0222dc --- /dev/null +++ b/src/factorio_log_parser.cpp @@ -0,0 +1,19 @@ +#include "./factorio_log_parser.hpp" + +#include "./log_parse.hpp" + +FactorioLogParser::FactorioLogParser(void) : + _fw("test.txt", [this](const auto& path, const auto event){ this->onFileEvent(path, event);}) +{ +} + +FactorioLogParser::~FactorioLogParser(void) { +} + +void FactorioLogParser::onFileEvent(const std::string& path, const filewatch::Event change_type) { + std::cout << "file even " << filewatch::event_to_string(change_type) << " on '" << path << "'\n"; + + // on create, close open log file and reopen and skip to end + // on mod (?), read line, parse +} + diff --git a/src/factorio_log_parser.hpp b/src/factorio_log_parser.hpp new file mode 100644 index 0000000..3888c21 --- /dev/null +++ b/src/factorio_log_parser.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include + +#include + +class FactorioLogParser { + filewatch::FileWatch _fw; + + public: + FactorioLogParser(void); + virtual ~FactorioLogParser(void); + + protected: + void onFileEvent(const std::string& path, const filewatch::Event change_type); +}; +