增加了网页服务
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#ifndef HTTP_SERVER_H
|
||||
#define HTTP_SERVER_H
|
||||
#include "MOOS/libMOOS/Utils/MOOSThread.h"
|
||||
#include "mongoose.h"
|
||||
#include "../loguru.hpp"
|
||||
#include "../systemData.h"
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
class PowerManger; // 前向声明
|
||||
|
||||
class HttpServer {
|
||||
public:
|
||||
// 构造函数,传入PowerManger指针和端口号
|
||||
explicit HttpServer(int port = 8000);
|
||||
|
||||
// 析构函数
|
||||
~HttpServer();
|
||||
|
||||
// 启动HTTP服务器线程
|
||||
void start();
|
||||
|
||||
// 停止HTTP服务器线程
|
||||
void stop();
|
||||
|
||||
// 检查服务器是否正在运行
|
||||
bool isRunning() const;
|
||||
|
||||
// 设置系统数据
|
||||
void setSystemData(SystemData* systemData){
|
||||
m_systemData = systemData;
|
||||
}
|
||||
|
||||
// 推送系统数据到所有WebSocket客户端
|
||||
void pushSystemData();
|
||||
|
||||
private:
|
||||
// WebSocket事件处理函数
|
||||
static void handleWebSocketEvent(struct mg_connection* c, int ev, void* ev_data, void* fn_data);
|
||||
|
||||
// 线程回调函数
|
||||
static bool serverThreadCB(void* pParam);
|
||||
bool serverThreadFunc();
|
||||
|
||||
// 后台系统数据
|
||||
SystemData *m_systemData = nullptr;
|
||||
|
||||
struct mg_mgr mgr_; // Mongoose管理器
|
||||
int port_; // 监听端口
|
||||
bool running_; // 运行状态标志
|
||||
CMOOSThread m_ServerThread; // 服务器线程
|
||||
std::mutex ws_connections_mutex_; // WebSocket连接锁
|
||||
std::vector<mg_connection*> ws_connections_; // WebSocket连接列表
|
||||
std::unordered_map<mg_connection*, uint64_t> ws_last_io_time_; // 连接最后活动时间
|
||||
};
|
||||
|
||||
#endif // HTTP_SERVER_H
|
||||
Reference in New Issue
Block a user