message_communicator.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Created by zx on 2020/8/28.
  3. //
  4. #ifndef NNXX_TESTS_MESSAGE_COMMUNICATOR_H
  5. #define NNXX_TESTS_MESSAGE_COMMUNICATOR_H
  6. #include "singleton.h"
  7. #include "communication_socket_base.h"
  8. #include "error_code.h"
  9. class Message_communicator :public Singleton<Message_communicator>, public Communication_socket_base
  10. {
  11. friend class Singleton<Message_communicator>;
  12. public:
  13. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  14. Message_communicator(const Message_communicator& other) = delete;
  15. Message_communicator& operator =(const Message_communicator& other) = delete;
  16. /*
  17. * 发送消息
  18. */
  19. Error_manager send_msg(Communication_message* p_msg);
  20. ~Message_communicator();
  21. protected:
  22. // 父类的构造函数必须保护,子类的构造函数必须私有。
  23. Message_communicator();
  24. virtual Error_manager execute_msg(Communication_message* p_msg);
  25. /*
  26. * 检测消息是否可被处理
  27. */
  28. virtual Error_manager check_msg(Communication_message* p_msg);
  29. /*
  30. * 心跳发送函数,重载
  31. */
  32. virtual Error_manager encapsulate_send_data();
  33. //检查消息是否可以被解析, 需要重载
  34. virtual Error_manager check_executer(Communication_message* p_msg);
  35. };
  36. #endif //NNXX_TESTS_MESSAGE_COMMUNICATOR_H