system_executor.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // Created by huli on 2020/7/2.
  3. //
  4. #ifndef NNXX_TESTS_SYSTEM_EXECUTOR_H
  5. #define NNXX_TESTS_SYSTEM_EXECUTOR_H
  6. #include "../tool/thread_pool.h"
  7. #include "../tool/singleton.h"
  8. #include "../error_code/error_code.h"
  9. #include "../communication/communication_message.h"
  10. class System_executor:public Singleton<System_executor>
  11. {
  12. // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
  13. friend class Singleton<System_executor>;
  14. public:
  15. //系统执行者的状态
  16. enum System_executor_status
  17. {//default SYSTEM_EXECUTOR_UNKNOW = 0
  18. SYSTEM_EXECUTOR_UNKNOW = 0, //
  19. SYSTEM_EXECUTOR_READY = 1, //
  20. SYSTEM_EXECUTOR_FAULT = 10, //
  21. };
  22. private:
  23. // 父类的构造函数必须保护,子类的构造函数必须私有。
  24. System_executor();
  25. public:
  26. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  27. System_executor(const System_executor& other) = delete;
  28. System_executor& operator =(const System_executor& other) = delete;
  29. ~System_executor();
  30. public://API functions
  31. //初始化
  32. Error_manager system_executor_init(int threads_size);
  33. //反初始化
  34. Error_manager system_executor_uninit();
  35. //检查执行者的状态, 判断能否处理这条消息,
  36. Error_manager check_executer(Communication_message* p_msg);
  37. //处理消息的执行函数
  38. Error_manager execute_msg(Communication_message* p_msg);
  39. //检查状态
  40. Error_manager check_status();
  41. //判断是否为待机,如果已经准备好,则可以执行任务。
  42. bool is_ready();
  43. public://get or set member variable
  44. System_executor_status get_system_executor_status();
  45. public:
  46. //雷达感测定位 的处理函数
  47. //input::command_id, 消息指令id, 由主控制系统生成的唯一码
  48. //input::command_id, 终端id, 对应具体的某个车位
  49. //return::void, 没有返回, 执行结果直接生成一条答复消息, 然后通过通信返回
  50. void execute_for_measure(int command_id, int terminal_id);
  51. protected://member variable
  52. System_executor_status m_system_executor_status; //系统执行者的状态
  53. Thread_pool m_thread_pool; //执行多任务的线程池
  54. private:
  55. };
  56. #endif //NNXX_TESTS_SYSTEM_EXECUTOR_H