Skip to content

Commit

Permalink
separate out the log parsing, will throw events
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky committed Jun 11, 2024
1 parent 06bd55c commit 4295c6c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
5 changes: 5 additions & 0 deletions plugins/plugin_factorio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include <entt/entt.hpp>
#include <entt/fwd.hpp>

#include "factorio_log_parser.hpp"
#include "factorio.hpp"

#include <iostream>

static std::unique_ptr<FactorioLogParser> g_flp = nullptr;
static std::unique_ptr<Factorio> g_f = nullptr;

constexpr const char* plugin_name = "Factorio";
Expand Down Expand Up @@ -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<FactorioLogParser>();
g_f = std::make_unique<Factorio>(*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";
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
9 changes: 1 addition & 8 deletions src/factorio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
#include <solanaceae/message3/components.hpp>
#include <solanaceae/contact/components.hpp>

#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)
{


Expand All @@ -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";
}

9 changes: 0 additions & 9 deletions src/factorio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

#include <solanaceae/message3/registry_message_model.hpp>

#include <FileWatch.hpp>

#include <string>

class Factorio : public RegistryMessageModelEventI {
Contact3Registry& _cr;
RegistryMessageModel& _rmm;

filewatch::FileWatch<std::string> _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);
};

19 changes: 19 additions & 0 deletions src/factorio_log_parser.cpp
Original file line number Diff line number Diff line change
@@ -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
}

17 changes: 17 additions & 0 deletions src/factorio_log_parser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <FileWatch.hpp>

#include <string>

class FactorioLogParser {
filewatch::FileWatch<std::string> _fw;

public:
FactorioLogParser(void);
virtual ~FactorioLogParser(void);

protected:
void onFileEvent(const std::string& path, const filewatch::Event change_type);
};

0 comments on commit 4295c6c

Please sign in to comment.