Skip to content

Commit

Permalink
version 2.1.0 Replace wxAppConsole with wxEvtHandler, add TCP server
Browse files Browse the repository at this point in the history
  • Loading branch information
yan9a committed Aug 22, 2024
1 parent 3bbe875 commit 851ddda
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 22 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/tcpclient/src/tcpclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions include/ce/ceTcpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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{""};
Expand Down
4 changes: 2 additions & 2 deletions include/ce/ceTcpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions include/ce/ceUDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> bv); // return 0 = success, 1 = error
int Tx(std::vector<char> bv, std::string remoteHost, int txPort); // return 0 = success, 1 = error
int Open(); // return 0 = success, 1 = error
Expand All @@ -44,7 +44,7 @@ class ceUDP : public wxEvtHandler {
private:
void Rx(int socketid, std::vector<char> 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;
Expand Down
4 changes: 2 additions & 2 deletions include/ce/ceWxSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> Chk();
private:
wxTimer* _timer;
wxAppConsole* _app;
wxEvtHandler* _app;
int _id;
int _interval;
};
Expand Down
4 changes: 2 additions & 2 deletions include/ce/ceWxTmr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
22 changes: 21 additions & 1 deletion src/ceTcpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ceTcpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/ceUDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ceWxSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ceWxTmr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions vcprj/ceutil.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<ClCompile Include="..\src\ceWxSerial.cpp" />
<ClCompile Include="..\src\ceWxTmr.cpp" />
</ItemGroup>
<ItemGroup>
<Text Include="..\CMakeLists.txt" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{5397B256-872B-44E9-A100-8EE02B070E5A}</ProjectGuid>
Expand Down
8 changes: 8 additions & 0 deletions vcprj/ceutil.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="etc">
<UniqueIdentifier>{c27916e6-2986-4cf4-b618-991e007063f8}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\ce\ceConfig.h">
Expand Down Expand Up @@ -150,4 +153,9 @@
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="..\CMakeLists.txt">
<Filter>etc</Filter>
</Text>
</ItemGroup>
</Project>

0 comments on commit 851ddda

Please sign in to comment.