#pragma once #include "fsm.hpp" #include "config.hpp" #include using namespace nlohmann; using namespace std::chrono_literals; #define BUF_MAX 1024 * 10 enum class ServerState { START, READING, STOP, ERROR }; enum class ServerEvent { GO }; class Server : DeadSimpleFSM { Config &config; FILE *handle = nullptr; char buffer[BUF_MAX]; char *res = nullptr; std::chrono::milliseconds wait_time = 200ms; int fail_count = 0; public: Server(Config &config) : config(config) {}; bool stopped(); void event(ServerEvent ev); // states void START(ServerEvent ev); void READING(ServerEvent ev); void STOP(ServerEvent ev); void ERROR(ServerEvent ev); };