Merge branch 'master' of https://gitee.com/290198252/nim_duilib
# Conflicts: # examples/proto_debuger/udp_form.cpp # examples/proto_debuger/udp_form.h
This commit is contained in:
commit
7ff82302cb
@ -371,6 +371,11 @@ LuaBindInterface* BasicForm::FindCurrentFormByLuaPointer(lua_State* pointer)
|
|||||||
return (LuaBindInterface*)itr->second;
|
return (LuaBindInterface*)itr->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (auto itr = mUdpForm.begin(); itr != mUdpForm.end(); itr++) {
|
||||||
|
if (itr->second->LuaVM()->VM() == pointer) {
|
||||||
|
return (LuaBindInterface*)itr->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +174,7 @@
|
|||||||
<ClCompile Include="tcp_client_form.cpp" />
|
<ClCompile Include="tcp_client_form.cpp" />
|
||||||
<ClCompile Include="tcp_server_libevent.cpp" />
|
<ClCompile Include="tcp_server_libevent.cpp" />
|
||||||
<ClCompile Include="uart_form.cpp" />
|
<ClCompile Include="uart_form.cpp" />
|
||||||
|
<ClCompile Include="udp_group_libevent.cpp" />
|
||||||
<ClCompile Include="udp_form.cpp" />
|
<ClCompile Include="udp_form.cpp" />
|
||||||
<ClCompile Include="udp_libevent.cpp" />
|
<ClCompile Include="udp_libevent.cpp" />
|
||||||
<ClCompile Include="utils.cpp" />
|
<ClCompile Include="utils.cpp" />
|
||||||
@ -193,6 +194,7 @@
|
|||||||
<ClInclude Include="tcp_client_form.h" />
|
<ClInclude Include="tcp_client_form.h" />
|
||||||
<ClInclude Include="tcp_server_libevent.h" />
|
<ClInclude Include="tcp_server_libevent.h" />
|
||||||
<ClInclude Include="uart_process.h" />
|
<ClInclude Include="uart_process.h" />
|
||||||
|
<ClInclude Include="udp_group_libevent.h" />
|
||||||
<ClInclude Include="udp_form.h" />
|
<ClInclude Include="udp_form.h" />
|
||||||
<ClInclude Include="udp_libevent.h" />
|
<ClInclude Include="udp_libevent.h" />
|
||||||
<ClInclude Include="utils.h" />
|
<ClInclude Include="utils.h" />
|
||||||
|
@ -1,14 +1,49 @@
|
|||||||
#include "udp_form.h"
|
#include "udp_form.h"
|
||||||
|
#include <functional>
|
||||||
|
#include "utils.h"
|
||||||
|
#include "lua_bind.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define UDP_LUA_SCRIPT "udp_script.lua"
|
||||||
|
|
||||||
UdpForm::UdpForm(ui::Window* hwnd, string url, uint32_t port, UdpDataGramLibevent* p)
|
UdpForm::UdpForm(ui::Window* hwnd, string url, uint32_t port, UdpDataGramLibevent* p)
|
||||||
{
|
{
|
||||||
this->mUdpPeer = p;
|
this->mUdpPeer = p;
|
||||||
this->m_url = url;
|
this->m_url = url;
|
||||||
this->m_port = port;
|
this->m_port = port;
|
||||||
|
mLua = new LuaDelegate;
|
||||||
|
|
||||||
|
mLuaFile.open(UDP_LUA_SCRIPT);
|
||||||
|
std::string lua_script;
|
||||||
|
if (mLuaFile.is_open()) {
|
||||||
|
std::string s;
|
||||||
|
while (getline(mLuaFile, s)) {
|
||||||
|
lua_script += s + "\r\n";
|
||||||
|
}
|
||||||
|
mLuaFile.close();
|
||||||
|
}
|
||||||
|
mLuaScript = lua_script;
|
||||||
|
mLua->DoString(lua_script);
|
||||||
|
|
||||||
|
UdpDataGramLibevent::OnReadDataHandle onRecvCallBack
|
||||||
|
= [this](const char* dat, int len, struct sockaddr_in sendarr){
|
||||||
|
std::cout << "receive udp datagram len" << len << dat << "\r\n";
|
||||||
|
|
||||||
|
this->mLua->CallFuntion<std::string,std::string, LUA_INTEGER>("OnUdpData", std::string(dat),
|
||||||
|
inet_ntoa(sendarr.sin_addr),sendarr.sin_port);
|
||||||
|
|
||||||
|
};
|
||||||
|
if (mUdpPeer != nullptr) {
|
||||||
|
std::cout << "\r\n"<< &onRecvCallBack <<"\r\n";
|
||||||
|
mUdpPeer->SetOnReadHandle(onRecvCallBack);
|
||||||
|
}
|
||||||
|
this->mLua->BindFunction("showdata", LuaShowData);
|
||||||
|
std::cout << "lua script is " << lua_script << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
UdpForm::~UdpForm()
|
UdpForm::~UdpForm()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UdpForm::Init()
|
void UdpForm::Init()
|
||||||
@ -22,6 +57,82 @@ void UdpForm::Init()
|
|||||||
ui::Button* m_button_2 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_close_uart"));
|
ui::Button* m_button_2 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_close_uart"));
|
||||||
ui::Button* m_button_3 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_save_lua"));
|
ui::Button* m_button_3 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_save_lua"));
|
||||||
ui::Button* m_button_4 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_do_lua"));
|
ui::Button* m_button_4 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_do_lua"));
|
||||||
|
|
||||||
|
m_label_1 = dynamic_cast<ui::Label*>(FindSubControl(L"uart_info_label"));
|
||||||
|
m_rich_edit_1 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_recv_eidt"));
|
||||||
|
if (nullptr != m_rich_edit_1) {
|
||||||
|
m_rich_edit_1->SetReadOnly(true);
|
||||||
|
m_rich_edit_1->SetRich(false);
|
||||||
|
m_rich_edit_1->SetAttribute(L"autovscroll", L"true");
|
||||||
|
m_rich_edit_1->SetAttribute(L"multiline", L"true");
|
||||||
|
m_rich_edit_1->SetReturnMsgWantCtrl(true);
|
||||||
|
m_rich_edit_1->SetNeedReturnMsg(true);
|
||||||
|
m_rich_edit_1->SetWordWrap(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_rich_edit_2 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"lua_script"));
|
||||||
|
if (nullptr != m_rich_edit_2) {
|
||||||
|
m_rich_edit_2->SetRich(true);
|
||||||
|
m_rich_edit_2->SetReturnMsgWantCtrl(true);
|
||||||
|
m_rich_edit_2->SetText(string2wstring(mLuaScript));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_rich_edit_3 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_send_edit"));
|
||||||
|
m_button_1 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
|
||||||
|
m_button_2 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_close_uart"));
|
||||||
|
m_button_3 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_save_lua"));
|
||||||
|
m_button_4 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_do_lua"));
|
||||||
|
|
||||||
|
if (nullptr != m_label_1) {
|
||||||
|
m_label_1->SetText(wstring(L"udp:") + string2wstring(m_url)
|
||||||
|
+ L":" + std::to_wstring(m_port));
|
||||||
|
}
|
||||||
|
if (nullptr != m_button_1) {
|
||||||
|
m_button_1->AttachClick(
|
||||||
|
[this](ui::EventArgs*) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (nullptr != m_button_2) {
|
||||||
|
m_button_2->AttachClick(
|
||||||
|
[this](ui::EventArgs*) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (nullptr != m_button_3) {
|
||||||
|
m_button_3->AttachClick(
|
||||||
|
[this](ui::EventArgs*) {
|
||||||
|
std::cout << "±£´ælua½Å±¾\r\n";
|
||||||
|
std::string lua = wstring2string(this->m_rich_edit_2->GetText());
|
||||||
|
if (0 == this->mLua->UpdateScript(lua)) {
|
||||||
|
this->mLuaScript = lua;
|
||||||
|
mLuaFileEdit = std::ofstream(UDP_LUA_SCRIPT, std::ios::out | std::ios::trunc);
|
||||||
|
mLuaFileEdit.write(lua.c_str(), lua.size());
|
||||||
|
mLuaFileEdit.flush();
|
||||||
|
mLuaFileEdit.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MessageBox(0, L"lua½Å±¾´íÎó", L"", 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
std::cout << lua.c_str() << "\r\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (nullptr != m_button_4) {
|
||||||
|
m_button_4->AttachClick(
|
||||||
|
[this](ui::EventArgs* ev) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaDelegate* UdpForm::LuaVM()
|
LuaDelegate* UdpForm::LuaVM()
|
||||||
@ -29,9 +140,10 @@ LuaDelegate* UdpForm::LuaVM()
|
|||||||
return mLua;
|
return mLua;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UdpForm::ShowDataInEdit(const char*)
|
void UdpForm::ShowDataInEdit(const char*src)
|
||||||
{
|
{
|
||||||
|
std::cout << src << " from ShowDataInEdit";
|
||||||
|
this->m_rich_edit_1->AppendText(string2wstring(std::string(src)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UdpForm::HandleMessage(ui::EventArgs& msg)
|
void UdpForm::HandleMessage(ui::EventArgs& msg)
|
||||||
|
@ -23,26 +23,32 @@
|
|||||||
#include <istream>
|
#include <istream>
|
||||||
|
|
||||||
class UdpForm :
|
class UdpForm :
|
||||||
public ui::ChildBox
|
public ui::ChildBox,
|
||||||
|
LuaBindInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UdpForm(ui::Window* hwnd, string url, uint32_t port, UdpDataGramLibevent* p);
|
UdpForm(ui::Window* hwnd, string url, uint32_t port, UdpDataGramLibevent* p);
|
||||||
~UdpForm();
|
~UdpForm();
|
||||||
virtual void Init() override;
|
virtual void Init() override;
|
||||||
LuaDelegate* LuaVM();
|
LuaDelegate* LuaVM();
|
||||||
|
ui::RichEdit* m_rich_edit_2;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ShowDataInEdit(const char*) ;
|
void ShowDataInEdit(const char*) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ui::Label* m_label_1;
|
ui::Label* m_label_1;
|
||||||
ui::RichEdit* m_rich_edit_1;
|
ui::RichEdit* m_rich_edit_1;
|
||||||
ui::RichEdit* m_rich_edit_2;
|
|
||||||
ui::RichEdit* m_rich_edit_3;
|
ui::RichEdit* m_rich_edit_3;
|
||||||
ui::Button* m_button_1;
|
ui::Button* m_button_1;
|
||||||
ui::Button* m_button_2;
|
ui::Button* m_button_2;
|
||||||
ui::Button* m_button_3;
|
ui::Button* m_button_3;
|
||||||
ui::Button* m_button_4;
|
ui::Button* m_button_4;
|
||||||
|
|
||||||
|
|
||||||
|
std::ifstream mLuaFile;
|
||||||
|
std::ofstream mLuaFileEdit;
|
||||||
|
|
||||||
virtual void HandleMessage(ui::EventArgs& msg);
|
virtual void HandleMessage(ui::EventArgs& msg);
|
||||||
std::string mLuaScript;
|
std::string mLuaScript;
|
||||||
std::string m_url;
|
std::string m_url;
|
||||||
|
@ -39,7 +39,9 @@ void read_cb(evutil_socket_t fd, short event, void* arg) {
|
|||||||
printf("recv[%s:%d]\n", buf, len);
|
printf("recv[%s:%d]\n", buf, len);
|
||||||
// sendto(fd, buf, len, 0, (struct sockaddr*)&cli_addr, addr_len);
|
// sendto(fd, buf, len, 0, (struct sockaddr*)&cli_addr, addr_len);
|
||||||
if (parent->OnReadHandle() != nullptr) {
|
if (parent->OnReadHandle() != nullptr) {
|
||||||
(*parent->OnReadHandle())(buf, len, cli_addr);
|
UdpDataGramLibevent::OnReadDataHandle p = (parent->OnReadHandle());
|
||||||
|
if(p)
|
||||||
|
p(buf, len, cli_addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,11 +84,11 @@ int UdpDataGramLibevent::bind_socket(struct event* ev, const char* ip, uint16_t
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UdpDataGramLibevent::OnReadDataHandle* UdpDataGramLibevent::OnReadHandle() {
|
UdpDataGramLibevent::OnReadDataHandle UdpDataGramLibevent::OnReadHandle() {
|
||||||
return this->mOnRead;
|
return this->mOnRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UdpDataGramLibevent::SetOnReadHandle(UdpDataGramLibevent::OnReadDataHandle* p) {
|
void UdpDataGramLibevent::SetOnReadHandle(UdpDataGramLibevent::OnReadDataHandle p) {
|
||||||
this->mOnRead = p;
|
this->mOnRead = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,14 +26,14 @@ class UdpDataGramLibevent {
|
|||||||
public:
|
public:
|
||||||
typedef std::function<void(const char* dat, int len, struct sockaddr_in)> OnReadDataHandle;
|
typedef std::function<void(const char* dat, int len, struct sockaddr_in)> OnReadDataHandle;
|
||||||
UdpDataGramLibevent(std::string ip, uint32_t port);
|
UdpDataGramLibevent(std::string ip, uint32_t port);
|
||||||
OnReadDataHandle* OnReadHandle();
|
OnReadDataHandle OnReadHandle();
|
||||||
typedef enum {
|
typedef enum {
|
||||||
RUNNING,
|
RUNNING,
|
||||||
STOP,
|
STOP,
|
||||||
FAIL
|
FAIL
|
||||||
}STATUS;
|
}STATUS;
|
||||||
friend void read_cb(int, short, void*);
|
friend void read_cb(int, short, void*);
|
||||||
void SetOnReadHandle(OnReadDataHandle*);
|
void SetOnReadHandle(OnReadDataHandle);
|
||||||
void SendTo(const char* dat, uint32_t len, std::string ip, int port);
|
void SendTo(const char* dat, uint32_t len, std::string ip, int port);
|
||||||
int SocketFD();
|
int SocketFD();
|
||||||
private:
|
private:
|
||||||
@ -47,7 +47,7 @@ private:
|
|||||||
STATUS m_status; //
|
STATUS m_status; //
|
||||||
std::thread* m_thread; // 当前线程
|
std::thread* m_thread; // 当前线程
|
||||||
intptr_t mSocketFD; // 操作系统原生socket
|
intptr_t mSocketFD; // 操作系统原生socket
|
||||||
OnReadDataHandle* mOnRead;
|
OnReadDataHandle mOnRead;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user