Sectorpower.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2022-04-02 14:19:36
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2022-06-15 10:55:46
  8. */
  9. #ifndef __SECTORPOWER_HPP_
  10. #define __SECTORPOWER_HPP_
  11. #include <iostream>
  12. #include "ins_base.hpp"
  13. #include <mutex>
  14. #include <thread>
  15. #include <condition_variable>
  16. #include <queue>
  17. #include <vector>
  18. #include "Util/logger.h"
  19. #include "Util/NoticeCenter.h"
  20. #include "TaskCenter.hpp"
  21. using namespace std;
  22. using namespace toolkit;
  23. namespace ins
  24. {
  25. /**
  26. * @description: sectorPower 权力部门
  27. */
  28. class Sectorpower:public Module
  29. {
  30. private:
  31. Sectorpower();
  32. public:
  33. using Ptr = std::shared_ptr<Sectorpower>;
  34. ~Sectorpower(){this->Destroy();}
  35. /**
  36. * @description: 获取ptr
  37. * @param {*}
  38. * @return {*}
  39. */
  40. static std::shared_ptr<Sectorpower> getPtr();
  41. /**
  42. * @description: 初始化
  43. * @param {*}
  44. * @return {*}
  45. */
  46. int8_t Init() override;
  47. /**
  48. * @description: 释放
  49. * @param {*}
  50. * @return {*}
  51. */
  52. void Destroy() override;
  53. /**
  54. * @description: 是否正常
  55. * @param {*}
  56. * @return {*}
  57. */
  58. bool isNormally() override{
  59. return true;
  60. }
  61. /**
  62. * @description: 检查任务
  63. * @param {*}
  64. * @return {*}
  65. */
  66. bool reviewTask(ins::InsTask::Ptr& task);
  67. /**
  68. * @description: 获取工作流任务
  69. * @param {*}
  70. * @return {*}
  71. */
  72. InsTask::Ptr getWorkflowTask(InsPacket::Ptr pack);
  73. /**
  74. * @description: 业务入队
  75. * @param {*}
  76. * @return {*}
  77. */
  78. int8_t enqueue(InsPacket::Ptr packet);
  79. /**
  80. * @description: 使能
  81. * @return {*}
  82. */
  83. bool getEnable(){
  84. return Enable;
  85. }
  86. /**
  87. * @description: 设置使能
  88. * @param {bool} result
  89. * @return {*}
  90. */
  91. bool setEnable(bool result){
  92. Enable = result;
  93. return true;
  94. }
  95. protected:
  96. mutex m_mutex;
  97. condition_variable condition;
  98. bool stop = false;
  99. vector<thread> workers;
  100. queue<InsPacket::Ptr> Transactions;
  101. bool Enable = false;
  102. };
  103. } // namespace name
  104. #endif