system_executor.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #include "../dispatch/dispatch_manager.h"
  11. //#include "../locate/locate_manager.h"
  12. //#include "../locate/locate_manager_task.h"
  13. class System_executor:public Singleton<System_executor>
  14. {
  15. // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
  16. friend class Singleton<System_executor>;
  17. public:
  18. //系统执行者的状态
  19. enum System_executor_status
  20. {//default SYSTEM_EXECUTOR_UNKNOW = 0
  21. SYSTEM_EXECUTOR_UNKNOW = 0, //
  22. SYSTEM_EXECUTOR_READY = 1, //
  23. SYSTEM_EXECUTOR_FAULT = 10, //
  24. };
  25. private:
  26. // 父类的构造函数必须保护,子类的构造函数必须私有。
  27. System_executor();
  28. public:
  29. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  30. System_executor(const System_executor& other) = delete;
  31. System_executor& operator =(const System_executor& other) = delete;
  32. ~System_executor();
  33. public://API functions
  34. //初始化
  35. Error_manager system_executor_init(int threads_size);
  36. //反初始化
  37. Error_manager system_executor_uninit();
  38. //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
  39. Error_manager check_msg(Communication_message* p_msg);
  40. //检查执行者的状态, 判断能否处理这条消息,
  41. Error_manager check_executer(Communication_message* p_msg);
  42. //处理消息的执行函数
  43. Error_manager execute_msg(Communication_message* p_msg);
  44. //检查状态
  45. Error_manager check_status();
  46. //定时发送状态信息
  47. Error_manager encapsulate_send_status();
  48. //判断是否为待机,如果已经准备好,则可以执行任务。
  49. bool is_ready();
  50. public://get or set member variable
  51. System_executor_status get_system_executor_status();
  52. public:
  53. //雷达感测定位 的处理函数
  54. //input::command_id, 消息指令id, 由主控制系统生成的唯一码
  55. //input::command_id, 终端id, 对应具体的某个车位
  56. //return::void, 没有返回, 执行结果直接生成一条答复消息, 然后通过通信返回
  57. void execute_for_measure(std::string command_key, int terminal_id);
  58. //调度模块的处理函数
  59. void execute_for_dispatch(std::string command_key, Dispatch_manager::Dispatch_motion_direction dispatch_motion_direction,
  60. int terminal_id, int parkspace_id, Locate_information * p_locate_information);
  61. protected://member variable
  62. System_executor_status m_system_executor_status; //系统执行者的状态
  63. Thread_pool m_thread_pool; //执行多任务的线程池
  64. private:
  65. };
  66. #endif //NNXX_TESTS_SYSTEM_EXECUTOR_H