2025-10-15 14:27:21 +08:00
|
|
|
// 文件名: src/web/web_server.h
|
|
|
|
|
#ifndef WEB_SERVER_H
|
|
|
|
|
#define WEB_SERVER_H
|
|
|
|
|
|
2025-10-16 11:07:24 +08:00
|
|
|
#include "crow.h"
|
|
|
|
|
#include "crow/middlewares/cors.h"
|
|
|
|
|
|
2025-10-15 14:27:21 +08:00
|
|
|
#include "systemMonitor/system_monitor.h"
|
2025-10-16 11:07:24 +08:00
|
|
|
#include "deviceManager/device_manager.h"
|
2025-10-16 17:05:24 +08:00
|
|
|
#include "dataCache/live_data_cache.h"
|
2025-10-24 14:19:33 +08:00
|
|
|
#include "alarm/alarm_service.h"
|
2025-10-16 11:07:24 +08:00
|
|
|
|
2025-10-15 14:27:21 +08:00
|
|
|
#include <thread>
|
|
|
|
|
|
2025-10-16 11:07:24 +08:00
|
|
|
|
|
|
|
|
class WebServer : public crow::Crow<crow::CORSHandler> {
|
|
|
|
|
|
2025-10-15 14:27:21 +08:00
|
|
|
public:
|
2025-10-16 17:05:24 +08:00
|
|
|
WebServer(SystemMonitor::SystemMonitor& monitor,
|
|
|
|
|
DeviceManager& deviceManager,
|
|
|
|
|
LiveDataCache& liveDataCache,
|
2025-10-24 14:19:33 +08:00
|
|
|
AlarmService& alarm_service,
|
2025-10-16 17:05:24 +08:00
|
|
|
uint16_t port = 8080
|
|
|
|
|
);
|
2025-10-15 14:27:21 +08:00
|
|
|
~WebServer();
|
|
|
|
|
|
|
|
|
|
WebServer(const WebServer&) = delete;
|
|
|
|
|
WebServer& operator=(const WebServer&) = delete;
|
|
|
|
|
|
|
|
|
|
void start();
|
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void setup_routes();
|
|
|
|
|
|
|
|
|
|
SystemMonitor::SystemMonitor& m_monitor;
|
2025-10-16 11:07:24 +08:00
|
|
|
DeviceManager& m_device_manager;
|
2025-10-16 17:05:24 +08:00
|
|
|
LiveDataCache& m_live_data_cache;
|
2025-10-24 14:19:33 +08:00
|
|
|
AlarmService& m_alarm_service;
|
2025-11-03 09:37:54 +08:00
|
|
|
|
2025-10-16 17:05:24 +08:00
|
|
|
|
2025-10-15 14:27:21 +08:00
|
|
|
uint16_t m_port;
|
|
|
|
|
|
2025-10-16 11:07:24 +08:00
|
|
|
std::thread m_thread;
|
2025-10-15 14:27:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // WEB_SERVER_H
|