mmcs-quotes-bridge/main.cpp

38 lines
967 B
C++

#include "spdlog/spdlog.h"
#include "state.h"
#include <filesystem>
#include <uv.h>
#include <td/telegram/td_api.h>
#include <td/telegram/td_api.hpp>
void on_signal(uv_signal_t *h, int signum) {
uv_stop(uv_default_loop());
}
void create_signal_handles(uv_loop_t *loop, uv_signal_t handles[2]) {
uv_signal_init(loop, handles);
uv_signal_start(handles, on_signal, SIGINT);
uv_signal_init(loop, handles + 1);
uv_signal_start(handles + 1, on_signal, SIGTERM);
}
int main() {
uv_loop_t *loop = uv_default_loop();
uv_signal_t signalHandles[2] = {};
create_signal_handles(loop, signalHandles);
state::AppState state;
try {
state = state::AppState("bridge_state.json");
spdlog::info("state: {}", state.to_string());
} catch (state::InvalidSavedStateException &e) {
spdlog::error("invalid saved state: {}", e.message);
return 1;
}
uv_run(loop, UV_RUN_DEFAULT);
spdlog::info("event loop ended");
state.save();
return 0;
}