CMessagePush.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. void Start();
  28. void Run();
  29. void StopWork()
  30. {
  31. m_is_work = false;
  32. }
  33. void PushMessage(std::string msg);
  34. //专门处理推送消息
  35. void HandleMessage(std::string msg);
  36. //队列处理
  37. void HandleVoice();
  38. void HandleConfirm();
  39. void HandlePrinter();
  40. void HandleShouyinPrinter();
  41. void HandleChufangPrinter();
  42. void AddPinter(std::string order_id, std::string order_no);
  43. void AddShouyinPrinter(CWaimaiOrder order);
  44. void AddChufangPrinter(CWaimaiOrder order);
  45. private:
  46. void handle_read(const boost::system::error_code& error,
  47. size_t bytes_transferred);
  48. void handle_write(const boost::system::error_code& error);
  49. void AddVoice(std::string order_id);
  50. void AddConfirm(std::string order_id);
  51. private:
  52. bool m_is_work = true;
  53. boost::asio::io_context m_io_context;
  54. tcp::socket socket_;
  55. enum { max_length = 1024 };
  56. char data_[max_length];
  57. std::queue<std::string> m_voice_queue;
  58. std::queue<std::string> m_confirm_queue;
  59. std::queue<WaimaiPinterInfo> m_printer_queue;
  60. std::queue<CWaimaiOrder> m_shouyin_printer_queue;
  61. std::queue<CWaimaiOrder> m_chufang_printer_queue;
  62. std::mutex m_voice_mutex;
  63. std::mutex m_confirm_mutex;
  64. std::mutex m_printer_mutex;
  65. std::mutex m_shouyin_printer_mutex;
  66. std::mutex m_chufang_printer_mutex;
  67. };