From 4667077c30003b54a386f264b8dbd983489edbd5 Mon Sep 17 00:00:00 2001
From: zcy <290198252@qq.com>
Date: Fri, 18 Feb 2022 00:18:28 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=80=BB=E8=BE=91,=E6=89=80?=
=?UTF-8?q?=E6=9C=89=E7=95=8C=E9=9D=A2=E7=9A=84=E5=85=B3=E9=97=AD=E6=8C=89?=
=?UTF-8?q?=E9=92=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/themes/default/basic/basic.xml | 30 +++
.../themes/default/basic/newmonitor.xml | 40 ++++
.../themes/default/basic/uart_form.xml | 33 ++++
examples/proto_debuger/base_form.cpp | 43 ++++-
examples/proto_debuger/msgdef.h | 3 +
examples/proto_debuger/tcp_client.cpp | 24 ++-
examples/proto_debuger/tcp_client.h | 9 +-
examples/proto_debuger/tcp_client_form.cpp | 14 +-
examples/proto_debuger/tcp_client_form.h | 1 +
examples/proto_debuger/udp_form.cpp | 12 +-
examples/proto_debuger/udp_libevent.cpp | 1 +
.../x64/Debug/themes/default/global.xml | 171 ++++++++++++++++++
.../themes/default/basic/tcp_form.xml | 1 -
.../themes/default/basic/udp_form.xml | 30 +++
14 files changed, 393 insertions(+), 19 deletions(-)
create mode 100644 examples/Debug/resources/themes/default/basic/basic.xml
create mode 100644 examples/Debug/resources/themes/default/basic/newmonitor.xml
create mode 100644 examples/Debug/resources/themes/default/basic/uart_form.xml
create mode 100644 examples/proto_debuger/x64/Debug/themes/default/global.xml
create mode 100644 examples/x64/Debug/resources/themes/default/basic/udp_form.xml
diff --git a/examples/Debug/resources/themes/default/basic/basic.xml b/examples/Debug/resources/themes/default/basic/basic.xml
new file mode 100644
index 00000000..d3ed2809
--- /dev/null
+++ b/examples/Debug/resources/themes/default/basic/basic.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/Debug/resources/themes/default/basic/newmonitor.xml b/examples/Debug/resources/themes/default/basic/newmonitor.xml
new file mode 100644
index 00000000..f49310ad
--- /dev/null
+++ b/examples/Debug/resources/themes/default/basic/newmonitor.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/Debug/resources/themes/default/basic/uart_form.xml b/examples/Debug/resources/themes/default/basic/uart_form.xml
new file mode 100644
index 00000000..f663bc76
--- /dev/null
+++ b/examples/Debug/resources/themes/default/basic/uart_form.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/proto_debuger/base_form.cpp b/examples/proto_debuger/base_form.cpp
index 279489e9..486489ed 100644
--- a/examples/proto_debuger/base_form.cpp
+++ b/examples/proto_debuger/base_form.cpp
@@ -63,12 +63,47 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
PortNum = PortNum * 10 + (comname[i] - L'0');
}
SerialPort::ClosePort(PortNum);
- delete mRightShow;
}
- if (uMsg == WM_ADD_UART_RECVDATA) {
- printf("WM_ADD_UART_RECVDATA");
- //this->Paint();
+ if (uMsg == WM_USER_UDP_CLOSE) {
+ wprintf(L"close %s\r\n", ((wstring*)wParam)->c_str());
+ mRightShow->SetVisible(false);
+ mRightShow = nullptr;
+ mRightSide->SetAutoDestroy(true);
+ mRightSide->RemoveAll();
+ mUdpForm.erase(*(wstring*)(wParam));
+ int cnt = mMonitor->GetRootNode()->GetChildNode(3)->GetChildNodeCount();
+ ui::TreeNode* p = nullptr;
+ for (int i = 0; i < cnt; i++) {
+ if (mMonitor->GetRootNode()->GetChildNode(3)->GetChildNode(i)->GetText()
+ == *(wstring*)(wParam)) {
+ p = mMonitor->GetRootNode()->GetChildNode(3)->GetChildNode(i);
+ break;
+ }
+ }
+ mMonitor->GetRootNode()->GetChildNode(3)->RemoveChildNode(p);
+ delete mRightShow;
+ mRightShow = nullptr;
+ }
+ if (uMsg == WM_USER_TCP_CLIENT_CLOSE) {
+ wprintf(L"close %s\r\n", ((wstring*)wParam)->c_str());
+ mRightShow->SetVisible(false);
+ mRightSide->SetAutoDestroy(true);
+ mRightSide->RemoveAll();
+
+ mTcpClientForm.erase(*(wstring*)(wParam));
+ int cnt = mMonitor->GetRootNode()->GetChildNode(1)->GetChildNodeCount();
+ ui::TreeNode* p = nullptr;
+ for (int i = 0; i < cnt; i++) {
+ if (mMonitor->GetRootNode()->GetChildNode(1)->GetChildNode(i)->GetText()
+ == *(wstring*)(wParam)) {
+ p = mMonitor->GetRootNode()->GetChildNode(1)->GetChildNode(i);
+ break;
+ }
+ }
+ mMonitor->GetRootNode()->GetChildNode(1)->RemoveChildNode(p);
+ delete mRightShow;
+ mRightShow = nullptr;
}
if (uMsg == WM_USER_POS_CHANGED) {
diff --git a/examples/proto_debuger/msgdef.h b/examples/proto_debuger/msgdef.h
index d683ce6b..0f848bfd 100644
--- a/examples/proto_debuger/msgdef.h
+++ b/examples/proto_debuger/msgdef.h
@@ -10,3 +10,6 @@
#define WM_ADD_UDP_MONITOR (WM_USER + 8)
#define WM_ADD_UDP_GROUP_MONITOR (WM_USER + 9)
+#define WM_USER_UDP_CLOSE (WM_USER + 10)
+#define WM_USER_TCP_CLIENT_CLOSE (WM_USER + 11)
+#define WM_USER_TCP_SERVER_CLOSE (WM_USER + 12)
diff --git a/examples/proto_debuger/tcp_client.cpp b/examples/proto_debuger/tcp_client.cpp
index 2bd7d416..170b7b0a 100644
--- a/examples/proto_debuger/tcp_client.cpp
+++ b/examples/proto_debuger/tcp_client.cpp
@@ -76,14 +76,18 @@ void conn_eventcb(struct bufferevent *bev, short events, void *user_data)
if (nullptr != p->mObserver)
p->mObserver->OnDisConnected("服务器主动断开连接");
if (p != nullptr)
- p->mStatus = TcpClientLibevent::UNCONNECTED;
+ if (p->mStatus != TcpClientLibevent::STOP)
+ p->mStatus = TcpClientLibevent::UNCONNECTED;
printf("Connection closed\n");
}
else if (events & BEV_EVENT_ERROR) {
printf("Got an error on the connection: %s\n", strerror(errno));
- if (nullptr != p->mObserver)
- p->mObserver->OnDisConnected("连接失败");
- p->mStatus = TcpClientLibevent::FAIL;
+ if (nullptr != p) {
+ if (nullptr != p->mObserver)
+ p->mObserver->OnDisConnected("连接失败");
+ if(p->mStatus != TcpClientLibevent::STOP)
+ p->mStatus = TcpClientLibevent::FAIL;
+ }
}
else if (events & BEV_EVENT_CONNECTED) {
p->mSocketFD = (uint64_t)event_get_fd(&(bev->ev_read));
@@ -107,6 +111,7 @@ bool TcpClientLibevent::Connected() {
return (((mStatus != UNCONNECTED)&& (mStatus != FAIL) )?true : false);
}
+
TcpClientLibevent::TcpClientLibevent(std::string addrinfo, int port, TcpClientLibevent::TcpClientObserver *p) :
mStatus(UNCONNECTED),
mObserver(nullptr)
@@ -141,10 +146,13 @@ TcpClientLibevent::TcpClientLibevent(std::string addrinfo, int port, TcpClientLi
int TcpClientLibevent::ConnectServer() {
printf("server conecting...\r\n");
evthread_make_base_notifiable(mBase);
+ mMux.lock();
+
mBev = bufferevent_socket_new(mBase, -1,
BEV_OPT_CLOSE_ON_FREE | BEV_OPT_THREADSAFE);
if (nullptr == mBev) {
this->mStatus = TcpClientLibevent::FAIL;
+
return - 1;
}
bufferevent_setcb(mBev, conn_readcb, conn_writecb, conn_eventcb, this);
@@ -152,17 +160,20 @@ int TcpClientLibevent::ConnectServer() {
bufferevent_enable(mBev, EV_READ | EV_WRITE);
if (-1 == flag) {
this->mStatus = TcpClientLibevent::FAIL;
+
bufferevent_free(mBev);
mBev = nullptr;
printf("Connect failed\n");
return -1;
}
this->mStatus = TcpClientLibevent::CONNECTING;
+ mMux.unlock();
return 0;
}
int TcpClientLibevent::ConnectServerSync()
{
+ mMux.lock();
evthread_make_base_notifiable(mBase);
if (nullptr != mBev)
{
@@ -172,6 +183,7 @@ int TcpClientLibevent::ConnectServerSync()
BEV_OPT_CLOSE_ON_FREE | BEV_OPT_THREADSAFE);
if (nullptr == mBev) {
this->mStatus = TcpClientLibevent::FAIL;
+ mMux.unlock();
return -1;
}
bufferevent_setcb(mBev, conn_readcb, conn_writecb, conn_eventcb, this);
@@ -182,10 +194,11 @@ int TcpClientLibevent::ConnectServerSync()
bufferevent_free(mBev);
mBev = nullptr;
printf("Connect failed\n");
+ mMux.unlock();
return -1;
}
-
this->mStatus = TcpClientLibevent::CONNECTING;
+
auto start = system_clock::to_time_t(system_clock::now());
while (this->mStatus != TcpClientLibevent::CONNECTED) {
auto end = system_clock::to_time_t(system_clock::now());
@@ -195,6 +208,7 @@ int TcpClientLibevent::ConnectServerSync()
break;
}
}
+ mMux.unlock();
return 0;
}
diff --git a/examples/proto_debuger/tcp_client.h b/examples/proto_debuger/tcp_client.h
index b8ced753..e4d8aa61 100644
--- a/examples/proto_debuger/tcp_client.h
+++ b/examples/proto_debuger/tcp_client.h
@@ -59,11 +59,15 @@ public:
};
TcpClientLibevent(std::string addrinfo, int port, TcpClientObserver* p);
~TcpClientLibevent() {
+ mMux.lock();
+ mStatus = STOP;
+ mMux.unlock();
+
+ mThread->join();
event_base_free(mBase);
+
};
-
friend void conn_eventcb(struct bufferevent*, short, void*);
-
int ConnectServer();
int ConnectServerSync();
@@ -89,6 +93,7 @@ private:
uint64_t mByteSend; // 发送字节数
uint64_t mByteRecv; // 接收字节数
evutil_socket_t mSocketFD; // 操作系统原生socket
+ mutex mMux;
};
diff --git a/examples/proto_debuger/tcp_client_form.cpp b/examples/proto_debuger/tcp_client_form.cpp
index ccdace47..aeb311b8 100644
--- a/examples/proto_debuger/tcp_client_form.cpp
+++ b/examples/proto_debuger/tcp_client_form.cpp
@@ -5,6 +5,7 @@
#define TCP_CLIENT_SCRIPT "tcp_client.lua"
TcpClientForm::~TcpClientForm() {
+ delete mClient;
}
@@ -56,7 +57,8 @@ void TcpClientForm::Init()
m_check_box_3 = dynamic_cast(FindSubControl(L"check_hex_send"));
m_check_box_4 = dynamic_cast(FindSubControl(L"check_hex_recv"));
m_btn_save_lua = dynamic_cast(FindSubControl(L"btn_save_lua"));
-
+ m_btn_close_form = dynamic_cast(FindSubControl(L"btn_close_uart"));
+
m_rich_edit_2->SetRich(true);
m_rich_edit_2->SetReturnMsgWantCtrl(true);
m_rich_edit_2->SetText(string2wstring(mLuaScript));
@@ -65,6 +67,16 @@ void TcpClientForm::Init()
wsprintf(p, L"ַ%s,˿ں%d δ", string2wstring(m_url).c_str(),m_port);
m_label_1->SetText(std::wstring(p));
+ if (nullptr != m_btn_close_form) {
+ m_btn_close_form->AttachClick([this](ui::EventArgs*) {
+ wstring* name = new wstring(this->GetName());
+ ::PostMessage(this->GetWindow()->GetHWND(),
+ WM_USER_TCP_CLIENT_CLOSE, (WPARAM)name, 0);
+ return true;
+ });
+
+ }
+
m_btn_send_data->AttachAllEvents([this](ui::EventArgs* ev) {
if (ev->Type == ui::EventType::kEventClick) {
std::wcout << m_uart_send_edit->GetText() << std::endl;
diff --git a/examples/proto_debuger/tcp_client_form.h b/examples/proto_debuger/tcp_client_form.h
index 1cb77d4c..d11aadce 100644
--- a/examples/proto_debuger/tcp_client_form.h
+++ b/examples/proto_debuger/tcp_client_form.h
@@ -48,6 +48,7 @@ private:
ui::RichEdit* m_uart_send_edit;
ui::Button* m_btn_send_data;
ui::Button* m_btn_save_lua;
+ ui::Button* m_btn_close_form;
ui::CheckBox* m_check_box_1;
ui::CheckBox* m_check_box_2;
ui::CheckBox* m_check_box_3;
diff --git a/examples/proto_debuger/udp_form.cpp b/examples/proto_debuger/udp_form.cpp
index 4fb6df93..b5802998 100644
--- a/examples/proto_debuger/udp_form.cpp
+++ b/examples/proto_debuger/udp_form.cpp
@@ -96,12 +96,12 @@ void UdpForm::Init()
);
}
if (nullptr != m_button_2) {
- m_button_2->AttachClick(
- [this](ui::EventArgs*) {
-
- return true;
- }
- );
+ m_button_2->AttachClick([this](ui::EventArgs*) {
+ wstring* name = new wstring(this->GetName());
+ ::PostMessage(this->GetWindow()->GetHWND(),
+ WM_USER_UDP_CLOSE, (WPARAM)name, 0);
+ return true;
+ });
}
if (nullptr != m_button_3) {
m_button_3->AttachClick(
diff --git a/examples/proto_debuger/udp_libevent.cpp b/examples/proto_debuger/udp_libevent.cpp
index f832d3aa..0dd06268 100644
--- a/examples/proto_debuger/udp_libevent.cpp
+++ b/examples/proto_debuger/udp_libevent.cpp
@@ -203,6 +203,7 @@ UdpDataGramLibevent::UdpDataGramLibevent(std::string ip, uint32_t port, std::str
printf("event_init() failed\n");
}
m_event = new struct event;
+
if (0 > bind_socket_with_group(m_event, ip.c_str(), port, group_addr.c_str())) {
return;
}
diff --git a/examples/proto_debuger/x64/Debug/themes/default/global.xml b/examples/proto_debuger/x64/Debug/themes/default/global.xml
new file mode 100644
index 00000000..5e49293b
--- /dev/null
+++ b/examples/proto_debuger/x64/Debug/themes/default/global.xml
@@ -0,0 +1,171 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/x64/Debug/resources/themes/default/basic/tcp_form.xml b/examples/x64/Debug/resources/themes/default/basic/tcp_form.xml
index 753eed1c..32b44ad9 100644
--- a/examples/x64/Debug/resources/themes/default/basic/tcp_form.xml
+++ b/examples/x64/Debug/resources/themes/default/basic/tcp_form.xml
@@ -18,7 +18,6 @@
-
diff --git a/examples/x64/Debug/resources/themes/default/basic/udp_form.xml b/examples/x64/Debug/resources/themes/default/basic/udp_form.xml
new file mode 100644
index 00000000..4f22d8ee
--- /dev/null
+++ b/examples/x64/Debug/resources/themes/default/basic/udp_form.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+