task_auto_plan_execute_project/include/app.hpp

274 lines
7.7 KiB
C++
Raw Normal View History

2026-05-01 05:54:47 +00:00
#ifndef C2SYS_APP_HPP
#define C2SYS_APP_HPP
/**
* @file app.hpp
* @brief C2SYS
*
* C2SYS
*
*
*/
#include "config.hpp"
#include <vector>
#include <string>
#include <memory>
#include <functional>
#include <map>
namespace c2sys {
/**
* @brief
*/
enum class SystemState : uint8_t {
/// 初始化中
Initializing = 0,
/// 已就绪
Ready = 1,
/// 运行中
Running = 2,
/// 异常态
Error = 3,
/// 已停止
Stopped = 4
};
/**
* @class App
* @brief C2SYS
*
*
* "人在回路" "自主执行"
*
* 使
* @code
* c2sys::App app;
* app.initialize("config.txt");
* app.setRunMode(c2sys::RunMode::Autonomous);
* app.start();
* // ... 运行期间自动处理事件与任务 ...
* app.stop();
* @endcode
*/
class App {
public:
/// @brief 默认构造函数
App();
/// @brief 析构函数
~App();
// ======================== 生命周期管理 ========================
/**
* @brief
* @param configFile 使
* @return true
*
*
* 1.
* 2.
* 3.
*/
bool initialize(const std::string& configFile = "");
/**
* @brief
* @return true
*
* Running
*/
bool start();
/**
* @brief
*/
void stop();
/**
* @brief
* @return
*/
SystemState getState() const;
// ======================== 模式管理 ========================
/**
* @brief
* @param mode /
* @return true
*
* ModeStateCache
*
*/
bool setRunMode(RunMode mode);
/**
* @brief
* @return
*/
RunMode getRunMode() const;
// ======================== 方案管理 (F-001, F-002, F-003) ========================
/**
* @brief
* @param plan
* @return true
*/
bool addPlan(const PlanData& plan);
/**
* @brief
* @return
*/
const std::vector<PlanData>& getAllPlans() const;
/**
* @brief ID
* @param planId ID
* @return nullptr
*/
const PlanData* findPlanById(const std::string& planId) const;
/**
* @brief
* @param planIds ID
* @return
*/
std::string comparePlans(const std::vector<std::string>& planIds) const;
// ======================== 事件管理 (F-006, F-007) ========================
/**
* @brief
* @param raw
* @return ID
*
*
* 1.
* 2. /
* 3. StandardEvent
* 4. ID
*/
std::string ingestRawEvent(const EventRaw& raw);
/**
* @brief
* @return
*/
std::vector<StandardEvent> getPendingEvents() const;
/**
* @brief
* @param eventId ID
* @param accept true false /
* @return true
*/
bool processEvent(const std::string& eventId, bool accept);
// ======================== 任务生成 (F-008) ========================
/**
* @brief
* @param eventId ID
* @return ID
*
* "自主执行"
* "人在回路"
*/
std::string generateTaskFromEvent(const std::string& eventId);
// ======================== 模板管理 (F-009, F-010) ========================
/**
* @brief
* @param tmpl
* @return true
*/
bool addTemplate(const TaskTemplate& tmpl);
/**
* @brief
* @param scenario
* @return optional
*/
const TaskTemplate* matchBestTemplate(const std::string& scenario) const;
/**
* @brief
* @return
*/
std::string saveSnapshot();
/**
* @brief
* @param version
* @return true
*/
bool rollbackToSnapshot(const std::string& version);
// ======================== 分发监控 (F-004, F-005) ========================
/**
* @brief
* @param planId ID
* @param nodeIds ID
* @return
*
* maxRetryCount
*/
int dispatchPlan(const std::string& planId, const std::vector<std::string>& nodeIds);
/**
* @brief
* @return
*/
std::vector<DistributionAck> getDistributionAcks() const;
/**
* @brief
* @param status
*/
void reportExecutionStatus(const ExecutionStatus& status);
/**
* @brief
* @param taskId ID
* @return nullptr
*/
const ExecutionStatus* getExecutionStatus(const std::string& taskId) const;
// ======================== 配置与日志 ========================
/**
* @brief
* @param log
*/
void logOperation(const OperationLog& log);
/**
* @brief
* @return
*/
std::vector<OperationLog> getOperationLogs() const;
/**
* @brief
* @return
*/
const SystemConfig& getConfig() const;
private:
/// @brief 内部实现类,隐藏具体实现细节
class Impl;
/// @brief PIMPL 模式实现指针
std::unique_ptr<Impl> pImpl_;
};
} // namespace c2sys
#endif // C2SYS_APP_HPP