system_communication.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // Created by huli on 2020/6/28.
  3. //
  4. #include "system_communication.h"
  5. #include "../system/system_executor.h"
  6. System_communication::System_communication()
  7. {
  8. }
  9. System_communication::~System_communication()
  10. {
  11. }
  12. //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
  13. Error_manager System_communication::check_msg(Communication_message* p_msg)
  14. {
  15. return System_executor::get_instance_references().check_msg(p_msg);
  16. }
  17. //检查执行者的状态, 判断能否处理这条消息, 需要子类重载
  18. Error_manager System_communication::check_executer(Communication_message* p_msg)
  19. {
  20. //检查对应模块的状态, 判断是否可以处理这条消息
  21. //同时也要判断是否超时, 超时返回 COMMUNICATION_ANALYSIS_TIME_OUT
  22. //如果处理器正在忙别的, 那么返回 COMMUNICATION_EXCUTER_IS_BUSY
  23. // std::cout << "Communication_socket_base::check_msg p_buf = " << p_msg->get_message_buf() << std::endl;
  24. // std::cout << "Communication_socket_base::check_msg size = " << p_msg->get_message_buf().size() << std::endl;
  25. Error_manager t_error;
  26. if ( p_msg->is_over_time() )
  27. {
  28. std::cout << "COMMUNICATION_ANALYSIS_TIME_OUT , " << std::endl;
  29. //超时:接收方不做处理,发送方会进行超时处理
  30. return Error_code::COMMUNICATION_ANALYSIS_TIME_OUT;
  31. }
  32. else
  33. {
  34. return System_executor::get_instance_references().check_executer(p_msg);
  35. }
  36. return Error_code::SUCCESS;
  37. }
  38. //处理消息, 需要子类重载
  39. Error_manager System_communication::execute_msg(Communication_message* p_msg)
  40. {
  41. return System_executor::get_instance_references().execute_msg(p_msg);
  42. }
  43. //定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
  44. Error_manager System_communication::encapsulate_send_data()
  45. {
  46. return System_executor::get_instance_references().encapsulate_send_status();
  47. }