no message
This commit is contained in:
parent
701c00d8ce
commit
bfb52281e8
@ -30,7 +30,7 @@ std::wstring BasicForm::GetWindowClassName() const
|
||||
{
|
||||
return kClassName;
|
||||
}
|
||||
|
||||
int gTcpServerCnt = 0;
|
||||
int gTcpClientCnt = 0;
|
||||
LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
@ -122,38 +122,37 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
if (uMsg == WM_ADD_TCPSERVER_MONITOR) {
|
||||
TcpServerInfo* info = (TcpServerInfo*)wParam;
|
||||
TcpServerLibevent* cli = (TcpServerLibevent*)lParam;
|
||||
TcpServerLibevent* server = (TcpServerLibevent*)lParam;
|
||||
ui::TreeNode* node = new ui::TreeNode;
|
||||
auto key = info->ip + L":" + std::to_wstring(gTcpClientCnt);
|
||||
auto key = info->ip + L":" + std::to_wstring(gTcpServerCnt);
|
||||
node->SetText(key);
|
||||
node->SetClass(L"listitem");
|
||||
node->SetFixedHeight(20);
|
||||
node->SetMargin({ 20, 0, 0, 0 });
|
||||
mMonitor->GetRootNode()->GetChildNode(1)->AddChildNode(node);
|
||||
gTcpClientCnt++;
|
||||
mMonitor->GetRootNode()->GetChildNode(2)->AddChildNode(node);
|
||||
gTcpServerCnt++;
|
||||
|
||||
printf("WM_ADD_TCPSERVER_MONITOR\r\n");
|
||||
if (mTcpClientForm.find(info->ip + L":"
|
||||
+ std::to_wstring(gTcpClientCnt)) == mTcpClientForm.end())
|
||||
if (mTcpServerForm.find(info->ip + L":"
|
||||
+ std::to_wstring(gTcpServerCnt)) == mTcpServerForm.end())
|
||||
{
|
||||
/*
|
||||
auto form = new TcpClientForm(this, wstring2string(info->ip), info->port, cli);
|
||||
form->SetChildLayoutXML(L"basic/tcp_form.xml");
|
||||
auto form = new TcpServerFrom(this, wstring2string(info->ip), info->port, server);
|
||||
form->SetChildLayoutXML(L"basic/tcp_server_form.xml");
|
||||
form->SetName(key);
|
||||
form->SetVisible(false);
|
||||
mTcpClientForm[key] = form;
|
||||
mTcpServerForm[key] = form;
|
||||
if (!mRightSide->Add(form))
|
||||
printf("erroer 1");
|
||||
*/
|
||||
printf("error 1");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
node->AttachAllEvents(
|
||||
[this](ui::EventArgs* ev) {
|
||||
if (ui::EventType::kEventSelect == ev->Type) {
|
||||
wprintf(L"%s\r\n", dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText().c_str());
|
||||
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
|
||||
TcpClientForm* p = mTcpClientForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
|
||||
TcpServerFrom* p = mTcpServerForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
|
||||
|
||||
if (p != nullptr) {
|
||||
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
|
||||
@ -177,7 +176,7 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
|
||||
);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "new_monitor_form.h"
|
||||
#include "uart_process.h"
|
||||
#include "tcp_client_form.h"
|
||||
#include "tcp_server_form.h"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
@ -55,6 +56,7 @@ private:
|
||||
ui::TreeView *mMonitor;
|
||||
std::map<std::wstring,UartForm*> mUartForm;
|
||||
std::map<std::wstring, TcpClientForm*> mTcpClientForm;
|
||||
std::map<std::wstring, TcpServerFrom*> mTcpServerForm;
|
||||
|
||||
ui::Control* mRightShow;
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
#define WM_USER_POS_CHANGED (WM_USER + 2)
|
||||
#define WM_ADD_UART_MONITOR (WM_USER + 3)
|
||||
#define WM_ADD_TCPCLIENT_MONITOR (WM_USER + 4)
|
||||
#define WM_ADD_TCPSERVER_MONITOR (WM_USER + 4)
|
||||
|
||||
#define WM_ADD_UART_RECVDATA (WM_USER + 5)
|
||||
#define WM_ADD_UART_CLOSE (WM_USER + 6)
|
||||
#define WM_ADD_UART_CLOSE (WM_USER + 6)
|
||||
#define WM_ADD_TCPSERVER_MONITOR (WM_USER + 7)
|
||||
|
@ -161,6 +161,7 @@ void NewMonitorForm::InitWindow()
|
||||
wprintf(L"%s\r\n", m_port_select->GetText().c_str());
|
||||
int port = atoi(wstring2string(m_port_select->GetText()).c_str());
|
||||
m_tcp_server = new TcpServerLibevent(port, wstring2string(m_ip_select->GetText().c_str()));
|
||||
m_tcp_server->StartServerAsync();
|
||||
TcpServerInfo* p = new TcpServerInfo;
|
||||
p->ip = m_ip_select->GetText();
|
||||
p->port = port;
|
||||
|
@ -168,6 +168,7 @@
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="new_monitor_form.cpp" />
|
||||
<ClCompile Include="serial_port.cpp" />
|
||||
<ClCompile Include="tcp_server_form.cpp" />
|
||||
<ClCompile Include="tcp_client.cpp" />
|
||||
<ClCompile Include="tcp_client_form.cpp" />
|
||||
<ClCompile Include="tcp_server_libevent.cpp" />
|
||||
@ -182,6 +183,7 @@
|
||||
<ClInclude Include="new_monitor_form.h" />
|
||||
<ClInclude Include="resource1.h" />
|
||||
<ClInclude Include="serial_port.h" />
|
||||
<ClInclude Include="tcp_server_form.h" />
|
||||
<ClInclude Include="tcp_client_form.h" />
|
||||
<ClInclude Include="uart_process.h" />
|
||||
<ClInclude Include="utils.h" />
|
||||
@ -192,6 +194,7 @@
|
||||
<Xml Include="..\Debug\resources\themes\default\basic\uart_form.xml" />
|
||||
<Xml Include="..\Debug\resources\themes\default\global.xml" />
|
||||
<Xml Include="..\x64\Debug\resources\themes\default\basic\tcp_form.xml" />
|
||||
<Xml Include="..\x64\Debug\resources\themes\default\basic\tcp_server_form.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="proto_debuger.rc" />
|
||||
|
@ -48,6 +48,9 @@
|
||||
<ClCompile Include="loger.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tcp_server_form.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="main.h">
|
||||
@ -80,6 +83,9 @@
|
||||
<ClInclude Include="lua_wraper.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tcp_server_form.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Xml Include="..\Debug\resources\themes\default\global.xml">
|
||||
@ -97,6 +103,9 @@
|
||||
<Xml Include="..\x64\Debug\resources\themes\default\basic\tcp_form.xml">
|
||||
<Filter>资源文件</Filter>
|
||||
</Xml>
|
||||
<Xml Include="..\x64\Debug\resources\themes\default\basic\tcp_server_form.xml">
|
||||
<Filter>资源文件</Filter>
|
||||
</Xml>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="proto_debuger.rc">
|
||||
|
@ -109,31 +109,31 @@ TcpClientLibevent::TcpClientLibevent(std::string addrinfo, int port, TcpClientLi
|
||||
mStatus(UNCONNECTED),
|
||||
mObserver(nullptr)
|
||||
{
|
||||
memset(&mSrv, 0, sizeof(mSrv));
|
||||
memset(&mSrv, 0, sizeof(mSrv));
|
||||
#ifdef linux
|
||||
mSrv.sin_addr.s_addr = inet_addr(addrinfo.c_str());
|
||||
mSrv.sin_family = AF_INET;
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
mSrv.sin_addr.S_un.S_addr = inet_addr(addrinfo.c_str());
|
||||
mSrv.sin_family = AF_INET;
|
||||
mSrv.sin_addr.S_un.S_addr = inet_addr(addrinfo.c_str());
|
||||
mSrv.sin_family = AF_INET;
|
||||
#endif
|
||||
mSrv.sin_port = htons(port);
|
||||
mBase = event_base_new();
|
||||
if (!mBase)
|
||||
{
|
||||
printf("Could not initialize libevent\n");
|
||||
}
|
||||
mSrv.sin_port = htons(port);
|
||||
mBase = event_base_new();
|
||||
if (!mBase)
|
||||
{
|
||||
printf("Could not initialize libevent\n");
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
evthread_use_windows_threads();
|
||||
evthread_use_windows_threads();
|
||||
#else
|
||||
evthread_use_pthreads();
|
||||
evthread_use_pthreads();
|
||||
#endif
|
||||
this->mThread = new thread(ThreadRun,this);
|
||||
this->mObserver = p;
|
||||
mByteRecv = 0;
|
||||
mByteSend = 0;
|
||||
this->mThread = new thread(ThreadRun, this);
|
||||
this->mObserver = p;
|
||||
mByteRecv = 0;
|
||||
mByteSend = 0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,6 @@ protected:
|
||||
virtual void OnData(uint8_t* dat, uint64_t len) ;
|
||||
virtual void OnClose();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
ui::Label* m_label_1;
|
||||
ui::RichEdit* m_rich_edit_1;
|
||||
|
@ -127,7 +127,8 @@ void event_cb(struct bufferevent* bev, short events, void* arg)
|
||||
bufferevent_free(bev);
|
||||
server->RemoveConnection(conn->SocketFd());
|
||||
}
|
||||
delete conn;
|
||||
|
||||
//delete conn;
|
||||
}
|
||||
|
||||
void ServerCallbacks::cb_listener(struct evconnlistener* listener, evutil_socket_t fd, struct sockaddr* addr, int len, void* ptr)
|
||||
@ -198,8 +199,10 @@ void ServerCallbacks::server_run(TcpServerLibevent* p) {
|
||||
if (nullptr != p) {
|
||||
if (p->m_status == TcpServerLibevent::STOP) {
|
||||
p->m_status = TcpServerLibevent::RUNNING;
|
||||
|
||||
event_base_dispatch(p->m_event_base);
|
||||
evconnlistener_free(p->m_event_listener);
|
||||
if(!p->m_event_listener)
|
||||
evconnlistener_free(p->m_event_listener);
|
||||
event_base_free(p->m_event_base);
|
||||
}
|
||||
}
|
||||
@ -275,6 +278,7 @@ TcpServerLibevent::TcpServerLibevent(int port, string bindip) :
|
||||
m_backlog,
|
||||
(struct sockaddr*)&m_server_addr,
|
||||
sizeof(m_server_addr));
|
||||
|
||||
if (NULL == m_event_listener)
|
||||
{
|
||||
m_status = FAIL;
|
||||
@ -323,4 +327,10 @@ TcpServerLibevent::~TcpServerLibevent() {
|
||||
event_base_loopbreak(m_event_base);
|
||||
this->m_status = STOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint64_t TcpServerLibevent::SocketFd()
|
||||
{
|
||||
return mSocketFD;
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ public:
|
||||
int RemoveConnection(uint32_t);
|
||||
int SetNewConnectionHandle(OnAccept);
|
||||
int AddConnection(uint32_t fd, ConnectionLibevent* p);
|
||||
uint64_t SocketFd();
|
||||
friend struct ServerCallbacks;
|
||||
private:
|
||||
uint32_t m_port; // 监听端口号
|
||||
@ -83,6 +84,8 @@ private:
|
||||
thread* m_thread;
|
||||
map<uint32_t, ConnectionLibevent*> m_map_client;
|
||||
OnAccept m_handle_accept;
|
||||
intptr_t mSocketFD; // 操作系统原生socket
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<ChildBox name="tcp_form" width="stretch" height="stretch">
|
||||
<VBox width="stretch" height="stretch">
|
||||
<Label name="uart_info_label" text="当前串口: COM" margin="0,10,0,0" height="25" />
|
||||
<HBox height="25" width="stretch">
|
||||
<Label text="数据接收:" margin="0,10,0,0" height="25" width="stretch"/>
|
||||
<Label text="lua脚本:" margin="0,10,0,0" height="25" width="stretch"/>
|
||||
<Control width="stretch"/>
|
||||
|
||||
<Control width="stretch"/>
|
||||
</HBox>
|
||||
<HBox>
|
||||
<RichEdit class="simple input" width="stretch" name="uart_recv_eidt" height="stretch" margin="5,5,5,5" padding="6,6,6" multiline="true" vscrollbar="true" hscrollbar="true" autovscroll="true" normaltextcolor="darkcolor" wantreturnmsg="true" rich="true" />
|
||||
<RichEdit class="simple input" width="stretch" name="lua_script" height="stretch" margin="5,5,5,5" padding="6,6,6" multiline="true" vscrollbar="true" hscrollbar="true" autovscroll="true" normaltextcolor="darkcolor" wantreturnmsg="true" rich="true" />
|
||||
</HBox>
|
||||
<Label text="发送数据" height="25" />
|
||||
<RichEdit class="simple input" width="stretch" name="uart_send_edit" height="30" margin="5,5,5,5" padding="6,6,6" />
|
||||
<HBox height="40">
|
||||
<Button class="btn_global_blue_80x30" name="btn_send_data" width="100" text="发送" bkcolor="lightcolor" margin="25,3,5,3" />
|
||||
<CheckBox class="checkbox_font12" name="check_new_line" text="发送新行" margin="10,12,0,0" selected="true"/>
|
||||
<CheckBox class="checkbox_font12" name="check_time_send" text="定时发送" margin="10,12,0,0" selected="true"/>
|
||||
<RichEdit class="simple input" name="cycle_eidt" width="50" margin="5,5,5,5" padding="6,6,6" />
|
||||
<Label text="ms" margin="5,5,5,5" width="50" />
|
||||
<CheckBox class="checkbox_font12" name="check_hex_send" text="hex显示" margin="10,12,0,0" selected="true"/>
|
||||
<CheckBox class="checkbox_font12" name="check_hex_recv" text="hex接受" margin="10,12,0,0" selected="true"/>
|
||||
<Button class="btn_global_blue_80x30" name="btn_close_uart" width="100" text="关闭" bkcolor="lightcolor" margin="25,3,5,3" />
|
||||
<Label name="title" text="客户端:" width="60" valign="bottom" margin="0,0,0,0" height="30" font="arial_14"/>
|
||||
<Combo class="list" name="clients" width="100" height="30" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
|
||||
</HBox>
|
||||
<HBox height="40">
|
||||
<Button class="btn_global_blue_80x30" name="btn_do_lua" width="100" text="执行" bkcolor="lightcolor" margin="25,3,5,3" />
|
||||
<RichEdit class="simple input" width="stretch" name="lua_do" height="30" margin="5,5,5,5" multiline="true" vscrollbar="true" hscrollbar="true" autovscroll="true" normaltextcolor="darkcolor" wantreturnmsg="true" rich="true" />
|
||||
</HBox>
|
||||
</VBox>
|
||||
</ChildBox>
|
Loading…
Reference in New Issue
Block a user