Vehicle_Road_Counter/src/web/web_server.h

48 lines
1.2 KiB
C
Raw Normal View History

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