refactor: Heavy refactoring to modern code style

This commit is contained in:
2025-04-03 21:31:08 +02:00
parent 04a8904cbe
commit 9ebbedb04a
32 changed files with 2360 additions and 4112 deletions
+34 -51
View File
@@ -79,14 +79,6 @@ class SPITSocket {
//-------- class --------------
SPITSocket(IPAddress ip) : mOwnIp(ip) {
m_UDPSocketIP4 = INVALID_SOCKET;
m_ServerIP = "";
m_ServerPort = "";
m_ClientIP = "";
m_ClientPort = "";
m_BoundClientPort = "";
m_BoundClientFamily = 0;
m_IsBound = false;
createSocket_UDP();
}
virtual ~SPITSocket() {
@@ -102,65 +94,56 @@ class SPITSocket {
}
private:
string m_ServerIP;
string m_ServerPort;
string m_ClientIP;
string m_ClientPort; // port given by the user maybe "0"
string m_BoundClientPort; // port set after bind
int m_BoundClientFamily;
bool m_IsBound;
string m_ServerIP{};
string m_ServerPort{};
string m_ClientIP{};
string m_ClientPort{}; // port given by the user maybe "0"
string m_BoundClientPort{}; // port set after bind
bool m_IsBound{};
public:
/**
* Sets the ip address and port for server and client.
* @param p_ServerIP
* @param p_ServerPort
* @param p_ClientIP
* @param p_ClientPort
*/
void setConnectionParams(string p_ServerIP, string p_ServerPort, string p_ClientIP, string p_ClientPort) {
m_ServerIP = p_ServerIP;
m_ServerPort = p_ServerPort;
m_ClientIP = p_ClientIP;
m_ClientPort = p_ClientPort;
// Sets the ip address and port for server and client.
void setConnectionParams(const string &serverIp, const string &serverPort, const string &clientIp, const string &clientPort) {
m_ServerIP = serverIp;
m_ServerPort = serverPort;
m_ClientIP = clientIp;
m_ClientPort = clientPort;
}
/**
* Send a message to the server as set by setConnectionParams
* @param p_MessageBytes byte buffer containing the message
* @param p_MessageLength length of the messaeg
* @param message byte buffer containing the message
* @param length length of the message
* @return
*/
int sendMessage(const char *p_MessageBytes, int p_MessageLength) {
if (m_ServerPort.length() <= 0)
int sendMessage(const char *message, int length) {
if (m_ServerPort.length() <= 0) {
return -1;
int intResult;
{
if (m_IsBound == false)
return -1;
intResult = sendMessageTo(m_BoundClientFamily, m_ServerIP, m_ServerPort, p_MessageBytes, p_MessageLength);
}
if (m_IsBound == false) {
return -1;
}
int intResult = sendMessageTo(m_ServerIP, m_ServerPort, message, length);
return intResult;
}
int receiveMessage(int p_InetFamily, char *p_Buffer, int p_BufferLength, string *p_ServerIP);
int setBroadcast(bool p_Broadcast);
int bindSocket(string p_ServerIP, string p_ClientIP, string p_ClientPort);
int receiveMessage(char *p_Buffer, int p_BufferLength, string *serverIp) const;
int setBroadcast(bool p_Broadcast) const;
int bindSocket(string clientIp, string clientPort);
// * Internal usage - don't use this manually
// * Use sendMessage instead
int sendMessageTo(int p_InetFamily, string p_ServerIP, string p_Port, const char *p_MessageBytes, int p_MessageLength);
int sendMessageTo(const string &ip, const string &port, const char *message, int msgLength);
string getServerIP() { return m_ServerIP; }
string getServerPort() { return m_ServerPort; }
string getClientIP() { return m_ClientIP; }
string getClientPort() { return m_ClientPort; }
string getBoundClientPort() { return m_BoundClientPort; }
void setBoundClientPort(string p_Port) { m_BoundClientPort = p_Port; }
void setBoundClientFamily(int p_Family) { m_BoundClientFamily = p_Family; }
int getBoundClientFamily() { return m_BoundClientFamily; }
string getServerIP() const { return m_ServerIP; }
string getServerPort() const { return m_ServerPort; }
string getClientIP() const { return m_ClientIP; }
string getClientPort() const { return m_ClientPort; }
string getBoundClientPort() const { return m_BoundClientPort; }
void setBoundClientPort(const string &p_Port) { m_BoundClientPort = p_Port; }
void setIsBound(bool p_IsBound) { m_IsBound = p_IsBound; }
bool getIsBound() { return m_IsBound; }
bool getIsBound() const { return m_IsBound; }
private:
};
#endif /* SPITSOCKET_H */