AuditPlugin.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "AuditPlugin.hpp"
  2. namespace gsd
  3. {
  4. /**
  5. * @description: CreateNew
  6. * @return {*}
  7. */
  8. std::shared_ptr<AuditPlugin> AuditPlugin::getPtr(){
  9. static std::shared_ptr<AuditPlugin> m_AuditPlugin = nullptr;
  10. if(m_AuditPlugin == nullptr) m_AuditPlugin = std::shared_ptr<AuditPlugin>(new AuditPlugin);
  11. return m_AuditPlugin;
  12. }
  13. /**
  14. * @description: 初始化
  15. * @return {*}
  16. */
  17. bool AuditPlugin::Init(){
  18. if(this->pool == nullptr) this->pool = std::make_shared<ThreadPool>(1,ThreadPool::PRIORITY_HIGHEST, false);
  19. return true;
  20. }
  21. /**
  22. * @description: 启动任务
  23. * @return {*}
  24. */
  25. bool AuditPlugin::StartTask(){
  26. if(this->timer == nullptr) this->timer = std::make_shared<toolkit::Timer>(10.0f, [&](){
  27. this->PluginTaskCheck();
  28. return true;
  29. }, nullptr);
  30. return true;
  31. }
  32. /**
  33. * @description: Destroy
  34. * @return {*}
  35. */
  36. void AuditPlugin::Destroy(){
  37. }
  38. /**
  39. * @description: Alive
  40. * @return {*}
  41. */
  42. bool AuditPlugin::Alive(){
  43. return true;
  44. }
  45. /**
  46. * @description: PluginTaskCheck
  47. * @return {*}
  48. */
  49. bool AuditPlugin::PluginTaskCheck(){
  50. this->map_ = PuginFactory::getPtr()->getMap();
  51. for(auto iter = this->map_.begin(); iter != this->map_.end(); iter++){
  52. if(!iter->second()->Alive()) {
  53. if(this->pool == nullptr) continue;
  54. auto pluginPtr = iter->second();
  55. this->pool->async([pluginPtr](){
  56. pluginPtr->RestPlugin();
  57. });
  58. this->pool->start();
  59. }
  60. }
  61. return true;
  62. }
  63. } // namespace gsd