system_executor.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 check_executer(Communication_message* p_msg);
  35. //处理消息的执行函数
  36. Error_manager execute_msg(Communication_message* p_msg);
  37. //检查状态
  38. Error_manager check_status();
  39. //判断是否为待机,如果已经准备好,则可以执行任务。
  40. bool is_ready();
  41. public://get or set member variable
  42. public:
  43. //雷达感测定位 的处理函数
  44. //input::command_id, 消息指令id, 由主控制系统生成的唯一码
  45. //input::command_id, 终端id, 对应具体的某个车位
  46. //return::void, 没有返回, 执行结果直接生成一条答复消息, 然后通过通信返回
  47. void execute_for_measure(int command_id, int terminal_id);
  48. protected://member variable
  49. System_executor_status m_system_executor_status; //系统执行者的状态
  50. Thread_pool m_thread_pool; //执行多任务的线程池
  51. private:
  52. };
  53. #endif //NNXX_TESTS_SYSTEM_EXECUTOR_H