process_task.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // Created by zx on 2020/8/26.
  3. //
  4. #ifndef NNXX_TESTS_PROCESS_TASK_H
  5. #define NNXX_TESTS_PROCESS_TASK_H
  6. #include <error_code.h>
  7. #include "thread_condition.h"
  8. #include "TaskQueue/BaseTask.h"
  9. #include "process_message.pb.h"
  10. #include <glog/logging.h>
  11. /*
  12. * 停取车流程基类, 包括任务创建, 状态消息发布线程启动, 任务取消等公共功能
  13. * 该类继承自tq::BaseTask类, 可放入 tq 线程池, 执行虚函数 Main
  14. * 派生出 停车任务类(StoreProcessTask)与取车任务类(PickupProcessTask)
  15. */
  16. class Process_task : public tq::BaseTask{
  17. public:
  18. Process_task(unsigned int command_id,message::Car_info car_info);
  19. virtual ~Process_task();
  20. /*
  21. * 获取当前任务相关属性
  22. */
  23. unsigned int terminal_id(){return m_terminor_id;}
  24. std::string license(){ return m_car_info.license();}
  25. message::Step_type current_step_type(){return m_current_step_type;}
  26. message::Step_statu current_step_statu(){return m_current_step_statu;}
  27. // 获取任务类型
  28. virtual message::Process_type get_process_type() const=0;
  29. /*
  30. * 取消任务
  31. */
  32. virtual void Cancel();
  33. /*
  34. * 任务是否取消
  35. */
  36. virtual bool is_canceled();
  37. /*
  38. * 控制流程到下一步
  39. */
  40. virtual Error_manager next_step(){
  41. LOG(ERROR)<<"process base virtual called";
  42. return ERROR;};
  43. virtual void updata_step_statu(message::Step_statu statu)=0;
  44. protected:
  45. /*
  46. * 发布进度消息
  47. */
  48. static void publish_thread_func(Process_task* ptask);
  49. virtual void publish_step_status()=0;
  50. protected:
  51. unsigned int m_terminor_id;
  52. message::Car_info m_car_info; //当前流程的车辆信息
  53. message::Step_type m_current_step_type; //当前流程正在哪一步
  54. message::Step_statu m_current_step_statu; //当前步骤所处的状态
  55. std::thread* m_publish_statu_thread; //广播状态线程
  56. Thread_condition m_publish_exit_condition; //发送的条件变量
  57. Thread_condition m_cancel_condition; //取消任务标志位
  58. std::mutex m_process_msg_lock; //状态消息锁
  59. };
  60. #endif //NNXX_TESTS_PROCESS_TASK_H