#include "AuditPlugin.hpp" namespace gsd { /** * @description: CreateNew * @return {*} */ std::shared_ptr AuditPlugin::getPtr(){ static std::shared_ptr m_AuditPlugin = nullptr; if(m_AuditPlugin == nullptr) m_AuditPlugin = std::shared_ptr(new AuditPlugin); return m_AuditPlugin; } /** * @description: 初始化 * @return {*} */ bool AuditPlugin::Init(){ if(this->pool == nullptr) this->pool = std::make_shared(1,ThreadPool::PRIORITY_HIGHEST, false); return true; } /** * @description: 启动任务 * @return {*} */ bool AuditPlugin::StartTask(){ if(this->timer == nullptr) this->timer = std::make_shared(10.0f, [&](){ this->PluginTaskCheck(); return true; }, nullptr); return true; } /** * @description: Destroy * @return {*} */ void AuditPlugin::Destroy(){ } /** * @description: Alive * @return {*} */ bool AuditPlugin::Alive(){ return true; } /** * @description: PluginTaskCheck * @return {*} */ bool AuditPlugin::PluginTaskCheck(){ this->map_ = PuginFactory::getPtr()->getMap(); for(auto iter = this->map_.begin(); iter != this->map_.end(); iter++){ if(!iter->second()->Alive()) { if(this->pool == nullptr) continue; auto pluginPtr = iter->second(); this->pool->async([pluginPtr](){ pluginPtr->RestPlugin(); }); this->pool->start(); } } return true; } } // namespace gsd