dispatch_network.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // Created by huli on 2023/1/3.
  3. //
  4. #include "dispatch_network.h"
  5. #include "../dispatch/dispatch_manager.h"
  6. Dispatch_network::Dispatch_network()
  7. {
  8. }
  9. Dispatch_network::~Dispatch_network()
  10. {
  11. }
  12. //初始化 通信 模块。如下三选一
  13. Error_manager Dispatch_network::network_init()
  14. {
  15. return Network_base::network_init();
  16. }
  17. //初始化 通信 模块。如下三选一
  18. Error_manager Dispatch_network::network_init(int dispatch_id)
  19. {
  20. // return Network_base::network_init();
  21. switch ( dispatch_id )
  22. {
  23. case 0:
  24. {
  25. return Network_base::network_init_from_protobuf(NETKORK_PARAMETER_PATH_A);
  26. break;
  27. }
  28. case 1:
  29. {
  30. return Network_base::network_init_from_protobuf(NETKORK_PARAMETER_PATH_B);
  31. break;
  32. }
  33. case 2:
  34. {
  35. return Network_base::network_init_from_protobuf(NETKORK_PARAMETER_PATH_C);
  36. break;
  37. }
  38. default:
  39. {
  40. return Error_manager(Error_code::COMMUNICATION_READ_PROTOBUF_ERROR, Error_level::MINOR_ERROR,
  41. " Dispatch_network::communication_init dispatch_id error ");
  42. break;
  43. }
  44. }
  45. return Error_code::SUCCESS;
  46. }
  47. //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
  48. Error_manager Dispatch_network::check_msg(Network_message* p_msg)
  49. {
  50. return Error_code::SUCCESS;
  51. }
  52. //检查执行者的状态, 判断能否处理这条消息, 需要子类重载
  53. Error_manager Dispatch_network::check_executer(Network_message* p_msg)
  54. {
  55. return Error_code::SUCCESS;
  56. }
  57. //处理消息, 需要子类重载
  58. Error_manager Dispatch_network::execute_msg(Network_message* p_msg)
  59. {
  60. return Dispatch_manager::get_instance_references().execute_network_message_new(p_msg);
  61. }
  62. //定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
  63. Error_manager Dispatch_network::auto_encapsulate_status()
  64. {
  65. return Error_code::SUCCESS;
  66. }