Vehicle_Road_Counter/src/web/web_server.h

51 lines
1.2 KiB
C
Raw Normal View History

2025-12-17 13:32:05 +08:00
#pragma once
#include "crow.h"
#include "crow/middlewares/cors.h"
#include "alarm/alarm_service.h"
#include "dataCache/live_data_cache.h"
#include "deviceManager/device_manager.h"
#include "systemMonitor/system_monitor.h"
#include "nlohmann/json.hpp"
#include <functional>
#include <thread>
class WebServer : public crow::Crow<crow::CORSHandler> {
public:
WebServer(SystemMonitor::SystemMonitor &monitor, DeviceManager &deviceManager,
LiveDataCache &liveDataCache, AlarmService &alarm_service,
uint16_t port = 8080);
~WebServer();
WebServer(const WebServer &) = delete;
WebServer &operator=(const WebServer &) = delete;
void start();
void stop();
void set_shutdown_handler(std::function<void()> handler);
private:
void setup_routes();
bool validate_video_config(const std::string &json_string,
std::string &error_message);
bool validate_main_config(const std::string &json_string,
std::string &error_message);
SystemMonitor::SystemMonitor &m_monitor;
DeviceManager &m_device_manager;
LiveDataCache &m_live_data_cache;
AlarmService &m_alarm_service;
uint16_t m_port;
std::thread m_thread;
std::function<void()> m_shutdown_handler;
};