process_task.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Created by zx on 2020/8/26.
  3. //
  4. #include "process_task.h"
  5. Process_task::Process_task(unsigned int terminal_id,message::Car_info car_info)
  6. :m_publish_statu_thread(nullptr)
  7. {
  8. m_terminor_id=terminal_id;
  9. m_car_info=car_info;
  10. }
  11. Process_task::~Process_task()
  12. {
  13. //退出线程
  14. m_publish_exit_condition.set_pass_ever(true);
  15. if(m_publish_statu_thread!= nullptr)
  16. {
  17. if(m_publish_statu_thread->joinable())
  18. {
  19. m_publish_statu_thread->join();
  20. }
  21. delete m_publish_statu_thread;
  22. m_publish_statu_thread=nullptr;
  23. }
  24. }
  25. /*
  26. * 取消任务
  27. */
  28. void Process_task::Cancel()
  29. {
  30. m_current_step_type= message::eBackComplete;
  31. m_cancel_condition.set_pass_ever(true);
  32. tq::BaseTask::Cancel();
  33. }
  34. /*
  35. * 发布进度
  36. */
  37. void Process_task::publish_thread_func(Process_task* ptask)
  38. {
  39. if(ptask)
  40. {
  41. //未收到退出信号
  42. while(false==ptask->m_publish_exit_condition.wait_for_ex(std::chrono::milliseconds(100))) {
  43. ptask->publish_step_status();
  44. }
  45. }
  46. }
  47. /*
  48. * 任务是否取消
  49. */
  50. bool Process_task::is_canceled()
  51. {
  52. return m_cancel_condition.wait_for_millisecond(1);
  53. }