system_communication_mq.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * @Author: yct 18202736439@163.com
  3. * @Date: 2022-09-30 18:09:07
  4. * @LastEditors: yct 18202736439@163.com
  5. * @LastEditTime: 2022-09-30 18:35:01
  6. * @FilePath: /puai_wj_2021/system/system_communication_mq.h
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. //
  10. // Created by huli on 2020/6/28.
  11. //
  12. #ifndef NNXX_TESTS_SYSTEM_COMMUNICATION_MQ_H
  13. #define NNXX_TESTS_SYSTEM_COMMUNICATION_MQ_H
  14. #include "../tool/singleton.h"
  15. #include "../rabbitmq/rabbitmq_base.h"
  16. #include "../message/message.pb.h"
  17. #include <map>
  18. #include <mutex>
  19. class System_communication_mq:public Singleton<System_communication_mq>, public Rabbitmq_base
  20. {
  21. // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
  22. friend class Singleton<System_communication_mq>;
  23. private:
  24. // 父类的构造函数必须保护,子类的构造函数必须私有。
  25. System_communication_mq();
  26. public:
  27. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  28. System_communication_mq(const System_communication_mq& other) = delete;
  29. System_communication_mq& operator =(const System_communication_mq& other) = delete;
  30. ~System_communication_mq();
  31. public://API functions
  32. //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
  33. virtual Error_manager check_msg(Rabbitmq_message* p_msg);
  34. //检查执行者的状态, 判断能否处理这条消息, 需要子类重载
  35. virtual Error_manager check_executer(Rabbitmq_message* p_msg);
  36. //处理消息, 需要子类重载
  37. virtual Error_manager execute_msg(Rabbitmq_message* p_msg);
  38. //定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
  39. virtual Error_manager auto_encapsulate_status();
  40. //get dispatch status, save local
  41. Error_manager execute_dispatch_status_msg(Rabbitmq_message* p_msg);
  42. public://get or set member variable
  43. protected://member variable
  44. public:
  45. std::mutex m_lock; //锁,
  46. std::map<int, dispatch_region_info> dispatch_region_info_map;
  47. private:
  48. };
  49. #endif //NNXX_TESTS_SYSTEM_COMMUNICATION_MQ_H