dispatch_network.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // Created by huli on 2023/1/3.
  3. //
  4. #ifndef NNXX_TESTS_DISPATCH_NETWORK_H
  5. #define NNXX_TESTS_DISPATCH_NETWORK_H
  6. #include "../tool/singleton.h"
  7. #include "../network_communication/network_base.h"
  8. class Dispatch_network:public Singleton<Dispatch_network>, public Network_base
  9. {
  10. // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
  11. friend class Singleton<Dispatch_network>;
  12. public:
  13. #define NETKORK_PARAMETER_PATH_A "../setting/network_a.prototxt"
  14. #define NETKORK_PARAMETER_PATH_B "../setting/network_b.prototxt"
  15. #define NETKORK_PARAMETER_PATH_C "../setting/network_c.prototxt"
  16. private:
  17. // 父类的构造函数必须保护,子类的构造函数必须私有。
  18. Dispatch_network();
  19. public:
  20. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  21. Dispatch_network(const Dispatch_network& other) = delete;
  22. Dispatch_network& operator =(const Dispatch_network& other) = delete;
  23. ~Dispatch_network();
  24. public://API functions
  25. //初始化 通信 模块。如下三选一
  26. virtual Error_manager network_init();
  27. virtual Error_manager network_init(int dispatch_id);
  28. //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
  29. virtual Error_manager check_msg(Network_message* p_msg);
  30. //检查执行者的状态, 判断能否处理这条消息, 需要子类重载
  31. virtual Error_manager check_executer(Network_message* p_msg);
  32. //处理消息, 需要子类重载
  33. virtual Error_manager execute_msg(Network_message* p_msg);
  34. //定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
  35. virtual Error_manager auto_encapsulate_status();
  36. public://get or set member variable
  37. protected://member functions
  38. protected://member variable
  39. private:
  40. };
  41. #endif //NNXX_TESTS_DISPATCH_NETWORK_H