|
|
@@ -10,9 +10,15 @@ CMessagePush::~CMessagePush()
|
|
|
|
|
|
void CMessagePush::Start()
|
|
|
{
|
|
|
+ std::thread t(&CMessagePush::Run, this);
|
|
|
+ t.detach();
|
|
|
+}
|
|
|
+
|
|
|
+void CMessagePush::Run()
|
|
|
+{
|
|
|
try
|
|
|
{
|
|
|
- char host[] = "192.168.3.29";
|
|
|
+ char host[] = "127.0.0.1";
|
|
|
char port[] = "9001";
|
|
|
|
|
|
tcp::resolver resolver(m_io_context);
|
|
|
@@ -43,13 +49,13 @@ void CMessagePush::Start()
|
|
|
boost::bind(&CMessagePush::handle_read, this,
|
|
|
boost::asio::placeholders::error,
|
|
|
boost::asio::placeholders::bytes_transferred));
|
|
|
+
|
|
|
+ m_io_context.run();
|
|
|
}
|
|
|
catch (std::exception& e)
|
|
|
{
|
|
|
std::cerr << "Exception: " << e.what() << "\n";
|
|
|
}
|
|
|
-
|
|
|
- CSystem::my_sleep(100);
|
|
|
}
|
|
|
|
|
|
void CMessagePush::PushMessage(std::string msg)
|
|
|
@@ -74,12 +80,22 @@ void CMessagePush::HandleMessage(std::string msg)
|
|
|
}
|
|
|
|
|
|
int type = document["type"].GetInt();
|
|
|
- std::string username = document["username"].GetString();
|
|
|
- std::string order_id = document["order_id"].GetString();
|
|
|
- std::string order_no = document["order_no"].GetString();
|
|
|
|
|
|
- if (type == 1)
|
|
|
+ if (type == 0)
|
|
|
+ {
|
|
|
+ std::string status = document["status"].GetString();
|
|
|
+
|
|
|
+ if (status == "ok")
|
|
|
+ {
|
|
|
+ //表示连接服务器成功了
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (type == 1)
|
|
|
{
|
|
|
+ std::string username = document["username"].GetString();
|
|
|
+ std::string order_id = document["order_id"].GetString();
|
|
|
+ std::string order_no = document["order_no"].GetString();
|
|
|
+
|
|
|
CPosPrinter printer;
|
|
|
printer.PrintWaimaiOrder(order_id, order_no);
|
|
|
}
|
|
|
@@ -96,29 +112,7 @@ void CMessagePush::handle_read(const boost::system::error_code& error,
|
|
|
if (!error)
|
|
|
{
|
|
|
string s_reply = data_;
|
|
|
-
|
|
|
- rapidjson::Document document;
|
|
|
- document.Parse(s_reply.c_str());
|
|
|
- if (!document.IsObject())
|
|
|
- {
|
|
|
- LOG_INFO("message 非法!");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- int type = document["type"].GetInt();
|
|
|
- if (type == 0)
|
|
|
- {
|
|
|
- std::string status = document["status"].GetString();
|
|
|
-
|
|
|
- if (status == "ok")
|
|
|
- {
|
|
|
- //表示连接服务器成功了
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- HandleMessage(s_reply);
|
|
|
- }
|
|
|
+ HandleMessage(s_reply);
|
|
|
|
|
|
memset(data_, 0, max_length);
|
|
|
socket_.async_read_some(boost::asio::buffer(data_, max_length),
|