process_task.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. /*
  11. * 停取车流程基类, 包括任务创建, 状态消息发布线程启动, 任务取消等公共功能
  12. * 该类继承自tq::BaseTask类, 可让入 tq 线程池, 执行虚函数 Main
  13. * 派生出 停车任务类(StoreProcessTask)与取车任务类(PickupProcessTask)
  14. */
  15. class Process_task : public tq::BaseTask{
  16. public:
  17. Process_task(unsigned int command_id,message::Car_info car_info);
  18. virtual ~Process_task();
  19. unsigned int terminal_id(){return m_terminor_id;}
  20. std::string license(){ return m_car_info.license();}
  21. message::Step_type current_step_type(){return m_current_step_type;}
  22. message::Step_statu current_step_statu(){return m_current_step_statu;}
  23. /*
  24. * 取消任务
  25. */
  26. virtual void Cancel();
  27. /*
  28. * 任务是否取消
  29. */
  30. virtual bool is_canceled();
  31. /*
  32. * 控制流程到下一步
  33. */
  34. virtual Error_manager next_step()=0;
  35. protected:
  36. /*
  37. * 发布进度消息
  38. */
  39. static void publish_thread_func(Process_task* ptask);
  40. virtual void publish_step_status()=0;
  41. protected:
  42. unsigned int m_terminor_id;
  43. message::Car_info m_car_info; //当前流程的车辆信息
  44. message::Step_type m_current_step_type; //当前流程正在哪一步
  45. message::Step_statu m_current_step_statu; //当前步骤所处的状态
  46. std::thread* m_publish_statu_thread; //广播状态线程
  47. Thread_condition m_publish_exit_condition; //发送的条件变量
  48. Thread_condition m_cancel_condition; //取消任务标志位
  49. std::mutex m_process_msg_lock; //状态消息锁
  50. };
  51. #endif //NNXX_TESTS_PROCESS_TASK_H