From 5ea8e79428d859e513330b17cd77a3feb7ae2d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Fri, 15 Sep 2017 22:55:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E5=8F=91=E6=B6=88=E6=81=AF=EF=BC=8C?= =?UTF-8?q?=E7=AE=AD=E5=A4=B4=E4=B9=8B=E5=89=8D=E4=BD=BF=E7=94=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Link/LinkClient.cpp | 12 +++++++++--- Link/TinyLink.cpp | 26 +++++++++++++++++++++++--- Link/TinyLink.h | 5 +++-- vs/SmartOS.vcxproj | 1 + vs/SmartOS.vcxproj.filters | 3 +++ 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Link/LinkClient.cpp b/Link/LinkClient.cpp index ced6eda7..993fa8e8 100644 --- a/Link/LinkClient.cpp +++ b/Link/LinkClient.cpp @@ -180,7 +180,9 @@ void LinkClient::OnReceive(LinkMessage& msg) TS("LinkClient::OnReceive"); #if DEBUG - debug_printf("Link <= "); + auto obj = dynamic_cast(Master); + obj->Show(false); + debug_printf(" <= "); msg.Show(true); #endif // DEBUG @@ -269,7 +271,9 @@ bool LinkClient::Invoke(const String& action, const Json& args) { if (_g_seq == 0)_g_seq++; #if DEBUG - debug_printf("Link => "); + auto obj = dynamic_cast(Master); + obj->Show(false); + debug_printf(" => "); msg.Show(true); #endif @@ -300,7 +304,9 @@ bool LinkClient::Reply(const String& action, int seq, int code, const String& re msg.Code = 1; #if DEBUG - debug_printf("Link => "); + auto obj = dynamic_cast(Master); + obj->Show(false); + debug_printf(" => "); msg.Show(true); #endif diff --git a/Link/TinyLink.cpp b/Link/TinyLink.cpp index fe6f7b4b..ce5b6d0e 100644 --- a/Link/TinyLink.cpp +++ b/Link/TinyLink.cpp @@ -24,8 +24,23 @@ void TinyLink::Open() TS("TinyLink::Open"); assert(Port, "未指定Port"); + Port->Register(Dispatch, this); + Port->Open(); + + if (PingTime > 0) _task = Sys.AddTask(&TinyLink::LoopTask, this, 0, PingTime * 1000, "微联定时"); + + Opened = true; +} + +void TinyLink::Listen() +{ + if (Opened) return; + + TS("TinyLink::Open"); + assert(Port, "未指定Port"); + + Port->Register(Dispatch, this); Port->Open(); - _task = Sys.AddTask(&TinyLink::LoopTask, this, 0, 1000, "微联定时"); Opened = true; } @@ -34,6 +49,7 @@ void TinyLink::Close() { if (!Opened) return; + Port->Register(nullptr, nullptr); Port->Close(); Sys.RemoveTask(_task); @@ -77,7 +93,9 @@ void TinyLink::OnReceive(LinkMessage& msg) TS("TinyLink::OnReceive"); #if DEBUG - debug_printf("Link <= "); + auto obj = dynamic_cast(Port); + obj->Show(false); + debug_printf(" <= "); msg.Show(true); #endif // DEBUG @@ -102,7 +120,9 @@ bool TinyLink::Send(LinkMessage& msg, const String& data) { msg.Code = 1; #if DEBUG - debug_printf("Link => "); + auto obj = dynamic_cast(Port); + obj->Show(false); + debug_printf(" => "); str.Show(true); #endif diff --git a/Link/TinyLink.h b/Link/TinyLink.h index fdc36b95..04c84bb1 100644 --- a/Link/TinyLink.h +++ b/Link/TinyLink.h @@ -24,8 +24,9 @@ public: TinyLink(); - void Open(); - void Close(); + void Open(); // 打开连接,登录并定时心跳 + void Close(); // 关闭连接 + void Listen(); // 打开并监听连接,作为服务端,没有登录和心跳 // 发送消息 bool Send(LinkMessage& msg, const String& data); diff --git a/vs/SmartOS.vcxproj b/vs/SmartOS.vcxproj index e18d2d9e..7d49409c 100644 --- a/vs/SmartOS.vcxproj +++ b/vs/SmartOS.vcxproj @@ -112,6 +112,7 @@ + diff --git a/vs/SmartOS.vcxproj.filters b/vs/SmartOS.vcxproj.filters index 03a4e38b..56121f77 100644 --- a/vs/SmartOS.vcxproj.filters +++ b/vs/SmartOS.vcxproj.filters @@ -602,5 +602,8 @@ Message + + Link + \ No newline at end of file