// // Created by xtkuang on 2025/6/6. // #ifndef ABSTRACT_MONITOR_H #define ABSTRACT_MONITOR_H #include #include #include "rapidxml/xml_parser.h" #include "../utils/base/timer.h" namespace cmvr::monitor{ class AbstractMonitor { public: explicit AbstractMonitor(const XmlNode &cfg){ cfg_ = cfg; freq_ = cfg_.getAttrDefault("freq", 1); timer_ = std::make_unique(); timer_->start(std::chrono::milliseconds(1000/freq_), [this](){run();}); } virtual ~AbstractMonitor() {timer_->stop();} void run() { if (!check_()) { execution_(); } } protected: XmlNode cfg_; int freq_; std::unique_ptr timer_; virtual bool check_() = 0; virtual bool execution_() = 0; }; } #endif //ABSTRACT_MONITOR_H