process_task.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "thread_condition.h"
  7. #include "TaskQueue/BaseTask.h"
  8. #include "process_message.pb.h"
  9. /*
  10. * 停取车流程基类, 包括任务创建, 状态消息发布线程启动, 任务取消等公共功能
  11. * 该类继承自tq::BaseTask类, 可让入 tq 线程池, 执行虚函数 Main
  12. * 派生出 停车任务类(StoreProcessTask)与取车任务类(PickupProcessTask)
  13. */
  14. class Process_task : public tq::BaseTask{
  15. protected:
  16. enum EStep_type
  17. {
  18. eAlloc_step=0,
  19. eMeasure_step,
  20. eCompare_step,
  21. eDispatch_step,
  22. eConfirm_step,
  23. eSearch_step, //查询数据库
  24. eWait_step, //等待车辆离开
  25. eRelease_step, //释放车位
  26. eComplete, //完成
  27. eBackConfirm_step,
  28. eBack_compare_step,
  29. eBackMeasure_step,
  30. eBackAlloc_step,
  31. eBackWait_step,
  32. eBackDispatch_step,
  33. eBackSearch_step,
  34. eBackComplete
  35. };
  36. public:
  37. Process_task(unsigned int command_id,message::Car_info car_info);
  38. virtual ~Process_task();
  39. unsigned int terminal_id(){return m_terminor_id;}
  40. std::string license(){ return m_car_info.license();}
  41. EStep_type step_type(){return m_step_type;}
  42. /*
  43. * 取消任务
  44. */
  45. virtual void Cancel();
  46. /*
  47. * 任务是否取消
  48. */
  49. virtual bool is_canceled();
  50. protected:
  51. /*
  52. * 发布进度消息
  53. */
  54. static void publish_thread_func(Process_task* ptask);
  55. virtual void publish_step_status()=0;
  56. protected:
  57. unsigned int m_terminor_id;
  58. message::Car_info m_car_info; //当前流程的车辆信息
  59. EStep_type m_step_type;
  60. std::thread* m_publish_statu_thread; //广播状态线程
  61. Thread_condition m_publish_exit_condition; //发送的条件变量
  62. Thread_condition m_cancel_condition; //取消任务标志位
  63. std::mutex m_process_msg_lock; //状态消息锁
  64. };
  65. #endif //NNXX_TESTS_PROCESS_TASK_H