You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
717 B
40 lines
717 B
3 weeks ago
|
#pragma once
|
||
|
#include "fsm.hpp"
|
||
|
#include "config.hpp"
|
||
|
#include <chrono>
|
||
|
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<ServerState, ServerEvent> {
|
||
|
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);
|
||
|
};
|