| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #pragma once
- #include "../pch/pch.h"
- #include "../order/CWaimaiOrder.h"
- using boost::asio::ip::tcp;
- class CClientMessage
- {
- public:
- int m_type; //消息类型 0:新的外卖订单
- std::string m_username;
- std::string m_order_id;
- std::string m_order_no;
- };
- class WaimaiPinterInfo
- {
- public:
- std::string order_id;
- std::string order_no;
- };
- class CMessagePush
- {
- public:
- CMessagePush()
- : socket_(m_io_context)
- {
- }
- ~CMessagePush();
- void Start();
- void Run();
- void StopWork()
- {
- m_is_work = false;
- }
- void PushMessage(std::string msg);
- //专门处理推送消息
- void HandleMessage(std::string msg);
- //队列处理
- void HandleVoice();
- void HandleConfirm();
- void HandlePrinter();
- void HandleShouyinPrinter();
- void HandleChufangPrinter();
- void AddPinter(std::string order_id, std::string order_no);
- void AddShouyinPrinter(CWaimaiOrder order);
- void AddChufangPrinter(CWaimaiOrder order);
- private:
- void handle_read(const boost::system::error_code& error,
- size_t bytes_transferred);
- void handle_write(const boost::system::error_code& error);
- void AddVoice(std::string order_id);
- void AddConfirm(std::string order_id);
- private:
- bool m_is_work = true;
- boost::asio::io_context m_io_context;
- tcp::socket socket_;
- enum { max_length = 1024 };
- char data_[max_length];
- std::queue<std::string> m_voice_queue;
- std::queue<std::string> m_confirm_queue;
- std::queue<WaimaiPinterInfo> m_printer_queue;
- std::queue<CWaimaiOrder> m_shouyin_printer_queue;
- std::queue<CWaimaiOrder> m_chufang_printer_queue;
- std::mutex m_voice_mutex;
- std::mutex m_confirm_mutex;
- std::mutex m_printer_mutex;
- std::mutex m_shouyin_printer_mutex;
- std::mutex m_chufang_printer_mutex;
- };
|