nim_duilib/examples/proto_debuger/tcp_server_form.cpp

83 lines
2.6 KiB
C++
Raw Normal View History

2021-12-30 17:27:33 +08:00
#include "tcp_server_form.h"
2021-12-31 15:35:46 +08:00
#include "utils.h"
2022-01-06 00:31:24 +08:00
#include <functional>
extern "C" {
#include "event2/bufferevent.h"
#include "event2/buffer.h"
#include "event2/listener.h"
#include "event2/util.h"
#include "event2/event.h"
#include "event2/thread.h"
};
2021-12-30 17:27:33 +08:00
TcpServerFrom::TcpServerFrom(ui::Window* hwnd, string url, uint32_t port, TcpServerLibevent* p)
{
2021-12-31 01:12:11 +08:00
m_server = p;
m_url = url;
m_port = port;
2022-01-08 00:23:09 +08:00
TcpServerLibevent::OnAccept handler = std::bind(&TcpServerFrom::OnNewConnAccept, this,std::placeholders::_1 );
2022-01-06 00:31:24 +08:00
m_server->SetNewConnectionHandle(handler);
TcpServerLibevent::OnDisconnect handler2 = std::bind(&TcpServerFrom::OnDisConnected,
this, std::placeholders::_1);
m_server->SetConnectionLeaveHandle(handler2);
2021-12-30 17:27:33 +08:00
}
TcpServerLibevent* TcpServerFrom::ServerP()
{
return this->m_server;
}
void TcpServerFrom::Init()
{
ui::ChildBox::Init(); // <20>dz<EFBFBD><C7B3><EFBFBD>Ҫ,û<><C3BB><EFBFBD>º<EFBFBD>childbox <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FindSubControl<6F>޷<EFBFBD><DEB7><EFBFBD>Ч
2022-01-06 00:31:24 +08:00
m_label_1 = dynamic_cast<ui::Label*>(FindSubControl(L"server_info"));
m_rich_edit_1 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"server_recv_edit"));
m_rich_edit_2 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"lua_script_edit"));
m_rich_edit_3 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"server_send_edit"));
m_button_1 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
m_check_box_2 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_time_send"));
m_rich_edit_4 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"cycle_eidt"));
m_check_box_3 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_send"));
m_check_box_4 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_recv"));
m_button_2 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_close_uart"));
m_label_2 = dynamic_cast<ui::Label*>(FindSubControl(L"title"));
m_combo_1 = dynamic_cast<ui::Combo*>(FindSubControl(L"clients"));
m_button_3 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_do_lua"));
2021-12-30 17:27:33 +08:00
2021-12-31 15:35:46 +08:00
wchar_t p[200] = L"";
wsprintf(p,L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ: %s <20>˿<EFBFBD>: %d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ: %d",string2wstring(m_url).c_str(),
m_port,
m_server->ConnectionCount());
m_label_1->SetText(p);
2021-12-30 17:27:33 +08:00
}
2022-01-05 01:41:58 +08:00
2022-01-08 00:23:09 +08:00
void TcpServerFrom::OnNewConnAccept(ConnectionLibevent*p)
2022-01-06 00:31:24 +08:00
{
2022-01-08 00:23:09 +08:00
std::cout << "TcpServerFrom OnNewConnAccept addr " << p->IpAddress()<<std::endl;
updateStatus();
2022-01-06 00:31:24 +08:00
2022-01-08 00:23:09 +08:00
return;
2022-01-06 00:31:24 +08:00
}
void TcpServerFrom::OnDisConnected(ConnectionLibevent* cli)
2022-01-05 01:41:58 +08:00
{
2022-01-06 00:31:24 +08:00
std::cout << "TcpServerFrom Disconnected" << cli->IpAddress() << " fd " << cli->SocketFd() << std::endl;
2022-01-05 01:41:58 +08:00
2022-01-08 00:23:09 +08:00
updateStatus();
}
void TcpServerFrom::updateStatus()
{
wchar_t tmp[200] = L"";
wsprintf(tmp, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ: %s <20>˿<EFBFBD>: %d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ: %d", string2wstring(m_url).c_str(),
m_port,
m_server->ConnectionCount());
m_label_1->SetText(tmp);
2022-01-05 01:41:58 +08:00
}