20260707/include/app.hpp

193 lines
5.8 KiB
C++
Raw Permalink Normal View History

2026-07-07 07:54:41 +00:00
#ifndef ODF_MANAGER_APP_HPP
#define ODF_MANAGER_APP_HPP
#include <string>
#include <vector>
#include <map>
#include <optional>
#include <chrono>
#include <mutex>
namespace odf {
// 端口状态枚举
enum class PortStatus {
ACTIVE,
INACTIVE,
ERROR_STATE
};
// 端口映射数据结构
struct PortMapping {
int mapping_id;
std::string port_code;
std::string fiber_core;
std::string splice_tray;
std::string cable_core;
std::string route_info;
std::chrono::system_clock::time_point create_time;
std::chrono::system_clock::time_point update_time;
};
// 设备健康状态
struct DeviceHealth {
std::string node_id;
double temperature_celsius;
double humidity_percent;
bool is_online;
PortStatus port_status;
};
// 用户角色枚举
enum class UserRole {
ADMIN,
OPERATOR,
VIEWER
};
// 用户信息
struct UserInfo {
std::string username;
UserRole role;
bool is_session_valid;
};
/**
*
*/
class PortMappingManager {
public:
/**
*
*
* @requirement(name="端口唯一编号系统", id="SRS-F-05-001")
* @requirement(name="产品型号编码结构", id="SRS-F-05-002")
* @requirement(name="内部组件编号与溯源", id="SRS-F-05-003")
* @requirement(name="端口映射记录表支持", id="SRS-F-05-004")
* @param port_code
* @param fiber_core
* @param splice_tray
* @param cable_core
* @param route_info
* @return ID -1
*/
int addMapping(const std::string& port_code, const std::string& fiber_core,
const std::string& splice_tray = "", const std::string& cable_core = "",
const std::string& route_info = "");
/**
*
*
* @requirement(name="端口映射记录表支持", id="SRS-F-05-004")
* @param port_code
* @return
*/
bool deleteMapping(const std::string& port_code);
/**
*
*
* @requirement(name="端口唯一编号系统", id="SRS-F-05-001")
* @param port_code
* @return std::nullopt
*/
std::optional<PortMapping> getMapping(const std::string& port_code);
/**
*
*
* @requirement(name="内部组件编号与溯源", id="SRS-F-05-003")
* @requirement(name="端口映射记录表支持", id="SRS-F-05-004")
* @param port_code
* @param new_fiber_core
* @param splice_tray
* @param cable_core
* @param route_info
* @return
*/
bool updateMapping(const std::string& port_code, const std::string& new_fiber_core,
const std::string& splice_tray = "", const std::string& cable_core = "",
const std::string& route_info = "");
private:
// 模拟数据库存储
std::map<std::string, PortMapping> mappings_;
int next_id_ = 1;
std::mutex mutex_;
// 辅助:验证端口编码格式 (SRS-F-05-002)
bool validatePortCodeFormat(const std::string& code) const;
};
/**
* 线/
*/
class DeviceMonitor {
public:
/**
*
*
* @requirement(name="CSCI运行适应性需求", id="SRS-NFR-SRS-010")
* @param node_id ID
* @param temperature
* @param humidity 湿
* @param is_connected
* @return
*/
DeviceHealth checkStatus(const std::string& node_id, double temperature,
double humidity, bool is_connected);
/**
*
*
* @requirement(name="CSCI运行适应性需求", id="SRS-NFR-SRS-010")
* @param health
* @param temp_threshold
* @param humidity_threshold 湿
* @return
*/
std::string generateAlert(const DeviceHealth& health, double temp_threshold = 40.0,
double humidity_threshold = 80.0);
};
/**
* RBAC角色权限控制及会话管理
*/
class UserService {
public:
/**
*
*
* @requirement(name="安全性需求", id="SRS-NFR-SRS-011")
* @param username
* @param password
* @return nullopt
*/
std::optional<UserInfo> authenticate(const std::string& username, const std::string& password);
/**
*
*
* @requirement(name="安全性需求", id="SRS-NFR-SRS-011")
* @param user
* @param required_role
* @return
*/
bool hasPermission(const UserInfo& user, UserRole required_role);
/**
* 使
*
* @requirement(name="安全性需求", id="SRS-NFR-SRS-011")
* @param username
*/
void logout(const std::string& username);
private:
std::map<std::string, UserInfo> users_;
std::mutex mutex_;
};
} // namespace odf
#endif // ODF_MANAGER_APP_HPP