exception_solver.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // Created by zx on 2020/8/20.
  3. //
  4. #include "exception_solver.h"
  5. #include "command_manager.h"
  6. Exception_solver::Exception_solver() {
  7. }
  8. Exception_solver::~Exception_solver() {
  9. }
  10. Error_manager Exception_solver::add_task_cancel_condition(std::string license,tq::BaseTask* task)
  11. {
  12. if(m_ptask_map.find(license)==true || task== nullptr)
  13. {
  14. return Error_manager(ERROR,MINOR_ERROR,"任务标识已存在,或者标识地址为null");
  15. }
  16. m_ptask_map[license]=task;
  17. return SUCCESS;
  18. }
  19. Error_manager Exception_solver::delete_task_cancel_condition(std::string license)
  20. {
  21. if(m_ptask_map.find(license)==true)
  22. {
  23. m_ptask_map.erase(license);
  24. return SUCCESS;
  25. }
  26. return Error_manager(ERROR,MINOR_ERROR,"任务取消标志不存在");
  27. }
  28. Error_manager Exception_solver::encapsulate_msg(Communication_message* message)
  29. {
  30. Error_manager code;
  31. //记录请求
  32. switch (message->get_message_type())
  33. {
  34. default:
  35. code= Communication_socket_base::encapsulate_msg(message);
  36. break;
  37. }
  38. return code;
  39. }
  40. Error_manager Exception_solver::execute_msg(Communication_message* p_msg)
  41. {
  42. if(p_msg== nullptr)
  43. return Error_manager(POINTER_IS_NULL,CRITICAL_ERROR,"dispatch response msg pointer is null");
  44. //测量response消息
  45. switch (p_msg->get_message_type())
  46. {
  47. default:break;
  48. }
  49. return SUCCESS;
  50. }
  51. /*
  52. * 检测消息是否可被处理
  53. */
  54. Error_manager Exception_solver::check_msg(Communication_message* p_msg)
  55. {
  56. //通过 p_msg->get_message_type() 和 p_msg->get_receiver() 判断这条消息是不是给我的.
  57. //子类重载时, 增加自己模块的判断逻辑, 以后再写.
  58. /*if ( (p_msg->get_message_type() == Communication_message::Message_type::eDispatch_response_msg
  59. ||p_msg->get_message_type() == Communication_message::Message_type::eDispatch_status_msg)
  60. && p_msg->get_receiver() == Communication_message::Communicator::eMain )
  61. {
  62. return Error_code::SUCCESS;
  63. }
  64. else
  65. {
  66. //认为接受人
  67. return Error_code::INVALID_MESSAGE;
  68. }*/
  69. }
  70. /*
  71. * 心跳发送函数,重载
  72. */
  73. Error_manager Exception_solver::encapsulate_send_data()
  74. {
  75. return SUCCESS;
  76. }
  77. //检查消息是否可以被解析, 需要重载
  78. Error_manager Exception_solver::check_executer(Communication_message* p_msg)
  79. {
  80. return SUCCESS;
  81. }
  82. /*
  83. * 处理故障
  84. */
  85. Error_manager Exception_solver::solve_exception(Error_manager code,tq::BaseTask* task)
  86. {
  87. if(code.get_error_level()==CRITICAL_ERROR)
  88. {
  89. //系统急停
  90. Command_manager::get_instance_pointer()->pause_system();
  91. return SUCCESS;
  92. }
  93. if(code.get_error_level()==MAJOR_ERROR)
  94. {
  95. task->Cancel();
  96. //关闭出入口
  97. if(task->GetCategory()==message::eStoring) {
  98. StoreProcessTask* pstoring=(StoreProcessTask*)task;
  99. Command_manager::get_instance_pointer()->enable_entrance(pstoring->terminal_id(),false);
  100. }
  101. if(task->GetCategory()==message::ePicking) {
  102. PickupProcessTask* pPicking=(PickupProcessTask*)task;
  103. Command_manager::get_instance_pointer()->enable_export(pPicking->terminal_id(),false);
  104. }
  105. return SUCCESS;
  106. }
  107. switch(code.get_error_code())
  108. {
  109. case ERROR:
  110. {
  111. break;
  112. }
  113. }
  114. }