command_manager.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // Created by zx on 2020/7/14.
  3. //
  4. /*
  5. * 指令管理, 包括指令的接收,指令的执行控制,指令的状态追踪,出入口状态检查
  6. */
  7. #ifndef NNXX_TESTS_COMMAND_MANAGER_H
  8. #define NNXX_TESTS_COMMAND_MANAGER_H
  9. #include <error_code.h>
  10. #include <terminal_message.pb.h>
  11. #include <communication_message.h>
  12. #include "thread_condition.h"
  13. #include "singleton.h"
  14. #include "TaskQueue/TQFactory.h"
  15. #include "TaskQueue/BaseTask.h"
  16. #include "central_control_message.pb.h"
  17. #include "thread_safe_map.h"
  18. #include "system_setting.pb.h"
  19. class Command_manager :public Singleton<Command_manager>{
  20. friend Singleton<Command_manager>;
  21. public:
  22. enum Entrance_statu
  23. {
  24. Enable=0,
  25. Disable,
  26. Paused,
  27. };
  28. public:
  29. ~Command_manager();
  30. /*
  31. * 初始化函数,创建线程池,创建状态广播线程,根据配置创建停取车流程
  32. */
  33. Error_manager init(setting::System_setting system_setting);
  34. /*
  35. * 执行停车请求
  36. */
  37. Error_manager execute_store_command(message::Store_command_request_msg& request,message::Store_command_response_msg& response);
  38. /*
  39. * 执行取车请求
  40. */
  41. Error_manager execute_pickup_command(message::Pickup_command_request_msg& request,message::Pickup_command_response_msg& response);
  42. /*
  43. * 控制入口 开放或者关闭
  44. */
  45. Error_manager enable_entrance(int terminal_id,Entrance_statu statu);
  46. /*
  47. * 控制出口 开放或者关闭
  48. */
  49. Error_manager enable_export(int terminal_id, Entrance_statu statu);
  50. /*
  51. * pause,系统急停,急停状态下不允许自动流程的指令执行,允许管理员手动指令执行
  52. */
  53. void pause_system();
  54. private:
  55. Command_manager();
  56. static void publish_statu_function(Command_manager* commander);
  57. void publish_statu();
  58. protected:
  59. tq::IQueue* m_thread_queue_process; //指令流程线程池
  60. bool m_system_paused;
  61. std::vector<Entrance_statu> m_input_entrance_statu; //入口状态(关闭/开放)
  62. std::vector<Entrance_statu> m_output_entrance_statu; //出口状态(关闭/开放)
  63. setting::System_setting m_system_setting;
  64. std::thread* m_publish_statu_thread; //广播状态线程
  65. Thread_condition m_publish_exit_condition; //发送的条件变量
  66. };
  67. #endif //NNXX_TESTS_COMMAND_MANAGER_H