no message

This commit is contained in:
zcy 2022-01-13 01:37:24 +08:00
parent 8a1cc7a1c8
commit 511f3432b4
11 changed files with 68 additions and 39 deletions

View File

@ -15,8 +15,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_ LPWSTR lpCmdLine, _In_ LPWSTR lpCmdLine,
_In_ int nCmdShow) _In_ int nCmdShow)
{ {
AllocConsole(); //AllocConsole();
freopen("CONOUT$", "w", stdout); //freopen("CONOUT$", "w", stdout);
UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine); UNREFERENCED_PARAMETER(lpCmdLine);

View File

@ -42,7 +42,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
@ -203,6 +203,15 @@
<ProjectReference Include="..\..\ui_components\ui_components.vcxproj"> <ProjectReference Include="..\..\ui_components\ui_components.vcxproj">
<Project>{0149ba6e-3c0a-426d-aa0a-0b9ec7742f19}</Project> <Project>{0149ba6e-3c0a-426d-aa0a-0b9ec7742f19}</Project>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\layouts\layouts.vcxproj">
<Project>{2bffa1ee-039d-479e-9bcc-2d12f8aedd16}</Project>
</ProjectReference>
<ProjectReference Include="..\richlist\richlist.vcxproj">
<Project>{878f5bf0-652a-4fdb-992b-bb7f26d62f0d}</Project>
</ProjectReference>
<ProjectReference Include="..\VirtualBox\VirtualBox.vcxproj">
<Project>{e35589c6-9509-4116-996f-1d045c2dacae}</Project>
</ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -1,5 +1,4 @@
#include "stdafx.h" #include "stdafx.h"
#include "controls_form.h"
#include "Utils\DpiManager.h" #include "Utils\DpiManager.h"
#include <fstream> #include <fstream>

View File

@ -4,7 +4,6 @@
#include "stdafx.h" #include "stdafx.h"
#include "main.h" #include "main.h"
#include "controls_form.h" #include "controls_form.h"
#include "Utils\DpiManager.h"
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
@ -12,8 +11,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_ LPWSTR lpCmdLine, _In_ LPWSTR lpCmdLine,
_In_ int nCmdShow) _In_ int nCmdShow)
{ {
AllocConsole(); //AllocConsole();
freopen("CONOUT$", "w", stdout); //freopen("CONOUT$", "w", stdout);
auto dpiManager = ui::DpiManager::GetInstance(); auto dpiManager = ui::DpiManager::GetInstance();
dpiManager->SetAdaptDPI(); // 设置适配自动dpi dpiManager->SetAdaptDPI(); // 设置适配自动dpi

View File

@ -42,7 +42,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">

View File

@ -130,8 +130,7 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
auto key = info->ip + L":" + std::to_wstring(info->port); auto key = info->ip + L":" + std::to_wstring(info->port);
node->SetText(key); node->SetText(key);
node->SetClass(L"listitem"); node->SetClass(L"listitem");
node->SetFixedHeight(20); std::cout << "node heigjt" << node->GetHeight();
node->SetMargin({ 20, 0, 0, 0 });
mMonitor->GetRootNode()->GetChildNode(2)->AddChildNode(node); mMonitor->GetRootNode()->GetChildNode(2)->AddChildNode(node);
gTcpServerCnt++; gTcpServerCnt++;
@ -189,8 +188,7 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
ui::TreeNode* node = new ui::TreeNode; ui::TreeNode* node = new ui::TreeNode;
node->SetText(p->name); node->SetText(p->name);
node->SetClass(L"listitem"); node->SetClass(L"listitem");
node->SetFixedHeight(20);
node->SetMargin({ 20, 0, 0, 0 });
mMonitor->GetRootNode()->GetChildNode(0)->AddChildNode(node); mMonitor->GetRootNode()->GetChildNode(0)->AddChildNode(node);
if (mUartForm.find(p->name) == mUartForm.end()) { if (mUartForm.find(p->name) == mUartForm.end()) {
@ -255,48 +253,45 @@ void BasicForm::InitWindow(){
}); });
} }
mMonitor = dynamic_cast<ui::TreeView*>(FindControl(L"tree")); mMonitor = dynamic_cast<ui::TreeView*>(FindControl(L"tree"));
mMonitor->SetClass(L"list");
mMonitor->SetIndent(5);
if (nullptr != mMonitor) { if (nullptr != mMonitor) {
ui::TreeNode* node = new ui::TreeNode; ui::TreeNode* node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"uart")); node->SetText(nbase::StringPrintf(L"uart"));
node->SetClass(L"listitem"); node->SetClass(L"list_topitem");
node->SetFixedHeight(20); node->SetFixedHeight(30);
node->SetMargin({ 10, 0, 0, 0 });
mMonitor->GetRootNode()->AddChildNode(node);
mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode; node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"tcp client")); node->SetText(nbase::StringPrintf(L"tcp client"));
node->SetClass(L"listitem"); node->SetClass(L"list_topitem");
node->SetFixedHeight(20); node->SetFixedHeight(30);
node->SetMargin({ 10, 0, 0, 0 });
mMonitor->GetRootNode()->AddChildNode(node); mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode; node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"tcp server")); node->SetText(nbase::StringPrintf(L"tcp server"));
node->SetClass(L"listitem"); node->SetClass(L"list_topitem");
node->SetFixedHeight(20); node->SetFixedHeight(30);
node->SetMargin({ 10, 0, 0, 0 });
mMonitor->GetRootNode()->AddChildNode(node); mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode; node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"udp client")); node->SetText(nbase::StringPrintf(L"udp client"));
node->SetClass(L"listitem"); node->SetClass(L"list_topitem");
node->SetFixedHeight(20); node->SetFixedHeight(30);
node->SetMargin({ 10, 0, 0, 0 });
mMonitor->GetRootNode()->AddChildNode(node); mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode; node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"udp server")); node->SetText(nbase::StringPrintf(L"udp server"));
node->SetClass(L"listitem"); node->SetClass(L"list_topitem");
node->SetFixedHeight(20); node->SetFixedHeight(30);
node->SetMargin({ 10, 0, 0, 0 });
mMonitor->GetRootNode()->AddChildNode(node); mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode; node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"udp group")); node->SetText(nbase::StringPrintf(L"udp group"));
node->SetClass(L"listitem"); node->SetClass(L"list_topitem");
node->SetFixedHeight(20);
node->SetMargin({ 10, 0, 0, 0 });
mMonitor->GetRootNode()->AddChildNode(node); mMonitor->GetRootNode()->AddChildNode(node);
} }

View File

@ -192,9 +192,9 @@
<Xml Include="..\Debug\resources\themes\default\basic\basic.xml" /> <Xml Include="..\Debug\resources\themes\default\basic\basic.xml" />
<Xml Include="..\Debug\resources\themes\default\basic\newmonitor.xml" /> <Xml Include="..\Debug\resources\themes\default\basic\newmonitor.xml" />
<Xml Include="..\Debug\resources\themes\default\basic\uart_form.xml" /> <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_form.xml" />
<Xml Include="..\x64\Debug\resources\themes\default\basic\tcp_server_form.xml" /> <Xml Include="..\x64\Debug\resources\themes\default\basic\tcp_server_form.xml" />
<Xml Include="x64\Debug\themes\default\global.xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="proto_debuger.rc" /> <ResourceCompile Include="proto_debuger.rc" />

View File

@ -88,9 +88,6 @@
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Xml Include="..\Debug\resources\themes\default\global.xml">
<Filter>资源文件</Filter>
</Xml>
<Xml Include="..\Debug\resources\themes\default\basic\basic.xml"> <Xml Include="..\Debug\resources\themes\default\basic\basic.xml">
<Filter>资源文件</Filter> <Filter>资源文件</Filter>
</Xml> </Xml>
@ -106,6 +103,9 @@
<Xml Include="..\x64\Debug\resources\themes\default\basic\tcp_server_form.xml"> <Xml Include="..\x64\Debug\resources\themes\default\basic\tcp_server_form.xml">
<Filter>资源文件</Filter> <Filter>资源文件</Filter>
</Xml> </Xml>
<Xml Include="x64\Debug\themes\default\global.xml">
<Filter>资源文件</Filter>
</Xml>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="proto_debuger.rc"> <ResourceCompile Include="proto_debuger.rc">

View File

@ -84,8 +84,13 @@ void TcpServerFrom::OnNewConnAccept(ConnectionLibevent* p)
element->SetTextPadding({ 6,0,6,0 }); element->SetTextPadding({ 6,0,6,0 });
element->SetText(std::to_wstring(p->SocketFd())); element->SetText(std::to_wstring(p->SocketFd()));
mClients[p->SocketFd()] = p; mClients[p->SocketFd()] = p;
m_combo_1->Add(element); m_combo_1->Add(element);
p->SetRecvHandler(
[this](char* p, uint32_t len) {
std::cout << "SetRecvHandler " << p;
}
);
return; return;
} }

View File

@ -8,6 +8,11 @@ extern "C" {
#include "event2/thread.h" #include "event2/thread.h"
}; };
void defaultConnRead(char* p, uint32_t len) {
std::cout << p;
return;
}
class ServerCallbacks { class ServerCallbacks {
public: public:
@ -19,7 +24,8 @@ ConnectionLibevent::ConnectionLibevent(TcpServerLibevent* p, struct bufferevent*
m_parent_server(nullptr), m_parent_server(nullptr),
m_event(nullptr), m_event(nullptr),
m_fd(-1), m_fd(-1),
m_addr(nullptr) m_addr(nullptr),
m_recv_handle(defaultConnRead)
{ {
m_parent_server = p; m_parent_server = p;
m_event = ev; m_event = ev;
@ -50,8 +56,13 @@ void defaultConnClose(ConnectionLibevent*p) {
} }
int ConnectionLibevent::OnRecv(char* p, uint32_t len) { int ConnectionLibevent::OnRecv(char* p, uint32_t len) {
std::cout << "OnRecv " << p << std::endl; std::cout << "OnRecv " << p << std::endl;
if (m_recv_handle != nullptr) {
(m_recv_handle)(p, len);
}
m_bytes_recv += len; m_bytes_recv += len;
return 0; return 0;
} }
@ -82,6 +93,12 @@ int ConnectionLibevent::Close() {
} }
return 0; return 0;
} }
int ConnectionLibevent::SetRecvHandler(OnRecvHandle p) {
if (nullptr == p)
return -1;
this->m_recv_handle = p;
return 0;
}
int ConnectionLibevent::SetServer(TcpServerLibevent* p) { int ConnectionLibevent::SetServer(TcpServerLibevent* p) {
if (nullptr != p) { if (nullptr != p) {
@ -271,6 +288,8 @@ int TcpServerLibevent::SetConnectionLeaveHandle(OnDisconnect p) {
return 0; return 0;
} }
/** /**
* @description: * @description:
* @param {int} ports * @param {int} ports

View File

@ -35,11 +35,13 @@ public:
uint32_t fd, uint32_t fd,
struct sockaddr_in* p1); struct sockaddr_in* p1);
typedef std::function<void (char* p, uint32_t len)> OnRecvHandle;
virtual int OnRecv(char* p, uint32_t len); // data ready callback virtual int OnRecv(char* p, uint32_t len); // data ready callback
virtual int OnClose(); // close callback virtual int OnClose(); // close callback
virtual int OnWrite(); // write data done callback virtual int OnWrite(); // write data done callback
int WriteData(const char* p, uint16_t len); int WriteData(const char* p, uint16_t len);
int SetServer(TcpServerLibevent*); int SetServer(TcpServerLibevent*);
int SetRecvHandler(OnRecvHandle);
TcpServerLibevent* Server(); TcpServerLibevent* Server();
string IpAddress(); string IpAddress();
uint32_t SocketFd(); uint32_t SocketFd();
@ -51,6 +53,7 @@ private:
struct bufferevent* m_event; struct bufferevent* m_event;
struct sockaddr_in* m_addr; struct sockaddr_in* m_addr;
uint32_t m_fd; uint32_t m_fd;
OnRecvHandle m_recv_handle;
}; };
// 管理服务端 // 管理服务端