diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cf8ed9..f6fbff2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.0.0) -project (ceutil VERSION 1.1.0) +project (ceutil VERSION 2.1.0) # version 1.1.0 Added DES, SHA, RSA +# version 2.1.0 Replace wxAppConsole with wxEvtHandler, add TCP server + set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/examples/tcpclient/src/tcpclient.cpp b/examples/tcpclient/src/tcpclient.cpp index fff76e3..5c25c3f 100644 --- a/examples/tcpclient/src/tcpclient.cpp +++ b/examples/tcpclient/src/tcpclient.cpp @@ -13,7 +13,7 @@ #include "ce/ceUtil.h" using namespace ce; -// IDs for the controls and the menu commands +// IDs for the controls and the menu commandscm enum { ID_BTNSEND = 101, diff --git a/include/ce/ceTcpClient.h b/include/ce/ceTcpClient.h index dd2e8ca..8735cee 100644 --- a/include/ce/ceTcpClient.h +++ b/include/ce/ceTcpClient.h @@ -27,7 +27,7 @@ typedef wxIPV4address IPaddress; namespace ce { class ceTcpClient : public wxEvtHandler { public: - ceTcpClient(wxAppConsole* app, int socketid); // port = listening port number + ceTcpClient(wxEvtHandler* app, int socketid); // port = listening port number ~ceTcpClient(); void Open(); @@ -40,9 +40,13 @@ class ceTcpClient : public wxEvtHandler { void SetRemote(std::string remotehost, int port); bool IsConnected(); bool IsOK(); + void SetRemotehost(std::string remotehost); + void SetPort(int port); + std::string GetRemotehost(); + int GetPort(); private: void OnSocketEvent(wxSocketEvent& event); - wxAppConsole* _app; + wxEvtHandler* _app; int _socket_id; int _port{ 0 }; std::string _remotehost{""}; diff --git a/include/ce/ceTcpServer.h b/include/ce/ceTcpServer.h index 2ec22d5..ec7acdd 100644 --- a/include/ce/ceTcpServer.h +++ b/include/ce/ceTcpServer.h @@ -27,7 +27,7 @@ typedef wxIPV4address IPaddress; namespace ce { class ceTcpServer : public wxEvtHandler { public: - ceTcpServer(wxAppConsole* app, int serverid, int socketid, int port); // port = listening port number + ceTcpServer(wxEvtHandler* app, int serverid, int socketid, int port); // port = listening port number ~ceTcpServer(); bool Open(); // return true = success, false = error @@ -39,7 +39,7 @@ class ceTcpServer : public wxEvtHandler { private: void OnServerEvent(wxSocketEvent& event); void OnSocketEvent(wxSocketEvent& event); - wxAppConsole* _app; + wxEvtHandler* _app; int _socket_id; int _server_id; int _port; diff --git a/include/ce/ceUDP.h b/include/ce/ceUDP.h index 2c05cc2..4d8d4f7 100644 --- a/include/ce/ceUDP.h +++ b/include/ce/ceUDP.h @@ -28,9 +28,9 @@ typedef wxIPV4address IPaddress; namespace ce { class ceUDP : public wxEvtHandler { public: - ceUDP(wxAppConsole* app, int socketid, int rx_port); // rx_port = 0 for not listening - ceUDP(wxAppConsole* app, int socketid, int rx_port, int tx_port); - ceUDP(wxAppConsole* app, int socketid, int rx_port, int tx_port, std::string remotehost); + ceUDP(wxEvtHandler* app, int socketid, int rx_port); // rx_port = 0 for not listening + ceUDP(wxEvtHandler* app, int socketid, int rx_port, int tx_port); + ceUDP(wxEvtHandler* app, int socketid, int rx_port, int tx_port, std::string remotehost); int Tx(std::vector bv); // return 0 = success, 1 = error int Tx(std::vector bv, std::string remoteHost, int txPort); // return 0 = success, 1 = error int Open(); // return 0 = success, 1 = error @@ -44,7 +44,7 @@ class ceUDP : public wxEvtHandler { private: void Rx(int socketid, std::vector bv, std::string ip, int port); void OnSocketEvent(wxSocketEvent& event); - wxAppConsole* _app; + wxEvtHandler* _app; int SOCKET_ID; int udp_port_rx; int udp_port_tx; diff --git a/include/ce/ceWxSerial.h b/include/ce/ceWxSerial.h index 49b2cda..cc2a74f 100644 --- a/include/ce/ceWxSerial.h +++ b/include/ce/ceWxSerial.h @@ -15,14 +15,14 @@ namespace ce { class ceWxSerial : public wxEvtHandler, public ce::ceSerial { public: - ceWxSerial(wxAppConsole* app,int id, int interval, + ceWxSerial(wxEvtHandler* app,int id, int interval, std::string Device, long BaudRate, long DataSize, char ParityType, float NStopBits); ~ceWxSerial(); void OnTimer(wxTimerEvent& event); std::vector Chk(); private: wxTimer* _timer; - wxAppConsole* _app; + wxEvtHandler* _app; int _id; int _interval; }; diff --git a/include/ce/ceWxTmr.h b/include/ce/ceWxTmr.h index ee09d10..76c799a 100644 --- a/include/ce/ceWxTmr.h +++ b/include/ce/ceWxTmr.h @@ -13,12 +13,12 @@ namespace ce { class ceWxTmr : public wxEvtHandler { public: - ceWxTmr(wxAppConsole* app,int id, int interval); + ceWxTmr(wxEvtHandler* app,int id, int interval); void OnTimer(wxTimerEvent& event); void Start(); private: wxTimer* _timer; - wxAppConsole* _app; + wxEvtHandler* _app; int _id; int _interval; }; diff --git a/src/ceTcpClient.cpp b/src/ceTcpClient.cpp index eaec5f0..8492e3d 100644 --- a/src/ceTcpClient.cpp +++ b/src/ceTcpClient.cpp @@ -16,7 +16,7 @@ void ceTcpClient::PrintLog(string str) // printf("%s \n",str.c_str()); } -ceTcpClient::ceTcpClient(wxAppConsole* app, int socketid): +ceTcpClient::ceTcpClient(wxEvtHandler* app, int socketid): _app(app),_socket_id(socketid) { // Create the socket @@ -43,6 +43,26 @@ void ceTcpClient::SetRemote(string remotehost, int port) _port = port; } +void ceTcpClient::SetRemotehost(std::string remotehost) +{ + _remotehost = remotehost; +} + +void ceTcpClient::SetPort(int port) +{ + _port = port; +} + +std::string ceTcpClient::GetRemotehost() +{ + return _remotehost; +} + +int ceTcpClient::GetPort() +{ + return _port; +} + void ceTcpClient::Open() { // Create the address diff --git a/src/ceTcpServer.cpp b/src/ceTcpServer.cpp index 2067719..0fd5415 100644 --- a/src/ceTcpServer.cpp +++ b/src/ceTcpServer.cpp @@ -16,7 +16,7 @@ void ceTcpServer::PrintLog(string str) // printf("%s \n",str.c_str()); } -ceTcpServer::ceTcpServer(wxAppConsole* app, int serverid, int socketid, int port): +ceTcpServer::ceTcpServer(wxEvtHandler* app, int serverid, int socketid, int port): _app(app),_server_id(serverid),_socket_id(socketid),_port(port) { Connect(serverid, wxEVT_SOCKET, wxSocketEventHandler(ceTcpServer::OnServerEvent)); @@ -90,7 +90,7 @@ void ceTcpServer::OnServerEvent(wxSocketEvent& event) switch (event.GetSocketEvent()) { case wxSOCKET_CONNECTION: - PrintLog("OnServerEvent"); + PrintLog("Connection event"); break; default: perror("Unexpected event"); diff --git a/src/ceUDP.cpp b/src/ceUDP.cpp index 872a03a..e71fa2d 100644 --- a/src/ceUDP.cpp +++ b/src/ceUDP.cpp @@ -9,19 +9,19 @@ #if CE_WX==1 namespace ce { -ceUDP::ceUDP(wxAppConsole* app, int socketid, int rx_port) : +ceUDP::ceUDP(wxEvtHandler* app, int socketid, int rx_port) : _app(app),SOCKET_ID(socketid),udp_port_rx(rx_port),udp_port_tx(rx_port),udp_remote_host("localhost") { _ok = false; } -ceUDP::ceUDP(wxAppConsole* app, int socketid, int rx_port, int tx_port) : +ceUDP::ceUDP(wxEvtHandler* app, int socketid, int rx_port, int tx_port) : _app(app),SOCKET_ID(socketid),udp_port_rx(rx_port),udp_port_tx(tx_port),udp_remote_host("localhost") { _ok = false; } -ceUDP::ceUDP(wxAppConsole* app, int socketid, int rx_port, int tx_port, std::string remotehost) : +ceUDP::ceUDP(wxEvtHandler* app, int socketid, int rx_port, int tx_port, std::string remotehost) : _app(app),SOCKET_ID(socketid),udp_port_rx(rx_port),udp_port_tx(tx_port),udp_remote_host(remotehost) { _ok = false; diff --git a/src/ceWxSerial.cpp b/src/ceWxSerial.cpp index 5562d7b..0f394bf 100644 --- a/src/ceWxSerial.cpp +++ b/src/ceWxSerial.cpp @@ -11,7 +11,7 @@ using namespace std; namespace ce { //ctor -ceWxSerial::ceWxSerial(wxAppConsole* app,int id, int interval, +ceWxSerial::ceWxSerial(wxEvtHandler* app,int id, int interval, std::string Device, long BaudRate, long DataSize, char ParityType, float NStopBits) : _app(app), _id(id), _interval(interval), ceSerial(Device, BaudRate, DataSize, ParityType, NStopBits) { diff --git a/src/ceWxTmr.cpp b/src/ceWxTmr.cpp index 8889d03..d99bb61 100644 --- a/src/ceWxTmr.cpp +++ b/src/ceWxTmr.cpp @@ -10,7 +10,7 @@ using namespace std; namespace ce { //ctor -ceWxTmr::ceWxTmr(wxAppConsole* app,int id, int interval) : _app(app), _id(id), _interval(interval) +ceWxTmr::ceWxTmr(wxEvtHandler* app,int id, int interval) : _app(app), _id(id), _interval(interval) { this->_timer = new wxTimer(this, _id); Connect(_id, wxEVT_TIMER, wxTimerEventHandler(ceWxTmr::OnTimer)); diff --git a/vcprj/ceutil.vcxproj b/vcprj/ceutil.vcxproj index 9d9d043..ebed8eb 100644 --- a/vcprj/ceutil.vcxproj +++ b/vcprj/ceutil.vcxproj @@ -66,6 +66,9 @@ + + + 16.0 {5397B256-872B-44E9-A100-8EE02B070E5A} diff --git a/vcprj/ceutil.vcxproj.filters b/vcprj/ceutil.vcxproj.filters index 445c617..a12fbc9 100644 --- a/vcprj/ceutil.vcxproj.filters +++ b/vcprj/ceutil.vcxproj.filters @@ -13,6 +13,9 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {c27916e6-2986-4cf4-b618-991e007063f8} + @@ -150,4 +153,9 @@ Source Files + + + etc + + \ No newline at end of file