CMessagePush.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include "../pch/pch.h"
  3. #include "../order/CWaimaiOrder.h"
  4. using boost::asio::ip::tcp;
  5. class CClientMessage
  6. {
  7. public:
  8. int m_type; //消息类型 0:新的外卖订单
  9. std::string m_username;
  10. std::string m_order_id;
  11. std::string m_order_no;
  12. };
  13. class WaimaiPinterInfo
  14. {
  15. public:
  16. std::string order_id;
  17. std::string order_no;
  18. };
  19. class CMessagePush
  20. {
  21. public:
  22. CMessagePush()
  23. : socket_(m_io_context)
  24. {
  25. }
  26. ~CMessagePush();
  27. //开始工作
  28. void Start();
  29. void StopWork()
  30. {
  31. m_is_work = false;
  32. }
  33. //发送心跳包
  34. void KeepAlive();
  35. //专门处理推送消息
  36. void ReceiveMessage();
  37. //队列处理
  38. void HandleVoice();
  39. void HandleConfirm();
  40. void HandlePrinter();
  41. void HandleShouyinPrinter();
  42. void HandleChufangPrinter();
  43. void AddVoice(std::string order_id);
  44. void AddConfirm(std::string order_id);
  45. void AddPinter(std::string order_id, std::string order_no);
  46. void AddShouyinPrinter(CWaimaiOrder order);
  47. void AddChufangPrinter(CWaimaiOrder order);
  48. private:
  49. bool m_is_work = true;
  50. boost::asio::io_context m_io_context;
  51. tcp::socket socket_;
  52. enum { max_length = 1024 };
  53. char data_[max_length];
  54. std::queue<std::string> m_voice_queue;
  55. std::queue<std::string> m_confirm_queue;
  56. std::queue<WaimaiPinterInfo> m_printer_queue;
  57. std::queue<CWaimaiOrder> m_shouyin_printer_queue;
  58. std::queue<CWaimaiOrder> m_chufang_printer_queue;
  59. std::mutex m_voice_mutex;
  60. std::mutex m_confirm_mutex;
  61. std::mutex m_printer_mutex;
  62. std::mutex m_shouyin_printer_mutex;
  63. std::mutex m_chufang_printer_mutex;
  64. };