增加mooos信息
This commit is contained in:
@@ -7,13 +7,18 @@
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include <fstream>
|
||||
#include <deque>
|
||||
#include "../LowerCommManager.h"
|
||||
class PowerManger; // 前向声明
|
||||
#include "../PowerManger.h"
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
class HttpServer {
|
||||
public:
|
||||
// 构造函数,传入PowerManger指针和端口号
|
||||
explicit HttpServer(int port = 8000);
|
||||
HttpServer(int port = 8000);
|
||||
|
||||
// 析构函数
|
||||
~HttpServer();
|
||||
@@ -34,10 +39,19 @@ public:
|
||||
void setLowerCommManager(LowerCommManager* lowerCommManager){
|
||||
m_lowerCommManager = lowerCommManager;
|
||||
}
|
||||
void setPowerManger(PowerManger* powerManger){
|
||||
m_powerManger = powerManger;
|
||||
}
|
||||
|
||||
// 推送系统数据到所有WebSocket客户端
|
||||
void pushSystemData();
|
||||
|
||||
// 推送日志数据到指定客户端
|
||||
void pushLogData(struct mg_connection* c, int page, int pageSize, const std::string& level, const std::string& search);
|
||||
|
||||
// 监控日志文件变化并推送新内容
|
||||
void monitorLogFile();
|
||||
|
||||
private:
|
||||
// WebSocket事件处理函数
|
||||
void handleWebSocketEvent(struct mg_connection* c, int ev, void* ev_data, void* fn_data);
|
||||
@@ -49,6 +63,7 @@ private:
|
||||
// 后台系统数据
|
||||
SystemData *m_systemData = nullptr;
|
||||
LowerCommManager *m_lowerCommManager = nullptr;
|
||||
PowerManger *m_powerManger = nullptr;
|
||||
|
||||
struct mg_mgr mgr_; // Mongoose管理器
|
||||
int port_; // 监听端口
|
||||
@@ -57,6 +72,27 @@ private:
|
||||
std::mutex ws_connections_mutex_; // WebSocket连接锁
|
||||
std::vector<mg_connection*> ws_connections_; // WebSocket连接列表
|
||||
std::unordered_map<mg_connection*, uint64_t> ws_last_io_time_; // 连接最后活动时间
|
||||
|
||||
// 读取日志文件
|
||||
std::vector<std::string> readLogFile(int page, int pageSize, const std::string& level, const std::string& search);
|
||||
|
||||
// 处理WebSocket消息
|
||||
void handleWebSocketMessage(struct mg_connection* c, const std::string& msg);
|
||||
|
||||
// 日志文件相关
|
||||
std::string m_logFilePath = "pPowerManger.log";
|
||||
std::ifstream m_logFile;
|
||||
std::streampos m_lastLogPosition = 0;
|
||||
std::deque<std::string> m_logCache; // 缓存最近的日志
|
||||
static const size_t MAX_CACHE_SIZE = 1000; // 最大缓存条数
|
||||
|
||||
// Log monitoring
|
||||
std::string m_logPath;
|
||||
std::deque<std::string> m_logCache;
|
||||
std::mutex m_logMutex;
|
||||
std::vector<struct mg_connection*> m_logSubscribers;
|
||||
std::mutex m_subscriberMutex;
|
||||
std::atomic<off_t> m_lastLogSize;
|
||||
};
|
||||
|
||||
#endif // HTTP_SERVER_H
|
||||
Reference in New Issue
Block a user